Just want to understand. Please, correct mistakes and write advices
Hacker can access to VPS:
1. Through (using) console terminal, for example, using PuTTY.
To access, hacker need to know port number, username and password.
Port number hacker can know scanning open ports and try to login. The only way to login as I understand need to know username and password.
To block (make more difficult) port scanning, need to use iptables configure
/etc/sysconfig/iptables. I followed this https://www.digitalocean.com/community/articles/how-to-setup-a-basic-ip-tables-configuration-on-centos-6 tutorial and got
*nat :PREROUTING ACCEPT [87:4524] :POSTROUTING ACCEPT [77:4713] :OUTPUT ACCEPT [77:4713] COMMIT *mangle :PREROUTING ACCEPT [2358:200388] :INPUT ACCEPT [2358:200388] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [2638:477779] :POSTROUTING ACCEPT [2638:477779] COMMIT *filter :INPUT DROP [1:40] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [339:56132] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP -A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m tcp --dport 110 -j ACCEPT -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -s 22.214.171.124/32 -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT -A INPUT -s 126.96.36.199/32 -p tcp -m tcp --dport 21 -j ACCEPT COMMIT
Regarding ports that need to be opened.
If does not use ssl, then seems must leave open port 80 for website.
Then for ssh (default 22) and for ftp (default 21). And set ip address, from which can connect. So if hacker uses other ip address, he can not access even knowing username and password?
Regarding emails not sure.
If I send email, using Gmail (Send mail as: (Use Gmail to send from your other email addresses)), then port 25 not necessary.
For incoming emails at dynadot.com I use Email Forwarding. Does it mean that emails “does not arrive to VPS” (before arriving to VPS, emails are forwarded, for example to Gmail)? If emails does not arrive to VPS, then seems port 110 also not necessary.
If use only ssl, must open port 443 and close port 80.
Do not understand regarding port 3306
In PuTTY with
/bin/netstat -lnp see
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 992/mysqld
As understand it is for mysql. But does not remember that I have opened such port (may be when installed mysql, the port is opened automatically?). Mysql is installed on the same server, where all other content. Need to understand regarding port 3306
2. Also hacker may be able access console terminal through VPS hosting provider Control Panel (serial console emergency access).
As understand only using console terminal (PuTTY, etc.) can make “global” changes (changes that can not modify with ftp).
3. Hacker can access to my VPS exploiting some hole in my php code and uploading, for example, Trojan.
Unfortunately, faced situation that VPS was hacked. As understand it was because I used ZPanel. On VPS ( \etc\zpanel\panel\bin) ) found one php file, that was identified as Trojan by some virus scanners (at virustotal.com).
Experimented with the file on local computer (wamp).
And appears that hacker can see all content of VPS, rename, delete, upload etc. From my opinion, if in PuTTY use command like
chattr +i /etc/php.ini then hacker could not be able to modify php.ini.
Is there any other way to get into VPS?