-
Notifications
You must be signed in to change notification settings - Fork 26
/
cs_validation.php
397 lines (238 loc) · 9.83 KB
/
cs_validation.php
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?php
/*
bWAPP, or a buggy web application, is a free and open source deliberately insecure web application.
It helps security enthusiasts, developers and students to discover and to prevent web vulnerabilities.
bWAPP covers all major known web vulnerabilities, including all risks from the OWASP Top 10 project!
It is for security-testing and educational purposes only.
Enjoy!
Malik Mesellem
Twitter: @MME_IT
bWAPP is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License (http://creativecommons.org/licenses/by-nc-nd/4.0/). Copyright © 2014 MME BVBA. All rights reserved.
*/
include("security.php");
include("security_level_check.php");
include("connect_i.php");
include("selections.php");
$message = "";
// Checks if the password is complex
// Password policy: minimum 6 characters containing at least one uppercase letter, lowercase letter and number.
function check_password($string)
{
if(preg_match("/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/", $string) == false)
{
return false;
}
return true;
}
// Checks the input fields
function check_input($password_new,$password_conf)
{
$error = "";
if($password_new == "")
{
$error = "<font color=\"red\">Please enter a new password...</font>";
return $error;
}
if($password_new != $password_conf)
{
$error = "<font color=\"red\">The passwords don't match!</font>";
return $error;
}
if(!check_password($password_new) && $_COOKIE["security_level"] == "2")
{
$error = "<font color=\"red\">The new password is not valid!<br />Password policy: minimum 6 characters containing at least one uppercase letter, lowercase letter and number.";
return $error;
}
return $error;
}
if(isset($_POST["action"]))
{
$password_new = $_REQUEST["password_new"];
$password_conf = $_REQUEST["password_conf"];
$message = check_input($password_new, $password_conf);
// Debugging
// echo "I was here!";
if(!$message)
{
$login = $_SESSION["login"];
$password_new = mysqli_real_escape_string($link, $password_new);
$password_new = hash("sha1", $password_new, false);
$password_curr = $_REQUEST["password_curr"];
$password_curr = mysqli_real_escape_string($link, $password_curr);
$password_curr = hash("sha1", $password_curr, false);
$sql = "SELECT password FROM users WHERE login = '" . $login . "' AND password = '" . $password_curr . "'";
// Debugging
// echo $sql;
$recordset = $link->query($sql);
if(!$recordset)
{
die("Error: " . $link->error);
}
// Debugging
// echo "<br />Affected rows: ";
// printf($link->affected_rows);
$row = $recordset->fetch_object();
if($row)
{
// Debugging
// echo "<br />Row: ";
// print_r($row);
$sql = "UPDATE users SET password = '" . $password_new . "' WHERE login = '" . $login . "'";
// Debugging
// echo $sql;
$recordset = $link->query($sql);
if(!$recordset)
{
die("Error: " . $link->error);
}
// Debugging
// echo "<br />Affected rows: ";
// printf($link->affected_rows);
$message = "<font color=\"green\">The password has been changed!</font>";
}
else
{
$message = "<font color=\"red\">The current password is not valid!</font>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Architects+Daughter">-->
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<!--<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>-->
<script src="js/html5.js"></script>
<title>bWAPP - Client-Side Validation</title>
<script type="text/javascript">
function check_password(string)
{
var pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}$/;
return pattern.test(string);
}
function check_form(form)
{
if(form.password_new.value == "")
{
form.password_new.focus();
document.getElementById("message").innerHTML = "<font color=\"red\">Please enter a new password...</font>";
return false;
}
if(form.password_new.value != form.password_conf.value)
{
form.password_new.focus();
document.getElementById("message").innerHTML = "<font color=\"red\">The passwords don't match!</font>";
return false;
}
if(!check_password(form.password_new.value))
{
form.password_new.focus();
document.getElementById("message").innerHTML = "<font color=\"red\">The new password is not valid!<br />Password policy: minimum 6 characters containing at least one uppercase letter, lowercase letter and number.</font>";
return false;
}
return true;
}
</script>
</head>
<body>
<header>
<h1>bWAPP</h1>
<h2>an extremely buggy web app !</h2>
</header>
<div id="menu">
<table>
<tr>
<td><a href="portal.php">Bugs</a></td>
<td><font color="#ffb717">Change Password</font></td>
<td><a href="user_extra.php">Create User</a></td>
<td><a href="security_level_set.php">Set Security Level</a></td>
<td><a href="reset.php" onclick="return confirm('All settings will be cleared. Are you sure?');">Reset</a></td>
<td><a href="credits.php">Credits</a></td>
<td><a href="http://itsecgames.blogspot.com" target="_blank">Blog</a></td>
<td><a href="logout.php" onclick="return confirm('Are you sure you want to leave?');">Logout</a></td>
<td><font color="red">Welcome <?php if(isset($_SESSION["login"])){echo ucwords($_SESSION["login"]);}?></font></td>
</tr>
</table>
</div>
<div id="main">
<h1>Client-Side Validation (Password)</h1>
<p>Please change your password <b><?php if(isset($_SESSION["login"])){echo ucwords($_SESSION["login"]);}?></b>.</p>
<?php
if($_COOKIE["security_level"] == "1" || $_COOKIE["security_level"] == "2")
{
?>
<form action="<?php echo($_SERVER["SCRIPT_NAME"]);?>" method="POST" onsubmit="return check_form(this);">
<?php
}
else
{
?>
<form action="<?php echo($_SERVER["SCRIPT_NAME"]);?>" method="POST">
<?php
}
?>
<p><label for="password_curr">Current password:</label><br />
<input type="password" id="password_curr" name="password_curr"></p>
<p><label for="password_new">New password:</label><br />
<input type="password" id="password_new" name="password_new"></p>
<p><label for="password_conf">Re-type new password:</label><br />
<input type="password" id="password_conf" name="password_conf"></p>
<button type="submit" name="action" value="change">Change</button>
</form>
<br />
<div id="message">
<?php echo $message;?>
</div>
<?php
$link->close();
?>
</div>
<div id="side">
<a href="http://twitter.com/MME_IT" target="blank_" class="button"><img src="./images/twitter.png"></a>
<a href="http://be.linkedin.com/in/malikmesellem" target="blank_" class="button"><img src="./images/linkedin.png"></a>
<a href="http://www.facebook.com/pages/MME-IT-Audits-Security/104153019664877" target="blank_" class="button"><img src="./images/facebook.png"></a>
<a href="http://itsecgames.blogspot.com" target="blank_" class="button"><img src="./images/blogger.png"></a>
</div>
<div id="disclaimer">
<p>bWAPP is licensed under <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank"><img style="vertical-align:middle" src="./images/cc.png"></a> © 2014 MME BVBA / Follow <a href="http://twitter.com/MME_IT" target="_blank">@MME_IT</a> on Twitter and ask for our cheat sheet, containing all solutions! / Need an exclusive <a href="http://www.mmebvba.com" target="_blank">training</a>?</p>
</div>
<div id="bee">
<img src="./images/bee_1.png">
</div>
<div id="security_level">
<form action="<?php echo($_SERVER["SCRIPT_NAME"]);?>" method="POST">
<label>Set your security level:</label><br />
<select name="security_level">
<option value="0">low</option>
<option value="1">medium</option>
<option value="2">high</option>
</select>
<button type="submit" name="form_security_level" value="submit">Set</button>
<font size="4">Current: <b><?php echo $security_level?></b></font>
</form>
</div>
<div id="bug">
<form action="<?php echo($_SERVER["SCRIPT_NAME"]);?>" method="POST">
<label>Choose your bug:</label><br />
<select name="bug">
<?php
// Lists the options from the array 'bugs' (bugs.txt)
foreach ($bugs as $key => $value)
{
$bug = explode(",", trim($value));
// Debugging
// echo "key: " . $key;
// echo " value: " . $bug[0];
// echo " filename: " . $bug[1] . "<br />";
echo "<option value='$key'>$bug[0]</option>";
}
?>
</select>
<button type="submit" name="form_bug" value="submit">Hack</button>
</form>
</div>
</body>
</html>