3306 - Pentesting Mysql

RootedCON 是西班牙最重要的网络安全活动之一,也是欧洲最重要的之一。作为促进技术知识的使命,这个大会是技术和网络安全专业人士在各个领域的热点交流之地。
基本信息
MySQL可以被描述为一种开源关系数据库管理系统(RDBMS),可免费使用。它运行在**结构化查询语言(SQL)**上,可以管理和操作数据库。
默认端口: 3306
连接
本地
远程
外部枚举
一些枚举操作需要有效的凭据。
写入任何二进制数据
MySQL 命令
MySQL权限枚举
MySQL文件RCE
您可以在文档中查看每个权限的含义:https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html
MySQL客户端的任意文件读取
实际上,当您尝试将本地数据加载到表中时,MySQL或MariaDB服务器会要求客户端读取文件并发送内容。因此,如果您能够篡改一个MySQL客户端以连接到您自己的MySQL服务器,您就可以读取任意文件。 请注意,这是使用以下行为:
(注意"local"这个词) 因为没有"local",你可能会得到:
初始 PoC: https://github.com/allyshka/Rogue-MySql-Server 在这篇论文中,您可以看到对攻击的完整描述,甚至如何将其扩展到 RCE: https://paper.seebug.org/1113/ 在这里,您可以找到对攻击的概述: http://russiansecurity.expert/2016/04/20/mysql-connect-file-read/

RootedCON 是西班牙最重要的网络安全活动之一,也是欧洲最重要的之一。作为促进技术知识的使命,这个大会是技术和网络安全专业人士在各个领域的热点聚会。
POST
Mysql 用户
如果 mysql 以 root 用户身份运行,将会非常有趣:
MySQL 配置文件 mysqld.cnf 的危险设置
在 MySQL 服务的配置中,采用了各种设置来定义其操作和安全措施:
user设置用于指定 MySQL 服务将在哪个用户下执行。password用于建立与 MySQL 用户关联的密码。admin_address指定在管理网络接口上监听 TCP/IP 连接的 IP 地址。debug变量表示当前的调试配置,包括日志中的敏感信息。sql_warnings管理在单行 INSERT 语句出现警告时是否生成信息字符串,其中包含日志中的敏感数据。通过
secure_file_priv,数据导入和导出操作的范围受到限制以增强安全性。
通过库进行权限提升
如果 mysql 服务器以 root 用户身份运行(或其他更高特权用户),您可以让其执行命令。为此,您需要使用 用户定义函数。要创建用户定义函数,您将需要一个运行 mysql 的操作系统的 库。
可以在 sqlmap 和 metasploit 中找到要使用的恶意库,方法是执行 locate "*lib_mysqludf_sys*" 命令。.so 文件是 Linux 库,而 .dll 是 Windows 库,请选择您需要的那个。
如果您 没有 这些库,您可以 寻找它们,或者下载这个 Linux C 代码 并在易受攻击的 Linux 机器上 编译。
现在您已经有了库,作为特权用户(root?)登录到Mysql,并按照以下步骤操作:
Linux
Windows
从文件中提取MySQL凭据
在 /etc/mysql/debian.cnf 中,您可以找到用户 debian-sys-maint 的明文密码
您可以使用这些凭据登录到MySQL数据库。
在文件:/var/lib/mysql/mysql/user.MYD 中,您可以找到所有MySQL用户的哈希值(可以从数据库中的mysql.user中提取出来).
您可以执行以下操作提取它们:
启用日志记录
您可以在/etc/mysql/my.cnf文件中取消注释以下行以启用mysql查询的日志记录:

