March 12, 2010, 18:44:04 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Please support SEO4smf further development donating here or use paypal button from left menu.
 
  Home   Forum   Help Search Directory Calendar Login Register    RSS 2.0 feedAtom feed


News
Please support SEO4smf further development donating here or use paypal button from left menu.
IT Resources
Pages: [1]
  Print  
Author Topic:

mod_security Instalation/Configuration

 (Read 6613 times)
0 Members and 1 Guest are viewing this topic.
TheGodFather
Administrator
Hero Member
*****

Points: 202
Offline Offline

Posts: 2571



WWW
« on: June 29, 2006, 05:40:56 »


What is mod_security ?

Quote
ModSecurityTM is an open source intrusion detection and prevention engine for web applications (or a web application firewall). Operating as an Apache Web server module or standalone, the purpose of ModSecurity is to increase web application security, protecting web applications from known and unknown attacks."

Also mod_security support prevention attacks. Because it's stay between client and server can filter a lot of bad requests and can perform a number of built-in actions.

Overview

    * Request filtering; incoming requests are analysed as they come in, and before they get handled by the web server or other modules.
    * Anti-evasion techniques; paths and parameters are normalised before analysis takes place in order to fight evasion techniques.
    * Understanding of the HTTP protocol; since the engine understands HTTP, it performs very specific and fine granulated filtering.
    * POST payload analysis; the engine will intercept the contents transmitted using the POST method, too.
    * Audit logging; full details of every request (including POST) can be logged for later analysis.
    * HTTPS filtering; since the engine is embedded in the web server, it gets access to request data after decryption takes place.

If you want a more detailed list you can check http://www.modsecurity.org

Installation

For mod security you need apache 1.3.x or 2.x and apache module utils for compilation (apxs). If you don't have apxs installed you need
to install him. In my case under debian is simple: apt-get install apache-dev. Under  other system the packes is named httpd-dev or something like that.

From mod_security site you can chose from a stable and a development version. I suggest you to get stable version.
http://www.modsecurity.org/download/modsecurity-apache_1.9.4.tar.gz. Anyway please check what version is available when you read this.

Log on in your server and get the latest version. Before download the sources go to /usr/src dir (the work place for compiling)

Code:
#cd /usr/src

You can get the sources with wget or links or whatever you want.
I recommend you to get it with wget:

Code:
# wget http://www.modsecurity.org/download/modsecurity-apache_1.9.4.tar.gz

After that you need to decompress the sources

Code:
#tar -xzf modsecurity-apache_1.9.4.tar.gz

Now we have 2 options:

 1. to compile static in apache
 2. to compile a DSO module for apache

1. Compiling static in apache (1.3.x)
This require to have enough experience to do that.

To compile the module into the body of the web server do
the following:

    Copy the file mod_security.c to /src/modules/extra
    Configure Apache distribution with two additional configuration options:
       --activate-module=src/modules/extra/mod_security
       --enable-module=security
    3. Compile and install as usual

2. Compiling as a DSO module

 Change directory to modsecurity sources:

Code:
# cd modsecurity-apache_1.9.4/apachex

 where x is you major version of your apache (1 or 2)

 After that we compile the module:

Code:
# apxs -cia mod_security.c

And that's all folks !

Configuration

Now we need to configure apache to

Usualy apxs will add module for us directly in configuration but is better to check that.
So open for reading /etc/apache/httpd.conf and look after mod_security if is not there add in your module section:

LoadModule security_module /usr/lib/apache/1.3/mod_security.so

(take care path can differ from a distro to other)

Now we need to configure mod_security to take action. A minimal conf is comming with the sources:
Code:
<IfModule mod_security.c>

    # Enable ModSecurity
    SecFilterEngine On

    # Reject requests with status 403
    SecFilterDefaultAction "deny,log,status:403"

    # Some sane defaults
    SecFilterScanPOST On
    SecFilterCheckURLEncoding On
    SecFilterCheckUnicodeEncoding Off

    # Accept almost all byte values
    SecFilterForceByteRange 1 255

    # Server masking is optional
    # SecServerSignature "Microsoft-IIS/5.0"

    # Designate a directory for temporary files
    # storage. It is a good idea to change the
    # value below to a private directory, just as
    # an additional measure against race conditions
    SecUploadDir /tmp
    SecUploadKeepFiles Off

    # Only record the interesting stuff
    SecAuditEngine RelevantOnly
    # Uncomment below to record responses with unusual statuses
    # SecAuditLogRelevantStatus ^5
    SecAuditLog /var/log/apache/modsec_audit.log

    ##  You normally won't need debug logging
    SecFilterDebugLevel 0
    SecFilterDebugLog /var/log/apache/modsec_debug.log

    # Only accept request encodings we know how to handle
    # we exclude GET requests from this because some (automated)
    # clients supply "text/html" as Content-Type
    SecFilterSelective REQUEST_METHOD "!^(GET|HEAD)$" chain
    SecFilterSelective HTTP_Content-Type "!(^application/x-www-form-urlencoded$|^multipart/form-data;)"

    # Do not accept GET or HEAD requests with bodies
    SecFilterSelective REQUEST_METHOD "^(GET|HEAD)$" chain
    SecFilterSelective HTTP_Content-Length "!^$"

    # Require Content-Length to be provided with
    # every POST request
    SecFilterSelective REQUEST_METHOD "^POST$" chain
    SecFilterSelective HTTP_Content-Length "^$"

    # Don't accept transfer encodings we know we don't handle
    SecFilterSelective HTTP_Transfer-Encoding "!^$"

