Someone Desperately trying to Hack into my Cpanel

Status
Not open for further replies.

DOST_FRIEND59

Active Member
230
2012
47
506
Hi,

daily I receiving over 10 emails from my server that someone is trying to hack into my Dedicated server, I have cpanel installed on it and after No. of specified failures, I get a Email stating - Excessive Number of Failed Login Attempts from IP XXX.XXX.XXX.XXX

most of the Ip's are from China, few from other countries.
Chinese Ip address are of Broadband and other countries are of generally dedicated.

is there any way to block all incoming connection from China?
 
8 comments
Yes, you can block it or even allow login from white list of IP only. But it's better to ask your host support how to do this. Or look at this: support.cartika.com/customer/portal/articles/1584569-how-to-whitelist-or-blacklist-an-ip-in-csf-cpanel-server-
 
or
just setup some "gatekeeper"
as for me, i've configured my systems in a way, that only the VPN-Connection on the cluster or a specific ip can access the Systems via ssh.

so go and look for some real cheap LEB-Prized VPS-Systems and install only ssh. So that's now your gateway with a fixed ip.
Then connecto to this gateway and from this to your systems.
it looks like a bit of hasse, but it will get you rid of lots of problems.

Moreover: it can also help to change SSH-Ports :)
(and perhaps installing a honeypot - which is nice if you want so see what they would have done to your system :D )
 
or
just setup some "gatekeeper"
as for me, i've configured my systems in a way, that only the VPN-Connection on the cluster or a specific ip can access the Systems via ssh.

so go and look for some real cheap LEB-Prized VPS-Systems and install only ssh. So that's now your gateway with a fixed ip.
Then connecto to this gateway and from this to your systems.
it looks like a bit of hasse, but it will get you rid of lots of problems.

Moreover: it can also help to change SSH-Ports :)
(and perhaps installing a honeypot - which is nice if you want so see what they would have done to your system :D )

Can you give me a more detailed guide to it.
 
use at your own risk! don't blame me, if you do s.th. wrong
(or if i had forgotten s.th. or have typos)

i'm going to explain this further. and i'm doing it for debian (if you have centOS - it should nearly be the same)

Change SSH-Port

  • connect via SSH to your system the way you are used to
  • open your sshd config with an editor of your choice. e.g.
    Code:
     nano /etc/ssh/sshd_config
  • Search "Port 22" (should be at the top)
  • Change the Number to any port that's free and you are willing to use. E.g. 224 or 228 or s.th. else
  • Verify that you don't have any firewall in place, which will lock you out (i don't know if you have s.th. like this, so no code)
  • Restart ssh service: service ssh restart
  • don't close your terminal. Open a new one and try to connect via ssh and your newly defined code.
  • If this login worked, you can close the first session.


Restrict Access to one (or many) ips:
so, there are now multiple possibilities.

  • Using sshd_config
    • editing /etc/ssh/ssd_config
      Code:
       nano /etc/ssh/sshd_config
      go to the end of the file
      add the following to allow the user jim to connect from the ips 11.22.33.56 and 141.212.133.36
      Code:
      AllowUsers jim@11.22.33.56 jim@141.212.133.36
      (Wildcards are supported
    • restart ssh-service (look obove)
  • using IPtables (should work on all *nix-Systems):
    • adding the allow-rule:
      Code:
      iptables -I INPUT -p tcp -s <your ip> --dport <portNr> -j ACCEPT
      This will allow access via protocoll tcp and source <your ip> on port <portNr>
      replace <your ip> with the ip you want to allow (also remove the <>)
      replace <portNr> with the Port you have specified above (also remove the <>)
    • now drop all other requests on the port
      Code:
      iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport <portNr> -j DROP
      This will drop all requests coming from all IPs around the world on PortNr.


denying root-ssh-login
that's s.th. you really should do.
don't allow directly root-access to your system via ssh.

  • Generate a user, if you don't have one already one
    Code:
    adduser <Username>
  • Check if you can login with the new username, by opening a new ssh session
  • Go to sshd_config
    Code:
    nano /etc/ssh/ssd_config
    look out for "PermitRootLogin yes"
    change this to
    Code:
    PermitRootLogin no
  • now restart your ssh service
  • to now gain access to your root-account, if needed, type
    Code:
    su
    Debian will now ask you for the root-pw
  • if you are using s.th. like deiban or sudolikeaboss use your command with sudo or type
    Code:
    sudo su



Installing a gateway
Just go to a site who offer budget-VPS-Systems (the virtualisation doesn't matter)
look here: VPS or here Low End Box - Cheap VPS Hosting Providers Listing & Reviews
as for the gateway you absolutly don't need any hardware-requirements or traffic. So a very cheap package is enough. E.g. around 10-30$ a year. you only have to check, if you have a dedicated IP (though can be optional, but natted-access sure is some strange things to do)just take a look around around and read reviews.
Then let them install a default OS - (in my case debian)
now you can change the Port of your ssh-service, if you want (as above)
if you are now connected to your gateway open the ssh-connection to your server typing
Code:
ssh -P<PortNr> username@ipOrDomain
Make sure to allow access via your gatway-ip to your system. (prepare a backup solution, if the IP of your gateway will change - normally no problem with KVM / VNC access to the system)

Using a VPN
just in short, since i don't have anymore time now:
install openvpn - allow openvpn-connections.
Connect via openvpn & check connection.
only allow ssh-connections via the new setup network-range (you have to specify while installing openvpn)


edit
what i totally have forgotten:
there are always tools like fail2ban - but i think cpanel could have already added this to your system.
Moreover you can enable passwor-less login, but when you loose your keys, you can't access anymore - if your provider don't provide you with s.th. like VNC or KVM (since this would then be a local access, you can do it as you are used, since we haven't touched ssh_config)
(all the above should work with cpanel, but since i don't use s.th. like this, i don't really know use at your own risk)
 
Last edited:
Install CSF firewall and set config to perm ban with 1 failed attempt.


Code:
http://download.configserver.com/csf/install.txt


If you edit SSHD config wrong you wont be able to login to shell to fix the problem, Its handy to have a file editor in WHM

Config Explorer - WHM Module
Code:
cd ~
wget http://www.configserver.com/free/cse.tgz
tar -xzf cse.tgz
cd cse/
sh install.sh
 
Last edited:
Status
Not open for further replies.
Back
Top