Root-me PHP Loose Comparison (Incomplete)
PHP - Loose Comparison
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
<html>
<body>
<form action="index.php" class="authform" method="post" accept-charset="utf-8">
<fieldset>
<legend>Unbreakable Random</legend>
<input type="text" id="s" name="s" value="" placeholder="seed" />
<input type="text" id="h" name="h" value="" placeholder="hash" />
<input type="submit" name="submit" value="Check" />
<div class="return-value" style="padding: 10px 0"> </div>
</fieldset>
</form>
<?php
function gen_secured_random() { // cause random is the way
$a = rand(1337,2600)*42;
$b = rand(1879,1955)*42;
$a < $b ? $a ^= $b ^= $a ^= $b : $a = $b;
return $a+$b;
}
function secured_hash_function($plain) { // cause md5 is the best hash ever
$secured_plain = sanitize_user_input($plain);
return md5($secured_plain);
}
function sanitize_user_input($input) { // cause someone told me to never trust user input
$re = '/[^a-zA-Z0-9]/';
$secured_input = preg_replace($re, "", $input);
return $secured_input;
}
if (isset($_GET['source'])) {
show_source(__FILE__);
die();
}
require_once "secret.php";
if (isset($_POST['s']) && isset($_POST['h'])) {
$s = sanitize_user_input($_POST['s']);
$h = secured_hash_function($_POST['h']);
$r = gen_secured_random();
if($s != false && $h != false) {
if($s.$r == $h) {
print "Well done! Here is your flag: ".$flag;
}
else {
print "Fail...";
}
}
else {
print "<p>Hum ...</p>";
}
}
?>
<p><em><a href="index.php?source">source code</a></em></p>
</body>
</html>
Solution
This post is licensed under CC BY 4.0 by the author.