diff --git a/TestPR b/TestPR new file mode 100644 index 0000000..e2a06d6 --- /dev/null +++ b/TestPR @@ -0,0 +1,30 @@ +const express = require('express'); +const mongoose = require('mongoose'); + +const app = express(); +const port = 3000; + +// Connect to MongoDB +mongoose.connect('mongodb://localhost:27017/users_db', { + useNewUrlParser: true, + useUnifiedTopology: true +}); + +const User = mongoose.model('User', new mongoose.Schema({ username: String, password: String })); + +// ⚠️ SAST ISSUE: NoSQL Injection vulnerability ⚠️ +app.get('/user', async (req, res) => { + const username = req.query.username; // User-controlled input + + // 🚨 UNSAFE: Directly passing user input into MongoDB query 🚨 + const user = await User.findOne({ username: username }); + + if (!user) { + return res.status(404).send('User not found'); + } + + res.json(user); +}); + +app.listen(port, () => { + console.log(`Server running on http://localhost:${port}`); \ No newline at end of file diff --git a/add.py b/add.py new file mode 100644 index 0000000..371957b --- /dev/null +++ b/add.py @@ -0,0 +1,183 @@ +# adding comments +# move line +from flask import Flask, request, render_template_string, jsonify +import subprocess +import os +import sqlite3 +import requests +from lxml import etree + +# Example hardcoded AWS credentials (sensitive data leakage) +aws_access_key_id = '****64VE' +aws_secret = '****9yO5' + +app = Flask(__name__) + +@app.route('/', methods=['GET', 'POST']) +def index(): + output = '' + # 1 - SQL Injection + db = sqlite3.connect("tutorial.db") + cursor = db.cursor() + username = '' + password = '' + try: + cursor.execute("SELECT * FROM users WHERE username = '%s' AND password = '%s'" % (username, password)) + except: + pass + + if request.method == 'POST': + # 2 - Command Injection + if 'command' in request.form: + cmd = request.form['command'] + process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + if process.returncode == 0: + output = stdout.decode('utf-8') + else: + output = f"Error (Exit Code: {process.returncode}):\n{stderr.decode('utf-8')}" + + # 3 - File Upload with no restrictions, and path traversal + elif 'file' in request.files: + uploaded_file = request.files['file'] + uploaded_file.save(os.path.join('/uploads', uploaded_file.filename)) + output = f"File {uploaded_file.filename} uploaded successfully!" + + # 4 - SQL Injection via input + elif 'sql' in request.form: + sql = request.form['sql'] + try: + # Execute the user's SQL query + cursor.execute(sql) + # Fetch all rows from the query result + rows = cursor.fetchall() + # Format the results for display + if rows: + output = "Results:\n" + "\n".join(str(row) for row in rows) + else: + output = "Query executed successfully, but no results found." + except Exception as e: + output = f"SQL Error: {e}" + + # 5 - Cross-Site Scripting (XSS) + elif 'xss' in request.form: + xss_input = request.form['xss'] + output = f"Reflected XSS result: {xss_input}" + + # 6 - XML External Entity (XXE) Injection + elif 'xml' in request.form: + xml_data = request.form['xml'] + try: + # Use lxml to parse the XML data + parser = etree.XMLParser(load_dtd=True, resolve_entities=True) + tree = etree.fromstring(xml_data.encode(), parser) + output = f"Parsed XML: {etree.tostring(tree, encoding='unicode')}" + except Exception as e: + output = f"XML Parsing Error: {e}" + + # 7 - Server-Side Request Forgery (SSRF) + elif 'url' in request.form: + url = request.form['url'] + try: + response = requests.get(url) + output = f"SSRF Response: {response.text[:200]}" + except Exception as e: + output = f"SSRF Error: {e}" + + # 8 - SQL injection with parameter instead of whole query + if 'username' in request.form: + username = request.form['username'] + try: + # Vulnerable SQL query using string interpolation + query = "SELECT password FROM users WHERE username = '{}'".format(username) + cursor.execute(query) + result = cursor.fetchone() + if result: + output = f"Password for {username}: {result[0]}" + else: + output = "User not found." + except Exception as e: + output = f"SQL Error: {e}" + + return render_template_string(""" +
Try uploading a file named: ../../../../etc/passwd
{{ output|safe }}
+ """, output=output)
+
+if __name__ == '__main__':
+ app.run(host='0.0.0.0', port=8080)
+Aikido Recommendation
+
+Very high priority to fix
+
+According to Aikido, this is a very high impact issue. We recommend fixing the issue as soon as possible.
+
+AI Autotriage Summary
+
+The Flask application runs in debug mode while being publicly accessible, exposing sensitive debug information and enabling remote code execution.
+
+Call Tree
+
+insecure-app/app.py
diff --git a/insecure-app/app.py b/insecure-app/app.py
index 64e4a8f..4ebcd2a 100644
--- a/insecure-app/app.py
+++ b/insecure-app/app.py
@@ -165,4 +165,4 @@ def index():
""", output=output)
if __name__ == '__main__':
- app.run(host='0.0.0.0', port=8080, debug=True)
+ app.run(host='0.0.0.0', port=8080)