FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

move run into /test and integrate into test.py · python-security/pyt@5da0c20 · GitHub

Repository navigation

Commit 5da0c20

Browse files
committed
move run into /test and integrate into test.py
1 parent 341f892 commit 5da0c20

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎tests/results‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\XSS.py\r\n > User input at line 6, trigger word "get(": \r\n\tparam = request.args.get(\'param\', \'not set\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\XSS.py\r\n\t > Line 6: param = request.args.get(\'param\', \'not set\')\r\n\tFile: ..\\example\\vulnerable_code\\XSS.py\r\n\t > Line 10: ret_make_response = resp\r\nFile: ..\\example\\vulnerable_code\\XSS.py\r\n > reaches line 9, trigger word "replace(": \r\n\tresp = make_response(html.replace(\'{{ param }}\', param))\r\n\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\command_injection.py\r\n > User input at line 15, trigger word "form[": \r\n\tparam = request.form[\'suggestion\']\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\command_injection.py\r\n\t > Line 15: param = request.form[\'suggestion\']\r\n\tFile: ..\\example\\vulnerable_code\\command_injection.py\r\n\t > Line 16: command = \'echo \' + param + \' >> \' + \'menu.txt\'\r\nFile: ..\\example\\vulnerable_code\\command_injection.py\r\n > reaches line 18, trigger word "subprocess.call(": \r\n\tsubprocess.call(command,shell=True)\r\n\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\path_traversal.py\r\n > User input at line 8, trigger word "get(": \r\n\timage_name = request.args.get(\'image_name\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\path_traversal.py\r\n\t > Line 8: image_name = request.args.get(\'image_name\')\r\n\tFile: ..\\example\\vulnerable_code\\path_traversal.py\r\n\t > Line 10: ret_request.args.get = 404\r\nFile: ..\\example\\vulnerable_code\\path_traversal.py\r\n > reaches line 11, trigger word "send_file(": \r\n\tret_request.args.get = send_file(os.path.join(os.getcwd(), image_name))\r\n\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\path_traversal_sanitised.py\r\n > User input at line 8, trigger word "get(": \r\n\timage_name = request.args.get(\'image_name\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\path_traversal_sanitised.py\r\n\t > Line 8: image_name = request.args.get(\'image_name\')\r\n\tFile: ..\\example\\vulnerable_code\\path_traversal_sanitised.py\r\n\t > Line 10: image_name = image_name.replace(\'..\', \'\')\r\nFile: ..\\example\\vulnerable_code\\path_traversal_sanitised.py\r\n > reaches line 12, trigger word "send_file(": \r\n\tret_image_name.replace = send_file(os.path.join(os.getcwd(), image_name))\r\nThis vulnerability is potentially sanitised by: ["\'..\'", "\'..\' in"]\r\n\r\n'#�%&/()=?b'2 vulnerabilities found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\sql\\sqli.py\r\n > User input at line 33, trigger word "get(": \r\n\tparam = request.args.get(\'param\', \'not set\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\sql\\sqli.py\r\n\t > Line 33: param = request.args.get(\'param\', \'not set\')\r\nFile: ..\\example\\vulnerable_code\\sql\\sqli.py\r\n > reaches line 36, trigger word "filter(": \r\n\tresult = session.query(User).filter(\'username={}\'.format(param))\r\n\r\nVulnerability 2:\r\nFile: ..\\example\\vulnerable_code\\sql\\sqli.py\r\n > User input at line 26, trigger word "get(": \r\n\tparam = request.args.get(\'param\', \'not set\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\sql\\sqli.py\r\n\t > Line 26: param = request.args.get(\'param\', \'not set\')\r\nFile: ..\\example\\vulnerable_code\\sql\\sqli.py\r\n > reaches line 27, trigger word "execute(": \r\n\tresult = db.engine.execute(param)\r\n\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\XSS_form.py\r\n > User input at line 14, trigger word "form[": \r\n\tdata = request.form[\'my_text\']\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\XSS_form.py\r\n\t > Line 14: data = request.form[\'my_text\']\r\n\tFile: ..\\example\\vulnerable_code\\XSS_form.py\r\n\t > Line 17: ret_resp.set_cookie = resp\r\nFile: ..\\example\\vulnerable_code\\XSS_form.py\r\n > reaches line 15, trigger word "replace(": \r\n\tresp = make_response(html1.replace(\'{{ data }}\', data))\r\n\r\n'#�%&/()=?b'0 vulnerabilities found:\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\XSS_reassign.py\r\n > User input at line 6, trigger word "get(": \r\n\tparam = request.args.get(\'param\', \'not set\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\XSS_reassign.py\r\n\t > Line 6: param = request.args.get(\'param\', \'not set\')\r\n\tFile: ..\\example\\vulnerable_code\\XSS_reassign.py\r\n\t > Line 8: param = param + \'\'\r\n\tFile: ..\\example\\vulnerable_code\\XSS_reassign.py\r\n\t > Line 12: ret_make_response = resp\r\nFile: ..\\example\\vulnerable_code\\XSS_reassign.py\r\n > reaches line 11, trigger word "replace(": \r\n\tresp = make_response(html.replace(\'{{ param }}\', param))\r\n\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\XSS_sanitised.py\r\n > User input at line 7, trigger word "get(": \r\n\tparam = request.args.get(\'param\', \'not set\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\XSS_sanitised.py\r\n\t > Line 7: param = request.args.get(\'param\', \'not set\')\r\n\tFile: ..\\example\\vulnerable_code\\XSS_sanitised.py\r\n\t > Line 9: param = Markup.escape(param)\r\n\tFile: ..\\example\\vulnerable_code\\XSS_sanitised.py\r\n\t > Line 13: ret_make_response = resp\r\nFile: ..\\example\\vulnerable_code\\XSS_sanitised.py\r\n > reaches line 12, trigger word "replace(": \r\n\tresp = make_response(html.replace(\'{{ param }}\', param))\r\nThis vulnerability is potentially sanitised by: [\'escape\']\r\n\r\n'#�%&/()=?b'0 vulnerabilities found:\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\XSS_variable_assign.py\r\n > User input at line 6, trigger word "get(": \r\n\tparam = request.args.get(\'param\', \'not set\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_assign.py\r\n\t > Line 6: param = request.args.get(\'param\', \'not set\')\r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_assign.py\r\n\t > Line 8: other_var = param + \'\'\r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_assign.py\r\n\t > Line 12: ret_make_response = resp\r\nFile: ..\\example\\vulnerable_code\\XSS_variable_assign.py\r\n > reaches line 11, trigger word "replace(": \r\n\tresp = make_response(html.replace(\'{{ param }}\', other_var))\r\n\r\n'#�%&/()=?b'1 vulnerability found:\r\nVulnerability 1:\r\nFile: ..\\example\\vulnerable_code\\XSS_variable_multiple_assign.py\r\n > User input at line 6, trigger word "get(": \r\n\tparam = request.args.get(\'param\', \'not set\')\r\nReassigned in: \r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_multiple_assign.py\r\n\t > Line 6: param = request.args.get(\'param\', \'not set\')\r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_multiple_assign.py\r\n\t > Line 8: other_var = param + \'\'\r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_multiple_assign.py\r\n\t > Line 10: not_the_same_var = \'\' + other_var\r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_multiple_assign.py\r\n\t > Line 12: another_one = not_the_same_var + \'\'\r\n\tFile: ..\\example\\vulnerable_code\\XSS_variable_multiple_assign.py\r\n\t > Line 17: ret_make_response = resp\r\nFile: ..\\example\\vulnerable_code\\XSS_variable_multiple_assign.py\r\n > reaches line 15, trigger word "replace(": \r\n\tresp = make_response(html.replace(\'{{ param }}\', another_one))\r\n\r\n'#�%&/()=?
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
delimiter = '#¤%&/()=?'
55
results_file = 'results'
6-
pyt_path = '../../pyt/pyt.py'
6+
pyt_path = '../pyt/pyt.py'
7+
example_file_path = '../example/vulnerable_code/'
78

89
parser = argparse.ArgumentParser()
910
parser.add_argument('python', help='Specify Python 3.', type=str)
1011
parser.add_argument('-s', '--save-results', help='Add new results', action='store_true')
1112
parser.add_argument('-p', '--pyt-output', help='Print output of PyT for each file.', action='store_true')
1213

13-
files = ['XSS.py', 'command_injection.py', 'path_traversal.py', 'path_traversal_sanitised.py', 'path_traversal_sanitised_2.py', 'sql/sqli.py', 'XSS_form.py', 'XSS_no_vuln.py', 'XSS_reassign.py', 'XSS_sanitised.py', 'XSS_variable_assign_no_vuln.py', 'XSS_variable_assign.py', 'XSS_variable_multiple_assign.py']
14+
files = ['XSS.py', 'command_injection.py', 'path_traversal.py', 'path_traversal_sanitised.py', 'sql/sqli.py', 'XSS_form.py', 'XSS_no_vuln.py', 'XSS_reassign.py', 'XSS_sanitised.py', 'XSS_variable_assign_no_vuln.py', 'XSS_variable_assign.py', 'XSS_variable_multiple_assign.py']
15+
files = [example_file_path + filename for filename in files]
1416

1517
def check_files(python):
1618
try:
@@ -19,14 +21,18 @@ def check_files(python):
1921
except FileNotFoundError:
2022
print(results_file + ' file was not found. Generate this file by running this script with option --save-results or -s.')
2123
exit(1)
24+
25+
passed = True
2226
for i, f in enumerate(files):
2327
print('################# ' + f + ' #################')
24-
process = run([args.python, pyt_path, f], stdout=PIPE)
28+
process = run([python, pyt_path, f], stdout=PIPE)
2529
stdout = str(process.stdout)
2630
if results[i] == stdout:
2731
print('Test passed.')
2832
else:
2933
print('Test failed.')
34+
passed = False
35+
return passed
3036

3137
def save_results(python):
3238
with open(results_file, 'w') as fd:

‎tests/test.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from unittest import TestSuite
33
from unittest import makeSuite
44
from unittest import TestLoader
5+
from run import check_files
6+
7+
python = 'python'
58

69
test_suite = TestSuite()
710

@@ -11,7 +14,10 @@
1114

1215
runner = TextTestRunner(verbosity=2)
1316
result = runner.run(suite)
14-
if result.wasSuccessful():
17+
18+
passed = check_files(python)
19+
20+
if result.wasSuccessful() and passed:
1521
print('Success')
1622
exit(0)
1723
else:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL