ModSecurity2 Installation, and Configuration

Similar documents
If you re the administrator on any network,

Install latest version of Roundcube (Webmail) on CentOS 7

BEGINNER PHP Table of Contents

An internal CA that is part of your IT infrastructure, like a Microsoft Windows CA

Installing LAMP on Ubuntu and (Lucid Lynx, Maverick Meerkat)

We want to install putty, an ssh client on the laptops. In the web browser goto:

ModSecurity 2 Deployment

Installing MyDNS And The MyDNSConfig Control Panel On Fedora 8

Setting Up PHPlist (Open-Source Newsletter Manager)

Installing FreePBX 14 on CentOS 7

L.A.M.P. Stack Part I

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Read Source Code the HTML Way

Managing Xen With Xen-Tools, Xen-Shell, And Argo

Installing FreePBX 13 on CentOS 7

Physics REU Unix Tutorial

Introduction to Linux

LAMP Stack with VirtualHosts On Centos 6.x

SELinux Workshop Redux Jamie Duncan, Red Hat RVaLUG 19 April 2014

1 Installation 2 "Add New Printer"... Window 3 "Device for" Window "Device URI for"... Window. 7 Specify Printer... Model

Setting up the Apache Web Server

EX200 Q&A. DEMO Version

Web Application Firewall (WAF) Evasion Techniques

commands exercises Linux System Administration and IP Services AfNOG 2015 Linux Commands # Notes

ViMP 2.0. Installation Guide. Verfasser: ViMP GmbH

CentOS 6.7 with Vault MySQL 5.1

Configuring Multiple Instances of Railo on Linux

Django urls Django Girls Tutorial

Apache Httpd Manual Configuration File Httpd Conf Location

Tomcat Load Balancing for Progress Application Server for OpenEdge

Masquerading Made Simple HOWTO

Tungsten Dashboard for Clustering. Eric M. Stone, COO

Getting Started with Phalcon

AWS/LAMP/Wordpress/Bootstrap Extravaganza. I am determined to make this shit fun.

Get Your Game On. Getting and Installing PCSX. Getting Plugins and BIOS. Installing the "Easy Stuff" Playing PlayStation Games in Linux

3. Apache Server Vulnerability Identification and Analysis

A PAtCHy server: developed by the Apache group formed 2/95 around by a number of people who provided patch files for NCSA httpd 1.3 by Rob McCool.

Twiki Installation Notes. Ned Brush 4/13/06. Everything is left as is (default settings) unless specified below. Distribution: RHEL 4

Purpose. Target Audience. Prerequisites. What Is An Event Handler? Nagios XI. Introduction to Event Handlers

Why You Should Not Use Arch

Setting up my Dev Environment ECS 030

SIM Bank Scheduler Server User Manual. (for Version )

Apache + PHP + MySQL. bdnog November 2017 Dhaka, Bangladesh

EVALUATION ONLY. WA2097 WebSphere Application Server 8.5 Administration on Linux. Student Labs. Web Age Solutions Inc.

Apache Httpd Manual Conf Virtualhost Redirect

Linux Systems Administration Getting Started with Linux

Take Command Configuring pppd in Linux, Part I

Nagios User Guide. You can use apt-get to install these packages by running the following commands:

Linux Essentials Objectives Topics:

This document is intended for use by Nagios Administrators that want to use Slack for notifications.

Check the FQDN of your server by executing following two commands in the terminal.

Client Side JavaScript and AJAX

Who am I? I m a python developer who has been working on OpenStack since I currently work for Aptira, who do OpenStack, SDN, and orchestration

CentOS 7 with MariaDB

When you first launch CrushFTP you may be notified that port 21 is locked. You will be prompted to fix this.

This documentation can used to generate a request that can be submitted to any of these CA types.

What's the Slope of a Line?

Apache MySQL PHP PHPAdmin Install

CSN09101 Networked Services. Module Leader: Dr Gordon Russell Lecturers: G. Russell

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

9.2 Linux Essentials Exam Objectives

HylaFAX Enterprise Web Interface Admin Guide. HylaFAX Enterprise Web Interface Admin Guide

Illustrated Steps to create greggroeten.net with AWS

Preparing Your Working Environment

Installing FreePBX 12 on CentOS 6.5

WA2031 WebSphere Application Server 8.0 Administration on Windows. Student Labs. Web Age Solutions Inc. Copyright 2012 Web Age Solutions Inc.

Web Application Firewall (WAF) Evasion Techniques #2

Ganglia is monitring system for high performance computing systems. We have two node potter.isb.ots.com and harry.isb.ots.com both are HPC nodes.

CS Students Linux User's Guide

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

Virtual Hosting With PureFTPd And MySQL (Incl. Quota And Bandwidth Management) On CentOS 6.4

Apache Httpd Manual Conf Listen Ipv6 >>>CLICK HERE<<<

Integrate Apache Web Server

Exim Practical. Patrick Okui. (based on materials from Brian Candler)

