Páginas

quinta-feira, 14 de maio de 2026

Hardening Redis Against Memory Corruption and Lua Sandbox Escapes

Mageia
 

Stop chasing Redis CVEs. Master Linux security with a pro's approach. Learn to check for memory corruption & Lua flaws, apply fixes via script, and lock down your server with iptables & ACLs. Includes an automation script and a pro-level book.

Every few months, a fresh Redis vulnerability shows up. The pattern is always the same – memory corruption in RESTORE, a use-after-free in the Lua engine, or an ACL bypass. In May 2026, Mageia users saw this firsthand with a batch of RCE flaws (MGASA-2026-0134), but the real lesson isn’t about a specific date. It’s about building a repeatable process to check, patch, and lock down Redis, no matter what CVE drops next.

This guide gives you that process. You’ll get actual commands for Mageia, a Bash script to automate the fix, and fallback mitigations using iptables and AppArmor.

How to Check if Your Mageia Redis Is Vulnerable

Run these commands to see if your Redis version is affected by memory corruption issues in RESTORE or Lua engine flaws. Vulnerable versions generally include Redis up to 7.2.13.

bash
# Check installed Redis version
rpm -q redis

# Verify the package came from Mageia updates
rpm -qi redis | grep Vendor

# Test if Lua scripting is enabled (a common attack vector)
redis-cli EVAL "return 1" 0

# Check if RESTORE command is available (used in buffer overflow exploits)
redis-cli COMMAND INFO RESTORE | head -1
If the version is below 7.2.14, you need the update. If you see EVAL returning 1, Lua is active and you’re in scope.


Automation Script to Apply the Fix

Save this as update-redis.sh and run it as root. It patches Redis, restarts the service, and validates the installation.

bash
#!/bin/bash
# Mageia Redis security update script - for MGASA-2026-0134 and related flaws
# Run as: sudo bash update-redis.sh

set -e
echo "[+] Updating package database..."
urpmi.update -a

echo "[+] Installing latest Redis packages..."
urpmi redis --auto

echo "[+] Restarting Redis service..."
systemctl restart redis

echo "[+] Verifying patched version..."
redis_version=$(redis-server --version | awk '{print $3}')
echo "Current Redis version: $redis_version"

if [[ "$redis_version" > "7.2.14" ]]; then
    echo "[✓] Update successful. Redis is patched."
else
    echo "[!] WARNING: Redis may still be vulnerable. Check manually."
fi

echo "[+] Testing basic Redis functionality..."
redis-cli PING

This script solves one specific CVE. But CVEs never stop coming. To learn how to write your own security tools, analyze new threats, and build automation for any vulnerability, you need Practical Binary Analysis: Build Your Own Linux Tools for Binary Instrumentation, Analysis, and Disassembly. This book solves all the CVEs you haven’t seen yet.


This script solves one specific CVE. But CVEs never stop coming. To learn how to write your own security tools, analyze new threats, and build automation for any vulnerability, you need Practical Binary Analysis: Build Your Own Linux Tools for Binary Instrumentation, Analysis, and Disassembly. This book solves all the CVEs you haven’t seen yet. (adversitng) - > https://amzn.to/4dGoavs 

Note: I earn a comission with you make a purchase.


Alternative Mitigation (If You Can’t Update Right Now)

Sometimes patching isn’t possible – legacy app dependencies, frozen production windows, or just bureaucratic delays. Here’s how to lock down Redis without changing the binary.

Option 1: Kill the Attack Surface with iptables

The simplest fix is to block unauthenticated access entirely. Most Redis exploits require the attacker to reach the port first.

bash
# Block all external access to Redis default port
iptables -A INPUT -p tcp --dport 6379 -j DROP

# Allow only specific trusted IPs (e.g., your app server at 10.0.0.5)
iptables -A INPUT -p tcp -s 10.0.0.5 --dport 6379 -j ACCEPT

# Rate-limit connections to mitigate brute-force
iptables -A INPUT -p tcp --dport 6379 -m state --state NEW -m recent --set
iptables -A INPUT -p tcp --dport 6379 -m state --state NEW -m recent --update --seconds 60 --hitcount 10 -j DROP

# Save rules (Mageia uses iptables-service)
service iptables save


Option 2: Restrict Dangerous Commands

If you must keep Redis network-accessible, use Access Control Lists to revoke the exact commands used in the exploit chain. These CVEs abuse RESTORE and Lua EVAL.
bash
# Connect to Redis CLI
redis-cli

# Create a restricted user with no dangerous commands
ACL SETUSER appuser on >StrongPass123 ~* +@all -RESTORE -EVAL -SCRIPT

# Disable the default user entirely
ACL SETUSER default off

# List current ACL rules to verify
ACL LIST


Option 3: Contain Redis with AppArmor

AppArmor can limit what Redis can do even if someone executes code. Create a profile that prevents writes to sensitive system directories and blocks shell execution.

bash
# Install AppArmor utilities
urpmi apparmor-parser apparmor-profiles

# Place this profile at /etc/apparmor.d/usr.bin.redis-server
cat > /etc/apparmor.d/usr.bin.redis-server << 'EOF'
#include <tunables/global>

/usr/bin/redis-server {
    #include <abstractions/base>
    #include <abstractions/nameservice>

    # Allow only necessary file access
    /var/lib/redis/** rwk,
    /var/log/redis/** w,
    /etc/redis/** r,

    # Block shell execution (deny writes to /bin, /usr/bin, etc.)
    deny /bin/** w,
    deny /usr/bin/** w,
    deny /sbin/** w,

    # Limit network to Redis port only
    network inet stream,
    network inet6 stream,
}
EOF

# Load and enforce the profile
aa-enforce /usr/bin/redis-server
systemctl restart apparmor

Conclusion

Your Redis server is a high-value target. Attackers know its Lua sandbox has a long history of holes, and memory corruption in commands like RESTORE keeps appearing. You can’t predict the next CVE – but you can be ready for it. Stop playing whack-a-mole with security updates.

Nenhum comentário:

Postar um comentário