OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :

Improving Security On A cPanel System

2004-11-29 13:36:45, 15929 views, from category Top Level -> Sysadmin Resources -> Control Panels -> cPanel

A number of suggestions to improve system security. Some of this is specific to CPanel, but much can be applied to most Linux systems.

--------------------------------------------------

Use The Latest Software

Keep the OS and 3rd party software up to date. Always!

CPanel itself can be updated from the root WHM.

--------------------------------------------------

Change Passwords

Change the root passwords at least once a month and try to make them hard to guess. Yes it's a pain to have to keep remembering them, but it's better than being hacked.

--------------------------------------------------

Set Up A More Secure SSH Environment

As described here.

--------------------------------------------------

Disable Telnet

1. Type: pico -w /etc/xinetd.d/telnet
2. Change the disable = no line to disable = yes.
3. Hit CTRL+X press y and then enter to save the file.
4. Restart xinted with: /etc/rc.d/init.d/xinetd restart

Also, add the following line to /etc/deny.hosts to flag Telnet access attempts as 'emergency' messages.


in.telnetd : ALL : severity emerg


--------------------------------------------------

Install Firewall & Block Unnecessary Ports

I recommend APF firewall personally, but they all do a similar job.

APF can be found at: http://www.rfxnetworks.com/apf.php

Also guard against 'brute force' attacks with: http://www.rfxnetworks.com/bfd.php


--------------------------------------------------

Disable Unnecessary Ports

First backup the file that contains your list of ports with:

cp /etc/services /etc/services.original

Now configure /etc/services so that it only has the ports you need in it. This will match the ports enabled in your firewall.

On a typical CPanel system it would look something like this:

<?php

tcpmux          1
/tcp                           # TCP port service multiplexer
echo            7/tcp
echo            7/udp
ftp
-data        20/tcp
ftp             21
/tcp
ssh             22
/tcp                          # SSH Remote Login Protocol
smtp            25/tcp          mail
domain          53
/tcp                          # name-domain server
domain          53/udp
http            80
/tcp          www www-http    # WorldWideWeb HTTP
pop3            110/tcp         pop-3           # POP version 3
imap            143/tcp         imap2           # Interim Mail Access Proto v2
https           443/tcp                         # MCom
smtps           465/tcp                         # SMTP over SSL (TLS)
syslog          514/udp
rndc            953
/tcp                         # rndc control sockets (BIND 9)
rndc            953/udp                         # rndc control sockets (BIND 9)
imaps           993/tcp                         # IMAP over SSL
pop3s           995/tcp                         # POP-3 over SSL
cpanel          2082/tcp
cpanels         2083
/tcp
whm             2086
/tcp
whms            2087
/tcp
webmail         2095
/tcp
webmails        2096
/tcp
mysql           3306
/tcp                        # MySQL

?>


Additional ports are controlled by /etc/rpc. These aren't generally needed, so get shot of that file with: mv /etc/rpc /etc/rpc-moved

--------------------------------------------------

Watch The Logs

Install something like logwatch to keep an eye on your system logs. This will extract anything 'interesting' from the logs and e-mail to you on a daily basis.

Logwatch can be found at: http://www.logwatch.org

Install instructions here.

--------------------------------------------------

Run A Root Kit Checker Regularly

You can get a root kit from http://www.chkrootkit.org and make sure you run it on a regular basis, perhaps including it in a cron job.

Install instructions here

--------------------------------------------------

Limit The Kernel's Capabilities

1. Type: wget ftp://rpmfind.net/linux/PLD/current....0.6-3.i686.rpm
2. Type: rpm -Uvh lcap-0.0.6-3.i686.rpm
3. Type: lcap CAP_SYS_PTRACE

This will limit the ptrace option which allows attaching to, and controlling the execution of, arbitrary processes. Debuggers do this sort of thing.

Much can be done with LCAP, but it's also worth remembering that you can lock yourself out of things you actually need, so research it well.

LCAP changes will be forgotten after reboot (unless you include them in a startup file of course).

--------------------------------------------------

Avoid CPanel Demo Mode

Switch it off via WHM Account Functions => Disable or Enable Demo Mode.

--------------------------------------------------

Jail All Users

Via WHM Account Functions => Manage Shell Access => Jail All Users.

Better still never allow shell access to anyone - no exceptions.

--------------------------------------------------

Disable Troublesome Formmails

Cpanel's formmails are known to be insecure and, worse, every time one attempts to disable them, the next CPanel upgrade comes along and enables them again.