Installing FreePBX 13 on CentOS 6

The Wonderful World of Services VINCE

Apache Manual Install Ubuntu Php Mysql. Phpmyadmin No >>>CLICK HERE<<<

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Setting up a compiler

CherryPy on Apache2 with mod_python

macos High Sierra Apache Setup: Multiple PHP Versions First part in a multi-part blog series for Mac developers

How To Start Mysql Use Linux Command Line Client In Ubuntu

My Favorite bash Tips and Tricks

Two factor authentication for Apache using mod_auth_radius

2. Installing OpenBiblio 1.0 on a Windows computer

How To Manually Update Google Play Apps On Kindle Fire Without Rooting

Unix basics exercise MBV-INFX410

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Public-Key Infrastructure (PKI) Lab

15-122: Principles of Imperative Computation

FreeBSD Install VIM Editor Without X11 GUI

How to force automatic removal of deleted files in nextcloud

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Red Hat Ceph Storage 3

Flexible Engine. Startup Guide

Advanced topics, part 2

Exploring UNIX: Session 3

Stacking LAMPs. Tom Ryder

How To Update My Java Plug In Firefox Ubuntu 10.04

Transcription:

ModSecurity2 Installation, and Configuration Hi, I actually searched a lot of times through Mr. Google looking for a ModSecurity2 HOWTO, but unfortunately I didn't find any. So I decided to write this simple HOWTO to help Sys Admin's to install and implement the ModSecurity2 Apache Module. For those whom are now wondering by now!!!, what is this ModSecurity???, Well let's use the official definition: ModSecurity is an open source, free web application firewall (WAF) Apache module. With over 70% of all attacks now carried out over the web application level, organizations need all the help they can get in making their systems secure. WAFs are deployed to establish an external security layer that increases security, detects and prevents attacks before they reach web applications. It provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring and real-time analysis with little or no changes to existing infrastructure. Great now that you know what it is, for sure you know if you really need it or not. Before we start, please note that this HOWTO is for ModSecurity2 with Apache2. I shall not be discussing ModSecurity Version1 and Apache Version1. And by the way they are completely different in configuration and other issues. Okay before we start the installation, first of all we need to install the Apache2 and all the other software needed to install ModSecurity2. In case you don't have already an Apache2 server up and running, please do the following: # yum install httpd system-config-httpd httpd-devel mod_ssl # apt-get install apache2 apache2-utils Okay, now Apache is ready, lets move on to install other ModSecurity2 prerequisites. We need mod_unique_id which comes by default with the Apache2 main package, and we need to other libraries: libxml2 ---> http://xmlsoft.org/downloads.html liblua5 ---> http://www.lua.org/download.html Make sure they don't currently exists by: $ ls -l /usr/lib/ If you find them there? well great let's move on. If not? then please download them from the sites supplied above.

Before we start the installation process, let's just stop Apache from running. /etc/init.d/httpd stop /etc/init.d/apache2 stop Now the great part, Installing the ModSecurity2. I shall be using the packages provided from the main developers (BreachSecurity), which you can find here --> DOWNLOAD I used modsecurity-apache_2.5.6 the time I was writing this HOWTO, so please make sure to choose the latest, because there always is updates and other cool stuff added to the new releases. Okay let's start downloading: $ wget -c http://www.modsecurity.org/download/modsecurity-apache_2.5.6.tar.gz Now let's extract the files: $ tar xvfz modsecurity-apache_2.5.6.tar.gz Change into the directory: $ cd modsecurity-apache_2.5.6/apache2/ Now we shall start with the configuration part, I always like to use the --with-apxs option (it is optional), now do: $./configure --with-apxs=/usr/sbin/apxs After that lets compile the package: $ make A test is always good to go for: $ make test And if everything went well, a clean install is done (as root user): # make install Okay, now we have ModSecurity2 installed this doesn't mean that it is activated. To make it active we need to add some lines into the Apache main configuration files which tell Apache to load the ModSecurity Modules. So let's edit the main Apache configuration file (please use any editor that you prefer, for me I stick with vim): # vim /etc/httpd/conf/httpd.conf Now go to the end of the LoadModule lines, and add the following: ## Load Mod Security Modules and Required Libraries LoadFile /usr/lib/libxml2.so LoadFile /usr/lib/liblua5.1.so LoadModule security2_module modules/mod_security2.so Include conf.d/modsecurity2/*.conf Include conf.d/modsecurity2/optional_rules/*.conf LoadModule unique_id_module modules/mod_unique_id.so

