Skip to content

Commit 3206f32

Browse files
committed
renew file_put_content
1 parent e48f13d commit 3206f32

13 files changed

+1056
-1038
lines changed

README.md

+85-84
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,85 @@
1-
# Audit-Learning
2-
3-
开新坑了,准备花一个月的时间对学过的代码审计知识好好总结一下,持续更新,欢迎各位师傅star支持一下。
4-
5-
## Todo
6-
- [x] open_basedir 绕过研究
7-
- [x] allow_url_fopen 和 allow_url_include
8-
- [x] 宽字节注入及数据库编码分析
9-
- [x] 通用代码审计思路
10-
- [x] 危险的file_put_contents函数
11-
- [x] escapeshellarg 和 escapeshellcmd 函数.md
12-
- [ ] disable_functions 绕过研究
13-
- [ ] parse_url 函数研究
14-
- [ ] curl 函数研究
15-
- [ ] addslashes 函数绕过研究
16-
- [ ] move_uploaded_file
17-
- [ ] str_shuffle 函数缺陷
18-
19-
## 一些资源
20-
21-
### 代码审计练习题
22-
23-
https://github.com/CHYbeta/Code-Audit-Challenges
24-
25-
wonderkun师傅的ctf web练习题: https://github.com/wonderkun/CTF_web
26-
27-
https://github.com/bowu678/php_bugs
28-
29-
30-
### 漏洞exp
31-
推荐一波自己的仓库: https://github.com/jiangsir404/PHP-code-audit
32-
33-
各种开源CMS 各种版本的漏洞以及EXP: https://github.com/Mr5m1th/0day
34-
35-
CMS漏洞测试用例集合: https://github.com/SecWiki/CMS-Hunter
36-
37-
38-
### 乌云
39-
40-
Xyntax师傅整理的乌云1000个PHP代码审计案例: https://github.com/Xyntax/1000php
41-
42-
乌云Drops文章备份: https://github.com/SecWiki/wooyun_articles
43-
44-
45-
46-
### 思维导图,资料集合
47-
48-
cheybeta师傅的Web学习资料整理: https://github.com/CHYbeta/Web-Security-Learning
49-
50-
https://github.com/CHYbeta/phith0n-Mind-Map
51-
52-
https://github.com/bit4woo/code2sec.com
53-
54-
python 代码审计: https://github.com/bit4woo/python_sec
55-
56-
高级PHP应用程序漏洞审核技术(by黑哥)https://github.com/Jyny/pasc2at
57-
58-
59-
### 博客
60-
离别歌:https://www.leavesongs.com/
61-
62-
漏洞时代: http://0day5.com/
63-
64-
lorexxar师傅: http://lorexxar.cn/
65-
66-
知道创宇paper: https://paper.seebug.org/
67-
68-
69-
### 书籍
70-
《代码审计》
71-
72-
《PHP7内核剖析》 https://github.com/pangudashu/php7-internal
73-
74-
《深入理解PHP内核》https://github.com/reeze/tipi
75-
76-
### 代码审计工具
77-
78-
cobra: https://github.com/wufeifei/cobra
79-
80-
Seay源代码审计系统2.1: http://www.cnseay.com/
81-
82-
rips: https://github.com/ripsscanner/rips
83-
84-
1+
# Audit-Learning
2+
3+
开新坑了,准备花一个月的时间对学过的代码审计知识好好总结一下,持续更新,欢迎各位师傅star支持一下。
4+
5+
## Todo
6+
- [x] open_basedir 绕过研究
7+
- [x] allow_url_fopen 和 allow_url_include
8+
- [x] 宽字节注入及数据库编码分析
9+
- [x] 通用代码审计思路
10+
- [x] 危险的file_put_contents函数
11+
- [x] escapeshellarg 和 escapeshellcmd 函数.md
12+
- [ ] disable_functions 绕过研究
13+
- [ ] parse_url 函数研究
14+
- [ ] curl 函数研究
15+
- [ ] addslashes 函数绕过研究
16+
- [ ] move_uploaded_file
17+
- [ ] str_shuffle 函数缺陷
18+
- [ ] unlink漏洞的原理和利用 http://wonderkun.cc/index.html/?cat=1&paged=3
19+
- [ ] 其他
20+
## 一些资源
21+
22+
### 代码审计练习题
23+
24+
https://github.com/CHYbeta/Code-Audit-Challenges
25+
26+
wonderkun师傅的ctf web练习题: https://github.com/wonderkun/CTF_web
27+
28+
https://github.com/bowu678/php_bugs
29+
30+
31+
### 漏洞exp
32+
推荐一波自己的仓库: https://github.com/jiangsir404/PHP-code-audit
33+
34+
各种开源CMS 各种版本的漏洞以及EXP: https://github.com/Mr5m1th/0day
35+
36+
CMS漏洞测试用例集合: https://github.com/SecWiki/CMS-Hunter
37+
38+
39+
### 乌云
40+
41+
Xyntax师傅整理的乌云1000个PHP代码审计案例: https://github.com/Xyntax/1000php
42+
43+
乌云Drops文章备份: https://github.com/SecWiki/wooyun_articles
44+
45+
46+
47+
### 思维导图,资料集合
48+
49+
cheybeta师傅的Web学习资料整理: https://github.com/CHYbeta/Web-Security-Learning
50+
51+
https://github.com/CHYbeta/phith0n-Mind-Map
52+
53+
https://github.com/bit4woo/code2sec.com
54+
55+
python 代码审计: https://github.com/bit4woo/python_sec
56+
57+
高级PHP应用程序漏洞审核技术(by黑哥)https://github.com/Jyny/pasc2at
58+
59+
60+
### 博客
61+
离别歌:https://www.leavesongs.com/
62+
63+
漏洞时代: http://0day5.com/
64+
65+
lorexxar师傅: http://lorexxar.cn/
66+
67+
知道创宇paper: https://paper.seebug.org/
68+
69+
70+
### 书籍
71+
《代码审计》
72+
73+
《PHP7内核剖析》 https://github.com/pangudashu/php7-internal
74+
75+
《深入理解PHP内核》https://github.com/reeze/tipi
76+
77+
### 代码审计工具
78+
79+
cobra: https://github.com/wufeifei/cobra
80+
81+
Seay源代码审计系统2.1: http://www.cnseay.com/
82+
83+
rips: https://github.com/ripsscanner/rips
84+
85+
+94-94
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,94 @@
1-
## allow_url_fopen
2-
3-
只要在php.ini 文件中激活了allow_url_fopen选项, 就可以在大多数需要用文件名作为参数的函数中适用httpftp的url来代替文件名.
4-
5-
比如: fopen,file_get_contents,copy,readfile等函数都可以接收一个stream作为文件名来读取stream里的文件内容, imagecreatefromxxx等图像处理函数也可以传入一个url图片作为文件名
6-
7-
但也有一些函数不能接收一个url作为文件名,比如include,include_once,require,require_once 函
8-
.
9-
10-
```
11-
imagecreatefrombmp — 由文件或 URL 创建一个新图象。
12-
imagecreatefromgd2 — 从 GD2 文件或 URL 新建一图像
13-
imagecreatefromgd2part — 从给定的 GD2 文件或 URL 中的部分新建一图像
14-
imagecreatefromgd — 从 GD 文件或 URL 新建一图像
15-
imagecreatefromgif — 由文件或 URL 创建一个新图象。
16-
imagecreatefromjpeg — 由文件或 URL 创建一个新图象。
17-
imagecreatefrompng — 由文件或 URL 创建一个新图象。
18-
imagecreatefromstring — 从字符串中的图像流新建一图像
19-
imagecreatefromwbmp — 由文件或 URL 创建一个新图象。
20-
imagecreatefromwebp — 由文件或 URL 创建一个新图象。
21-
imagecreatefromxbm — 由文件或 URL 创建一个新图象。
22-
imagecreatefromxpm — 由文件或 URL 创建一个新图象。
23-
```
24-
25-
26-
27-
如果关闭allow_url_fopen, 那么这些函数是无法获取远程文件内容
28-
29-
30-
需要注意的一点
31-
32-
1. 出于安全性考虑, 此选项只能在php.ini中设置,无法直接在脚本中通过`ini_set('allow_url_fopen',1)` 这样来修改
33-
34-
原文:
35-
36-
`ini_set() cannot be used for allow_url_fopen and allow_url_include (note that they are marked "PHP_INI_SYSTEM")`
37-
38-
这里要明白php_ini_system的意思, 配置可被修改的设定范围通常有五种:
39-
```
40-
php_ini_user: 该配置选项可在用户的php脚本中修改
41-
42-
php_ini_perdir:该配置选项可在php.ini , .htaccess 或 httpd.conf 中设
43-
44-
php_ini_system: 该配置选项可在php.ini或httpd.conf中设置
45-
46-
php.ini_all: 该配置选项可在任何地方设置
47-
48-
php.ini only: 该配置选项可仅可在php.ini 中设置
49-
```
50-
51-
52-
在php.ini中这两个tag的范围为:
53-
54-
```
55-
allow_url_fopen "1" PHP_INI_SYSTEM 在 PHP <= 4.3.4 时是 PHP_INI_ALL。
56-
allow_url_include "0" PHP_INI_ALL 在 PHP 5 时是 PHP_INI_SYSTEM。 从 PHP 5.2.0 起可用。(貌似有误)
57-
```
58-
59-
参考: http://www.php.net/manual/zh/ini.list.php
60-
61-
62-
63-
## allow_url_include
64-
65-
该值如果设定为1,那么include,require,include_once,require_once 就可以把url当作文件名参数来远程包含了。
66-
67-
> Note:
68-
This setting requires allow_url_fopen to be on.
69-
70-
71-
### 支持的协议和封装协议
72-
73-
PHP 带有很多内置 URL 风格的封装协议,可用于类似 fopen()、 copy()、 file_exists() 和 filesize() 的文件系统函数。 除了这些封装协议,还能通过 stream_wrapper_register() 来注册自定义的封装协议。
74-
75-
```
76-
file:// — 访问本地文件系统
77-
http:// — 访问 HTTP(s) 网址
78-
ftp:// — 访问 FTP(s) URLs
79-
php:// — 访问各个输入/输出流(I/O streams)
80-
zlib:// — 压缩流
81-
data:// — 数据(RFC 2397)
82-
glob:// — 查找匹配的文件路径模式
83-
phar:// — PHP 归档
84-
ssh2:// — Secure Shell 2
85-
rar:// — RAR
86-
ogg:// — 音频流
87-
expect:// — 处理交互式的流
88-
```
89-
90-
91-
92-
93-
参考: http://www.php.net/manual/zh/filesystem.configuration.php
94-
1+
## allow_url_fopen
2+
3+
只要在php.ini 文件中激活了allow_url_fopen选项, 就可以在大多数需要用文件名作为参数的函数中适用httpftp的url来代替文件名.
4+
5+
比如: fopen,file_get_contents,copy,readfile等函数都可以接收一个stream作为文件名来读取stream里的文件内容, imagecreatefromxxx等图像处理函数也可以传入一个url图片作为文件名
6+
7+
但也有一些函数不能接收一个url作为文件名,比如include,include_once,require,require_once 函
8+
.
9+
10+
```
11+
imagecreatefrombmp — 由文件或 URL 创建一个新图象。
12+
imagecreatefromgd2 — 从 GD2 文件或 URL 新建一图像
13+
imagecreatefromgd2part — 从给定的 GD2 文件或 URL 中的部分新建一图像
14+
imagecreatefromgd — 从 GD 文件或 URL 新建一图像
15+
imagecreatefromgif — 由文件或 URL 创建一个新图象。
16+
imagecreatefromjpeg — 由文件或 URL 创建一个新图象。
17+
imagecreatefrompng — 由文件或 URL 创建一个新图象。
18+
imagecreatefromstring — 从字符串中的图像流新建一图像
19+
imagecreatefromwbmp — 由文件或 URL 创建一个新图象。
20+
imagecreatefromwebp — 由文件或 URL 创建一个新图象。
21+
imagecreatefromxbm — 由文件或 URL 创建一个新图象。
22+
imagecreatefromxpm — 由文件或 URL 创建一个新图象。
23+
```
24+
25+
26+
27+
如果关闭allow_url_fopen, 那么这些函数是无法获取远程文件内容
28+
29+
30+
需要注意的一点
31+
32+
1. 出于安全性考虑, 此选项只能在php.ini中设置,无法直接在脚本中通过`ini_set('allow_url_fopen',1)` 这样来修改
33+
34+
原文:
35+
36+
`ini_set() cannot be used for allow_url_fopen and allow_url_include (note that they are marked "PHP_INI_SYSTEM")`
37+
38+
这里要明白php_ini_system的意思, 配置可被修改的设定范围通常有五种:
39+
```
40+
php_ini_user: 该配置选项可在用户的php脚本中修改
41+
42+
php_ini_perdir:该配置选项可在php.ini , .htaccess 或 httpd.conf 中设
43+
44+
php_ini_system: 该配置选项可在php.ini或httpd.conf中设置
45+
46+
php.ini_all: 该配置选项可在任何地方设置
47+
48+
php.ini only: 该配置选项可仅可在php.ini 中设置
49+
```
50+
51+
52+
在php.ini中这两个tag的范围为:
53+
54+
```
55+
allow_url_fopen "1" PHP_INI_SYSTEM 在 PHP <= 4.3.4 时是 PHP_INI_ALL。
56+
allow_url_include "0" PHP_INI_ALL 在 PHP 5 时是 PHP_INI_SYSTEM。 从 PHP 5.2.0 起可用。(貌似有误)
57+
```
58+
59+
参考: http://www.php.net/manual/zh/ini.list.php
60+
61+
62+
63+
## allow_url_include
64+
65+
该值如果设定为1,那么include,require,include_once,require_once 就可以把url当作文件名参数来远程包含了。
66+
67+
> Note:
68+
This setting requires allow_url_fopen to be on.
69+
70+
71+
### 支持的协议和封装协议
72+
73+
PHP 带有很多内置 URL 风格的封装协议,可用于类似 fopen()、 copy()、 file_exists() 和 filesize() 的文件系统函数。 除了这些封装协议,还能通过 stream_wrapper_register() 来注册自定义的封装协议。
74+
75+
```
76+
file:// — 访问本地文件系统
77+
http:// — 访问 HTTP(s) 网址
78+
ftp:// — 访问 FTP(s) URLs
79+
php:// — 访问各个输入/输出流(I/O streams)
80+
zlib:// — 压缩流
81+
data:// — 数据(RFC 2397)
82+
glob:// — 查找匹配的文件路径模式
83+
phar:// — PHP 归档
84+
ssh2:// — Secure Shell 2
85+
rar:// — RAR
86+
ogg:// — 音频流
87+
expect:// — 处理交互式的流
88+
```
89+
90+
91+
92+
93+
参考: http://www.php.net/manual/zh/filesystem.configuration.php
94+

0 commit comments

Comments
 (0)