Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Commit 85b5588

Browse files
authored
Merge pull request #94 from wufeifei/develop
Improves #84
2 parents b6ec04f + 78cfa3e commit 85b5588

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

engine/parse.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, rule, file_path, line, code):
3737
self.line = line
3838
self.code = code
3939
self.param_name = None
40+
self.param_value = None
4041

4142
def functions(self):
4243
logging.info('---------------------- [-]. Functions --------------------------------------')
@@ -189,7 +190,7 @@ def is_controllable_param(self):
189190
logging.info("Check controllable param rule")
190191
controllable_param_rule = [
191192
{
192-
'rule': r'\\s?=\s?(\$\w+(?:\[(?:[^[\]]|(\?R))*\])*)'.format(param_name),
193+
'rule': r'(\{0}\s?=\s?\$\w+(?:\[(?:[^[\]]|\?R)*\])*)'.format(param_name),
193194
'example': '$param_name = $variable',
194195
'test': """
195196
$param_name = $_GET
@@ -200,18 +201,18 @@ def is_controllable_param(self):
200201
"""
201202
},
202203
{
203-
'rule': r'function\s+\w+\s?\(.*(\{0})'.format(param_name),
204+
'rule': r'(function\s*\w+\s*\(.*\{0})'.format(param_name),
204205
'example': 'function ($param_name)',
205206
'test': """
206207
function ($param_name)
207208
function ($some, $param_name)
208209
"""
209210
}
210-
211211
]
212212
for c_rule in controllable_param_rule:
213213
c_rule_result = re.findall(c_rule['rule'], param_block_code)
214214
if len(c_rule_result) >= 1:
215+
self.param_value = c_rule_result[0]
215216
logging.info("R: True (New rule: controllable param: {0}, {1})".format(param_name, c_rule['example']))
216217
return True
217218
logging.info("R: True")

engine/static.py

+6
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def analyse(self):
211211
if match_result.group(0) is not None and match_result.group(0) is not "":
212212
logging.info("In Annotation")
213213
else:
214+
param_value = None
214215
# parse file function structure
215216
if file_path[-3:] == 'php' and rule.regex_repair.strip() != '':
216217
try:
@@ -220,6 +221,8 @@ def analyse(self):
220221
logging.info("Static: repaired")
221222
continue
222223
else:
224+
if parse_instance.param_value is not None:
225+
param_value = parse_instance.param_value
223226
found_vul = True
224227
else:
225228
logging.info("Static: uncontrollable param")
@@ -238,6 +241,9 @@ def analyse(self):
238241
if exist_result is not None:
239242
logging.warning("Exists Result")
240243
else:
244+
code_content = '# 触发位置\r' + code_content
245+
if param_value is not None:
246+
code_content = '# 参数可控\r' + param_value + '\r//\r// ------ 省略部分代码 ------\r//\r' + code_content
241247
logging.debug('File: {0}:{1} {2}'.format(file_path, line_number, code_content))
242248
vul = CobraResults(self.task_id, rule.id, file_path, line_number, code_content)
243249
db.session.add(vul)

0 commit comments

Comments
 (0)