題目地址:http://ctf5.shiyanbar.com/web/kzhan.php
在頁面源碼沒發現什么,於是用burp進行抓包重放
看到有setcookie,於是重新刷新頁面攔截數據包(這次才會帶上cookie)
這個source=0 一看就很可疑,改成source=1,就得到了源碼
1 <?php 2 $flag = "XXXXXXXXXXXXXXXXXXXXXXX"; 3 $secret = "XXXXXXXXXXXXXXX"; // This secret is 15 characters long for security! 4 5 $username = $_POST["username"]; 6 $password = $_POST["password"]; 7 8 if (!empty($_COOKIE["getmein"])) { 9 if (urldecode($username) === "admin" && urldecode($password) != "admin") { 10 if ($COOKIE["getmein"] === md5($secret . urldecode($username . $password))) { 11 echo "Congratulations! You are a registered user.\n"; 12 die ("The flag is ". $flag); 13 } 14 else { 15 die ("Your cookies don't match up! STOP HACKING THIS SITE."); 16 } 17 } 18 else { 19 die ("You are not an admin! LEAVE."); 20 } 21 } 22 23 setcookie("sample-hash", md5($secret . urldecode("admin" . "admin")), time() + (60 * 60 * 24 * 7)); 24 25 if (empty($_COOKIE["source"])) { 26 setcookie("source", 0, time() + (60 * 60 * 24 * 7)); 27 } 28 else { 29 if ($_COOKIE["source"] != 0) { 30 echo ""; // This source code is outputted here 31 } 32 }
通讀源碼,知道要得到flag的條件是:提交一個post包,其包含username,password還有一個名為getmein的cookie, 而且要滿足username是'admin',password不是'admin',而且(secret+username+password)的md5值要等於getmein,但問題是我們根本不知道secret的值,只知道secret位數為15。還有通過setcookie知道的東西是 (secret+'admin'+'admin')的MD5值為571580b26c65f306376d4f64e53cb5c7
典型的hash長度擴展攻擊,也就是如果我們知道
1.secret的長度
2.data的值
2.secret+data 的MD5值
我們就能構造出
secret+data+其他值 的MD5
想想是不是我們就可以繞過這題的驗證了?
具體原理移步這里:http://www.freebuf.com/articles/web/69264.html https://www.cnblogs.com/p00mj/p/6288337.html
自己寫工具也挺麻煩,所以我就用現成的了,在kali上裝了一個hashpump,用法如下
最后我們的 "其他值" 就是\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\xc8\x00\x00\x00\x00\x00\x00\x00xxx
所以我們構造post包如下