This is the recommended procedure for disabling them:

1. SSH into the box.

2. Type: cd /usr/local/cpanel/cgi-sys

3. Type: chmod 0 cgiemail formmail.cgi FormMail.cgi FormMail-clone.cgi formmail.pl FormMail.pl helpdesk.cgi realhelpdesk.cgi realsignup.cgi signup.cgi

4. Type: chattr +i cgiemail formmail.cgi FormMail.cgi FormMail-clone.cgi formmail.pl FormMail.pl helpdesk.cgi realhelpdesk.cgi realsignup.cgi signup.cgi

--------------------------------------------------

Immediate Notification Of Specific Attackers

If you need immediate notification of a specific attacker (TCPWrapped services only), add the following to /etc/hosts.deny


ALL : nnn.nnn.nnn.nnn : spawn /bin/ 'date' %c %d | mail -s"Access attempt by nnn.nnn.nnn.nnn on for hostname" notify@mydomain.com

Replacing nnn.nnn.nnn.nnn with the attacker's IP address.
Replacing hostname with your hostname.
Replacing notify@mydomain.com with your e-mail address.

This will deny access to the attacker and e-mail the sysadmin about the access attempt.

--------------------------------------------------

Check Open Ports

From time to time it's worth checking which ports are open to the outside world. This can be done with:

nmap -sT -O localhost

If nmap isn't installed, it can be selected from root WHM's Install an RPM option.

--------------------------------------------------

Set The MySQL Root Password

This can be done in CPanel from the root WHM Server Setup -> Set MySQL Root Password.

Make it different to your root password!

--------------------------------------------------

Tweak Security (CPanel)

From the root WHM, Server Setup -> Tweak Security, you will most likely want to enable:

- php open_basedir Tweak.
- SMTP tweak.

You may want to enable:

- mod_userdir Tweak. But that will disable domain preview.

--------------------------------------------------

Use SuExec (CPanel)

From root WHM, Server Setup -> Enable/Disable SuExec. This is CPanel's decription of what it does:

"suexec allows cgi scripts to run with the user's id. It will also make it easier to track which user has sent out an email. If suexec is not enabled, all cgi scripts will run as nobody. "

Even if you don't use phpsuexec (which often causes more problems), SuExec should be considered.

--------------------------------------------------

Use PHPSuExec (CPanel)

This needs to built into Apache (Software -> Update Apache from the root WHM) and does the same as SuExec but for PHP scripts.

Wisth PHPSuExec enabled, you users will have to make sure that all their PHP files have permissions no greater than 0755 and that their htaccess files contain no PHP directives.

--------------------------------------------------

Disable Compilers

This will prevent hackers from compiling worms, root kits and the like on your machine.

To disable them, do the following:


chmod 000 /usr/bin/perlcc
chmod 000 /usr/bin/byacc
chmod 000 /usr/bin/yacc
chmod 000 /usr/bin/bcc
chmod 000 /usr/bin/kgcc
chmod 000 /usr/bin/cc
chmod 000 /usr/bin/gcc
chmod 000 /usr/bin/i386*cc
chmod 000 /usr/bin/*c++
chmod 000 /usr/bin/*g++
chmod 000 /usr/lib/bcc /usr/lib/bcc/bcc-cc1
chmod 000 /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cc1


You will need to enable them again when you need to perform system updates. To do this, run:


chmod 755 /usr/bin/perlcc
chmod 755 /usr/bin/byacc
chmod 755 /usr/bin/yacc
chmod 755 /usr/bin/bcc
chmod 755 /usr/bin/kgcc
chmod 755 /usr/bin/cc
chmod 755 /usr/bin/gcc
chmod 755 /usr/bin/i386*cc
chmod 755 /usr/bin/*c++
chmod 755 /usr/bin/*g++
chmod 755 /usr/lib/bcc /usr/lib/bcc/bcc-cc1
chmod 755 /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cc1


--------------------------------------------------

Obfuscate The Apache Version Number

1. Type: pico /etc/httpd/conf/httpd.conf

2. Change the line that begins ServerSignature to:


ServerSignature Off


3. Add a line underneath that which reads:


ServerTokens ProductOnly


4. Hit CTRL+X, they y, the enter to save the file.

5. Restart Apache with: /etc/rc.d/init.d/httpd restart
 
   Print this page

Top Sponsor
Symantec\'s Norton SystemWorks 2006
Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting

Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005