Created
March 14, 2025 11:37
-
-
Save toufik-airane/182aa50077ea79813c1353ddf46520ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import os | |
import hashlib | |
import pickle | |
from flask import Flask, request | |
app = Flask(__name__) | |
USERNAME = "admin" | |
PASSWORD = "password123" | |
def authenticate(user, pwd): | |
if user == USERNAME and pwd == PASSWORD: | |
return "Authenticated!" | |
return "Access Denied." | |
@app.route("/login", methods=["GET"]) | |
def login(): | |
user = request.args.get("user") | |
pwd = request.args.get("password") | |
conn = sqlite3.connect("users.db") | |
cursor = conn.cursor() | |
query = f"SELECT * FROM users WHERE username = '{user}' AND password = '{pwd}'" | |
cursor.execute(query) # π¨ SQL Injection risk | |
result = cursor.fetchone() | |
if result: | |
return "Login Successful!" | |
return "Invalid Credentials!" | |
@app.route("/run", methods=["POST"]) | |
def run_command(): | |
cmd = request.form.get("cmd") | |
os.system(cmd) # π¨ Dangerous: allows arbitrary command execution | |
return "Command executed!" | |
@app.route("/serialize", methods=["POST"]) | |
def deserialize_data(): | |
data = request.form.get("data") | |
obj = pickle.loads(data.encode()) # π¨ Unsafe: can execute arbitrary code | |
return "Data Deserialized!" | |
@app.route("/hash", methods=["POST"]) | |
def hash_password(): | |
password = request.form.get("password") | |
hashed = hashlib.md5(password.encode()).hexdigest() # π¨ Weak: MD5 is outdated | |
return f"MD5 Hash: {hashed}" | |
@app.route("/upload", methods=["POST"]) | |
def upload_file(): | |
file = request.files["file"] | |
file.save(f"/uploads/{file.filename}") # π¨ No validation: Can overwrite critical files | |
return "File uploaded!" | |
@app.route("/xss", methods=["GET"]) | |
def xss(): | |
name = request.args.get("name") | |
return f"<h1>Welcome {name}</h1>" # π¨ No sanitization: vulnerable to XSS | |
if __name__ == "__main__": | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment