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...

DeliciousFacebookTwitterLinkedInShare/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

    advertising AI apple behavioural-targeting business Computing cPanel deep packet inspection Downloads DSP Games GNU/Linux google hacking hacking Hardware headphones hosting Ideas Instant Messaging iphone marketing 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 ExchangeWire.com

      • The PostView: Are Facebook And Amazon About To Disrupt The Multi-Billion Euro/Dollar Traditional Display Model? 26 January, 2012
      • Adfonic CTO, Wes Biggs, Discusses The Huge Opportunity Around Rich Media Formats In The Mobile Channel 25 January, 2012
      • Retargeting Centralised: Why Agencies Should Internalise This DR Buying Function And How It Would Benefit Advertisers 24 January, 2012
    • RSS Lies, Damned Lies…

      • Building the Perfect Display Ad Performance Dashboard, Part II – metrics 20 December, 2011
      • Should Wikipedia accept advertising? 21 November, 2011
      • Building the Perfect Display Ad Performance Dashboard, Part I – creating a measurement framework 9 November, 2011
    • RSS iMedia Connection: Consumer Strategies

      • A consumer-driven mindset in a big media package
      • Learn to leverage the social-search connection
      • Your social media disaster kit
    • RSS Segmentacion por comportamiento

      • Your Stats Have a New Home 26 January, 2012
      • Reblogging is Back! 22 January, 2012
      • New Theme: Newsy 20 January, 2012
    • RSS Sandlines

      • The Social Phone doesn’t come with an IVR menu 7 November, 2011
      • Are you ready for Big Data? 2 November, 2011
      • Sandlines @ Mediapro 29 October, 2011
    • RSS Adotas

      • Sponsormob Leads the Way Into RTB for Mobile 26 January, 2012
      • Compass Labs Relaunches Behavior-Based Social Ad Targeting Platform 26 January, 2012
      • The User Data Ecosystem, Visualized 26 January, 2012
    • RSS NMA

      • Facebook urges clearer understanding of social commerce 26 January, 2012
      • McDonald’s admits Twitter campaign failure 25 January, 2012
      • Google to consolidate privacy data to bolster ad targeting 25 January, 2012
    • RSS Brand Republic

      • Surf signs TOWIE sponsorship deal 26 January, 2012
      • Samsung invites customers to shoot Tulisa music video 26 January, 2012
      • MPs to quiz beauty marketers on body confidence 26 January, 2012
    • RSS MarketingVox

      • Closing Bell: Privacy | iPhone to be delivered this summer | Public alerts on Google maps 25 January, 2012
      • The BBB Takes on 4G Claims 25 January, 2012
      • The Art and Science of Using Images in Email Marketing 25 January, 2012
    • RSS Behavioural Targeting news

      • 15 worst Internet privacy scandals of all time - PC Advisor 26 January, 2012
      • Videology Partners with I-Behavior and Kantar Shopcom to Extend CPG Purchase ... - MarketWatch (press release) 26 January, 2012
      • Channel 4's 'Richard Wilson On Hold' - I don't believe it… - The Drum 26 January, 2012
      • Advertisers to police themselves when targeting online users - Toronto Star 25 January, 2012
      • Zumobi hires former Microsoft director Marla Schimke to lead marketing - TechFlash (blog) 25 January, 2012
    • Ads

    • Blogroll

      • 90kts
      • Acxiom Poker Nights
      • Amy’s blog
      • Bytter’s blog
      • Impare Arquitectura
      • Impare Design
      • 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

      • Banksy
      • Designarte
      • Made to measure shirts – Atelier de Camisa
      • 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

      99,712 spam comments blocked by
      Akismet
    • Meta

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

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