Redis - Port 6379

Basic info

What is Redis?

Redis is an in-memory data structure store that supports various data types including:

  • Strings - Simple key-value pairs

  • Lists - Ordered collections of strings

  • Sets - Unordered collections of unique strings

  • Sorted Sets - Sets with scores for ordering

  • Hashes - Maps between string fields and string values

  • Bitmaps - Bit-level operations on strings

  • HyperLogLogs - Probabilistic data structures

  • Streams - Append-only log data structures

Redis Architecture

Redis Communication Protocol

Redis uses a text-based protocol called RESP (Redis Serialization Protocol). This means you can communicate with Redis using simple text commands over a TCP connection, making it easy to test with tools like netcat or telnet.

Default Port

Default Port: 6379

Note: Redis can be configured to use TLS/SSL encryption, though this is uncommon in practice.

Authentication Models

Redis supports several authentication configurations:

  1. No Authentication (default, extremely dangerous)

  2. Password Only - Single password, username is "default"

  3. Username + Password - ACL-based authentication (Redis 6.0+)

  4. TLS Client Certificates - Certificate-based authentication

Databases in Redis

Unlike traditional databases, Redis uses numbered databases (0-15 by default):

  • Database numbers start from 0

  • Default database is 0

  • Switch between databases using SELECT <number>

  • Each database is logically separated

Reconnaissance & Enumeration

Port Scanning

Basic Nmap Scan

Sample Output:

Automated Enumeration

Using Nmap Scripts

Using Metasploit

Manual Enumeration

Using netcat

Using redis-cli

Shodan Queries

Find exposed Redis servers:

Authentication Testing

Check Authentication Requirements

Password Brute Force

Using Nmap

Using Metasploit

Using Hydra

Using Custom Script

Authentication

Authenticate with Password

Check Authentication Status

Enumeration (Authenticated)

Get Server Information

INFO Command

Key Information to Look For:

Configuration Enumeration

Client Enumeration

Monitor Commands

Real-time Command Monitoring

Slow Query Log

Database Enumeration

List Databases

Enumerate Keys

Get Key Information

Extract Key Values

Dumping the Database

Manual Dump

Using redis-dump (Node.js)

Using redis-utils (Python)

Using RDB Tools

Exploitation Techniques

1. Webshell Upload (PHP)

Requirements:

  • Write access to web directory

  • Knowledge of web root path

  • PHP execution enabled

Exploitation Steps:

Advanced Webshell:

Common Web Root Paths:

Cleanup:

2. Template Engine Injection

Requirements:

  • Write access to template directory

  • Template engine that executes code (e.g., Nunjucks, Jinja2, Twig)

Example: Nunjucks Reverse Shell

Other Template Engines:

Jinja2 (Python)

Twig (PHP)

Note: Many template engines cache templates, so you may need to:

  1. Trigger a cache clear

  2. Restart the application

  3. DoS the application to force a restart

3. SSH Key Injection

Requirements:

  • Redis running as user with home directory

  • Write access to user's .ssh directory

  • SSH service enabled

Exploitation Steps:

Alternative Method (for other users):

Automated Tool:

Another Automated Tool:

4. Crontab Injection

Requirements:

  • Write access to cron directories

  • Cron service enabled

  • Redis running as root or user with crontab

Exploitation Steps:

Advanced Cron Payload:

Python Reverse Shell (more reliable):

5. Redis Module Loading (RCE)

Requirements:

  • MODULE LOAD command not disabled

  • Ability to upload .so file

  • Redis 4.0+

Method 1: Using RedisModules-ExecuteCommand

Method 2: Using redis-rogue-server

Creating Custom Modules:

Compile:

6. Master-Slave Replication Abuse

Concept: Configure victim Redis as a slave of attacker-controlled master

Setup Attack:

Advanced Attack: Module Loading via Replication

7. Lua Sandbox Escape

Background: Redis uses Lua for scripting (EVAL command)

CVE-2022-0543: Lua Sandbox Escape

Automated Exploit:

8. Recent Lua CVEs (2025)

CVE-2025-49844: GC-Triggered UAF in Lua Parser

CVE-2025-46817: Integer Overflow in unpack

CVE-2025-46818: Metatable Poisoning

9. SSRF to Redis

Scenario: You found an SSRF vulnerability that can reach internal Redis

Basic SSRF Attack:

Gitlab SSRF + CRLF to RCE (CVE-2018-19571)

Gopher Protocol Abuse:

SSRF Automation Tool:

Post-Exploitation

Data Exfiltration

Extract Sensitive Data

Extract Session Data

Extract User Credentials

Persistence

Backdoor User Creation

Cron Persistence

Redis Config Backdoor

Module Persistence

Lateral Movement

Enumerate Network from Redis

Dump Redis Master-Slave Configuration

Search for Other Redis Instances

Defense & Hardening

Secure Configuration

Disable Dangerous Commands

Enable Authentication

Bind to Localhost Only

Disable Lua Scripting (if not needed)

Run as Unprivileged User

Disable Persistence (if caching only)

Enable TLS

Set Resource Limits

Network Security

Firewall Rules

Use VPN or SSH Tunnel

Monitoring & Detection

Enable Logging

Monitor Commands

Audit Logs

Intrusion Detection

File Integrity Monitoring

Regular Security Tasks

Tools & Scripts

Essential Tools

redis-cli - Official Redis CLI

redis-dump - Dump Redis database

redis-utils - Python utilities for Redis

nmap - Network scanning

Metasploit - Exploitation framework

redis-rogue-server - Automated RCE tool

Custom Scripts

Redis Enumeration Script

Automated Exploitation Script

Cheat Sheet

Quick Reference

Important Configs

Common Paths

Conclusion

Redis is a powerful in-memory data store, but when misconfigured, it becomes a critical security vulnerability. As demonstrated in this guide, Redis can be exploited in numerous ways:

Key Takeaways:

  1. Never expose Redis to the internet without proper authentication

  2. Always set a strong password (or use ACLs in Redis 6+)

  3. Bind to localhost only unless remote access is required

  4. Disable dangerous commands like CONFIG, MODULE, EVAL

  5. Run Redis as unprivileged user to limit impact

  6. Monitor Redis logs for suspicious activity

  7. Keep Redis updated to patch known vulnerabilities

  8. Use TLS for encrypted connections

  9. Regular backups to prevent data loss

  10. Test your security regularly with the techniques in this guide

Common Attack Vectors:

  • Unauthenticated access leading to data theft

  • Webshell upload via file write

  • SSH key injection for remote access

  • Cron job injection for persistence

  • Module loading for direct RCE

  • Lua sandbox escape (CVE-2022-0543, CVE-2025-*)

  • SSRF to internal Redis instances

  • Master-slave replication abuse

Remember to only use these techniques during authorized penetration testing engagements. Unauthorized access to computer systems is illegal.

Additional Resources

circle-check

Last updated