Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thearyanahmed/7cfa9306d88ce6c3ed9f2a81acba6b3d to your computer and use it in GitHub Desktop.
Save thearyanahmed/7cfa9306d88ce6c3ed9f2a81acba6b3d to your computer and use it in GitHub Desktop.
The program takes hmac,nonce and host from request and $secret from the .env. If nonce is sent from the request, the value of the secret is changed, but if the $hmac doesn't match, you can't go to the exec() command portion on line 20. You have no way of knowing the $secret from .env. Do you see the bug? How can you bypass the security exploitin…
<?php
if(empty($_POST['hmac']) || empty($_POST['host'])) {
header('HTTP/1.0 400 Bad Request');
exit;
}
$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');
}
echo exec("host " . $_POST['host']);
@thearyanahmed
Copy link
Author

@rifatron999 you are not supposed to give your answer here. :) I'll be deleting your comment shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment