通过php内核变量绕过,利用PHP内核变量绕过disable_functions(附完整代码)
0×01 概述
在https://rdot.org网站上面,有一篇俄语文章专门介绍了如何使用fopen/fread/fwrite函数来操纵内存文件/proc/self/mem。利用这种方法,人们就可以用system()函数的地址来替换GOT中open()函数的地址,这样的话,攻击者就可以通过readfile()函数来随心所欲地执行任意os命令了。
但是,这是需要一些前提条件的:
PHP 必须运行于PHP-CGI/PHP-FPM/CLI模式下。
POC只能运行于X86平台。
内核版本必须大于2.98。
open_basedir = off。
同时,它还会带来一些问题:
PHP的worker将会崩溃,因为GOT会被修改。
系统会变得不太稳定。
Good,不过这需要修改全局配置来打开“上帝模式”,即启用dl()并将extension_dir设为/tmp目录。
0×02 测试环境
ylbhz@ylbhz-Aspire-5750G:/tmp$ php -v
PHP 5.5.9-1ubuntu4.9 (cli) (built: Apr 17 2015 11:44:57) Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies ylbhz@ylbhz-Aspire-5750G:/tmp$ uname -a
Linux ylbhz-Aspire-5750G 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
0×03 为什么使用dl()函数?
这个php函数看起来于dlopen()有几分相似,可以方便地加载我们想要的其他代码。当然,我们无法使用intset()函数把enabledl设为true,以及把extension_dir设为其属下的目录。不过别急,我们要一步一步来。
0×04 相关内核变量结构
zendexecutor_globals的结构如下所示:
struct _zend_executor_globals { zval **return_value_ptr_ptr;
zval uninitialized_zval;
zval *uninitialized_zval_ptr;
zval error_zval;
zval *error_zval_ptr;
zend_ptr_stack arg_types_stack;
/\* symbol table cache *\/
HashTable *symtable_cache[SYMTABLE_CACHE_SIZE]; HashTable **symtable_cache_limit;
HashTable **symtable_cache_ptr;
zend_op **opline_ptr;
HashTable *active_symbol_table;
HashTable symbol_table; /\* main symbol table *\/
HashTable included_files; /\* files already included *\/
JMP_BUF *bailout;
int error_reporting; //value of error_reporting
int orig_error_reporting; int exit_status;
zend_op_array *active_op_array;
HashTable *function_table; /\* function symbol table *\/ HashTable *class_table; /\* class table *\/ HashTable*zend_constants; /\*constantstable*\/
zend_class_entry *scope;zend_class_entry *called_scope; /\* Scope of the calling class *\/ zval *This;
long precision;
int ticks_count; //10*8
zend_bool in_execution; //typedef unsigned char zend_bool; HashTable *in_autoload;
zend_function *autoload_func;
zend_bool full_tables_cleanup;
/\* for extended information support *\/ zend_bool no_extensions;
#ifdef ZEND_WIN32
zend_bool timed_out;
OSVERSIONINFOEX windows_version_info;
#endif
HashTable regular_list; HashTable persistent_list;
zend_vm_stack argument_stack;
int user_error_handler_error_reporting;
zval *user_error_handler;
zval *user_exception_handler;
zend_stack user_error_handlers_error_reporting; zend_ptr_stack user_error_handlers; zend_ptr_stack user_exception_handlers;
zend_error_handling_t error_handling; zend_class_entry *exception_class;
/\* timeout support *\/
int timeout_seconds; //value of set_time_limit
int lambda_count;
HashTable *ini_directives; //configuration comes from php.ini
HashTable *modified_ini_directives; zend_ini_entry *error_reporting_ini_entry;
zend_objects_store objects_store; zval *exception, *prev_exception; zend_op *opline_before_exception; zend_op exception_op[3];
struct _zend_execute_data *current_execute_data; struct _zend_module_entry *current_module; zend_property_info std_property_info;
zend_bool active;
zend_op *start_op;
void *saved_fpu_cw_ptr; #if XPFPA_HAVE_CW
XPFPA_CW_DATATYPE saved_fpu_cw; #endif
void *reserved[ZEND_MAX_RESERVED_RESOURCES]; };
请注意其中名为ini_directives的成员,其数据结构如下所示:
ypedef struct _hashtable { uint nTableSize;
uint nTableMask;
uint nNumOfElements;
ulong nNextFreeElement;
Bucket *pInternalPointer;
Bucket *pListHead;
Bucket *pListTail;
Bucket **arBuckets; //Item array dtor_func_t pDestructor; //pointer zend_bool persistent;
unsigned char nApplyCount; zend_bool bApplyProtection;
#if ZEND_DEBUG int inconsistent;
#endif
} HashTable;
所有的Bucket数据结构如下所示:
typedef struct bucket {
ulong h;
uint nKeyLength;
void *pData; //value of item void *pDataPtr;
struct bucket *pListNext; struct bucket *pListLast; struct bucket *pNext;
struct bucket *pLast;
const char *arKey;
} Bucket;
实际上,pData是指向_zend_ini_entry结构体的一个指针,该结构的定义如下所示。
struct _zend_ini_entry {
int module_number;
int modifiable; //whether it can be modified char *name; //name of option
通过php内核变量绕过,利用PHP内核变量绕过disable_functions(附完整代码)相关推荐
- Py之pygame:有趣好玩—利用pygame库实现鱼儿自动实时目标跟踪(附完整代码)
Py之pygame:有趣好玩-利用pygame库实现鱼儿自动实时目标跟踪(附完整代码) 目录 输出结果 实现代码 输出结果 实现代码 #Py之pygame:利用pygame库实现鱼儿自动实时目标跟踪i ...
- c++代码好玩_Py之pygame:有趣好玩—利用pygame库实现鱼儿自动实时目标跟踪(附完整代码)...
Py之pygame:有趣好玩-利用pygame库实现鱼儿自动实时目标跟踪(附完整代码) 目录 输出结果 实现代码 输出结果 实现代码 #Py之pygame:利用pygame库实现鱼儿自动实时目标跟 ...
- 利用OpenCV、Python和Ubidots构建行人计数器程序(附完整代码)
作者 | Jose Garcia 译者 | 吴振东 校对 | 张一豪.林亦霖,编辑 | 于腾凯 来源 | 数据派(ID:datapi) 导读:本文将利用OpenCV,Python和Ubidots来编写 ...
- linux命令行ps1变量_利用Shell中变量PS1定制Linux Shell命令主提示符
vim .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bas ...
- 利用pyecharts绘制新浪微博传播图(文末附完整代码地址)
文章目录 任务 来龙去脉 过程 绘图代码 绘图参数分析 结点参数格式 联系参数格式 类别参数格式 总览 获取转发关系 构造数据结构 集成json文件 代码地址 任务 延续之前的爬虫任务,最初同学提出的 ...
- 实战▍利用卷积神经网络(VGG19)实现火灾分类(附tensorflow代码及训练集)
作者| 帅虫哥 编辑|布袋熊 利用卷积神经网络(VGG19)实现火灾分类 先看两组数据: <新民周刊>:2018年6月到11月,美国加利福尼亚州的山火断断续续地烧了小半年,到入冬方才算 ...
- python firmata协议利用arduino操控麦克纳姆轮小车(附完整代码)
python firmata协议利用arduino操控麦克纳姆轮小车 前言 一.python中pyfirmata的环境 材料 二.使用步骤 1.小车的安装方式 我在这采用的是X型安装方式 总结 前言 ...
- 利用卷积神经网络(VGG19)实现火灾分类(附tensorflow代码及训练集)
源码地址 https://github.com/stephen-v/tensorflow_vgg_classify 1. VGG介绍 1.1. VGG模型结构 1.2. VGG19架构 2. 用Ten ...
- 91.video.ws index php_如何利用videojs实现视频列表循环播放(完整代码)
本篇文章给大家带来的内容是关于如何利用videojs实现视频列表循环播放(完整代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 庭审直播 .video-js { /* posit ...
最新文章
- vb.net 当前计算机用户,用VB写的一个组件,实现添加系统用户,并添加到指定组-.NET教程,VB.Net语言...
- python 画柱状图-Python 使用 matplotlib 画柱状图教程
- C语言时间管理小程序,写了一个时间管理的微信小程序
- 疫情退票引爆的潘多拉盒子,境外旅游商家濒临倒闭
- Hi3516A开发--RTC电路
- 音频处理十:( mp3 与wav 格式的相互转换)
- 【网络编程】之七、select聊天室
- Laravel 使用 Aliyun OSS 云存储
- Javaweb之session创建销毁问题
- 前端工程师做事的三重境界:我的进阶之路
- php怎么设置div圆角,不用图片的DIV圆角(兼容各浏览器)
- python dlib caffe人脸相似度_人脸检测学习笔记(数据集-DLIB人脸检测原理-DLIBOpenCV人脸检测方法及对比)...
- Dotnet WebAPI 项目启动提示 500.30 - ANCM In-Process Start Failure
- 域用户绑定计算机,域批量绑定用户帐户与计算机帐户
- 七夕节 看到许多停止更新的blog 莫名有点淡淡的忧桑
- [原创]酒好喝,好喝酒,喝好酒,酒喝好
- RTMPLive多流媒体协议转无插件直播协议(RTMP)解决方案
- rpgmvp文件转换图片_干货|如何快速将图片转换成CAD文件格式
- 04.声明式服务调用:Spring Cloud Feign(Greenwich.SR2)
- SEO基础知识:什么是网站结构,为什么重要?
热门文章
- C++11智能指针(unique_ptr、shared_ptr、weak_ptr)boost::scoped_ptr
- VUE调用WEB3.0实现代币查询,批量转账功能
- while 循环语法结构
- c# U盘禁用---守护进程(插入,拔出,卸载等操作)
- 【C语言/入门游戏】猜数字,关机指令游戏及go to语句
- 设计模式—策略模式(Strategy Pattern)
- 全球及中国3,4-二氯异噻唑-5-羧酸行业研究及十四五规划分析报告
- 【Spring】@Lazy注解
- 《机器人动力学与控制》第五章——速度运动学之机械臂的雅各比矩阵 5.0 导言
- dom4j解析xml错误-version 后面跟随的值必须是用引号括起来的字符串