forked from Rusheelraj/Supermart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
149 lines (131 loc) · 4.64 KB
/
app.py
File metadata and controls
149 lines (131 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from flask import Flask, request, render_template, render_template_string
import sqlite3
app = Flask(__name__)
@app.route('/index.html')
def home():
return render_template('index.html')
@app.route('/products')
def products():
query = request.args.get('query', '')
# The following line creates the XSS vulnerability
# by directly embedding user input into the HTML response
return render_template_string(f'''
<!DOCTYPE html>
<html>
<head>
<title>Supermart Products</title>
<link rel="stylesheet" type="text/css" href="{{{{ url_for('static', filename='style.css') }}}}">
</head>
<body>
<header>
<h1>Our Products</h1>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="products">Products</a></li>
<li><a href="login">Login</a></li>
<li><a href="contact">Contact</a></li>
</ul>
</nav>
</header>
<!-- The rest of your HTML content here, similar to newxss.py -->
<!-- Make sure to update static file paths with url_for -->
<form method="GET">
<label for="query">Search:</label>
<input type="text" id="query" name="query" value="{query}">
<input type="submit" value="Search">
</form>
<p>You searched for: {query}</p>
<div id="searchResults"></div>
<div class="filter-options">
<button onclick="sortProducts()">Sort by Price</button>
</div>
<div class="product-gallery">
<div class="product-item">
<p>Apple Watch Series 9 GPS 41mm Silver Aluminum Case with Storm Blue Sport Band - S/M</p>
<img src="{{{{ url_for('static', filename='iphone.jpeg') }}}}" alt="Product 1" style="width:450px; height:250px;">
<p>Price: $450 <span class="discount">Discount: 20%</span></p>
<button onclick="addToCart(this)">Add to Cart</button>
<button onclick="buyNow(this)">Buy Now</button>
</div>
<div class="product-item">
<p>Samsung Galaxy S23 Ultra 5G Dual S918B 256GB 8GB RAM GSM Unlocked – Black</p>
<img src="{{{{ url_for('static', filename='samsung.jpeg') }}}}" alt="Product 1" style="width:300px; height:200px;">
<p>Price: $150 <span class="discount">Discount: 15%</span></p>
<button onclick="addToCart(this)">Add to Cart</button>
<button onclick="buyNow(this)">Buy Now</button>
</div>
</div>
</main>
<footer>
<p>© 2023 Supermart</p>
</footer>
</body>
</html>
''')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact')
def contact():
query = request.args.get('query', '')
# The following line creates the SSTI vulnerability
# by directly embedding user input into the HTML response
return render_template_string(f'''
<!DOCTYPE html>
<html>
<head>
<title>Walmart Products</title>
<link rel="stylesheet" type="text/css" href="{{{{ url_for('static', filename='style.css') }}}}">
</head>
<body>
<header>
<h1>Contact Us!</h1>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="products">Products</a></li>
<li><a href="login">Login</a></li>
<li><a href="contact">Contact</a></li>
</ul>
</nav>
</header>
<form>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email" placeholder="email@example.com">
</div>
<div class="form-group">
<label for="phone">Phone:</label>
<input type="tel" class="form-control" id="phone" placeholder="+1 234 567 890">
</div>
</form>
<form method="GET">
<label for="query">Feedback:</label>
<input type="text" id="query" name="query" value="{query}">
<input type="submit" value="Submit">
</form>
<div id="searchResults"></div>
</body>
</html>
''')
@app.route('/login', methods=['GET', 'POST'])
def login():
message = ''
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
connection = sqlite3.connect('database.db')
cursor = connection.cursor()
# Vulnerable SQL query
query = f"SELECT * FROM users WHERE username='{username}' AND password='{password}'"
cursor.execute(query)
result = cursor.fetchone()
if result:
message = 'Logged in successfully'
else:
message = 'Invalid credentials'
connection.close()
return render_template('login.html', message=message)
if __name__ == '__main__':
app.run(debug=True)