forked from python-security/pyt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyse_scan_results.py
68 lines (58 loc) · 2.11 KB
/
analyse_scan_results.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
class Repo:
def __init__(self, url=None, vulnerabilities=None):
self.url = url
self.vulnerabilities = vulnerabilities
class Vulnerability:
def __init__(self):
self.filename = None
self.source = None
self.sink = None
self.source_line = None
self.sink_source = None
def parse_vulnerabilities(file_descriptor):
vulnerabilities = list()
vulnerability = Vulnerability()
for line in file_descriptor:
next_line = next(file_descriptor)
if line.strip() == '' and 'Vulnerability:' not in next_line:
return vulnerabilities
elif line.strip() == '':
vulnerabilities.append(vulnerability)
vulnerability = Vulnerability()
else:
if 'File:' in line:
vulnerability.filename = line.split(':')[1].strip()
elif ' > User input at line' in line:
vulnerability.source = line.split('"')[-2]
vulnerability.source_line = next_line
elif ' > reaches line' in line:
vulnerability.source = line.split('"')[-2]
vulnerability.source_line = next_line
def get_repos(filename):
repos = list()
repo = Repo()
previous_line = None
with open(filename, 'r') as fd:
for line in fd:
next_line = next(fd)
if not line.strip() == '' or 'Vulnera' in next_line:
if 'https://' in line:
repo.url = line.strip()
elif 'Vulnera' in next_line:
repo.vulnerabilities = parse_vulnerabilities(fd)
elif next_line.strip() == '':
continue
else:
repos.append(repo)
repo = Repo()
previous_line = line
return repos
def get_urls(filename):
with open(filename, 'r') as fd:
return sorted({line for line in fd if 'https' in line})
if __name__ == '__main__':
filename = 'scan_results/archived_26_10_scan.pyt'
filename = 'scan_results/test.pyt'
repos = get_repos(filename)
print([b.url for b in repos])
print(len(repos))