hash length extension attack

There put a Baidu Encyclopedia explanation of it, emmm
anyway, I do not understand the question or do something about it to consolidate
hash attack length of the CTF

To the web page you will find the display

I do not see anything here that can be utilized, grabbed my bag did not have anything you can use something sweep directory look, there I use a special tool to scan sensitive documents. Interested students can go to . what
tools here
to use: url 16 32 python3 1.py
the OK by scanning index.php ~ we found a file downloaded is actually a linux quit unexpectedly a swap file, emmmmm.

use vim in linux - r object files can be restored
source after recovery:

<html>
<head>
<title>Web 350</title>
<style type="text/css">
    body {
        background:gray;
        text-align:center;
    }
</style>
</head>
<body>
    <?php 
        $auth = false;
        $role = "guest";
        $salt = 
        if (isset($_COOKIE["role"])) {
            $role = unserialize($_COOKIE["role"]);
            $hsh = $_COOKIE["hsh"];
            if ($role==="admin" && $hsh === md5($salt.strrev($_COOKIE["role"]))) {
                $auth = true;
            } else {
                $auth = false;
            }
        } else {
            $s = serialize($role);
            setcookie('role',$s);
            $hsh = md5($salt.strrev($s));
            setcookie('hsh',$hsh);
        }
        if ($auth) {
            echo "<h3>Welcome Admin. Your flag is 
        } else {
            echo "<h3>Only Admin can see the flag!!</h3>";
        }
    ?>
    
</body>
</html>
下面来对代码的逻辑进行一下分析。
首先要想获取flag就要保证role反序列化的值为admin(这个好弄就是在burp里面改一下就行了),但是还要保证hsh===md5($salt.strrev($_COOKIE["role"]),hsh已经给我们了,你看看下面的代码逻辑,他是md5($salt.strrev($s)),而$s的值一开始就是guest,这里面就是将它给字符串给序列化后在反转一下整的。
首先我们先看一下我们的手中的条件,首先我们需要将role改为admin,这个是不用说的,其实我们还有让hsh这个hash值等于md5($salt.strrev($_COOKIE["role"])),,这个就要用到hash扩展攻击了。
下面讲一下hash和扩展攻击的利用方法,其一就是要知道salt的长度(这里面我们可以爆破一下),然后还有知道一个salt后面的string的值以及md5之后的hash值。
这里面我们刚好知道hsh的初始值
$s = serialize($role);//$role的初始值为guest
setcookie('role',$s);
$hsh = md5($salt.strrev($s));
setcookie('hsh',$hsh);
既然我们得到了这个一个hash值,那么我们就可以添加任意的字符串,那么我们添加的字符串就是admin不就好了,这样不仅可以完成条件role='admin',又因为hash长度扩展攻击,所以hsh==~~md5($salt.strrev($_COOKIE["role"])),大概的原理就是你在原来的基础上(已经知道hash值)在添加的字符串进行的hash加密是可以计算出来的。(emmmmmm,菜鸡一个有可能说的很差,见谅,见谅).
这里面我们用python写出爆破脚本(因为salt的长度未知)

Realization of hash length extension attack

url="http://web.jarvisoj.com:32778/"
string1=';"nimda":5:s'  #第一个我们需要添加的字符串
string2=';"tseug":5:s'
hash="3a4727d57463f122833d9e732f94e4e0"
for test in range(1,25) :
    hash_exp,message=hashpumpy.hashpump(hash,string2,string1,test)
    #print(message)
    payload={'role':urllib.parse.quote(message[::-1]),'hsh':hash_exp}
    print(test,payload)
    Mikasa=requests.get(url,cookies=payload).text
    if "Welcome" in Mikasa :
        print(Mikasa)
    #payload={'role':}
    ```
    
    
因为是倒叙进行的加密,所以我们也要倒叙的加密,当然也可以用hashpump这个工具来实现。
结语
感觉自己太差劲了,讲的也不算好,哎!还是太菜

Guess you like

Origin www.cnblogs.com/Mikasa-Ackerman/p/hash-hack.html