<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Erics Tech Blog &#187; EnGarde</title>
	<atom:link href="http://eric.lubow.org/category/engarde/feed/" rel="self" type="application/rss+xml" />
	<link>http://eric.lubow.org</link>
	<description>Thoughts, musings, and other idealistic (sometimes useful) systems and development hoopla.</description>
	<lastBuildDate>Mon, 16 Aug 2010 12:30:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Configuring mod_security for EnGarde Secure Linux</title>
		<link>http://eric.lubow.org/2007/engarde/configuring-mod_security-for-engarde-secure-linux/</link>
		<comments>http://eric.lubow.org/2007/engarde/configuring-mod_security-for-engarde-secure-linux/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 17:18:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[EnGarde]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/blog/2007/engarde/17/configuring-mod_security-for-engarde-secure-linux/</guid>
		<description><![CDATA[Introduction This document is intended to guide a user through initially setting up and understanding a mod_security+Apache2 under EnGarde Secure Linux setup. Once you have completed reading this document, you should be able to understand the basics of mod_security, what it is used for, and why it may apply to you and your environment. Why [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2007%2Fengarde%2Fconfiguring-mod_security-for-engarde-secure-linux%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2007%2Fengarde%2Fconfiguring-mod_security-for-engarde-secure-linux%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<h4>Introduction</h4>
<p>This document is intended to guide a user through initially setting up and understanding a mod_security+Apache2 under <a href="http://www.engardelinux.org/">EnGarde Secure Linux</a> setup. Once you have completed reading this document, you should be able to understand the basics of mod_security, what it is used for, and why it may apply to you and your environment.</p>
<h5>Why mod_security</h5>
<p>The need for mod_security may not be initially apparent since we are all perfect programmers and rarely make a mistake that could prove hazardous to security. It may not be for you, but it is for the users of your servers who may not be as adept in creating web applications.</p>
<p>mod_security is a web application intrusion detection and prevention engine.  It operates by &#8216;hook&#8217;ing itself into apache and inspecting all requests for your specific ruleset.  It can be used to monitor your server with logging or even protect it by &#8221;deny&#8221;ing attacks.</p>
<h5>Skills Needed</h5>
<p>You will need to have access to the WebTool and the GDSN Package Manager.  You need to have shell access to the machine and the ability to use a text editor to make the necessary changes to the configuration files.</p>
<h4>Installation</h4>
<p>To install mod_security, go into the GDSN Manager in the Guardian Digital WebTool.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;System -&gt; Guardian Digital Secure Network<br />
&nbsp;Module -&gt; Package Management</div></div>
<p>Find the line that says <strong>libapache-mod_security</strong> and check the checkbox next to it.  Click the <em>Install Selected Packages</em> button.  Let the mod_security package install.</p>
<h4>Configuration</h4>
<p>Now its time to configure the mod_security package.  The first thing that has to be done is to add the configuration file for mod_security (that we are going to create) to the apache2 configuration file.  To accomplish this, ensure that the following line is somewhere in your <em>/etc/httpd/conf/httpd.conf</em>:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;Include conf/mod_security.conf</div></div>
<p>This ensures that when apache2 starts up, the configuration that you spcify in <em>/etc/httpd/conf/httpd.conf</em> will be loaded.</p>
<h5>Basic Configuration</h5>
<p>Once you have installed mod_security, it&#8217;s time for some basic configuration. In order to keep consistency, the mod_security.conf configuration file should be created in the /etc/httpd/conf/ directory.  For a basic configuration (which we will walk through step-by-step), your <em>/etc/httpd/conf/mod_security.conf</em> file should looks as follows:</p>
<pre>
 LoadModule security_module /usr/libexec/apache/mod_security.so
 &lt;IfModule mod_security.c&gt;
   SecFilterEngine On
   SecFilterDefaultAction "log"
   SecFilterCheckURLEncoding On
   SecFilterForceByteRange 1 255

   SecServerSignature "Microsoft-IIS/5.0"

   SecAuditEngine RelevantOnly
   SecAuditLog /etc/httpd/logs/modsec_audit_log
   SecFilterDebugLog /etc/httpd/logs/modsec_debug_log
   SecFilterDebugLevel 0
 &lt;/IfModule&gt;
</pre>
<h6>SecFilterEngine</h6>
<p>This directive turns on mod_security.</p>
<h6>SecFilterDefaultAction</h6>
<p>This directive decides what happens to a request that is caught by the mod_security filtering engine.  In our case, we are going to log the request. By reading the documentation, you will find that there are many other options<br />
available.  By changing this line slightly (once you have logged and found out when and how the mod_security engine catches requests), you can deny requests and produce errors:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecFilterDefaultAction &quot;deny,log,status:404&quot;</div></div>
<p>This line denies the request, logs it to your log files, and send the requester back a HTTP status code 404 (also known as <em>Page Not Found</em>).</p>
<h6>SecFilterCheckURLEncoding</h6>
<p>This directive checks the URL to ensure that all characters in the URL are properly encoded.</p>
<h6>SecFilterForceByteRange</h6>
<p>This directive asserts which bytes are allowed in requests.  The <em>1&#8230;255</em> specified in the example allows almost all characters.  To bring this down to just the minimal ASCII character set, replace the above line with:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecFilterForceByteRange 32 126</div></div>
<h6>SecServerSignature</h6>
<p>This directive can be used to attempt to mask the identity of the apache server. Although this method works well, it is not 100% effective as there are other methods that can be used to determine the server type and version.  It should be noted that for this to work, the Apache2 configuration variable <strong>ServerTokens</strong> should be changed from <strong>Prod</strong> (default) to <strong>Full</strong> so the line reads as follows:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;ServerTokens Full</div></div>
<h6>SecAuditEngine</h6>
<p>This directive allows more information about the methods of an attacker to be logged to the specified logfile.  To turn this on to log every request object use the syntax:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecAuditEngine On</div></div>
<p>This is not very desirable as this produces a LOT of output.  The more desirable version is the one used above:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecAuditEngine RelevantOnly</div></div>
<p>This logs only the interesting stuff that may be useful in back tracing the methods of an attacker.</p>
<h6>SecAuditLog</h6>
<p>This is the location of the audit log file.  It is generally preferred to use absolute paths to files to ensure the correct path is being used.</p>
<h6>SecFilterDebugLevel</h6>
<p>This directive refers to the debug level logged to the specified logfile. The current value of <em>0</em> should be used on production systems.  While the environment is in testing, a level of 1..4 should be used with increasing<br />
verbosity between from 1 up to 4.</p>
<h6>SecFilterDebugLog</h6>
<p>This is the location of the audit log file.  It is generally preferred to use absolute paths to files to ensure the correct path is being used.</p>
<h5<Advanced Configuration</h5>
<p>We will add some lines to do some <em>Selective</em> filtering.  Selective filters are used to handle some specific situations that cannot be targeted with site-wide policy.  However you need to be careful of what you make site-wide policy since some of these security measures can break your current setup.</p>
<p>There are even more in depth uses where you can number rules and apply them to certain sets of directives and not to others.  mod_security allows for very granular control.  The in depth discussions on using these is beyond the scope of this document.</p>
<h6>General</h6>
<p>Since mod_security is a keyword driven engine, it will take the specified action on simple keyword matches.  This is to say that anything that follows the directive <strong>SecFilter</strong> will engage the appropriate action. For example:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecFilter &quot;&amp;gt;applet&quot;</div></div>
<p>If the &lt;applet&gt; tag appears anywhere in the request, then the log action specified above is taken.</p>
<h6>XSS Attacks</h6>
<p>To try to prevent some types of cross site scripting attacks, you can add the following lines to your configuration file:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecFilter &quot;&amp;lt;script&quot;<br />
&nbsp;SecFilter &quot;&amp;lt;.+&amp;gt;&quot;</div></div>
<p>This tries to prevent Javascript injections or HTML injections.</p>
<h6>Directory Traversal</h6>
<p>Rarely will it be necessary for a user to traverse directories using the &#8220;../&#8221; construct.  In order to prevent that, we can add the line:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecFilter &quot;\.\./&quot;</div></div>
<h6>GET/HEAD Requests</h6>
<p>With the use of these lines, we will not accept GET or HEAD requests that have bodies:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecFilterSelective REQUEST_METHOD &quot;^(GET|HEAD)$&quot; chain<br />
&nbsp;SecFilterSelective HTTP_Content-Length &quot;!^$&quot;</div></div>
<h6>Unknown Requests</h6>
<p>There are occasionally requests that come across (usually malicious) that we don&#8217;t know how to handle.  At that point we let mod_security handle the request by adding the following lines:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SecFilterSelective HTTP_Transfer-Encoding &quot;!^$&quot;</div></div>
<h4>Conclusion</h4>
<p>At this point, you should be capable of setting up a basic installation of mod_security.  They are many more combinations of both simple and advanced techniques and directives that can be used to protect your server.  By reading the documentation, you can have very granular control over your web server attack detection and prevention.</p>
<h4>Originally Posted:</h4>
<ul>
<li><a href="http://http://wiki.engardelinux.org/index.php/Mod_security">http://wiki.engardelinux.org/index.php/Mod_security</a></li>
</ul>
<h4>References</h4>
<ul>
<li><a href="http://www.modsecurity.org/"> mod_security</a></li>
<li><a href="http://www.modsecurity.org/documentation/index.html">mod_security documentation</a></li>
<li><a href="http://www.modsecurity.org/projects/rules/index.html">mod_security rules</a></li>
<li><a href="http://www.gotroot.com/downloads/ftp/mod_security/apache2/?page=apache2">Gotroot ruleset</a></li>
<li><a href="http://www.engardelinux.org/">EnGarde Secure Linux</a>
<li><a href="http://wiki.engardelinux.org/">EnGarde Secure Wiki</a>
</ul>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2007/linux-security/10-tips-to-start-securing-your-linux-system/' rel='bookmark' title='Permanent Link: 10 Tips To Start Securing Your Linux System'>10 Tips To Start Securing Your Linux System</a></li>
<li><a href='http://eric.lubow.org/2007/system-administration/a-few-apache-tips/' rel='bookmark' title='Permanent Link: A Few Apache Tips'>A Few Apache Tips</a></li>
<li><a href='http://eric.lubow.org/2007/linux-security/10-more-tips-towards-securing-your-linux-system/' rel='bookmark' title='Permanent Link: 10 More Tips Towards Securing Your Linux System'>10 More Tips Towards Securing Your Linux System</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2007/engarde/configuring-mod_security-for-engarde-secure-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
