Skip to content

Commit fd9efa4

Browse files
author
罗江
committed
更新了特殊了文件名写入技巧
1 parent 53624ac commit fd9efa4

File tree

5 files changed

+91
-7
lines changed

5 files changed

+91
-7
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
- [ ] move_uploaded_file
1717
- [ ] str_shuffle 函数缺陷
1818
- [ ] unlink漏洞的原理和利用 http://wonderkun.cc/index.html/?cat=1&paged=3
19+
- [ ] mail函数命令执行
1920
- [ ] 其他
21+
22+
2023
## 一些资源
2124

2225
### 代码审计练习题
@@ -42,7 +45,7 @@ Xyntax师傅整理的乌云1000个PHP代码审计案例: https://github.com/Xy
4245

4346
乌云Drops文章备份: https://github.com/SecWiki/wooyun_articles
4447

45-
48+
php_code_audit_project: https://github.com/SukaraLin/php_code_audit_project
4649

4750
### 思维导图,资料集合
4851

open_basedir 研究.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Open_basedir 指令用来限制php只能访问哪些目录,所有php中相关文件读写的函数都会经过 `open_bsaedir` 的检查
1+
Open_basedir 指令用来限制php只能访问哪些目录,所有php中相关文件读写的函数都会经过 `open_bsaedir` 的检查(但不限制system的命令执行)
22

33
设置open_basedir 的方法,在linux下,不同的目录由`:` 分割
44

代码审计圈/other.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,15 @@ if(stripos($url,'.')){
55
}
66
```
77

8-
这段代码是存在漏洞的,因为当.出现在第一位时候返回值为0
8+
这段代码是存在漏洞的,因为当.出现在第一位时候返回值为0
9+
10+
11+
## 注入
12+
13+
preg_match("/\b(select|insert|update|delete)\b/i",$message)
14+
15+
然后使用/*!00000select*/ 来bypass 语义分析的绕过
16+
17+
> \b”匹配单词边界,不匹配任何字符
18+
19+
/*!*/ 只在mysql中有用,在别的数据库中这只是注释,但是在mysql,/*!select 1*/可以成功执行,在语句前可以加上5位数字,代表版本号,表示只有在大于该版本的mysql中不作为注释

代码审计圈/some-articles.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
[某商城文件上传漏洞与SQL注入漏洞 - 先知社区 ](http://xianzhi.aliyun.com/forum/topic/2203)
1313

1414

15+
### Tool
16+
https://t.zsxq.com/F2jEUzv

代码审计圈/特殊的文件写入技巧.md

+72-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
> move_uploaded_file, file_put_contents,copy 都存在的一种特殊文件名的写入技巧
1+
> move_uploaded_file, file_put_contents,copy,readfile,file,fopen都存在的一种特殊文件名的写入技巧
2+
3+
```
4+
$name = "index.php/.";
5+
$name1 = "xxx/../index.php/.";
6+
```
7+
对于这两种文件名,如果我们用is_file函数判断,发现都是false,即判断为不是文件或文件不存在。
8+
9+
但上面这些函数判断的时候会认为$name文件不存在,但$name1文件存在,从而可能导致一些特殊的文件读取或者文件写入的漏洞。
210

311
### file_put_contents()
412
```
@@ -20,7 +28,6 @@ paylaod:
2028
### move_uploaded_file()
2129

2230
0ctf 上面的一道题目
23-
2431
```
2532
case 'upload':
2633
if (!isset($_GET["name"]) || !isset($_FILES['file'])) {
@@ -45,7 +52,29 @@ pathinfo 函数可以用`/.` 来绕过,取出来的后缀为空
4552

4653
move_uploaded_file函数无法写入`index.php/.`文件,执行函数报错但可以写入`xxx/../index.php/.` 这样来绕过重写index.php
4754

48-
https://www.anquanke.com/post/id/103784
55+
56+
测试demo:
57+
```
58+
<?php
59+
$name = "index.php/."; //覆盖index.php失败,报warning
60+
$name1 = "xxx/../index.php/."; //覆盖index.php成功
61+
move_uploaded_file($_FILES['file']['tmp_name'], $name1);
62+
?>
63+
64+
<!DOCTYPE html>
65+
<html>
66+
<head>
67+
<title></title>
68+
</head>
69+
<body>
70+
<form action="#" method="post" enctype="multipart/form-data">
71+
<input type="file" name="file">
72+
<input type="submit">
73+
</form>
74+
</body>
75+
</html>
76+
```
77+
> 注意move_uploaded_file 会判断是否为post上传的文件。
4978
5079
### copy
5180
php.net上的解释
@@ -60,4 +89,43 @@ test.php
6089
$name = "./index.php";
6190
$dest = "xxx/../ttt.php/.";
6291
copy($name,$dest);
63-
```
92+
```
93+
94+
### readfile
95+
```
96+
$name = "index.php/.";
97+
$name1 = "xxx/../index.php/.";
98+
readfile($name);
99+
readfile($name1);
100+
101+
>>>
102+
PHP Warning: readfile(index.php/.): failed to open stream: No such file or directory in /mnt/hgfs/F/sublime/php/audit/4/file_put_content.php on line 8
103+
ffffffffffff
104+
```
105+
106+
### file函数
107+
同readfile函数
108+
```
109+
$name = "index.php/.";
110+
$name1 = "xxx/../index.php/.";
111+
file($name1); //$name 读文件失败
112+
113+
array(1) {
114+
[0]=>
115+
string(12) "ffffffffffff"
116+
}
117+
```
118+
119+
### fopen函数
120+
```
121+
$name = "index.php/.";
122+
$name1 = "xxx/../index.php/.";
123+
$f = fopen($name,'w');fwrite($f,'ffff'); //报错
124+
$f = fopen($name1,'w');fwrite($f,'ffffffffffff'); //写入成功
125+
```
126+
127+
## 简要分析
128+
通过之前大佬对file_put_contents函数的分析`http://wonderkun.cc/index.html/?paged=5`可知php源码的`_php_stream_open_wrapper_ex`函数存在问题,而上面这些函数都直接或间接调用了这个函数,导致了这种文件名可以识别成功。
129+
130+
> move_uploaded_file 和copy函数调用了`php_copy_file_ctx`函数,fopen调用了`php_if_fopen` 这两个函数内部是调用了`_php_stream_open_wrapper_ex`了的。
131+

0 commit comments

Comments
 (0)