[Challenge] Can you find the bug? 02-26-2018, 08:57 PM
#1
Hello folks!
So a friend just sent me that piece of code with the explanation "The following script performs a DNS lookup for a host that a user provides. It uses an HMAC to make sure it is requested from a trusted source.". There is an important bug in it that's making the whole request source verification useless.
Let's see if anybody is able to find it
So a friend just sent me that piece of code with the explanation "The following script performs a DNS lookup for a host that a user provides. It uses an HMAC to make sure it is requested from a trusted source.". There is an important bug in it that's making the whole request source verification useless.
Let's see if anybody is able to find it

Code:
<?php
if(empty($_POST['hmac'])) || empty($_POST['host']))
{
header('HTTP/1.0 400 Bad Request');
}
$secret = getenv("SECRET");
if(isset($_POST['nonce']))
$secret = hash_hmac('sha256', $_POST['nonce'], $secret);
$hmac = hash_hmac('sha256', $_POST['host'], $secret);
if($hmac !== $_POST['hmac'])
{
header('HTTP/1.0 403 Forbidden');
exit;
}
echo exec("host ".$_POST['host']);
?>