Penetration Test(渗透测试):XSS 跨站脚本攻击

栏目: 编程工具 · 发布时间: 5年前

内容简介:一些声音:

Penetration Test(渗透测试):XSS 跨站脚本攻击

Penetration Test(渗透测试):XSS 跨站脚本攻击

一些声音:

“XSS?不就是弹出个对话框给自己看吗?!”

“反正XSS不能窃取我的root权限。“

“跨站脚本是在客户端执行,XSS漏洞管我什么事!”

“XSS等同于鸡肋漏洞。”

2011年新浪微博XSS蠕虫攻击,持续16分钟,感染的用户将近33000个。

危害:

  • 网络钓鱼,包括盗取各类用户账号;

  • 窃取用户cookies资料,从而获取用户的隐私信息,或利用用户身份进一步对网站执行操作;

  • 劫持用户(浏览器)会话,从而执行任意操作,例如进行非法转账、强制发表日志、发送电子邮件等;

  • 强制弹出广告页面、刷流量等;

  • 网页挂马;

  • 进行恶意操作,例如任意篡改页面信息、删除文章等;

  • 进行大量的用户端攻击,如DDoS攻击;

  • 获取客户端信息,例如用户的浏览历史、真是IP、开放端口等;

  • 控制受害者机器向其他网站发起攻击;

  • 结合其他漏洞,如CSRF漏洞,实施进一步作恶;

  • 提升用户权限,包括进一步渗透网站;

  • 传播跨站脚本蠕虫等;

Penetration Test(渗透测试):XSS 跨站脚本攻击

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中的内容,


 

< 转换成 &lt;


>转换成 &gt;


&转成成 &


"转换成 "


'转换成 ';

对于<Script></script>中的内容,


 

'转换成 \'


"转换成 \"


\转换成 \\


/转换成 \/

对于JS事件,如onClick, onLoad, onError,


 

< 转成 &lt;


> 转成 &gt;


& 转成 &


"转成 "


'转成 ';


\转成\\


/ 转成 \/

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,可以将重点放在来自用户的可以自由控制的变量或动态内容。例如全局变量

Penetration Test(渗透测试):XSS 跨站脚本攻击

Code snippet来自BLUECMS。

Penetration Test(渗透测试):XSS 跨站脚本攻击

