githubEdit

PHP hash_hmac Bypass

Investigation

If the website uses hash_hmac function on PHP as below, we can bypass by injecting parameters.

<?php
    if (empty($_POST['hmac']) || empty($_POST['host']) {
        header('HTTP/1.0 400 Bad Request');
        exit;
    }

    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;
    }
?>

When executing the following command, the hash_hmac returns false.

Exploitation

Create a Hmac hash by running below. In the above PHP script, $hmac needs to be the same as the parameter values of hmac.

So put the output hmac value into the paramter "hmac" and the second arguments ("example.com") into the host parameter.

Last updated