Home Database Stores
Post
Cancel

Database Stores

Overview

Relational and Non-Relational databases are a valuable target for attackers, with sensitive information often stored within the database tables such as Personally Identifiable Information (PII) and credentials. There are also several vulnerabilities and misconfigurations that can be exploited by an attacker to gain remote shell access to the host running the platform, privilege escalation and malicious program execution.

Relational Databases

Structured Query Language (SQL) is a language specifically designed for managing structured data within relational database systems and is commonly used as backend storage for many software and web applications. See the post SQL Overview for more background information.

There are multiple relational database management systems (RDBMS), some of the most commonly encountered, their default ports and tool applicability are listed in the below table:

ServicePortNmapMSFHydraSQLmapOther
MSSQL1433-1434Crackmapexec
Impacket
MySQL/MariaDB3306 
Oracle1521Oscanner
ODAT
PostgreSQL5432 

SQL Injection

See CAPEC 66 - SQL Injection for verbose information and steps involved in conducting a SQL Injection attack.

Non-Relational Databases

Non-Relational databases store data in a different format than Relational databases that rely on SQL. Non-Relational databases are often categorized as Not Only SQL (NoSQL) and are generally defined as a database that does not use tables, fields, and columns that structured data required. There are a few different catagories of Non-Relational databases such as; Document, Key-Value, Graph, File Systems, etc.

As with the various RDBMS solutions, there are a number of Non-Relational systems, some of the most commonly encountered, their default ports and tool applicability are listed in the below table. Other solutions which aren’t typically listed as NoSQL databases are added here also, such as Redis and Memcached which are memory storage solutions and Hadoop, NFS, AFP, and iSCSI which are file systems.

ServicePortNmapMSFHydraOther
AFP548 
Cassandra9042  
Hadoop HDFS50070
50075
50090
   
Hadoop Mapreduce50030
50060
   
Memcached11211 
MongoDB27017 
NFS2049 NFSshell
Redis6579 
iSCSI3260  Open-iSCSI
iSCSIadm

MSSQL

Microsoft SQL Server (MSSQL) often exposes two ports:

  1. 1433 - Used by clients to interact with the database
  2. 1434 - Used to list available instances (a Server can run multiple instances on high ports)

Default credentials are often set to sa:sa, which sa equivalent to Sysadmin.

MSSQL Scanning and Enumeration

ToolScript/ModuleAuthMITRE ATT&CK TacticCommand
MSFmssql_enum?Reconnaissance 
MSFmssql_ping?Reconnaissance 
Nmapms-sql-infoNReconnaissancesudo nmap -A -p 1433,1434 -n 10.10.10.10

MSSQL Exploitation

ToolScript/ModuleAuthMITRE ATT&CK TacticCommand
MSFmssql_escalate_dbowner
mssql_escalate_escalate_as
YPrivilege Escalation 
MSFmssql_hashdumpYCredential Access 
MSFmssql_idfYDiscovery 
MSFmssql_local_auth_bypassYPersistence
Privilege Escalation
 
MSFmssql_ntlm_stealerYCredential Access 
MSFmssql_payloadYExecution 
MSFmssql_sql_fileYExecution 

MSSQL Database Interaction

the mssqlclient.py python tool that comes pre-installed on Kali Linux as part of the Impacket suite, can be used to interact with a remote MSSQL server.

1
2
3
4
5
6
7
8
9
10
# Connecting to a Remote MSSQL Server (Requires Database selection, Domain, Username, Password, and IP address entry.)
mssqlclient.py -db %DATABASE% -windows-auth %DOMAIN%/%USERNAME%:%PASSWORD%@%IP%

# Database Enumeration
SELECT * from %TABLE% # Show all stored data under a select table
SELECT * FROM %DATABASE%.INFORMATION_SCHEMA.TABLES; # Show tables under a select database

# Exploitation
CREATE LOGIN &USERNAME% WITH PASSWORD = '&PASSWORD%' # Create a new user and assign sysadmin privileges
sp_addsrvrolemember '%USERNAME%', 'sysadmin'

MySQL/MariaDB

MySQL is commonly found running on either windows or linux servers. The original MySQL solution was bought by Oracle, the previous open-source variant was forked and is referred to as MariaDB.

Default credentials are often set to root:, within some instances as per the example not requiring a password.

MySQL/MariaDB Scanning and Enumeration

ToolScript/ModuleAuthMITRE ATT&CK TacticCommand
MSFmysql_enumYReconnaissance 
Nmapmysql-infoNReconnaissancesudo nmap -A -p 3306 -n 10.10.10.10

MySQL/MariaDB Exploitation

MSSQL Database Interaction

The MySQL command line tool can be used to interface with a remote MySQL/MariaDB instance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Accessing a Remote Server
mysql -h 10.10.10.10 -u root
mysql -h 10.10.10.10 -u root -e 'show databases;'

# Database Interaction
show databases; # Shows all available databases
use %DATABASE%; # Enter a select database
show tables; # Show tables under a select database
describe %TABLE%; # Show details of a select table
select * from %TABLE% # Show all stored data under a select table

# Exploitation
\! sh # Drop into a shell
mysql -h 10.10.10.10 -u root --password=%PASSWORD% -e "SELECT * FROM mysql.user;" # Credential Dumping
create user test identified by 'test'; # Create a new user and assign admin privileges
grant SELECT,CREATE,DROP,UPDATE,DELETE,INSERT on *.* to mysql identified by 'mysql' WITH GRANT OPTION;
This post is licensed under CC BY 4.0 by the author.