内容简介:一些声音:
一些声音:
“XSS?不就是弹出个对话框给自己看吗?!”
“反正XSS不能窃取我的root权限。“
“跨站脚本是在客户端执行,XSS漏洞管我什么事!”
“XSS等同于鸡肋漏洞。”
2011年新浪微博XSS蠕虫攻击,持续16分钟,感染的用户将近33000个。
危害:
-
网络钓鱼,包括盗取各类用户账号;
-
窃取用户cookies资料,从而获取用户的隐私信息,或利用用户身份进一步对网站执行操作;
-
劫持用户(浏览器)会话,从而执行任意操作,例如进行非法转账、强制发表日志、发送电子邮件等;
-
强制弹出广告页面、刷流量等;
-
网页挂马;
-
进行恶意操作,例如任意篡改页面信息、删除文章等;
-
进行大量的用户端攻击,如DDoS攻击;
-
获取客户端信息,例如用户的浏览历史、真是IP、开放端口等;
-
控制受害者机器向其他网站发起攻击;
-
结合其他漏洞,如CSRF漏洞,实施进一步作恶;
-
提升用户权限,包括进一步渗透网站;
-
传播跨站脚本蠕虫等;
01
分类
反射型 XSS :
通过URL参数发起攻击,使用最广,危害不如持久型XSS,容易被发现但是可以通过各种编码转换伪装,相对攻击成本较高。
持久型XSS:
通过网站的留言、评论、博客日志等交互处将恶意脚本上传或存储在漏洞服务器中,只要受害者浏览包含此恶意JS代码的页面就会执行恶意代码。
DOM XSS
前两种XSS一般出现在服务器端代码中, 而DOM-Based XSS是基于DOM文档对象模型的一种漏洞,受客户端浏览器的脚本代码所影响。
02
防范
-
与 SQL 注入防护的建议一样,假定所有输入都是可疑的,必须对所有输入中的script、iframe等字样进行严格的检查。这里的输入不仅仅是用户可以直接交互的输入接口,也包括HTTP请求中的Cookie中的变量,HTTP请求头部中的变量等。
-
不仅要验证数据的类型,还要验证其格式、长度、范围和内容。
-
不要仅仅在客户端做数据的验证与过滤,关键的过滤步骤在服务端进行。
-
对输出的数据也要检查,数据库里的值有可能会在一个大网站的多处都有输出,即使在输入做了编码等操作,在各处的输出点时也要进行安全检查。
-
在发布应用程序之前测试所有已知的威胁。
-
所有传到header的字符串都要进行escaped or encoded.
-
黑名单和白名单 。
黑名单:过滤可能造成危害的符号及标签, 可能因为过滤不净使攻击者绕过规则。
白名单:允许执行特定格式的语法,验证程序编写难度较高,用户可输入变化较少。
一些替换原则:
对于HTML标签及BODY中的内容,
< 转换成 <
>转换成 >
&转成成 &
"转换成 "
'转换成 ';
对于<Script></script>中的内容,
'转换成 \'
"转换成 \"
\转换成 \\
/转换成 \/
对于JS事件,如onClick, onLoad, onError,
< 转成 <
> 转成 >
& 转成 &
"转成 "
'转成 ';
\转成\\
/ 转成 \/
URL属性如<script>, <style>, <img> 等标签中的src,href属性,
规定href和src值都是以http://开头, 例如Discuz6.2 img图片加入http://;
规定不能有十进制和十六进制的编码字符;
规定属性以双引号”界定。
HTML和JavaScript环境:
< 转成 %3C
>转成 %3E
"转成 %22
'转成 %27
\转成 %5C
/转成 %2F
字符对URL的影响:
空格转成 %20
+转成%2B
%转成%25
&转成%26
#转成%23
?转成%3F
/转成%2F
对于DOM-Based XSS:
避免客户端文档重写、重定向或其他敏感操作,同时避免使用客户端数据,这些操作尽量在服务端使用动态页面来实现。
分析和清华客户端JS代码,尤其是一些收到影响的Dom对象。
从URL获取的:
Document.URL
Document.URLUnencoded
Document.location(.pathname|.href|.search|.hash)
Window.location(.pathname|.href|.search|.hash)
Referrer属性:
Document.referrer
windowname属性:
Window.name
其他的输入源也可能会导致DOM型的XSS,包括一些本地存储对象,如:
Document.cookie
HTML5 postMessage
localStorage/globalStorage
XMLHTTPRequest response
Input.value
同样要注意能直接修改DOM和创建HTML文件的相关函数或方法,如:
W rite raw HTML, e.g.:
Document.write( … )
Document.wirteln(…)
Document.body.innerHtml= …
Directly modifying the DOM (including DHTML events), e.g.:
document.forms[0].action=… (and various other collections)
document.attachEvent(…)
document.create…(…)
document.execCommand(…)
document.body. … (accessing the DOM through the body object)
window.attachEvent(…)
Replacing the document URL, e.g.:
document.location=… (and assigning to location’s href, host and hostname)
document.location.hostname=…
document.location.replace(…)
document.location.assign(…)
document.URL=…
window.navigate(…)
Opening/modifying a window, e.g.:
document.open(…)
window.open(…)
window.location.href=… (and assigning to location’s href, host and hostname)
Directly executing script, e.g.:
eval(…)
window.execScript(…)
window.setInterval(…)
window.setTimeout(…)
此外,在把变量输入到页面就是要做好相关的编码转义工作,如要输出到<script>中,可以进行Javascript编码;要输出到HTML内容或属性,则进行HTML编码处理。需要根据不同的语境采用不同的编码处理方式。
更多参考:
XSS Prevention Cheat Sheet. 【75】
XSS and CSRF cheat sheet. 【76】
DOM based XSS Prevention Cheat Sheet. 【88】
做前端开发测试对XSS感兴趣可以读一下【78】, HTML, JS,以及不同浏览器解析相同代码的不同行为。
03
测试
参考:
手动测试:
HTML Purifier XSS Attacks Smoke test. 【73】
XSS Filter Evasion Cheat Sheet. 【74】
黑盒测试时还需要考虑各种编码形式,浏览器种类及版本,服务端程序语言等内容。
利用自动化工具:参考Tools
04
Code Review
对于PHP,可以将重点放在来自用户的可以自由控制的变量或动态内容。例如全局变量
Code snippet来自BLUECMS。
更多参见:
Reviewing code for Cross-site scripting. 【77】
FPI(Flash Parameter Injection), 【87】
05
Tools
XSS Assistant ,the script allow users to easily test any web for XSS flaws.【79】
Technika , general purpose scripting platform for Firefox. 【80】
Burp Suite , is an integrated platform for performing security testing of web applications. 【81】
MTASC , Motion-Twin ActionScript Compiler, It can compile large number of .as class files in a very short time and generate directly the corresponding SWF bytecode without relying on Macromedia Flash or other tools. 【82】
XSS Proxy ,an advanced XSS attacking tool. 【84】
XSS Shell , powerful a XSS backdoor and zombie manager【85】
anehta , 基于JavaScript和 PHP 开发的一个XSS攻击利用平台,具有非常好的架构和可扩展性。【86】
WsockExpert , 一款比较常用的抓包工具,可以用来监视和截获执行进程网络数据的传输。
Reference
-
htt p://cwe.mitre.org/data/definitions/89.html
-
htt ps://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet
-
htt p://cwe.mitre.org/top25/index.html
-
htt ps://www.owasp.org/index.php/Query_Parameterization_Cheat_Sheet
-
htt ps://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/Criteria.html
-
htt ps://www.aspectsecurity.com/
-
htt p://www.huawei.com/ecommunity/bbs/10172909.html
-
htt p://docs.oracle.com/cd/B10501_01/text.920/a96518/cqspcl.htm
-
htt p://www.wooyun.org/
-
http s://www.owasp.org/images/5/52/OWASP_Testing_Guide_v4.pdf
-
http s://www.owasp.org/index.php/Testing_for_SQL_Injection_%28OTG-INPVAL-005%29
-
http ://www.websec.ca/kb/sql_injection
-
http ://wfuzz.googlecode.com/svn/trunk/wordlist/
-
http ://www.2cto.com/Article/201305/215007.html
-
http ://erlend.oftedal.no/blog/?blogid=110 , NOSQL injection
-
http s://media.blackhat.com/bh-us-11/Sullivan/BH_US_11_Sullivan_Server_Side_WP.pdf , Server Side JavaScript Injection.
-
http s://www.owasp.org/index.php/Testing_for_HTTP_Parameter_pollution_%28OTG-INPVAL-004%29
-
http ://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html
-
http ://cwe.mitre.org/data/definitions/78.html
-
http s://www.owasp.org/index.php/Command_injection
-
http s://www.owasp.org/index.php/XPATH_Injection
-
http s://www.owasp.org/index.php/Testing_for_XPath_Injection_%28OTG-INPVAL-010%29
-
http ://bbs.2cto.com/read.php?tid=86174
-
http ://ferruh.mavituna.com/sql-injection-cheatsheet-oku/ , SQL injection cheat sheet.
-
http s://www.ibm.com/developerworks/library/j-fuzztest/
-
http ://axis.apache.org/axis/java/security.html
-
http s://www.owasp.org/images/5/58/OWASP_ASVS_Version_2.pdf , Application Security Verification Standard(2014)
-
http s://www.owasp.org/index.php/ASVS#tab=Home
-
https://www.owasp.org/index.php/OWASP_WebScarab_Project
-
https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
-
https://www.wireshark.org/docs/wsug_html_chunked/
-
http://www.thoughtcrime.org/software/sslstrip/
-
https://github.com/moxie0/sslstrip
-
http://en.wikipedia.org/wiki/Man-in-the-middle_attack
-
http://www.monkey.org/~dugsong/dsniff/
-
http://blog.chinaunix.net/uid-2469966-id-2595315.html
-
http://www.elithecomputerguy.com/2013/02/19/introduction-to-subterfuge-for-easy-mitm-attacks-man-in-the-middle/
-
https://code.google.com/p/subterfuge/downloads/list
-
http://www.telerik.com/fiddler
-
http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html
-
https://www.owasp.org/index.php/Testing_for_User_Enumeration_and_Guessable_User_Account_%28OWASP-AT-002%29
-
https://www.owasp.org/index.php/Testing_for_Weak_password_policy_%28OWASP-AT-008%29
-
https://www.pcisecuritystandards.org/documents/PCI_DSS_v3-1.pdf , Payment Card Industry(PCI) data security standard.
-
https://www.pcisecuritystandards.org/security_standards/documents.php?agreements=pcidss&association=pcidss
-
http://portswigger.net/burp/intruder.html
-
https://github.com/sullo/nikto
-
http://www.hoobie.net/brutus/
-
https://www.thc.org/thc-hydra/
-
http://webgoat.github.io/
-
https://addons.mozilla.org/en-US/firefox/addon/cacheviewer2/?src=api
-
http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.13
-
http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
-
https://www.owasp.org/index.php/Password_length_%26_complexity
-
https://www.owasp.org/index.php/ESAPI
-
https://www.schneier.com/essays/archives/2005/02/the_curse_of_the_sec.html
-
http://webappsecmovies.sourceforge.net/webgoat/
-
http://yehg.net/lab/#home
-
http://www.bayden.com/TamperIE/
-
https://addons.mozilla.org/en-US/firefox/addon/tamper-data/
-
http://www.mcafee.com/us/downloads/free-tools/cookiedigger.aspx
-
https://www.owasp.org/index.php/JHijack
-
http://www.acrossecurity.com/papers/session_fixation.pdf
-
http://shiflett.org/articles/session-fixation
-
《 XSS 跨站脚本攻击剖析与防御》,邱永华
-
http://www.ietf.org/rfc/rfc2616.txt , RFC 2616
-
http://www.ietf.org/rfc/rfc2965.txt
-
http://puzzlemall.googlecode.com/files/Session%20Puzzles%20-%20Indirect%20Application%20Attack%20Vectors%20-%20May%202011%20-%20Whitepaper.pdf , Session Puzzles
-
http://web.securityinnovation.com/appsec-weekly/blog/bid/63266/How-to-Test-for-Command-Injection
-
http://dl.packetstormsecurity.net/papers/bypass/Blind_XPath_Injection_20040518.pdf
-
http://fe.baidu.com/doc/websafe/websafeCriterion/php.html
-
《 We b for pentester 》 , Louis Nyffenegger.
-
《 W eb for pentesterII 》 , Louis Nyffenegger.
-
http://htmlpurifier.org/live/smoketests/xssAttacks.php
-
https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
-
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
-
http://www.xenuser.org/xss-cheat-sheet/
-
https://www.owasp.org/index.php/Reviewing_Code_for_Cross-site_scripting
-
XSS Attacks: Cross Site scripting exploits and defense. Jeremiah Grossman, Robert "RSnake" Hansen, Petko "pdp" D. Petkov, Anton Rager, Seth Fogie .
-
http://www.whiteacid.org/greasemonkey/
-
http://www.gnucitizen.org/blog/technika/
-
http://www.portswigger.net/
-
http://www.mtasc.org/
-
http://www.gnucitizen.org/blog/javascript-port-scanner/
-
http://xss-proxy.sourceforge.net/
-
https://labs.portcullis.co.uk/tools/xss-shell/
-
http://code.google.com/p/anehta/
-
http://blog.watchfire.com/FPI.pdf
-
https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet
-
http://www.webappsec.org/projects/articles/071105.shtml
THE END
- 晚安 -
图片长按2秒,识别图中二维码,关注订阅号
以上所述就是小编给大家介绍的《Penetration Test(渗透测试):XSS 跨站脚本攻击》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Agile Web Development with Rails, Third Edition
Sam Ruby、Dave Thomas、David Heinemeier Hansson / Pragmatic Bookshelf / 2009-03-17 / USD 43.95
Rails just keeps on changing. Rails 2, released in 2008, brings hundreds of improvements, including new support for RESTful applications, new generator options, and so on. And, as importantly, we’ve a......一起来看看 《Agile Web Development with Rails, Third Edition》 这本书的介绍吧!