Save the file and exit. Now I assume that you are still in the directory modsecurity-apache_2.5.6/apache2/? If you are then let's copy the rules to the modsecurity2/ directory in the Apache configuration directory. This is done like this: # mv../modsecurity-apache_2.5.6/rules/* /etc/httpd/conf.d/modsecurity2/ If you are not in the modsecurity-apache_2.5.6/apache2/ directory then please switch to the following: # cp /path2/modsecurity-apache_2.5.6/rules/* /etc/httpd/conf.d/modsecurity2/ I always like to make checks as long as there is a syntax checker available, so lets check our Apache syntax: apachectl configtest If an error is shown please check the line number where the error exists, and solve it, if not? Then lets continue. Now let's start the Apache server: /etc/init.d/httpd start /etc/init.d/apache2 start Okay, now how can we know if ModSecurity2 is running or not? Well let's make a test and see. First of all create a PHP file name it anything (for me I chose checkmd.php) and add the following code to it: <? file $text=$_get['file']; echo "Content of File $text"; echo `cat $text`;?> Then goto your favorite web browser and try to browse the to the following link: http://localhost/checkmd.php?file=/etc/passwd Aha, you shall now have got a White Empty page saying in its title "501 Method Not Implemented", and its context is: Method Not Implemented GET to /checkmd.php not supported. Well done, this insures that ModSecurity2 is working and it blocked the try we are making to access the /etc/passwd file. --== CONGRATULATIONS INSTALLATION COMPLETE ==--

--== Some questions that you might be woundering of ==-- Question1: If for a reason or another I want to stop the ModSecurity2 from working, how is that Done? Answer1: Simply edit the following file: # vim /etc/httpd/conf.d/modsecurity2/modsecurity_crs_10_config.conf And switch the SecRuleEngine variable from On to Off: SecRuleEngine Off Save the file and a quick reload is needed to tell Apache to reread its configuration files: # /etc/init.d/httpd reload # /etc/init.d/apache2 force-reload You can also switch the SecRuleEngine to DetectionOnly in case you need to monitor you web application. Question2: I am hosting my own Blog, and every time I add a post I keep getting a not implemented error. Why is this happening? And how can I disable it for my posts? (I.e: disabling ModSecurity2 for a specific file). Answer2: This is happening because ModSecurity thinks that you are trying to inject some code to the PHP files of your Blog based on the pretested rules BreachSecurity provides with the ModSecurity2 package. It is called "False Positives", because it is a false alert (you are only posting a new post) and it's positive because it matched one of the rules that ModSecurity2 depends on. Disabling it shall need some work from your side, because as I told in the beginning, ModSecurity2 does not work like ModSecurity Version1, and disabling it in version 1 was much easier, but here in ModSecurity2 it is really much more powerful. First you need to monitor your Apache error log files. So let us start the following: # tail -f /var/log/httpd/error_log I shall assume that we have the Blog parked on the domain www.example.com. Open your favorite browser and goto: http://www.example.com/wp-admin/post-new.php And write the same post you got an error from. Now you shall get the same error, right? Great, now lets go and check what our error log has reported us. We shall see something like this: [Mon Sep 22 11:01:12 2008] [error] [client 211.158.21.152] ModSecurity: Access denied with code 501 (phase 2). Pattern match "^(?:ht f)tp:/" at ARGS:referredby. [file "/etc/httpd/conf.d/modsecurity2/optional_rules/modsecurity_crs_42_tight_security.conf"] [line "32"] [id "950117"] [msg "Remote File Inclusion Attack"] [severity "CRITICAL"] [hostname "www.example.com"] [uri "/wp-admin/post-new.php"] [unique_id "dgp7gxaaa8aaapqc4aaeaafz"]

Hey, wait a minute, What are these???? This is actually a single line of error. Let me explain the important parts of it, and what we shall need to disable this alert from happening in the future. I am interested now in: 1st: 211.158.21.152 this is the IP of the host who because of him the alert was raised. 2nd: modsecurity_crs_42_tight_security.conf is the file that includes the rule. 3rd: ModSecurity classified this as a Remote File Inclusion Attack. 4th: www.example.com is the domain where the problem came from (in case you are hosting more domains on the same server). 5th: The file that made the alert is /wp-admin/post-new.php. Finally: id, This is the important thing for us here, because we shall be using this number which is actually a rule number from the ModSecurity rule set. Great we have the id let us disable this error from happening again. Goto Apache's main config file and edit it: # vim /etc/httpd/conf/httpd.conf Add the following lines to disable the error above: <LocationMatch "/wp-admin/post-new.php"> SecRuleRemoveById 950117 </LocationMatch> Now save, close the file and reload Apache. Try making the same post again. If everything went well then great, if you get another error? then go back to the log files and get the id and add it to the SecRuleRemoveById we wrote above. Notes: 1- If you are hosting more than one domain on the server (VirtualHosting), then it is better to add the lines above to the configuration file of that domain. 2- You can also solve this error by witting your own rules, but it is not quite easy and you need some knowledge in writing Regex codes, and to be more precise you need to know how to write Perl- Compatible Regular Expression (PCRE), which ModSecurity rules are written with. If you are looking for further documentation, then the main site is always a good place to look in: http://www.modsecurity.org/documentation/modsecurity-apache/2.5.6/html-multipage/installation.html So that's it :) Written by: Ali Al-Shemery (B!n@ry) Linux Arab Community