MySQL默认库

image-20201101161119257

information_schema

在MySQL中,把 information_schema 看作是一个数据库,确切说是信息数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,字段类型与访问权 限等。

查询数据库、表名、字段等信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 爆所有用户
select group_concat(user) from mysql.user;

# 爆所有数据库
select group_concat(SCHEMA_NAME) from information_schema.schemata;

# 爆当前数据库的表名
select group_concat(table_name) from information_schema.tables where table_schema=database();

# 表中有主码约束,非空约束等完整性约束条件的情况下 爆表名
select group_concat(table_name) from information_schema.table_constraints where table_schema=database();

# 爆字段名(表名是 users,加引号或十六进制编码)
select group_concat(column_name) from information_schema.columns where table_name='users';
select group_concat(column_name) from information_schema.columns where table_name=0x7573657273;

# 爆字段内容
select first_name,password from users;

mysql

这个是mysql的核心数据库,类似于sql server中的master表,主要负责存储数据库的用户、权限设置、关键字等mysql自己需要使用的控制和管理信息。不可以删除,如果对mysql不是很了解,也不要轻易修改这个数据库里面的表信息。

performance_schema

MySQL 5.5开始新增一个数据库:PERFORMANCE_SCHEMA,主要用于收集数据库服务器性能参数。并且库里表的存储引擎PERFORMANCE_SCHEMA,而用户是不能创建存储引擎为PERFORMANCE_SCHEMA的表。

sys

Sys库所有的数据源来自:performance_schema。目标是把performance_schema的把复杂度降低,让DBA能更好的阅读这个库里的内容,让DBA更快的了解DB的运行情况。(详情

利用数据库的功能读写文件

条件

(1)数据库允许导入导出(secure_file_priv不为NULL)

查看数据库是否开启导入导出:

1
show global variables like 'secure_file_priv';

image-20201113225818984

说明:secure_file_priv是用来限制load_file、load data和select outfile操作哪个指定目录。

img

我这里默认是 /var/lib/mysql-files ,可以通过以下方式修改:

1
vi /etc/mysql/mysql.conf.d/mysqld.cnf

在最后添加

1
secure file priv=''

重启mysql服务:

1
service mysql restart

(2)当前用户的文件操作权限(File_priv:Y)

​ 查看当前用户是否具有文件读写权限:

1
select File_priv from mysql.user where user='root' and host ='localhost';

image-20201113230842289

读文件(mysql导入数据)

(1)load_file()

(2)load data infile()

(3)system cat

load_file()和load data infile读取文件的方法为:新建一个表,读取文件为字符串形式插入表中,然后读出表中数据。

system cat后加文件路径。

image-20201113233615626

image-20201113234015997

image-20201113234210769

写文件 (mysql导出数据)

select ‘ ‘ into outfile

如:

image-20201113234946913

image-20201113235046444

image-20201114184126130

hash相关

查询用户hash

目标:dvwa的admin用户的password

image-20201115110152189

破解

image-20201115110328511

使用 hashcat 来对获取的 hash 进行暴力破解

下载hashcat

在hashcat文件夹新建

hash.txt(保存要破解的hash值)

password.txt(保存密码字典)

使用cmd进入hashcat所在目录,用以下命令进行破解:

1
hashcat -a 0 -m 0 hash.txt password.txt

-a 0 代表使用字典破解模式

-m 0 代表Hash Type为md5

image-20201115113529889

结果:

image-20201115113724632

破解记录在hashcat.potfile文件中可查

或可直接使用字典进行破解

1
hashcat -a 0 5f4dcc3b5aa765d61d8327deb882cf99 password.txt

image-20201115114500987

结果一致。

参考资料

[1] 安装初始化mysql后,默认几个库介绍

[2] SQL注入读写文件

[3] 数据库系统表相关学习

[4] hashcat详细使用教程