Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# OS X
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -61,4 +64,4 @@ target/
#Ipython Notebook
.ipynb_checkpoints
*~
*#
*#
6 changes: 6 additions & 0 deletions example/import_test_project/A.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
def B(s):
return s

def C(s):
return s + "see"

def D(s):
return s + "dee"
6 changes: 6 additions & 0 deletions example/import_test_project/all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from all_folder.has_all import *


LemonGrass()
# MangoYuzu is not defined because it is not in __all__
MangoYuzu()
9 changes: 9 additions & 0 deletions example/import_test_project/all_folder/has_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__all__ = [
'LemonGrass'
]

def LemonGrass():
print ('LemonGrass')

def MangoYuzu():
print ('MangoYuzu')
5 changes: 5 additions & 0 deletions example/import_test_project/all_folder/no_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def _LemonGrass():
print ('LemonGrass')

def MangoYuzu():
print ('MangoYuzu')
2 changes: 2 additions & 0 deletions example/import_test_project/foo/bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def H(s):
return s + "end"
3 changes: 3 additions & 0 deletions example/import_test_project/from_directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from foo import bar

bar.H('hey')
4 changes: 4 additions & 0 deletions example/import_test_project/from_dot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import A


c = A.B('sss')
4 changes: 4 additions & 0 deletions example/import_test_project/import_as.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from A import B
import A as foo
b = B('str')
c = foo.B('sss')
4 changes: 4 additions & 0 deletions example/import_test_project/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import init_file_folder


init_file_folder.Eataly()
1 change: 1 addition & 0 deletions example/import_test_project/init_file_folder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .nested_folder import StarbucksVisitor as Eataly
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .starbucks import StarbucksVisitor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class StarbucksVisitor(object):
def __init__(self):
print ("Iced Mocha")
2 changes: 2 additions & 0 deletions example/import_test_project/multiple_files/A.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def cosme(s):
return s + "aaa"
2 changes: 2 additions & 0 deletions example/import_test_project/multiple_files/B.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def foo(s):
return s + "bee"
2 changes: 2 additions & 0 deletions example/import_test_project/multiple_files/C.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def foo(s):
return s + "see"
2 changes: 2 additions & 0 deletions example/import_test_project/multiple_files/D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def foo(s):
return s + "dee"
7 changes: 7 additions & 0 deletions example/import_test_project/multiple_files_with_aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .multiple_files import A, B as keens, C as per_se, D as duck_house


a = A.cosme('tlayuda')
b = keens.foo('mutton')
c = per_se.foo('tasting')
d = duck_house.foo('peking')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .A import B as keens, C, D as duck_house


a = keens('mutton')
b = C('tasting')
c = duck_house('peking')
6 changes: 6 additions & 0 deletions example/import_test_project/no_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from all_folder.no_all import *


# _LemonGrass is not defined because it starts with _
_LemonGrass()
MangoYuzu()
4 changes: 4 additions & 0 deletions example/import_test_project/other_dir/from_dot_dot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .. import A


c = A.B('sss')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ..foo.bar import H

result = H('hey')
5 changes: 5 additions & 0 deletions example/import_test_project/relative_from_directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Must be run as module via -m
from .foo import bar


bar.H('hey')
4 changes: 4 additions & 0 deletions example/import_test_project/relative_level_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .A import B
import A
b = B('str')
c = A.B('sss')
4 changes: 4 additions & 0 deletions example/import_test_project/relative_level_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ..A import B
import A
b = B('str')
c = A.B('sss')
1 change: 1 addition & 0 deletions example/nested_functions_code/nested_function_calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc = print(foo('bar'))
4 changes: 2 additions & 2 deletions example/vulnerable_code/command_injection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Flask, request, render_template
import subprocess
from flask import Flask, render_template, request

app = Flask(__name__)

Expand Down Expand Up @@ -28,7 +28,7 @@ def clean():

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
Expand Down
38 changes: 38 additions & 0 deletions example/vulnerable_code/inter_command_injection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import subprocess
from flask import Flask, render_template, request


app = Flask(__name__)

@app.route('/')
def index():
with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

def shell_the_arg(arg):
subprocess.call(arg, shell=True)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

shell_the_arg('echo ' + param + ' >> ' + 'menu.txt')

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

@app.route('/clean')
def clean():
subprocess.call('echo Menu: > menu.txt', shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
39 changes: 39 additions & 0 deletions example/vulnerable_code/inter_command_injection_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import subprocess
from flask import Flask, render_template, request


app = Flask(__name__)

@app.route('/')
def index():
with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

def return_the_arg(foo):
return foo

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

command = return_the_arg('echo ' + param + ' >> ' + 'menu.txt')
subprocess.call(command, shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

@app.route('/clean')
def clean():
subprocess.call('echo Menu: > menu.txt', shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import Flask, render_template, request

from other_file import shell_the_arg


app = Flask(__name__)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

shell_the_arg('echo ' + param + ' >> ' + 'menu.txt')

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
from flask import Flask, render_template, request

from other_file import return_the_arg


app = Flask(__name__)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

command = return_the_arg('echo ' + param + ' >> ' + 'menu.txt')
subprocess.call(command, shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
from flask import Flask, render_template, request

from other_file import does_not_exist


app = Flask(__name__)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

command = does_not_exist('echo ' + param + ' >> ' + 'menu.txt')
subprocess.call(command, shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import Flask, render_template, request

import other_file


app = Flask(__name__)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

other_file.shell_the_arg('echo ' + param + ' >> ' + 'menu.txt')

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
from flask import Flask, render_template, request

import other_file


app = Flask(__name__)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

command = other_file.return_the_arg('echo ' + param + ' >> ' + 'menu.txt')
subprocess.call(command, shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
22 changes: 22 additions & 0 deletions example/vulnerable_code_across_files/import_file_does_not_exist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
from flask import Flask, render_template, request

import other_file


app = Flask(__name__)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

command = other_file.does_not_exist('echo ' + param + ' >> ' + 'menu.txt')
subprocess.call(command, shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
from flask import Flask, render_template, request

from other_file import return_constant_string


app = Flask(__name__)

@app.route('/menu', methods=['POST'])
def menu():
param = request.form['suggestion']

command = return_constant_string('echo ' + param + ' >> ' + 'menu.txt')
subprocess.call(command, shell=True)

with open('menu.txt','r') as f:
menu = f.read()

return render_template('command_injection.html', menu=menu)

if __name__ == '__main__':
app.run(debug=True)
Loading