-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
325 lines (317 loc) · 12.1 KB
/
app.py
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
from flask import Flask, request, render_template_string
app = Flask(__name__)
app.secret_key = "VjJGeklHbDBJSEpsWVd4c2VTQnpkWEJ3YjNObFpDQjBieUJpWlNCelpXTnlaWFJwZG1VLw=="
# Simple SSTI vulnerability at /greet path
@app.route('/')
def index():
return '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ginger Juice Shop</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f2f2f2;
color: #333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-size: cover;
background-position: center;
}
.container {
background-color: rgba(255, 255, 255, 0.9);
padding: 40px;
border-radius: 15px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
}
h1 {
color: #3498db;
font-size: 2em;
margin-bottom: 20px;
}
input[type="text"] {
padding: 12px;
width: 80%;
margin-bottom: 20px;
border: 2px solid #ccc;
border-radius: 5px;
font-size: 1em;
}
input[type="submit"], .btn-hard {
background-color: #3498db;
color: white;
border: none;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
transition: background-color 0.3s, transform 0.3s;
display: block;
margin: 10px auto;
width: 80%;
position: relative;
overflow: hidden;
z-index: 0;
}
input[type="submit"]:hover, .btn-hard:hover {
background-color: #2980b9;
transform: scale(1.05);
}
input[type="submit"]::before, .btn-hard::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 200%;
height: 100%;
background: linear-gradient(90deg, rgba(255,255,255,0.1), rgba(255,255,255,0.5), rgba(255,255,255,0.1));
transition: left 0.5s ease-in-out;
z-index: -1;
}
input[type="submit"]:hover::before, .btn-hard:hover::before {
left: 100%;
}
.greeting-container {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container" id="form-container">
<h1>Welcome to Ginger Juice Shop!</h1>
<form method="POST" action="/greet">
<input type="text" name="name" placeholder="Enter your name" required>
<input type="submit" value="Greet">
</form>
<button class="btn-hard" onclick="window.location.href='/hard'">Go to Hard Challenge</button>
</div>
<div class="greeting-container" id="greeting-container" style="display: none;">
</div>
</body>
</html>
'''
@app.route('/greet', methods=['POST'])
def greet():
name = request.form.get('name', '')
template = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ginger Juice Shop</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f2f2f2;
color: #333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-image: url('https://images.unsplash.com/photo-1682530016867-6fcc63df0cfb?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D');
background-size: cover;
background-position: center;
}
.container {
background-color: #FFFFFF;
padding: 40px;
border-radius: 15px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
}
h2 {
color: #3498db;
font-size: 2em;
}
a {
text-decoration: none;
color: #3498db;
font-weight: bold;
display: inline-block;
margin-top: 20px;
font-size: 1.2em;
}
a:hover {
color: #2980b9;
}
</style>
</head>
<body>
<div class="container">
<h2>Hello, ''' + name + '''! Welcome to Ginger Juice Shop!</h2>
<a href="/">Back to Home</a>
</div>
</body>
</html>
'''
return render_template_string(template)
# More complex SSTI challenge at /hard
@app.route('/hard', methods=['GET', 'POST'])
def hard():
if request.method == 'POST':
name = request.form.get('name', '')
# Basic input validation to block common SSTI patterns
blacklist = ['__', 'class', 'mro', 'subclasses', 'eval', 'exec', 'import', 'os', 'sys', '.', '_', 'config']
if any(keyword in name for keyword in blacklist):
return "Invalid input detected! You might need to Try Hard!!", 400
template = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Ginger Juice Shop</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f2f2f2;
color: #333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-image: url('https://images.unsplash.com/photo-1709477992494-34e084eb1779?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D');
background-size: cover;
background-position: center;
}
.container {
background-color: #ffffff;
padding: 40px;
border-radius: 15px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
}
h2 {
color: #3498db;
font-size: 2em;
}
a {
text-decoration: none;
color: #3498db;
font-weight: bold;
display: inline-block;
margin-top: 20px;
font-size: 1.2em;
}
a:hover {
color: #2980b9;
}
</style>
</head>
<body>
<div class="container">
<h2>Hello, ''' + name + '''! Was it this hard?</h2>
<a href="/hard">Back to Hard Challenge</a>
</div>
</body>
</html>
'''
return render_template_string(template)
return '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Ginger Juice Shop</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f2f2f2;
color: #333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-size: cover;
background-position: center;
}
.container {
background-color: rgba(255, 255, 255, 0.9);
padding: 40px;
border-radius: 15px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
}
h1 {
color: #3498db;
font-size: 2em;
margin-bottom: 20px;
}
input[type="text"] {
padding: 12px;
width: 80%;
margin-bottom: 20px;
border: 2px solid #ccc;
border-radius: 5px;
font-size: 1em;
}
input[type="submit"] {
background-color: #3498db;
color: white;
border: none;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
transition: background-color 0.3s, transform 0.3s;
display: block;
margin: 10px auto;
width: 80%;
position: relative;
overflow: hidden;
z-index: 0;
}
input[type="submit"]:hover {
background-color: #2980b9;
transform: scale(1.05);
}
input[type="submit"]::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 200%;
height: 100%;
background: linear-gradient(90deg, rgba(255,255,255,0.1), rgba(255,255,255,0.5), rgba(255,255,255,0.1));
transition: left 0.5s ease-in-out;
z-index: -1;
}
input[type="submit"]:hover::before {
left: 100%;
}
.greeting-container {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container" id="form-container">
<h1>Welcome to the Advanced Ginger Juice Shop!</h1>
<form method="POST" action="/hard">
<input type="text" name="name" placeholder="Enter your name" required>
<input type="submit" value="Submit">
</form>
</div>
<div class="greeting-container" id="greeting-container" style="display: none;">
</div>
</body>
</html>
'''
if __name__ == '__main__':
app.run(debug=True)