-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearcher.patch
169 lines (143 loc) · 6.6 KB
/
searcher.patch
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
--- searcher.py.ori 2019-01-25 13:22:31.000000000 +0900
+++ searcher.py 2019-01-25 13:36:31.000000000 +0900
@@ -27,6 +27,7 @@
from persistence.server.server_io_exceptions import ResourceDoesNotExist, ConflictInDatabase
from validator import *
import urlparse
+import getpass
logger = logging.getLogger('Faraday searcher')
@@ -76,12 +77,16 @@
name = doc['name']
description = doc['description']
resolution = doc['resolution']
+ references = doc['references']
+ severity = doc['exploitation']
if str(_id) == data or name == data:
cwe = {
'id': _id,
'name': name,
'description': description,
- 'resolution': resolution
+ 'resolution': resolution,
+ 'references': references,
+ 'severity': severity
}
break
return cwe
@@ -169,9 +174,9 @@
if 'conditions' in rule:
environment = get_model_environment(m2, _models)
if can_execute_action(environment, rule['conditions']):
- execute_action(ws, _object, rule, _server)
+ execute_action(ws, _object, rule, _server, _refs)
else:
- execute_action(ws, _object, rule, _server)
+ execute_action(ws, _object, rule, _server, _refs)
logger.debug("<-- Finish Process models by similarity")
@@ -224,7 +229,7 @@
field.remove(value)
-def update_vulnerability(ws, vuln, key, value, _server):
+def update_vulnerability(ws, vuln, key, value, _server, _refs):
if key == 'template':
cwe = get_cwe(value, _server)
if cwe is None:
@@ -234,7 +239,13 @@
vuln.name = cwe['name']
vuln.description = cwe['description']
vuln.desc = cwe['description']
- vuln.resolution = cwe['resolution']
+ if cwe['resolution']:
+ vuln.resolution = cwe['resolution']
+ if _refs:
+ vuln.refs = cwe['references']
+ else:
+ vuln.refs.append(cwe['references'])
+ vuln.severity = cwe['severity']
logger.info("Applying template '%s' to vulnerability '%s' with id '%s'" % (value, vuln.name, vuln.id))
@@ -460,7 +471,7 @@
return True
-def execute_action(ws, objects, rule, _server):
+def execute_action(ws, objects, rule, _server, _refs):
logger.info("Running actions of rule '%s' :" % rule['id'])
actions = rule['actions']
_objs_value = None
@@ -479,7 +490,7 @@
key = array_exp[0]
value = str('=').join(array_exp[1:])
if obj.class_signature == 'VulnerabilityWeb' or obj.class_signature == 'Vulnerability':
- if update_vulnerability(ws, obj, key, value, _server):
+ if update_vulnerability(ws, obj, key, value, _server, _refs):
insert_rule(rule['id'], command, obj, _objs_value, fields=None, key=key, value=value)
if obj.class_signature == 'Service':
@@ -523,7 +534,7 @@
return True
-def process_vulnerabilities(ws, vulns, _server):
+def process_vulnerabilities(ws, vulns, _server, _refs):
logger.debug("--> Start Process vulnerabilities")
for rule in rules:
if rule['model'] == 'Vulnerability':
@@ -538,9 +549,9 @@
if objects is not None and len(objects) != 0:
if 'conditions' in rule:
if can_execute_action(vulnerabilities, rule['conditions']):
- execute_action(ws, objects, rule, _server)
+ execute_action(ws, objects, rule, _server, _refs)
else:
- execute_action(ws, objects, rule, _server)
+ execute_action(ws, objects, rule, _server, _refs)
logger.debug("<-- Finish Process vulnerabilities")
@@ -560,9 +571,9 @@
if objects is not None and len(objects) != 0:
if 'conditions' in rule:
if can_execute_action(services, rule['conditions']):
- execute_action(ws, objects, rule, _server)
+ execute_action(ws, objects, rule, _server, _refs)
else:
- execute_action(ws, objects, rule, _server)
+ execute_action(ws, objects, rule, _server, _refs)
logger.debug("<-- Finish Process services")
@@ -582,9 +593,9 @@
if objects is not None and len(objects) != 0:
if 'conditions' in rule:
if can_execute_action(hosts, rule['conditions']):
- execute_action(ws, objects, rule, _server)
+ execute_action(ws, objects, rule, _server, _refs)
else:
- execute_action(ws, objects, rule, _server)
+ execute_action(ws, objects, rule, _server, _refs)
logger.debug("<-- Finish Process Hosts")
@@ -613,6 +624,7 @@
parser.add_argument('-p', '--password', help='Faraday password', required=False, default="")
parser.add_argument('-o', '--output', help='Choose a custom output directory', required=False)
parser.add_argument('-l', '--log', help='Choose a custom log level', required=False)
+ parser.add_argument('-r', '--refs', action='store_true', help='Overwrite Refs from template', required=False)
args = parser.parse_args()
lockf = ".lock.pod"
@@ -632,11 +644,14 @@
if args.server:
_server = args.server
+ _refs = False
+ if args.refs:
+ _refs = True
+
_user = 'faraday'
if args.user:
_user = args.user
- _password = 'changeme'
if args.password:
_password = args.password
@@ -674,6 +689,8 @@
logger.addHandler(ch)
try:
+ if not _password:
+ getpass.getpass()
session_cookie = login_user(_server, _user, _password)
if not session_cookie:
raise UserWarning('Invalid credentials!')
@@ -699,7 +716,7 @@
vulns = models.get_all_vulns(workspace)
if validate_rules():
- process_vulnerabilities(workspace, vulns, _server)
+ process_vulnerabilities(workspace, vulns, _server, _refs)
process_services(workspace, services, _server)
process_hosts(workspace, hosts, _server)