-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrhel.py
76 lines (64 loc) · 2.28 KB
/
rhel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
import json
import os
import sys
import traceback
from datetime import datetime
sys.path.append('.')
from cybertestlab import CyberTestLab
__author__ = 'Jason Callaway'
__email__ = '[email protected]'
__license__ = 'GNU Public License v2'
__version__ = '0.3'
__status__ = 'beta'
def main(argv):
debug = True
now = datetime.now()
output_dir = sys.argv[1]
repo_dir = sys.argv[2]
swap_path = sys.argv[3]
repos = ['.']
ctl = CyberTestLab.CyberTestLab(repo_dir=repo_dir,
swap_path=swap_path,
repo_list=repos,
debug=True)
ctl.redteam.funcs.mkdir_p(repo_dir)
ctl.redteam.funcs.mkdir_p(swap_path)
# if debug:
# print('+ syncing repos')
# ctl.repo_sync('reposync')
for repo in ctl.repo_list:
if debug:
print('+ ' + repo)
for root, dirs, files in os.walk(repo_dir + '/' + repo):
for filename in files:
if debug:
print('+ ' + filename)
results_dir = output_dir + '/' + filename[0]
results_file = results_dir + '/' + filename + '.json'
if not os.path.isfile(results_file):
if debug:
print('++ analyzing ' + filename)
ctl.prep_swap()
try:
analyze(ctl, repo, filename, results_dir, results_file)
except Exception as e:
print('analysis failed on ' + filename)
traceback.print_exc()
continue
def analyze(ctl, repo, filename, results_dir, results_file):
ctl.prep_rpm(repo, filename)
metadata = ctl.get_metadata(filename)
elfs = ctl.find_elfs()
if elfs:
results = ctl.scan_elfs(filename, elfs)
ctl.redteam.funcs.mkdir_p(results_dir)
with open(results_file, 'w') as f:
json.dump({'metadata': metadata,
'results': results}, f, indent=4)
else:
with open(results_file, 'w') as f:
json.dump({'metadata': metadata,
'results': 'no elfs found'}, f, indent=4)
if __name__ == "__main__":
main(sys.argv)