githubEdit

MySQL

Port 3306

1) Nmap scan

nmap -sV -p 3306 --script "mysql-audit,mysql-databases,mysql-dump-hashes,mysql-empty-password,mysql-enum,mysql-info,mysql-query,mysql-users,mysql-variables,mysql-vuln-cve2012-2122" IP

2) Netexec

netexec mysql -d DATABASE -u USERNAME -p PASSWORD -x "SHOW DATABASES;" IP

3) Brute force

hydra -l USER -P PASSWORD_LIST -s 3306 IP mysql

4) Login

mysql -h IP -u USER -p DATABASE

Skip SSL errors

mysql -h IP -u USER -p --skip_ssl

5) Database Usage

SHOW DATABASES;

USE <database_name>;

SHOW TABLES;

DESCRIBE <table_name>;

SELECT * FROM <table_name>;

6) Exploitation

Database enumeration

Privilege Escalation

7) Check System permissions of the DB User

1. Copy an already existing file from Windows to another location

2. Check permissions of the new written file

3. An output like the one below indicates that the file was written with admin privileges, therefore the DB user has admin privilege (consider WerTrigger exploit for escalation).

8) Command execution via User-Defined Functions (UDFs)

In MySQL, command execution can be achieved via User-Defined Functions (UDFs), if applicable. Here's an example of how to upload a malicious shared object file to gain shell access:

1. Upload UDF library

2. Create the UDF to execute system commands

3. Execute commands

4. Reverse shell

8.1) Compile your own .so for UDF

lib_mysqludf_sys.c

Compile the .so file into a shared object (.so)

Last updated