SkyHorse.Org

Tweaking apache web server

1) Remove version information from Apache (check Security by Obscurity part)

2) Activate the Php open_basedir Tweak (go to Tweak Security in WHM)

3) Install Modsecurity

Mod security allows filtering the incoming requests. There are already filters available on the web to use straight away and they are updated regularly.

Check out the modsec.sh to keep your rules updated.

Another usual issue is the use of the PCRE regular expression in mod security. The current version available with cPanel does not support it, so you will need to download and install the latest version manually, with some simple procedures. It is really worth it especially in terms of performance. More details to come.

ACTION

Go to the “Addon Modules” in WHM and check the Modsecurity module

You now have to edit your Apache httpd.conf file (usually resides in /usr/local/apache/conf/httpd.conf)

cPanel should have added this line in there already for you, but double check anyway:

Include "/usr/local/apache/conf/modsec.conf"

Now, edit the modsec.conf file.
This is how my modsec.conf file looks like. You might want to change some settings. Notice the inclusion of the rules for the modsecurity module:

SecFilterEngine On
SecFilterCheckURLEncoding On
SecFilterForceByteRange 0 255
SecAuditEngine RelevantOnly
SecAuditLog logs/audit_log
SecFilterDebugLog logs/modsec_debug_log
SecFilterDebugLevel 0
SecFilterDefaultAction "deny,log,status:406"
SecFilterSelective REMOTE_ADDR "^127.0.0.1$" nolog,allow
Include "/usr/local/apache/conf/modsec.user.conf"
#And now, the rules
#Remove any of these Include lines you do not use or have rules for.

#First, add in your exclusion rules:
#These MUST come first!
Include /etc/modsecurity/exclude.conf

#Application protection rules
#Include /etc/modsecurity/rules.conf

#Comment spam rules
Include /etc/modsecurity/blacklist.conf

#Bad hosts, bad proxies and other bad players
Include /etc/modsecurity/blacklist2.conf

#Bad clients, known bogus useragents and other signs of malware
#Include /etc/modsecurity/useragents.conf

#Known bad software, rootkits and other malware
Include /etc/modsecurity/rootkits.conf

#Signatures to prevent proxying through your server
#only rule these rules if your server is NOT a proxy
Include /etc/modsecurity/proxy.conf

#Additional rules for Apache 2.x ONLY! Do not add this line if you use Apache 1.x
#Include /etc/modsecurity/apache2-rules.conf

The reason I don't use all rules is because some where crashing my apache. Anyway, you see the /etc/modsecurity needs to exist and the rules need to be there. So go ahead and mkdir /etc/modsecurity

Now, you need the rules. You can download them from gotroot.com website. I have, however, made a script to auto-update these rules, based on a existing script from gotroot.com. I was informed they will include my script on their page soon, but meanwhile you can download it here.

Here's the direct link to gotroot.com rules page:
http://www.gotroot.com/tiki-index.php?page=mod_security+rules

If you use my script, just put it in /etc/modsecurity and run it. It should download the rules if you don't have them yet or update them if you have an old version. It also tries to restart apache, so no need to do that manually. You'll get an error if apache doesn't load.

In case some web pages do not work properly with mod security, the best approach is to include an .htaccess file in the same directory allowing the file in question to be ignored by mod security. To do an entire directory, simply put this in the .htaccess file:

SecFilterInheritance Off

4) Enable PHP suEXEC support

This is an essential part of your webserver security. suEXEC makes your users php scripts run under their own usernames instead of the user "nobody". This has two major advantages: forces all scripts to only do what is permitted for that username keeping track of the user who ran it (like in the case of sending e-mails from a script) and allows includes the cpu used in the execution of php scripts for each user in the CPU utilization chart from WHM, which would otherwise be under "nobody" making it very hard to track down cpu intensive scripts.

Now that you know why you should use it, here's how:

- Rebuild apache with the PHP suEXEC support

You should already know how to do this...

- Fix your user's files permissions
Basically I found most of my users had some files under the user "nobody" (uploaded files from a php script for example). This was fine until suEXEC was enabled, since then those files were not accessible from php scripts (depending on file permissions).

As usual, I've put a simple solution in a script to fix this, here you go:

#this changes all files from the user "nobody" to the real user of the area
find /home -user nobody > list_of_nobodies
exec < list_of_nobodies
while read line
do
fileOwner=`echo $line | sed "s/\// /g" | awk '{print$2}'`
chown ${fileOwner}:${fileOwner} "$line"
#report it
echo "Changing owner to ${fileOwner}:${fileOwner}"
echo $line
done

Change /home to your home directory. Alternatively you might want to keep the group "nobody" for those files, if so change the line:

chown ${fileOwner}:${fileOwner} "$line"

to

chown ${fileOwner}:nobody "$line"

5) Installing Zend Optimizer and IonCube in the same server

Taken from http://forums.cpanel.net/showthread.php?t=46249 by Punk

1. SSH login/su as root

2. make sure ioncube is installed at your server

3. edit /scripts/installzendopt : >> pico /scripts/installzendopt

4. under " my %urls = ( " line, change to

Linux => 'http://downloads.zend.com/optimizer/2.5.10/ZendOptimizer-2.5.10a-linux-glibc21-i386.tar.gz',
Linux64 => 'http://downloads.zend.com/optimizer/2.5.10/ZendOptimizer-2.5.10a-linux-glibc23-x86_64.tar.gz',

5. save changes and install zend : >> /scripts/installzendopt

6. follow the instruction at the installation proccess

