07 Feb 2021 - OverTheWire - Natas
website: http://natas8.natas.labs.overthewire.org/ (password: DBfUBfqQG69KvJvJ1iAbMoIpwSNQ9bWe)
A piece of PHP code is given in this level:
<?
$encodedSecret = "3d3d516343746d4d6d6c315669563362";
function encodeSecret($secret) {
return bin2hex(strrev(base64_encode($secret)));
}
if(array_key_exists("submit", $_POST)) {
if(encodeSecret($_POST['secret']) == $encodedSecret) {
print "Access granted. The password for natas9 is <censored>";
} else {
print "Wrong secret";
}
}
?>
According to the source code above, we can learn two things:
Therefore, it’s possible for us to retrieve the secret. To retrieve it, we simply write a decode function by reversing the encodeSecret
:
<?
$encodedSecret = $argv[1];
echo base64_decode(strrev(hex2bin($encodedSecret)));
?>
Running this script gives us the secret oubWYf2kBq. Put the decoded secret in the textbox and I get the password for the next level.
CONCLUSION
In this challenge, we see that a secret is saved locally in an encoded way. Moreover, this secret can be reversed because the developer didn’t use a right way to enclose it. Here, we can follow a few suggestions to enhance the security of secret information:
References
Here are some additional references about reversible one-way hash:
«Prev | More About | Next» |
---|---|---|
Natas7 - File Inclusion Vulnerability | OverTheWire - Natas | Natas9 - Command Injection Part 1 |