更多参见:

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

  1. htt p://cwe.mitre.org/data/definitions/89.html

  2. htt ps://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet

  3. htt p://cwe.mitre.org/top25/index.html

  4. htt ps://www.owasp.org/index.php/Query_Parameterization_Cheat_Sheet

  5. htt ps://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/Criteria.html

  6. htt ps://www.aspectsecurity.com/

  7. htt p://www.huawei.com/ecommunity/bbs/10172909.html

  8. htt p://docs.oracle.com/cd/B10501_01/text.920/a96518/cqspcl.htm

  9. htt p://www.wooyun.org/

  10. http s://www.owasp.org/images/5/52/OWASP_Testing_Guide_v4.pdf

  11. http s://www.owasp.org/index.php/Testing_for_SQL_Injection_%28OTG-INPVAL-005%29

  12. http ://www.websec.ca/kb/sql_injection

  13. http ://wfuzz.googlecode.com/svn/trunk/wordlist/

  14. http ://www.2cto.com/Article/201305/215007.html

  15. http ://erlend.oftedal.no/blog/?blogid=110  ,  NOSQL injection

  16. http s://media.blackhat.com/bh-us-11/Sullivan/BH_US_11_Sullivan_Server_Side_WP.pdf Server Side     JavaScript Injection.

  17. http s://www.owasp.org/index.php/Testing_for_HTTP_Parameter_pollution_%28OTG-INPVAL-004%29

  18. http ://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html

  19. http ://cwe.mitre.org/data/definitions/78.html

  20. http s://www.owasp.org/index.php/Command_injection

  21. http s://www.owasp.org/index.php/XPATH_Injection

  22. http s://www.owasp.org/index.php/Testing_for_XPath_Injection_%28OTG-INPVAL-010%29

  23. http ://bbs.2cto.com/read.php?tid=86174

  24. http ://ferruh.mavituna.com/sql-injection-cheatsheet-oku/  SQL injection cheat     sheet.

  25. http s://www.ibm.com/developerworks/library/j-fuzztest/

  26. http ://axis.apache.org/axis/java/security.html

  27. http s://www.owasp.org/images/5/58/OWASP_ASVS_Version_2.pdf ,  Application Security     Verification Standard(2014)

  28. http s://www.owasp.org/index.php/ASVS#tab=Home

  29. https://www.owasp.org/index.php/OWASP_WebScarab_Project

  30. https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project

  31. https://www.wireshark.org/docs/wsug_html_chunked/

  32. http://www.thoughtcrime.org/software/sslstrip/

  33. https://github.com/moxie0/sslstrip

  34. http://en.wikipedia.org/wiki/Man-in-the-middle_attack

  35. http://www.monkey.org/~dugsong/dsniff/

  36. http://blog.chinaunix.net/uid-2469966-id-2595315.html

  37. http://www.elithecomputerguy.com/2013/02/19/introduction-to-subterfuge-for-easy-mitm-attacks-man-in-the-middle/

  38. https://code.google.com/p/subterfuge/downloads/list

  39. http://www.telerik.com/fiddler

  40. http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html

  41. https://www.owasp.org/index.php/Testing_for_User_Enumeration_and_Guessable_User_Account_%28OWASP-AT-002%29

  42. https://www.owasp.org/index.php/Testing_for_Weak_password_policy_%28OWASP-AT-008%29

  43. https://www.pcisecuritystandards.org/documents/PCI_DSS_v3-1.pdf Payment Card     Industry(PCI) data security standard.

  44. https://www.pcisecuritystandards.org/security_standards/documents.php?agreements=pcidss&association=pcidss

  45. http://portswigger.net/burp/intruder.html

  46. https://github.com/sullo/nikto

  47. http://www.hoobie.net/brutus/

  48. https://www.thc.org/thc-hydra/

  49. http://webgoat.github.io/

  50. https://addons.mozilla.org/en-US/firefox/addon/cacheviewer2/?src=api

  51. http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.13

  52. http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

  53. https://www.owasp.org/index.php/Password_length_%26_complexity

  54. https://www.owasp.org/index.php/ESAPI

  55. https://www.schneier.com/essays/archives/2005/02/the_curse_of_the_sec.html

  56. http://webappsecmovies.sourceforge.net/webgoat/

  57. http://yehg.net/lab/#home

  58. http://www.bayden.com/TamperIE/

  59. https://addons.mozilla.org/en-US/firefox/addon/tamper-data/

  60. http://www.mcafee.com/us/downloads/free-tools/cookiedigger.aspx

  61. https://www.owasp.org/index.php/JHijack

  62. http://www.acrossecurity.com/papers/session_fixation.pdf

  63. http://shiflett.org/articles/session-fixation

  64. XSS 跨站脚本攻击剖析与防御》,邱永华

  65. http://www.ietf.org/rfc/rfc2616.txt  RFC 2616

  66. http://www.ietf.org/rfc/rfc2965.txt

  67. http://puzzlemall.googlecode.com/files/Session%20Puzzles%20-%20Indirect%20Application%20Attack%20Vectors%20-%20May%202011%20-%20Whitepaper.pdf   Session Puzzles

  68. http://web.securityinnovation.com/appsec-weekly/blog/bid/63266/How-to-Test-for-Command-Injection

  69. http://dl.packetstormsecurity.net/papers/bypass/Blind_XPath_Injection_20040518.pdf

  70. http://fe.baidu.com/doc/websafe/websafeCriterion/php.html

  71. We b for pentester , Louis Nyffenegger.

  72. W eb for pentesterII , Louis Nyffenegger.

  73. http://htmlpurifier.org/live/smoketests/xssAttacks.php

  74. https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet

  75. https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet

  76. http://www.xenuser.org/xss-cheat-sheet/

  77. https://www.owasp.org/index.php/Reviewing_Code_for_Cross-site_scripting

  78. XSS Attacks: Cross     Site scripting exploits and defense.  Jeremiah Grossman, Robert "RSnake"     Hansen, Petko "pdp" D. Petkov, Anton Rager, Seth Fogie .

  79. http://www.whiteacid.org/greasemonkey/

  80. http://www.gnucitizen.org/blog/technika/

  81. http://www.portswigger.net/

  82. http://www.mtasc.org/

  83. http://www.gnucitizen.org/blog/javascript-port-scanner/

  84. http://xss-proxy.sourceforge.net/

  85. https://labs.portcullis.co.uk/tools/xss-shell/

  86. http://code.google.com/p/anehta/

  87. http://blog.watchfire.com/FPI.pdf

  88. https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet

  89. http://www.webappsec.org/projects/articles/071105.shtml

THE END

- 晚安 -

图片长按2秒,识别图中二维码,关注订阅号

Penetration Test(渗透测试):XSS 跨站脚本攻击


以上所述就是小编给大家介绍的《Penetration Test(渗透测试):XSS 跨站脚本攻击》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

法律论证理论

法律论证理论

罗伯特·阿列克西 / 舒国滢 / 中国法制出版社 / 2002-12-01 / 30.00

阿列克西的著作探讨的主要问题是如法律裁决之类的规范性陈述如何以理性的方式证立。阿列克西将规范性陈述的证立过程看作实践商谈或“实践言说”,而将法律裁决的证立过程视为“法律言说” 。由于支持法律规范的法律商谈是普遍实践言说的特定形式,所以法律论证理论应当立基于这种一般理论。 在阿列克西看来,如果裁决是理性言说的结果,那么这一规范性陈述就是真实的或可接受的。其基本观念在于法律裁决证立的合理性取决于......一起来看看 《法律论证理论》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具