mysql-enum

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| books              |
| data               |
| mysql              |
| password           |
| performance_schema |
| secret             |
| store              |
| upload             |
| vendors            |
| videos             |
+--------------------+
11 rows in set (0.001 sec)
circle-info

There are 11 databases on the server.

MySQL [(none)]> use books;
MySQL [books]> select count(*) from authors;
+----------+
| count(*) |
+----------+
|       10 |
+----------+
1 row in set (0.000 sec)
circle-info

There are 10 records in table authors inside the books database.


Metasploit Enum

  • Use the mysql_schemadump metasploit module to dump the schema of all databases: https://www.rapid7.com/db/modules/auxiliary/scanner/mysql/mysql_schemadump/

1

Run msfconsole

2

Load module and configure

Example output (schema dump):

  • Use the mysql_writable_dirs metasploit module to enumerate writable directories: https://www.rapid7.com/db/modules/auxiliary/scanner/mysql/mysql_writable_dirs/

1

Run msfconsole

2

Load module and configure

Example output (writable dirs scan):

circle-info

2 directories are writable: /tmp and /root

  • Use the mysql_file_enum metasploit module to enumerate readable files: https://www.rapid7.com/db/modules/auxiliary/scanner/mysql/mysql_file_enum/

1

Run msfconsole

2

Load module and configure

Example output (readable files):

circle-info

10 sensitive files are readable: /etc/passwd, /etc/shadow, /etc/group, /etc/mysql/my.cn, /etc/hosts, /etc/hosts.allow, /etc/hosts.deny, /etc/issue, /etc/fstab, /proc/version

  • Use the mysql_hashdump metasploit module to list database users and their password hashes: https://www.rapid7.com/db/modules/auxiliary/scanner/mysql/mysql_hashdump/

1

Run msfconsole

2

Load module and configure

Example output (hashdump):

circle-info

8 db users are present:

  • debian-sys-maint:*CDDA79A15EF590ED57BB5933ECD27364809EE90D

  • root:

  • filetest:*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B

  • ultra:*827EC562775DC9CE458689D36687DCED320F34B0

  • guest:*17FD2DDCC01E0E66405FB1BA16F033188D18F646

  • sigver:*027ADC92DD1A83351C64ABCD8BD4BA16EEDA0AB0

  • udadmin:*E6DEAD2645D88071D28F004A209691AC60A72AC9

  • sysadmin:*46CFC7938B60837F46B610A2D10C248874555C14

Example of checking file read via mysql client:

chevron-rightReveal Flag — System password hash for user “root”hashtag

S1eBFuRRxwD7qEcUIjHxV7Rkj9OXaIGbIOiHsjPZF2uGmGBjRQ3rrQY3/6M.fWHRBHRntsKhgqnClY2.KC.vA/


Nmap Enum

  • Use nmap mysql-empty-password script to check MySQL with an empty password for root and anonymous users: https://nmap.org/nsedoc/scripts/mysql-empty-password.html

Example output:

circle-info

root and anonymous users login is permitted without password.

  • Use nmap mysql-info script to check MySQL server information: https://nmap.org/nsedoc/scripts/mysql-info.html

Example output:

circle-info

InteractiveClient is supported on the server.

  • Use nmap mysql-users script to list all MySQL db users: https://nmap.org/nsedoc/scripts/mysql-users.html

Example output:

circle-info

DB users are: filetest, root, debian-sys-maint, guest, sigver, sysadmin, udadmin, ultra

  • Use nmap mysql-databases script to list all MySQL databases: https://nmap.org/nsedoc/scripts/mysql-databases.html

Example output:

circle-info

MySQL databases are information_schema, books, data, mysql, password, performance_schema, secret, store, upload, vendors, videos

  • Use nmap mysql-variables script to show MySQL variables: https://nmap.org/nsedoc/scripts/mysql-variables.html

circle-info

The data directory used by MySQL server is datadir: var/lib/mysql/

  • Use nmap mysql-audit script to audit MySQL server security configuration: https://nmap.org/nsedoc/scripts/mysql-audit.html

Example output summary:

circle-info

No File privileges can be granted to non admin users.

  • Use nmap mysql-dump-hashes script to dump password hashes: https://nmap.org/nsedoc/scripts/mysql-dump-hashes.html

Example output:

circle-info

Users hashes are:

  • debian-sys-maint:*CDDA79A15EF590ED57BB5933ECD27364809EE90D

  • filetest:*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B

  • ultra:*827EC562775DC9CE458689D36687DCED320F34B0

  • guest:*17FD2DDCC01E0E66405FB1BA16F033188D18F646

  • sigver:*027ADC92DD1A83351C64ABCD8BD4BA16EEDA0AB0

  • udadmin:*E6DEAD2645D88071D28F004A209691AC60A72AC9

  • sysadmin:*46CFC7938B60837F46B610A2D10C248874555C14

  • Use nmap mysql-query script to run a query against a MySQL db: https://nmap.org/nsedoc/scripts/mysql-query.html

Example output:


Lab 2

MySQL Recon: Dictionary Attack — https://attackdefense.com/challengedetails?cid=532

  • Target IP: 10.4.16.17

  • MySQL server dictionary attack.

Example reconnaissance:

Metasploit (bruteforce)

  • Use the mysql_login metasploit module: https://www.rapid7.com/db/modules/auxiliary/scanner/mysql/mysql_login/

1

Run msfconsole

2

Load module and configure

Example output:

circle-info

Reveal Flag — MySQL server "root" password is: catalina

Hydra (bruteforce)

  • Use hydra with the same unix_passwords list:

Example output:


Lab 3 - nmap (MSSQL)

Recon: MSSQL: Nmap Scripts — https://attackdefense.com/challengedetails?cid=2313

  • Target IP: 10.4.21.27

  • Windows MSSQL server enumeration with nmap

Basic host scan:

Service scripts:

Example output:

  • Use nmap --script ms-sql-info -p1433 10.4.21.27 and nmap --script ms-sql-ntlm-info --script-args mssql.instance-port=1433 -p1433 10.4.21.27 as needed.

circle-info

Server is Microsoft SQL Server 2019

  • Enumerate MSSQL users and passwords with ms-sql-brute:

Example output:

circle-info

Valid MSSQL users and passwords:

  • dbadmin:bubbles1

  • admin:anamaria

  • auditor:jasmine1

  • Check empty password users:

circle-info

sa user is enabled with empty password.

  • Extract syslogins:

  • Dump MSSQL user hashes:

Example hashes (summary):

  • Execute a command using ms-sql-xp-cmdshell (spawns a Windows command shell): https://nmap.org/nsedoc/scripts/ms-sql-xp-cmdshell.html

Reveal Flag:

1d1803570245aa620446518b2154f324


Lab 4 - Metasploit (MSSQL)

Recon: MSSQL: Metasploit — https://attackdefense.com/challengedetails?cid=2314

  • Target IP: 10.4.23.176

  • Windows MSSQL server enumeration with metasploit

Initial nmap scan:

Service info:

circle-info

Server is Microsoft SQL Server 2019

  • Use Metasploit to brute-force MSSQL logins:

1

Run msfconsole

2

Load module and configure

Example output:

circle-info

sa user has empty password.

Other users and passwords:

  • dbadmin:anamaria

  • auditor:nikita

  • Enumerate MSSQL configuration, logins and users:

Example output (enumeration):

  • Execute commands via metasploit module:

Example output:

  • Enumerate domain accounts:


Last updated 3 hours ago

Last updated