Database or Redis open to the internet
HighL08Linux serversList ports listening on 0.0.0.0 and bind databases and Redis that are used…
What is the risk
If ports such as MySQL 3306, PostgreSQL 5432, Redis 6379 or MongoDB 27017 face the internet, password guessing or unauthenticated access can leak all your data.
Redis is sometimes left open without a password, and that has often led to full server takeover.
How to check
Linux
sudo ss -tulpnAn address of 0.0.0.0, [::] or * accepts outside connections. 127.0.0.1 and [::1] are local only.
How to fix
Linux
bind-address = 127.0.0.1Add under [mysqld] in the MySQL or MariaDB config and restart. Ubuntu MySQL uses /etc/mysql/mysql.conf.d/mysqld.cnf; MariaDB on Debian and Ubuntu uses /etc/mysql/mariadb.conf.d/50-server.cnf.
Linux
bind 127.0.0.1 -::1
protected-mode yesEdit redis.conf and restart Redis. Set a password with requirepass too.
Linux
listen_addresses = 'localhost'For PostgreSQL edit postgresql.conf and restart.
Debian / Ubuntu
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcpIf an outside server must connect, open the port to that IP only. 203.0.113.10 is an example.
How to prevent it
- If the database is on the web server, bind it to 127.0.0.1. If it is on another server, connect over a private network only.
- With a default-deny firewall, a port opened by mistake still cannot be reached (L03).
Check again after fixing
Linux
sudo ss -tlnp | grep -E ':(3306|5432|6379|27017)\b'Only 127.0.0.1 or [::1] should appear.
Run the downloaded check again and make sure this item passes.