CPanel/WHM Based Systems
If you are using a web server from a web hosting company, chances are the CPanel/WHM is the system admin interface you use to manage your server.
The current revision of CPanel/WHM (Mar 5th, 2008) appears to rely on the host access file as a method of preventing access to the system. Access to iptables or ipchains rules is not readily apparent, however it is possible that we have overlooked these options.
Blocking An IP Range
The steps below will help you research who is connecting to your box and how to block them from gaining access to your system through software based IP blocking.
Real World Example
This implementation is based on our experiences after turning on the Logwatch utility on our web server. The logwatch report for PAM shows sshd authentication failures. From our most recent report:
--------------------- pam_unix Begin ------------------------ sshd: Authentication Failures: unknown (184.108.40.206): 45 Time(s) root (220.127.116.11): 10 Time(s) unknown (18.104.22.168): 9 Time(s) ftp (22.214.171.124): 4 Time(s) mail (126.96.36.199): 4 Time(s) root (c-68-58-191-51.hsd1.sc.comcast.net): 2 Time(s) apache (188.8.131.52): 1 Time(s) ftp (184.108.40.206): 1 Time(s) mysql (220.127.116.11): 1 Time(s) named (18.104.22.168): 1 Time(s) postgres (22.214.171.124): 1 Time(s) Invalid Users: Unknown Account: 54 Time(s) ---------------------- pam_unix End -------------------------
The first entry concerns us since there were 45 attempts to access our system that failed. We check the IP range doing a whois lookup (we use DNS Stuff to do our homework) to determine whether or not a general IP block makes sense. We then use CPanel/WHM utilities to shut down access from the offending IP.
Note: This procedure can prevent ANYONE from accessing your server, including yourself, if not done correctly. If you are not confident in your abilities do not even attempt this. Or as the boys like to say “Don’t attempt anything we’re about to do at home. EVER!”
- Run a DNSStuff whois lookup:
- This connection is from Korea. No clients on this server do much business with Korea so we’ll shut down the entire IP block.
- Connect to our CPanel/WHM service via the web connection that our hosting company gave us (http://host.<domain>.com:2086).
- Click on the security icon
- Click on security center
- Click on host access control
- In the four entry boxes that are presented, type:
- daemon : ALL (do not let them connect to ANYTHING on this box, even the web ports)
- access list: 126.96.36.199/255.255.255.0 (block anyone connecting from 210.205.231.*)
- Based on our whois lookup we know that all ip addresses under the 210.205.231.* range are from a specific ISP in Korea. While all the users under that range may not be bad guys, we know from experience that the hackers may get a different IP next week as they tend to be assigned their IP address dynamically. We prefer to block a few of the good guys to shut down the one nuisance user. Your beliefs in the goodness of humanity may dictate a different strategy.
- action: deny (versus allow which would always let them in regardless of other rules)
- comment: Korea (you can enter whatever you’d like)
- Click Save Host Access List on the bottom of the screen
Go back into security center and click Host Access List. Verify your latest entry appears and that the data is correct. If it is entered incorrectly you may block legitimate users from accessing your system.
Turning On Logwatch
Logwatch notifications may not be enabled on your CPanel/WHM system. Logwatch tends to be running in the background but the notifications go to Never-Never Land by default. You will need to look in system notifications and enter an email address to actually see your messages.
Software Based IP Blocking
Software based IP blocking is a method for preventing access to your system by using a program running on the target computer (the computer people are trying to hack) that intercepts the connection by hooking into the TCP/IP process flow.
Software based IP blocking will consume CPU resources and memory on the target box. It can also be susceptible to hacking, although this is unusual, because it is nothing more than another program that runs on the server. For these reasons, many people consider a separate hardware firewall appliance as the better solution.
However, many web hosting services do not offer external firewall appliances. Those that do may charge more than you are willing to spend on security. In these cases you can still protect yourself via a software based IP blocking program. The most common options on Linux boxes are to use a software based firewall (ipchains or iptables) or preventing connections via host access directives.
Implementation of these concepts is discussed elsewhere on this page.