I recently received a notification from OSSEC HIDS that warns me about a SSHD brute force attack. Below I report the whole message for the sake of completeness:
OSSEC HIDS Notification.
2020 Mar 03 12:00:17
Received From: commodore->/var/log/auth.log
Rule: 5712 fired (level 10) -> "SSHD brute force trying to get access to the system."
Src IP: 188.166.xxx.xxx
Portion of the log(s):
Mar 3 12:00:16 commodore sshd[21661]: Disconnected from invalid user www 188.166.xxx.xxx port 45788 [preauth]
Mar 3 12:00:16 commodore sshd[21661]: Invalid user www from 188.166.xxx.xxx port 45788
Mar 3 11:59:53 commodore sshd[21204]: Disconnected from invalid user weblogic 188.166.xxx.xxx port 34582 [preauth]
Mar 3 11:59:53 commodore sshd[21204]: Invalid user weblogic from 188.166.xxx.xxx port 34582
Mar 3 11:59:08 commodore sshd[21198]: Disconnected from invalid user stack 188.166.xxx.xxx port 40352 [preauth]
Mar 3 11:59:08 commodore sshd[21198]: Invalid user stack from 188.166.xxx.xxx port 40352
Mar 3 11:58:28 commodore sshd[21193]: Disconnected from invalid user jira 188.166.xxx.xxx port 46186 [preauth]
Mar 3 11:58:28 commodore sshd[21193]: Invalid user jira from 188.166.xxx.xxx port 46186
In order to harden SSH Access to my machine I uploaded my public key to my VPS and disabled SSH password authentication.
To sum up, I edited /etc/ssh/sshd_config
as follows:
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
Banner none
AllowTcpForwarding no
GatewayPorts no
AddressFamily inet
At present my iptables rules are:
-P INPUT ACCEPT
-P FORWARD DROP
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-ISOLATION-STAGE-1
-N DOCKER-ISOLATION-STAGE-2
-N DOCKER-USER
-A INPUT -i lo -j ACCEPT
-A INPUT -s 127.0.0.0/8 ! -i lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -p icmp -m state --state NEW -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables_INPUT_denied: " --log-level 7
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -m limit --limit 5/min -j LOG --log-prefix "iptables_FORWARD_denied: " --log-level 7
-A FORWARD -j REJECT --reject-with icmp-port-unreachable
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN
Since I am not an experienced administrator, I would appreciate if you could suggest what response am I expected to use against this kind of attacks. Are my sshd and firewall configurations enough or some further action is required, such as block the 188.166.xxx.xxx ip address?