|
| 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 | + |
0 commit comments