安洵杯web Hash
打开是一个登录框,抓包把Cooike中的 source=0 改成1
<?php @error_reporting(0); $flag = "flag{xxxxxxxxxxxxxxxxxxxxxxxxxxxx}"; $secret_key = "xxxxxxxxxxxxxxxx"; // the key is safe! no one can know except me $username = $_POST["username"]; $password = $_POST["password"]; header("hash_key:" . $hash_key); if (!empty($_COOKIE["getflag"])) { if (urldecode($username) === "D0g3" && urldecode($password) != "D0g3") { if ($COOKIE["getflag"] === md5($secret_key . urldecode($username . $password))) { echo "Great! You're in!\n"; die ("<!-- The flag is ". $flag . "-->"); } else { die ("Go out! Hacker!"); } } else { die ("LEAVE! You're not one of us!"); } } setcookie("sample-hash", md5($secret_key . urldecode("D0g3" . "D0g3")), time() + (60 * 60 * 24 * 7)); if (empty($_COOKIE["source"])) { setcookie("source", 0, time() + (60 * 60 * 24 * 7)); } else { echo "<source_code>"; } }
通过代码知道得满足以下条件:
【1】COOKIE中要有"getflag" 其值等于$secret_key加上urldecode($username . $password)的md5值
【2】POST数据username其值等于D0g3,POST数据password其数据不能等于D0g3
但是不知道secret_key的值得多少啊QAQ
往下看,还有一句
setcookie("sample-hash", md5($secret_key . urldecode("D0g3" . "D0g3")), time() + (60 * 60 * 24 * 7));
将md5($secret_key . urldecode("D0g3" . "D0g3")的值作为cookie输出,结合数据包知道其值为c3ef608fdc59d9143c39664ade7556d5
学习了hash扩展长度攻击及hashdump使用
打开心爱的ubantu。。
git clone https://github.com/bwall/HashPump
sudo apt-get install g++ libssl-dev
cd HashPump
make
make install
稍微整理下我们已经知道的:
$secret_key是密文,16位,算上D0g3,长度是20
数据是 D0g3
hash是c3ef608fdc59d9143c39664ade7556d5
# hashpump
Input Signature: 571580b26c65f306376d4f64e53cb5c7
Input Data: admin
Input Key Length: 20
Input Data to Add: r
运行后的得到:
fabd157ee4b3dbd643850d4881ee5ffe
D0g3\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0\x00\x00\x00\x00\x00\x00\x00r