When a scan lists 22/tcp or 3306/tcp as open on your public IP, anyone on the internet can connect to your SSH server or your MySQL/MariaDB server and read its version before logging in. For SSH, the fix is key-only login plus a source allow-list or a VPN. For MySQL, the fix is bind-address = 127.0.0.1 and an SSH tunnel for remote admin work.
What a qsa.sh scan reports for these ports
The free scan (curl qsa.sh) checks the top 1,000 TCP ports of the IP you connect from. Both ports are on that list: in nmap's nmap-services frequency data, 22/tcp ranks 5th and 3306/tcp ranks 14th among TCP ports, and both appear in the NmapTop1000 list that naabu 2.7.0 uses. For each open port the scan runs three open-source tools you can also run yourself:
- naabu reports the port as open.
- nmap -sV --script vulners reads the service and version, then lists CVEs that vulners.com associates with that version.
- nuclei runs templates from the public nuclei-templates repository against the services it finds.
The free output shows open ports, service versions, a severity count, and the top 3 findings in full. The Full tier ($5/month) scans all 65,535 ports and returns the full finding list. See how it works for the exact scope of each tier.
The vulners script matches on the upstream version string. Distributions often backport security fixes without changing that string, so check your distribution's security tracker before acting on a CVE line.
Port 22: SSH
SSH provides remote shell access, scp/sftp file transfer, and port forwarding. RFC 4253 requires both sides to send an identification string in the form SSH-protoversion-softwareversion as soon as the connection opens, so the server software and version are visible to anyone who connects.
What public exposure allows an attacker to attempt
- Password guessing. If the server accepts password or keyboard-interactive login, any client can submit username and password guesses.
- Version-specific flaws. CVE-2024-6387 is a race condition in Portable OpenSSH 8.5p1 through 9.7p1 that can allow remote code execution as root on non-OpenBSD systems, with exploitation demonstrated on 32-bit Linux/glibc; OpenSSH 9.8 fixed it. CVE-2023-48795 (Terrapin) affects OpenSSH before 9.6. CVE-2025-26466 is a pre-authentication denial of service in 9.5p1 through 9.9p1. The OpenSSH security page lists the affected versions for each.
- Weak configuration. Root login with a password and legacy ciphers or MACs widen what a client can try.
Nuclei templates for SSH
The public repository includes these SSH templates:
network/detection/openssh-detect.yamlextracts the OpenSSH banner.javascript/enumeration/ssh/ssh-password-auth.yaml(info) matches when the server offers password authentication.javascript/cves/2023/CVE-2023-48795.yaml(medium) detects Terrapin exposure.javascript/misconfiguration/ssh/ssh-weak-algo-supported.yaml(medium) matches arcfour ciphers.javascript/default-logins/ssh-default-logins.yaml(critical) tries a wordlist of default credentials, and only runs when the server advertises password authentication.
The free tier runs a curated set of about 2,000 templates. The Deep tier runs the full set of about 10,500.
How to close or restrict port 22
Keep your current SSH session open until you have tested a new login in a second terminal. A bad setting can lock you out.
1. Switch to key-only login. Copy your public key to the server and confirm a key login works:
ssh-copy-id [email protected]
ssh [email protected]
Then disable password logins. On Ubuntu, /etc/ssh/sshd_config starts with Include /etc/ssh/sshd_config.d/*.conf, and sshd uses the first value it reads for most keywords, so a drop-in file overrides the main file:
sudo tee /etc/ssh/sshd_config.d/10-keys-only.conf >/dev/null <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
EOF
sudo sshd -t
sudo sshd -T | grep -Ei '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin|pubkeyauthentication) '
sudo systemctl restart ssh.service
Both PasswordAuthentication and KbdInteractiveAuthentication default to yes. With UsePAM yes, keyboard-interactive login through PAM works like a password prompt, so set both to no. PermitRootLogin defaults to prohibit-password; no blocks root entirely. sshd -t checks the file, and sshd -T prints the effective settings. The service is ssh.service on Ubuntu; other distributions may name it sshd.service.
2. Allow only known source addresses. With ufw, add the allow rule for your admin IP, then remove any broader rule for port 22. ufw evaluates rules in order and the first match wins:
sudo ufw allow proto tcp from 203.0.113.10 to any port 22
sudo ufw status numbered
sudo ufw delete NUMBER_OF_THE_BROAD_22_RULE
Replace 203.0.113.10 with your own address. In a cloud provider, apply the same source restriction in the security group or network firewall. If the source cannot be pinned, ufw limit ssh/tcp denies an address that opens 6 or more connections within 30 seconds. OpenSSH 9.8 and later also apply PerSourcePenalties by default, which refuses connections for a period from addresses that repeatedly fail authentication.
3. Move SSH behind a VPN or a bastion. With WireGuard or another VPN, allow port 22 only from the VPN subnet and close it to the public internet. With a bastion host, only the bastion accepts public SSH, and you reach internal servers through it:
ssh -J [email protected] [email protected]
4. Keep OpenSSH patched through your distribution's updates.
Port 3306: MySQL and MariaDB
Port 3306 is the default port for the MySQL and MariaDB client protocol. When a client connects, the server sends its initial handshake packet first, and that packet includes the server version string. Nmap reads the version from there.
What public exposure allows an attacker to attempt
- Password guessing against any account whose host part allows remote connections, such as
'user'@'%'. - Empty or default passwords. An account with no password gives full access at the first attempt.
- Version-specific CVEs matched to the announced version.
MySQL 8.4 also runs X Plugin by default on port 33060, and mysqlx_bind_address defaults to *. Port 33060 sits outside the top 1,000 list, so the free scan does not check it. The Full and Deep tiers scan all 65,535 ports.
Nuclei templates for MySQL
network/detection/mysql-detect.yaml(info) detects a MySQL service.network/misconfig/mysql-native-password.yaml(info) matches when the handshake offersmysql_native_password.javascript/misconfiguration/mysql/mysql-empty-password.yaml(high) triesrootandanonymouswith an empty password.javascript/default-logins/mysql-default-login.yaml(high) tries a wordlist of common credentials.
How to close or restrict port 3306
1. Bind the server to localhost. The MySQL 8.4 default for bind_address is * (all IPv4 and IPv6 interfaces), and MariaDB listens on all addresses by default. MariaDB notes that many of its packages bind to 127.0.0.1 instead, so check the effective value. Add this under the [mysqld] section of an option file:
[mysqld]
bind-address = 127.0.0.1
# MySQL 8.4 only: also restrict X Plugin
mysqlx-bind-address = 127.0.0.1
If the application reaches the database from another server, use that server's private interface address instead of 127.0.0.1. If every client uses the local socket, skip-networking stops TCP listening entirely. MySQL reads several option files and the last value it reads wins; mysqld --verbose --help (or mariadbd --help --verbose) lists the files and their order. bind_address only changes at startup, so restart the database service, then confirm the listener:
sudo ss -tlnp | grep -E ':(3306|33060) '
The local address column should show 127.0.0.1:3306.
2. Firewall the port. Allow 3306 only from your application servers' private addresses, in ufw or the cloud security group:
sudo ufw allow proto tcp from 10.0.0.20 to any port 3306
If MySQL runs in Docker, a port published as -p 3306:3306 binds to all host addresses. Publish it as -p 127.0.0.1:3306:3306, and read Docker published ports skip UFW before relying on ufw.
3. Use an SSH tunnel for remote admin work. Forward a local port to the server's loopback address, then connect to it with an explicit 127.0.0.1. On Unix, the MySQL client treats localhost as a socket connection and ignores the port:
ssh -N -L 3307:127.0.0.1:3306 [email protected]
mysql --host=127.0.0.1 --port=3307 -u dbadmin -p
4. Review accounts that accept remote hosts. List them, then drop or rescope the ones you do not need:
SELECT User, Host FROM mysql.user
WHERE Host NOT IN ('localhost', '127.0.0.1', '::1');
Check both ports from outside and confirm the fix
Run nmap from a different network than the server, such as a second VPS or a laptop on another connection. A scan from inside the same network can bypass rules that apply only to internet traffic.
nmap -Pn -sV -p 22,3306 YOUR.PUBLIC.IP
-Pn skips host discovery and -sV reports service versions. After the fix, 3306 should show closed (reachable, with nothing listening) or filtered (a firewall drops the probes). Port 22 should show filtered from any address outside your allow-list. From an allowed address, confirm that the server offers only key login:
nmap -p 22 --script ssh-auth-methods YOUR.PUBLIC.IP
The output should list publickey and no password or keyboard-interactive. The script starts an authentication attempt with a username, which nmap classifies as intrusive, so run it against your own server only.
Then run curl qsa.sh from the server itself. It prints the detected IP and a 15-second countdown before anything is sent, and Ctrl-C cancels. The free scan runs once per IP per 24 hours. A Full key allows one scan per hour, which covers fix-and-verify cycles. To re-scan on a schedule and get alerted when results change, use the cron monitor script.
FAQ
Is an open port 22 always a problem?
SSH is built for network access, and many servers keep it reachable. With key-only authentication and a patched OpenSSH, password guessing has nothing to work against. A source allow-list or VPN then limits which addresses can reach the version banner at all.
Does moving SSH to another port help?
A new port number changes where the service listens and leaves its exposure the same. A scan of all 65,535 ports finds it, and the common alternative 2222 is on the top 1,000 list the free scan uses.
bind-address is 127.0.0.1, but 3306 still shows open. Why?
Common causes: a later option file sets a different value, the server was never restarted after the change, or a Docker container publishes 3306 on all host addresses. Check ss -tlnp to see which process owns the listener and which address it uses.
Can I run these checks myself instead of using qsa.sh?
Yes. naabu, nmap with the vulners script, and nuclei are free and open source, and the commands above use them directly. qsa.sh runs the same tools from outside your network and streams the results to your terminal.