实验吧——让我进去(hash长度扩展攻击)

题目地址: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.
";
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,用法如下

最后我们的 "其他值" 就是x80x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00xc8x00x00x00x00x00x00x00xxx

所以我们构造post包如下

原文地址:https://www.cnblogs.com/leixiao-/p/9749792.html