有用的文件
配置文件
windows *
config.ini
my.ini
windows\my.ini
winnt\my.ini
<InstDir>/mysql/data/
unix
my.cnf
/etc/my.cnf
/etc/mysql/my.cnf
/var/lib/mysql/my.cnf
~/.my.cnf
/etc/my.cnf
命令历史
~/.mysql.history
日志文件
connections.log
update.log
common.log
默认的MySQL数据库/表
ALL_PLUGINS APPLICABLE_ROLES CHARACTER_SETS CHECK_CONSTRAINTS COLLATIONS COLLATION_CHARACTER_SET_APPLICABILITY COLUMNS COLUMN_PRIVILEGES ENABLED_ROLES ENGINES EVENTS FILES GLOBAL_STATUS GLOBAL_VARIABLES KEY_COLUMN_USAGE KEY_CACHES OPTIMIZER_TRACE PARAMETERS PARTITIONS PLUGINS PROCESSLIST PROFILING REFERENTIAL_CONSTRAINTS ROUTINES SCHEMATA SCHEMA_PRIVILEGES SESSION_STATUS SESSION_VARIABLES STATISTICS SYSTEM_VARIABLES TABLES TABLESPACES TABLE_CONSTRAINTS TABLE_PRIVILEGES TRIGGERS USER_PRIVILEGES VIEWS INNODB_LOCKS INNODB_TRX INNODB_SYS_DATAFILES INNODB_FT_CONFIG INNODB_SYS_VIRTUAL INNODB_CMP INNODB_FT_BEING_DELETED INNODB_CMP_RESET INNODB_CMP_PER_INDEX INNODB_CMPMEM_RESET INNODB_FT_DELETED INNODB_BUFFER_PAGE_LRU INNODB_LOCK_WAITS INNODB_TEMP_TABLE_INFO INNODB_SYS_INDEXES INNODB_SYS_TABLES INNODB_SYS_FIELDS INNODB_CMP_PER_INDEX_RESET INNODB_BUFFER_PAGE INNODB_FT_DEFAULT_STOPWORD INNODB_FT_INDEX_TABLE INNODB_FT_INDEX_CACHE INNODB_SYS_TABLESPACES INNODB_METRICS INNODB_SYS_FOREIGN_COLS INNODB_CMPMEM INNODB_BUFFER_POOL_STATS INNODB_SYS_COLUMNS INNODB_SYS_FOREIGN INNODB_SYS_TABLESTATS GEOMETRY_COLUMNS SPATIAL_REF_SYS CLIENT_STATISTICS INDEX_STATISTICS USER_STATISTICS INNODB_MUTEXES TABLE_STATISTICS INNODB_TABLESPACES_ENCRYPTION user_variables INNODB_TABLESPACES_SCRUBBING INNODB_SYS_SEMAPHORE_WAITS
columns_priv column_stats db engine_cost event func general_log gtid_executed gtid_slave_pos help_category help_keyword help_relation help_topic host index_stats innodb_index_stats innodb_table_stats ndb_binlog_index plugin proc procs_priv proxies_priv roles_mapping server_cost servers slave_master_info slave_relay_log_info slave_worker_info slow_log tables_priv table_stats time_zone time_zone_leap_second time_zone_name time_zone_transition time_zone_transition_type transaction_registry user
accounts cond_instances events_stages_current events_stages_history events_stages_history_long events_stages_summary_by_account_by_event_name events_stages_summary_by_host_by_event_name events_stages_summary_by_thread_by_event_name events_stages_summary_by_user_by_event_name events_stages_summary_global_by_event_name events_statements_current events_statements_history events_statements_history_long events_statements_summary_by_account_by_event_name events_statements_summary_by_digest events_statements_summary_by_host_by_event_name events_statements_summary_by_program events_statements_summary_by_thread_by_event_name events_statements_summary_by_user_by_event_name events_statements_summary_global_by_event_name events_transactions_current events_transactions_history events_transactions_history_long events_transactions_summary_by_account_by_event_name events_transactions_summary_by_host_by_event_name events_transactions_summary_by_thread_by_event_name events_transactions_summary_by_user_by_event_name events_transactions_summary_global_by_event_name events_waits_current events_waits_history events_waits_history_long events_waits_summary_by_account_by_event_name events_waits_summary_by_host_by_event_name events_waits_summary_by_instance events_waits_summary_by_thread_by_event_name events_waits_summary_by_user_by_event_name events_waits_summary_global_by_event_name file_instances file_summary_by_event_name file_summary_by_instance global_status global_variables host_cache hosts memory_summary_by_account_by_event_name memory_summary_by_host_by_event_name memory_summary_by_thread_by_event_name memory_summary_by_user_by_event_name memory_summary_global_by_event_name metadata_locks mutex_instances objects_summary_global_by_type performance_timers prepared_statements_instances replication_applier_configuration replication_applier_status replication_applier_status_by_coordinator replication_applier_status_by_worker replication_connection_configuration replication_connection_status replication_group_member_stats replication_group_members rwlock_instances session_account_connect_attrs session_connect_attrs session_status session_variables setup_actors setup_consumers setup_instruments setup_objects setup_timers socket_instances socket_summary_by_event_name socket_summary_by_instance status_by_account status_by_host status_by_thread status_by_user table_handles table_io_waits_summary_by_index_usage table_io_waits_summary_by_table table_lock_waits_summary_by_table threads user_variables_by_thread users variables_by_thread
host_summary host_summary_by_file_io host_summary_by_file_io_type host_summary_by_stages host_summary_by_statement_latency host_summary_by_statement_type innodb_buffer_stats_by_schema innodb_buffer_stats_by_table innodb_lock_waits io_by_thread_by_latency io_global_by_file_by_bytes io_global_by_file_by_latency io_global_by_wait_by_bytes io_global_by_wait_by_latency latest_file_io memory_by_host_by_current_bytes memory_by_thread_by_current_bytes memory_by_user_by_current_bytes memory_global_by_current_bytes memory_global_total metrics processlist ps_check_lost_instrumentation schema_auto_increment_columns schema_index_statistics schema_object_overview schema_redundant_indexes schema_table_lock_waits schema_table_statistics schema_table_statistics_with_buffer schema_tables_with_full_table_scans schema_unused_indexes session session_ssl_status statement_analysis statements_with_errors_or_warnings statements_with_full_table_scans statements_with_runtimes_in_95th_percentile statements_with_sorting statements_with_temp_tables sys_config user_summary user_summary_by_file_io user_summary_by_file_io_type user_summary_by_stages user_summary_by_statement_latency user_summary_by_statement_type version wait_classes_global_by_avg_latency wait_classes_global_by_latency waits_by_host_by_latency waits_by_user_by_latency waits_global_by_latency x$host_summary x$host_summary_by_file_io x$host_summary_by_file_io_type x$host_summary_by_stages x$host_summary_by_statement_latency x$host_summary_by_statement_type x$innodb_buffer_stats_by_schema x$innodb_buffer_stats_by_table x$innodb_lock_waits x$io_by_thread_by_latency x$io_global_by_file_by_bytes x$io_global_by_file_by_latency x$io_global_by_wait_by_bytes x$io_global_by_wait_by_latency x$latest_file_io x$memory_by_host_by_current_bytes x$memory_by_thread_by_current_bytes x$memory_by_user_by_current_bytes x$memory_global_by_current_bytes x$memory_global_total x$processlist x$ps_digest_95th_percentile_by_avg_us x$ps_digest_avg_latency_distribution x$ps_schema_table_statistics_io x$schema_flattened_keys x$schema_index_statistics x$schema_table_lock_waits x$schema_table_statistics x$schema_table_statistics_with_buffer x$schema_tables_with_full_table_scans x$session x$statement_analysis x$statements_with_errors_or_warnings x$statements_with_full_table_scans x$statements_with_runtimes_in_95th_percentile x$statements_with_sorting x$statements_with_temp_tables x$user_summary x$user_summary_by_file_io x$user_summary_by_file_io_type x$user_summary_by_stages x$user_summary_by_statement_latency x$user_summary_by_statement_type x$wait_classes_global_by_avg_latency x$wait_classes_global_by_latency x$waits_by_host_by_latency x$waits_by_user_by_latency x$waits_global_by_latency
HackTricks自动命令

RootedCON 是西班牙最重要的网络安全活动之一,也是欧洲最重要的活动之一。以促进技术知识为使命,这个大会是技术和网络安全专业人士在各个领域的热点交流会。
最后更新于
