XSS漏洞基础
XSS入门介绍
https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
解析器如何工作
For example, a tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.
- XSS解析器就是浏览器
HTML entities(HTML 实体)
HTML中的保留字符(Reserved characters)都会被替换为HTML实体
https://www.w3schools.com/html/html_entities.asp
浏览器如何解码(Freebuf博主)
https://www.freebuf.com/articles/web/10121.html
XSS漏洞复现
- 标签内的标准弹框语句,不经过数据库存取
alert(1)
alert("xss")
alert(/xss/)
alert('xss')
- 经过数据库存取
alert(1)
alert("xss")
alert(/xss/)
alert(\ 'xss\ ')(mysql插入数据时默认用单引号包围,再包括单引号出现语法错误)
- DOM复现的绕过语句:
'>< img src=# οnerrοr="alert('XSS')""><'
' οnclick=alert(/xss/) //
' οnclick='alert(/xss/)' # 单引号双引号都没有关系
DVWA安装:
https://github.com/ethicalhack3r/DVWA
DVWA靶场游玩攻略(XSS):
https://www.freebuf.com/articles/web/123779.html
understanding-dom-based-xss-dvwa-bypass-security
DVWA XSS Reflected
- 过滤了“”标签,使用大小写,双写, 添加src属性绕过
- 若采用正则匹配过滤“”,之前方法都行不通,考虑使用其他标签:
iframe
input
img
body
- 添加src属性,利用鼠标事件(通用):
<IMG SRC="#">
- 利用error事件,适用img
<IMG SRC="/">
- htmlspecialchars($_GET[‘name’]);无解
DVWA XSS Store
- mysqli_real_escape_string()转移字符串(SQL中的特殊字符):一次转义对SQL命令并无太大影响,数据库会存储未转义前的字符
- stripslashes()去除反斜杠
- name字段的限制可以通过burp抓包修改
- impossible级别,多次转义,数据库中的特殊符号带上反斜杠,并且$message中的HTML保留字符被转换为HTML实体
addslashes($message);
mysqli_real_escape_string($ message);
htmlspecialchars( $ message);
DVWA DOM XSS
- 基于client的XSS漏洞
- the hash symbol(#)不会被服务端接收到(#后面的部分称为fragment)
XSS平台搭建
- 教程:
https://cread.jd.com/read/startRead.action?bookId=30432053&readType=1
https://blog.csdn.net/u011781521/article/details/53895363 - window10配置静态文件
https://blog.csdn.net/cz_devil/article/details/16826647
https://blog.csdn.net/qq_16241043/article/details/54176442 - 查看Apache启动失败的错误信息:
打开cmd,输入:D:\phpStudy\Apache\binhttpd.exe -t 回车,即显示错误信息
XSS漏洞挖掘
识别URL上的输入点
可控点:
- web2.0的URL与传统形式上的差异:更强调明确含义(web2.0url名称与传统URL的映射)
- 需要强大的爬虫进行识别
- fragment可能出现在服务端解析中
进行XSS测试时,可能的输出点
HTML标签之间
- 直接输入js代码
- 闭合标签(其他标签无法执行HTML代码)
- 这三个标签可以解析HTML代码,不可以解析的标签实际上是进行了htmencode编码
div
pre
code
HTML标签之内(属性)
- 利用事件(效果比较差)
- 闭合属性,闭合标签(成功率较低)
- 特殊属性src/href/action
- href执行javascript伪协议,过滤//,考虑js字符串的加减乘除
- onerror(适用img)
- data伪协议
成为js代码
- 闭合script标签
- 绕过变量引用
其他
HTML与js的自解码与编码函数
- HTML标签内(&)
- entity_name:&#xH &#D(可以去除分号)
- entity_number
http://www.behindthefirewalls.com/2014/06/xss-game-by-google-exercises-4-5-and-6.html