7. after installation, edit your php.ini : >> pico /usr/local/Zend/etc/php.ini

8. find the zend configuration zone

9. move your ioncube line (at my server: zend_extension=/usr/local/cpanel/3rdparty/etc/ioncube/ioncube_loader_lin_4.4.so) before zend_extension

example at my server :

[Zend]
zend_optimizer.optimization_level=15
zend_extension=/usr/local/cpanel/3rdparty/etc/ioncube/ioncube_loader_lin_4.4.so
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-2.5.10
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-2.5.10

zend_optimizer.version=2.5.10a

zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so

10. save changes and restart httpd >> /etc/init.d/httpd restart

done...

  • Google Buzz
  • Delicious
  • Facebook
  • Twitter
  • LinkedIn
  • Share/Bookmark

Related posts:

  • The Definite Guide of Obscure Tweaks to Install and Maintain cPanel / WHM (version 10)
  • ModSecurity 2.5 : a book by Magnus Mischel
  • DirectAdmin to cPanel : a partial BASH solution
  • Tags

    AI apple behavioural-targeting business Computing cPanel deep packet inspection design Downloads Games GNU/Linux google hacking hacking Hardware headphones hosting Ideas Instant Messaging iphone marketing mod-security online-advertising online media Personal Philosophy phorm poker Programming satire scripts Security sociology startups technology Travel ubuntu v-moda Visionarism web-2.0 web-marketing Web Design WHM wunderloop yahoo
  • Pages

    • About
    • Web Server Administration
      • Auto update modsecurity rules – modsec.sh
      • DirectAdmin to cPanel : a partial BASH solution
      • The Definite Guide of Obscure Tweaks to Install and Maintain cPanel / WHM (version 10)
        • Configuring E-mail (Exim) related areas
        • Fixing open DNS servers
        • Monitoring your server
        • Scripts and misc information
        • Security by Obscurity
        • Tweaking apache web server
  • Twitter Updates

    • Ads

    • RSS NMA

      • MySpace allows users to sync with Facebook 31 August, 2010
      • YouTube in first full-length movie deal with Blinkbox 27 August, 2010
      • nma Social Media Social takes place next Thursday 26 August, 2010
    • RSS Brand Republic

      • STV appoints Peter Reilly as commercial director 1 September, 2010
      • Binatone beats Samsung and BlackBerry with budget tablet launch 1 September, 2010
      • Alterian expands social media offer with Intrepid acquisition 1 September, 2010
    • RSS iMedia Connection: Consumer Strategies

      • Social media: What lies ahead
      • The truth about consumers' targeting fears
      • 3 reasons your brand doesn't have more Facebook fans
    • RSS Behavioural Targeting news

      • Moving Targets: Somebody Follow Me, Please? - MediaPost Publications 1 September, 2010
      • Moving Beyond Behavioral Ads - ClickZ News 1 September, 2010
      • Cybercrime Still a Major Concern - eMarketer 1 September, 2010
      • DigiRant: Retargeting Needs Some 411 - digiday:DAILY 31 August, 2010
      • How to Make Google Matter in Social Media - GigaOm (blog) 30 August, 2010
    • RSS Adotas

      • Rose Abdicates Digg Throne as Revolt Continues 1 September, 2010
      • Irony Alert: Zuck Wants Privacy Too 1 September, 2010
      • Yahoo & Dex One Expand Partnership for the Locals 1 September, 2010
    • RSS MarketingVox

      • Top Industry News for 9-01-10: Target to sell Facebook Credits gift cards 1 September, 2010
    • RSS ExchangeWire.com

      • OpenX Partners CCI To Build Out Automated Ad Trading Platform In Japan 1 September, 2010
      • AdAudience Moving Its Audience-Buying Offering From Wunderloop to Nugg.ad 31 August, 2010
      • Aegis H1 Report Shows Sluggish Growth In Europe, But Global Revenues Up 3.1% 27 August, 2010
    • RSS Segmentacion por comportamiento

      • Nota de prensa sobre la compra de wunderloop por Audience Science. 5 July, 2010
      • El gigante americano Audience Science compra wunderloop 5 July, 2010
      • Orange lanza su propio AdExchange 31 March, 2010
    • RSS Sandlines

      • the iPad and Marketing 28 January, 2010
      • The anticipation of disappointment 7 December, 2009
      • Groundhog Day 27 November, 2009
    • Ads

    • Blogroll

      • 90kts
      • Acxiom Poker Nights
      • Amy’s blog
      • Bytter’s blog
      • morena flor no samba da saudade
      • Not Quite There Yet
      • Swedish Pirate Party
    • Cartoons

      • Geek & Poke
      • Order of the Stick
      • User Friendly
    • Gaming

      • Neverwinter Nights
    • online media

      • Knowledge for the Digital Economy
      • Mike on Ads
    • Personal

      • Atelier de Camisa
      • Banksy
      • Designarte
      • My Amazon Wishlist
      • SkyServers.Org
    • Science

      • New Scientist
      • Rex Research
      • ScienceBox
      • Wired
    • Security

      • GPG4Win
      • GPGol
      • GPGShell
      • Mod Security
      • Offline Windows NT(2k,XP) Password Recovery
    • Web Design

      • PageStrength
      • SiteScore
      • UrlTrends
    • Akismet

      55,513 spam comments blocked by
      Akismet
    • Meta

      • Log in
      • Entries RSS
      • Comments RSS
      • WordPress.org

    © 2003 - 2010 Paulo Cunha | SkyHorse.Org is proudly powered by WordPress | Theme based on Bob