Skip to content

Commit c3f6a35

Browse files
author
unknown
committed
adds buggy Python code
1 parent 5e97d74 commit c3f6a35

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

Install_requirements_Windows.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This is a PowerShell script that will install dependencies
2+
# using a new virtual environment.
3+
#
4+
# This should work on the faculty machines 'dryadaXX' and possibly on other.
5+
# This might also work on students' machines.
6+
7+
8+
function ActivateVirtual() {
9+
py -m venv env
10+
.\env\scripts\activate.ps1
11+
}
12+
13+
function InstallRequirements() {
14+
pip install --upgrade pip
15+
pip install wheel
16+
pip install --requirement .\requirements.txt
17+
}
18+
19+
ActivateVirtual
20+
InstallRequirements

buggy_python_code.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import sys
2+
import os
3+
import yaml
4+
import flask
5+
6+
app = flask.Flask(__name__)
7+
8+
9+
@app.route("/")
10+
def index():
11+
version = flask.request.args.get("urllib_version")
12+
url = flask.request.args.get("url")
13+
return fetch_website(version, url)
14+
15+
16+
CONFIG = {"API_KEY": "771df488714111d39138eb60df756e6b"}
17+
class Person(object):
18+
def __init__(self, name):
19+
self.name = name
20+
21+
22+
def print_nametag(format_string, person):
23+
print(format_string.format(person=person))
24+
25+
26+
def fetch_website(urllib_version, url):
27+
# Import the requested version (2 or 3) of urllib
28+
exec(f"import urllib{urllib_version} as urllib", globals())
29+
# Fetch and print the requested URL
30+
31+
try:
32+
http = urllib.PoolManager()
33+
r = http.request('GET', url)
34+
except:
35+
print('Exception')
36+
37+
38+
def load_yaml(filename):
39+
stream = open(filename)
40+
deserialized_data = yaml.load(stream, Loader=yaml.Loader) #deserializing data
41+
return deserialized_data
42+
43+
def authenticate(password):
44+
# Assert that the password is correct
45+
assert password == "Iloveyou", "Invalid password!"
46+
print("Successfully authenticated!")
47+
48+
if __name__ == '__main__':
49+
print("Vulnerabilities:")
50+
print("1. Format string vulnerability:")
51+
print("2. Code injection vulnerability:")
52+
print("3. Yaml deserialization vulnerability:")
53+
print("4. Use of assert statements vulnerability:")
54+
choice = input("Select vulnerability: ")
55+
if choice == "1":
56+
new_person = Person("Vickie")
57+
print_nametag(input("Please format your nametag: "), new_person)
58+
elif choice == "2":
59+
urlib_version = input("Choose version of urllib: ")
60+
fetch_website(urlib_version, url="https://www.google.com")
61+
elif choice == "3":
62+
load_yaml(input("File name: "))
63+
print("Executed -ls on current folder")
64+
elif choice == "4":
65+
password = input("Enter master password: ")
66+
authenticate(password)
67+

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pyyaml
2+
flask==0.12.5
3+
urllib3
4+
jinja2==3.0.3
5+
itsdangerous==2.0.1

0 commit comments

Comments
 (0)