</IfModule>

Now let's explain the most important directives:

You probably heard about SQL Injection. Mod_security can protect us if it see something like this in POST Urls

Code:
SecFilter "drop[[:space:]]table"

is rejecting all GET or POSTS Requests what contains drop table
other examples:

Code:
SecFilter "delete[[:space:]]+from"
SecFilter "insert[[:space:]]+into"
SecFilter "select.+from"

Another way to stop atacks is too look after shell comands or files like "/bin/ps", "/bin/ls", "/etc/passwd"

Code:
SecFilter /bin/ls
SecFilter /bin/ps
SecFilter /etc/passwd

Directory traversal attacks ?

Code:
SecFilter "\.\./"

Or just looking after some common output:

Code:
SecFilterSelective OUTPUT "file(s) copied"
SecFilterSelective OUTPUT "Index of /cgi-bin/"
SecFilterSelective OUTPUT ".*uid\=\("

And not the last "masking" the server :

Code:
SecServerSignature "Microsoft-IIS/5.0"

This are just a few things of what to expect from mod_security. I warm recommend you this module.

Regards
Logged



xulescu
Administrator
Full Member
*****

Points: 8
Offline Offline

Posts: 249


WWW
« Reply #1 on: June 29, 2006, 06:04:24 »

This modules is "gold" for phpBB users Smiley .  It can correct all mistakes made by programmers Cheesy

Logged

TheGodFather
Administrator
Hero Member
*****

Points: 202
Offline Offline

Posts: 2571



WWW
« Reply #2 on: June 29, 2006, 06:07:56 »

It can't correct mistakes but can protect your work Smiley

Regards
Logged

xulescu
Administrator
Full Member
*****

Points: 8
Offline Offline

Posts: 249


WWW
« Reply #3 on: June 30, 2006, 00:20:08 »

Correct.

Logged

spiderx
Jr. Member
**

Points: 3
Offline Offline

Posts: 62



« Reply #4 on: June 30, 2006, 08:14:14 »

I will apply that on my new forum server Smiley
Logged

Regards
Spider X
chris3471
Full Member
***

Points: 3
Offline Offline

Posts: 187


WWW
« Reply #5 on: June 30, 2006, 11:16:20 »

That sounds like a good idea, do you have to have access to the apache config files to install that?
Logged

TheGodFather
Administrator
Hero Member
*****

Points: 202
Offline Offline

Posts: 2571



WWW
« Reply #6 on: June 30, 2006, 11:21:32 »

Probably yes if the module is not already loaded. You need to restart apache if you add a new module. After that all directives can go in a .htaccess file.

Regards
Logged

chris3471
Full Member
***

Points: 3
Offline Offline

Posts: 187


WWW
« Reply #7 on: June 30, 2006, 11:32:29 »

Can I check that with <?php phpinfo ?>?
Logged

TheGodFather
Administrator
Hero Member
*****

Points: 202
Offline Offline

Posts: 2571



WWW
« Reply #8 on: June 30, 2006, 12:08:42 »

Nope. If you want to see more info about Apache then you can send HEAD directive directly to port 80, something like this:

Code:
telnet www.webmasterstalks.com 80
Trying 195.137.204.73...
Connected to www.webmasterstalks.com.
Escape character is '^]'.
HEAD / HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 30 Jun 2006 19:04:12 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) PHP/4.4.2-0.dotdeb.1
X-Powered-By: PHP/4.4.2-0.dotdeb.1
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: private
Pragma: no-cache
Last-Modified: Fri, 30 Jun 2006 19:04:12 GMT
Connection: close
Content-Type: text/html; charset=ISO-8859-1

Connection closed by foreign host.


You can see in Server line : "Server: Apache/2.0.54 (Debian GNU/Linux) PHP/4.4.2-0.dotdeb.1"
But are more than 20 modules  loaded and it doesn't appear there Smiley

Regards

Logged

sintex
Jr. Member
**

Points: 7
Offline Offline

Posts: 96


« Reply #9 on: June 30, 2006, 14:15:35 »

This is a module only for Apache ?

Logged
TheGodFather
Administrator
Hero Member
*****

Points: 202
Offline Offline

Posts: 2571



WWW
« Reply #10 on: July 01, 2006, 00:13:52 »

Yes. Just for apache. But ptobably it exist something like that for IIS. you just need to search (and probably it costs)

Regards
Logged

Zerabira
Jr. Member
**

Points: 1
Offline Offline

Posts: 10


WWW
« Reply #11 on: July 12, 2006, 06:50:42 »

Nice guide.  We installed this a while back and it blocks a lot of brute force attacks.
Logged

CultIdols.com, where the sublime meets the ridiculous.
bostam
Jr. Member
**

Points: 1
Offline Offline

Posts: 55


« Reply #12 on: July 19, 2006, 05:27:24 »

Is great. It can avoid 90% security problems ...
Logged
hotrod1
Jr. Member
**

Points: 1
Offline Offline

Posts: 12


« Reply #13 on: July 23, 2006, 15:46:47 »

Awesome article, I will have to use this once I get my VPS.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC
TinyPortal v0.9.7 © Bloc
Valid XHTML 1.0! Valid CSS!