<?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>Security Advancements at the Monastery &#187; Apache</title>
	<atom:link href="http://blog.securitymonks.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.securitymonks.com</link>
	<description>Information about developments at the Monastery</description>
	<lastBuildDate>Fri, 03 Sep 2010 05:41:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WebGoat, Lua, and ModSecurity verses Password Guessing</title>
		<link>http://blog.securitymonks.com/2009/01/10/webgoat-lua-and-modsecurity-verses-password-guessing/</link>
		<comments>http://blog.securitymonks.com/2009/01/10/webgoat-lua-and-modsecurity-verses-password-guessing/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 00:54:52 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[ModSecurity]]></category>
		<category><![CDATA[OWASP]]></category>
		<category><![CDATA[Vulnerability]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[WebGoat]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/?p=826</guid>
		<description><![CDATA[Happiness abandoned Twitter this week as it was revealed that an 18-year-old was able to use an automated password-guesser to break into an account.  Twitter allowed for an unlimited number of log-in attempts.  The hacker used a simple dictionary attack that revealed at 11:00am Monday the password of &#8220;happiness.&#8221;  Once the hacker [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://sensitivitytothings.com/wp-content/uploads/2008/03/roller-coaster-monks.jpg" alt="" align="left" width=150 />Happiness abandoned <a href="http://twitter.com/">Twitter</a> this week as it was revealed that an 18-year-old was able to use an automated password-guesser to break into an account.  Twitter allowed for an unlimited number of log-in attempts.  The hacker used a simple <a href="http://en.wikipedia.org/wiki/Dictionary_attack">dictionary attack</a> that revealed at 11:00am Monday the password of &#8220;<strong>happiness</strong>.&#8221;  Once the hacker had the Twitter staffer&#8217;s password, through the administrative panel it was possible to change the email address of any Twitter account and reset the holder&#8217;s password.  See Tom&#8217;s post &#8220;<a href="http://spylogic.net/item/398">Summary of the Twitter Security Incidents</a>&#8221; for more details on the incident.</p>
<p>
To deal with administrative accounts at Twitter, Adam O&#8217;Donnell provides some great advices to corporate CSOs in his article, &#8220;<a href="http://blogs.zdnet.com/security/?p=2359">A roadmap for the Twitter CSO</a>.&#8221;  Dave Goldsmith post, &#8220;<a href="http://www.matasano.com/log/1342/my-pentest-secret-password-guessing/">My Pentest Secret: Password Guessing</a>,&#8221; provides more advice to mitigate risk of password guessing attacks.
</p>
<p>
Today&#8217;s post focuses on Dave&#8217;s point:<br />
<blockquote><strong>FAILED LOGIN DELAYS</strong>. What to do when someone is grinding passwords on the same account? Account lockout is pretty unpopular as it can lead to a denial of service attack. Doing nothing is pretty unpopular because attackers can grind forever. Enter the exponentially increasing login delay. Every failed login on an account causes the system to delay more and more on that account until a reset on that counter after a reasonable period of time or a valid login.</p></blockquote>
<p>The Open Web Application Security Project (<a href="http://www.owasp.org/index.php/Main_Page">OWASP</a>) has begun a podcast focused on web application security.  The podcast is hosted by <a href="http://www.linkedin.com/in/jmanico">Jim Manico</a>, a Web Application Architect and Security Engineer for Aspect Security.  In <a href="http://www.owasp.org/index.php/Podcast_2">Podcast #2</a>, Stephen Craig Evans, an independent software security consultant, talks about <a href="http://www.lua.org/">Lua</a> and the OWASP Summer of Code project wiki, <a href="http://www.owasp.org/index.php/OWASP_Securing_WebGoat_using_ModSecurity_Project">Securing WebGoat using ModSecurity</a>.  The project  goes through the steps involved in securing WebGoat using the combination of ModSecurity and Lua.  To quote <a href="http://blog.modsecurity.org/2008/10/securing-webgoat-using-modsecurity.html">Ivan Ristic</a>, creator of ModSecurity, the project &#8220;stretched the boundaries of what ModSecurity could do.&#8221;
</p>
<p>
<center><a href="http://www.owasp.org/index.php/Image:WebGoat-Bypass-Access-Control-Lesson.JPG"><img src="https://www.owasp.org/images/thumb/f/f3/WebGoat-Bypass-Access-Control-Lesson.JPG/300px-WebGoat-Bypass-Access-Control-Lesson.JPG" /></a></center>
</p>
<p>
To help address the problem of dictionary attacks against your web server, today&#8217;s post will be using ModSecurity with the scripting language Lua.  First, let&#8217;s setup WebGoat for testing purposes.  </p>
<h2>WebGoat</h2>
<p>For those unfamiliar with <a href="http://www.owasp.org/index.php/Category:OWASP_WebGoat_Project">OWASP WebGoat project</a>, WebGoat is:<br />
<blockquote>WebGoat is a deliberately insecure J2EE web application maintained by OWASP designed to teach web application security lessons. In each lesson, users must demonstrate their understanding of a security issue by exploiting a real vulnerability in the WebGoat application. For example, in one of the lessons the user must use SQL injection to steal fake credit card numbers. The application is a realistic teaching environment, providing users with hints and code to further explain the lesson.</p>
<p>Why the name &#8220;WebGoat&#8221;? Developers should not feel bad about not knowing security. Even the best programmers make security errors. What they need is a scapegoat, right? Just blame it on the &#8216;Goat!</p></blockquote>
<p>WebGoat is intended to teach a structured approach to test and exploiting vulnerabilities within an application security assessment.  Also being developed is the <a href="http://www.owasp.org/index.php/OWASP_Testing_Project">OWASP Testing Project</a>, which provides a full application security assessment testing methodology.  Through WebGoat, companies have a way to teach web application security lessons to their developers.  There are over 30 lessons dealing with such issues as:
</p>
<table>
<tr>
<td valign="top">
<ul>
<li> <a href="http://blog.securitymonks.com/index.php/Cross-site_Scripting_%28XSS%29" title="Cross-site Scripting (XSS)">Cross-site Scripting (XSS)</a>
</li>
<li> Access Control
</li>
<li> <a href="http://blog.securitymonks.com/index.php/Race_condition_within_a_thread" title="Race condition within a thread">Thread Safety</a>
</li>
<li> <a href="http://blog.securitymonks.com/index.php/Unvalidated_Input" title="Unvalidated Input">Hidden Form Field Manipulation</a>
</li>
<li> Parameter Manipulation
</li>
<li> <a href="http://blog.securitymonks.com/index.php/Session_Management#Weak_Session_Cryptographic_Algorithms" title="Session Management">Weak Session Cookies</a>
</li>
<li> Blind <a href="http://blog.securitymonks.com/index.php/SQL_injection" title="SQL injection">SQL Injection</a>
</li>
</ul>
</td>
<td valign="top">
<ul>
<li> Numeric SQL Injection
</li>
<li> String SQL Injection
</li>
<li> <a href="http://blog.securitymonks.com/index.php/Web_Services" title="Web Services">Web Services</a>
</li>
<li> <a href="http://blog.securitymonks.com/index.php/Improper_Error_Handling" title="Improper Error Handling">Fail Open Authentication</a>
</li>
<li> Dangers of HTML Comments
</li>
<li> &#8230; and many more!
</li>
</ul>
</td>
</tr>
</table>
<p>
The <a href="http://yehg.org/">YGN Ethical Hacker Group</a> has made available a series of video on walking through WebGoat v5.2.  The videos consist of:</p>
<table>
<tr>
<td>
<ul>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_general.zip">General</a> </li>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_codequality.zip">Code Quality</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_concurrency.zip">Concurrency</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_unvalidatedparams.zip">Unvalidated Parameters</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">Access Control Flaws</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">Authentication Flaws</a>  </li>
<li>Session Management Flaws  </li>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">Cross-Site Scripting (XSS)</a>  </li>
</ul>
</td>
<td>
<ul>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">Buffer Overflows</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">Injection Flaws</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_impropererrorhandling.zip">Improper Error Handling</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_insecurestorage_encoding_basics.zip">Insecure Storage</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_dos.zip">Denial of Service (DOS)</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/files.php/webgoat_simulation_insecurecofig.zip">Insecure Configuration</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">Web Services</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">AJAX Security</a>  </li>
<li><a href="http://yehg.org/lab/pr0js/training/webgoat.php#">Challenge</a>  </li>
</ul>
</td>
</tr>
</table>
<p>Please recognize that WebGoat is a vulnerable server and therefor you will want to set it up so no one but you can access the WebGoat server.  By default WebGoat only listens on the loopback address.  Below are the steps to pull down WebGoat and install it on a Linux server.  Since this is not a production system, we will be installing the WebGoat developer release.
</p>
<p><h2>Installing JDK</h2>
<p>WebGoat will require Sun JDK 6 to be installed.  Get the Sun JDK 6 from <a href="http://java.sun.com/javase/downloads/index.jsp">Sun&#8217;s website</a>.  Sun requires you to agree to terms, so you&#8217;ll need to go there and agree.  Run the installer which gets downloaded.  Agree again to the terms.  The installer will install a few rpms and jars.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# /bin/sh jdk-6u11-linux-i586-rpm.bin
root# ls -la /usr/java
default  jdk1.5.0_17  jdk1.6.0_11  latest
root# declare -x JAVA_HOME="/usr/java/latest"
root# declare -x PATH="${JAVA_HOME}/bin:${PATH}
root# java -version
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Server VM (build 11.0-b16, mixed mode)
</pre>
</td>
</table>
<p></p>
<h2>Running WebGoat Standard Release</h2>
<p>While the documentation for WebGoat says to install Tomcat, the WebGoat zip file will come with its own version of Tomcat.  Running WebGoat in this manner can prove to be the easiest path allowing the avoidence of Java software version problems.  We will go through both deployments.  First, installing WebGoat with Tomcat.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
/usr/local/src root# wget \

http://webgoat.googlecode.com/files/WebGoat-OWASP_Standard-5.2.zip

/usr/local/src root# /usr/bin/openssl sha1 WebGoat-OWASP_Standard-5.2.zip
SHA1(WebGoat-OWASP_Standard-5.2.zip)=
1e8950d8af0a1726ee1c4509cb64ee4ee6da7584
/usr/local/src root# unzip WebGoat-OWASP_Standard-5.2.zip
/usr/local/src root# cd WebGoat-5.2
</pre>
</td>
</table>
<p>
At this point, a slight modification needs to be made to webgoat.sh.  It checks if the java version is 1.5.  This is an odd check, since WebGoat was compiled under 1.6 and will not run under 1.5.  Find where <strong>webgoat.sh</strong> has <strong>grep &#8216;version \&#8221;1.5&#8242;</strong> and change 1.5 to 1.6.  At that point, you are read to start WebGoat.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/WebGoat-5.2 root# /bin/sh webgoat.sh start8080
Using CATALINA_BASE:   ./tomcat
Using CATALINA_HOME:   ./tomcat
Using CATALINA_TMPDIR: ./tomcat/temp
Using JAVA_HOME:       /usr/java/latest

  Open http://127.0.0.1:8080/WebGoat/attack
  Username: guest
  Password: guest
  Or try http://guest:guest@127.0.0.1:8080/WebGoat/attack
</pre>
</td>
</table>
<p>
This is running WebGoat accessible only to 127.0.0.1.  From your web browser, go to http://127.0.0.1:8080/WebGoat/attack and log in with username guest and password guest.  At this point, WebGoat is running and you are set to start going through the lesson plans and exercise.</p>
<h2>Installing WebGoat.war</h2>
<p>If you have Tomcat on your server, you will want to install only the WebGoat.war file.  I am going to make this a little more complicated by going through the steps to install Tomcat.  In previous posts, I have stepped through installation of Apache and ModSecurity.  Walking through the installation of Tomcat will help get us on the same page as far as configuration and installation.
</p>
<p>
There is a known issue with the latest stable release of Tomcat, 6.0.18.  It requires <strong>JDK 5</strong> at the moment, due to incompatibilities introduced by Sun JDK 6.  Sun changed the JDBC spec in an incompatible fashion that was discovered after Tomcat 6 went out.  There are changes in the trunk to replace the DB connection pooling mechanism with one that isn&#8217;t impacted by the 1.6 change.  Unfortunately, WebGoat required JDK 6.  To get a round this problem, we will use the subversion release of Tomcat.
</p>
<p>
We first need to install <strong>Apache Ant</strong>, which is a software tool for automating software build processes.  It is similar to make but is implemented using the Java language.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd  /usr/local/src/
/usr/local/src root# wget http://www.uniontransit.com/apache/ant/binaries/apache-ant-1.7.1-bin.tar.gz
/usr/local/src root# md5sum apache-ant-1.7.1-bin.tar.gz
cc5777c57c4e8269be5f3d1dc515301c  apache-ant-1.7.1-bin.tar.gz
/usr/local/src root# tar xzf apache-ant-1.7.1-bin.tar.gz
/usr/local/src root# mv apache-ant-1.7.1 /work/software
/usr/local/src root# cd  /work/software
/work/software root# ln -s apache-ant-1.7.1 ant
/work/software root# declare -x ANT_HOME="/work/software/ant"
/work/software root# declare -x PATH="${PATH}:${ANT_HOME}/bin"
/work/software root# ant
Buildfile: build.xml does not exist!
Build failed
</pre>
</td>
</table>
<p>
</p>
<p>
The error above indicate that ant command is recognized by shell but it did not find build.xml file that needed to compile ant projects. So, it’s absolutely normal and the installation was successful.
</p>
<p>
We are now ready to download and build <strong>Tomcat</strong>.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd  /usr/local/src/
/usr/local/src root# svn checkout \
http://svn.apache.org/repos/asf/tomcat/trunk tomcat-7
/usr/local/src root# cd tomcat-7
/usr/local/src/tomcat-7 root# ant download
/usr/local/src/tomcat-7 root# ant
/usr/local/src/tomcat-7 root# cd output
/usr/local/src/tomcat-7/output root# mv build \
/work/software/tomcat-7
/usr/local/src/tomcat-7 root# cd /work/software/
/work/software root# ln -s tomcat-7 tomcat
/work/software root# declare -x CATALINA_HOME="/work/software/tomcat"
/work/software root# chmod u+x $CATALINA_HOME/bin/*
/work/software root# mkdir $CATALINA_HOME/logs
</pre>
</td>
</table>
<p></p>
<h2>Configuring and Using Tomcat</h2>
<p>The following modifications can be done to configuration Tomcat files that came down as part of WebGoat or the latest version from the Tomcat site.  If you make the modifications to the Tomcat under Webgoat, keep in mind:</p>
<ol>
<li>Set $CATALINA_HOME appropriately</li>
<li>Modify webgoat.sh, removing the line &#8220;cp -f $CATALINA_HOME/conf/server_8080.xml $CATALINA_HOME/conf/server.xml&#8221;.</li>
<li>Adjust paths based on where WebGoat is installed.</li>
<li>Add to the $CATALINA_HOME/conf/tomcat-users.xml file.  Do not replace content.</li>
<li>You can use $CATALINA_HOME/bin/shutdown.sh to shutdown Tomcat.</li>
<li>You can start with $CATALINA_HOME/bin/startup.sh instead of webgoat.sh, provided you have $PATH, $JAVA_HOME, and $CATALINA_HOME set.
</li>
</ol>
<p>Before starting, create a manager username and password.  This is set in the $CATALINA_HOME/conf/tomcat-users.xml file.  The following is an example only:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/work/software root# vi $CATALINA_HOME/conf/tomcat-users.xml
&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;tomcat-users&gt;
  &lt;role rolename="tomcat"/&gt;
  &lt;role rolename="manager"/&gt;
  &lt;user username="jerry" password="mousepower" roles="tomcat"/&gt;
  &lt;user username="tom" password="catpower" roles="manager"/&gt;
&lt;/tomcat-users&gt;
</pre>
</td>
</table>
<p>
We can setup secure web authentication through the use of digital certificates using SSL.  First step is to use the <a href="http://java.sun.com/j2se/1.3/docs/tooldocs/win32/keytool.html">keytool utility</a>, which is included in the Sun Java Standard Edition JDK, to create a keystore file.  Use &#8220;changeit&#8221; as the password. (If you don&#8217;t use &#8220;<strong>changeit</strong>&#8221; you will have to state the password in with the keystorePass setting in server.xml).  For example:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/work/software root# mkdir /work/software/tomcat/keystore
/work/software root# cd /work/software/tomcat/keystore
/work/software/tomcat/keystore root# keytool -genkey -alias tomcat \
-keyalg RSA -keysize 2048 -keystore /work/software/tomcat/keystore/keystore
Enter keystore password:  <strong>changeit</strong>
What is your first and last name?
  [Unknown]:  John Gerber
What is the name of your organizational unit?
  [Unknown]:  SecurityMonks
What is the name of your organization?
  [Unknown]:  OrderOfUnix
What is the name of your City or Locality?
  [Unknown]:  Knoxville
What is the name of your State or Province?
  [Unknown]:  TN
What is the two-letter country code for this unit?
  [Unknown]:  US
Is CN=John Gerber, OU=SecurityMonks, O=OrderOfUnix, L=Knoxville, ST=TN, C=US correct?
  [no]:  yes

Enter key password for <tomcat>
        (RETURN if same as keystore password):
/work/software/tomcat/keystore root# ls  /work/software/tomcat/keystore
/work/software/tomcat/keystore root# keytool -list -keystore keystore
</tomcat></pre>
</td>
</table>
<p>
The keystore created will not be trusted by JVM until the certificate is imported into JVM’s trusted certificate keystore.  We will export the SSL certificate we just generated and import it into the JVM&#8217;s keystore.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/work/software/tomcat/keystore root# keytool -export \
-alias tomcat -keystore keystore -file tomcat.cer
/work/software/tomcat/keystore root# keytool -import \
-trustcacerts -keystore /usr/java/jdk1.5.0_17/jre/lib/security/cacerts  \
-alias tomcat -file /work/software/tomcat/keystore/tomcat.cer
/work/software/tomcat/keystore root# keytool -list -alias tomcat \
-keystore /usr/java/jdk1.5.0_17/jre/lib/security/cacerts
</pre>
</td>
</table>
<p>
Modify the <strong>$CATALINA_HOME/conf/server.xml</strong> section which defines a SSL HTTP/1.1 Connector on port 8443. It should go with the other connectors in the Service section and looks something like this: </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
    &lt;Connector port="8443" minSpareThreads="5" maxSpareThreads="75"
           enableLookups="true" disableUploadTimeout="true"
           acceptCount="100"  maxThreads="200"
           scheme="https" secure="true" SSLEnabled="true"
           keystore="/work/software/tomcat/keystore/keystore"  keypass="changeit"
           clientAuth="false" sslProtocol="TLS" /&gt;
</pre>
</td>
</table>
<p>
In order to require SSL on a specific site configure a security constrant for that app.  Do this by editing the <strong>$CATALINA_HOME/conf/web.xml</strong> file and adding the following section just before the ending &lt;/web-app&gt; tag:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
    &lt;security-constraint&gt;
    &lt;web-resource-collection&gt;
    &lt;web-resource-name&gt;Automatic SSL Forwarding&lt;/web-resource-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/web-resource-collection&gt;
    &lt;user-data-constraint&gt;
    &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
    &lt;/user-data-constraint&gt;
    &lt;/security-constraint&gt;
</pre>
</td>
</table>
<p>
Now startup Tomcat.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/work/software root# $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE:   /work/software/tomcat
Using CATALINA_HOME:   /work/software/tomcat
Using CATALINA_TMPDIR: /work/software/tomcat/temp
Using JRE_HOME:       /usr/java/jdk1.5.0_17
/work/software root# ps awx | grep tomcat
  783 pts/14   Sl     0:04 /usr/java/jdk1.5.0_17/bin/java
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=/work/software/tomcat/conf/logging.properties
-Djava.endorsed.dirs=/work/software/tomcat/endorsed
-classpath :/work/software/tomcat/bin/bootstrap.jar
-Dcatalina.base=/work/software/tomcat
-Dcatalina.home=/work/software/tomcat
-Djava.io.tmpdir=/work/software/tomcat/temp org.apache.catalina.startup.Bootstrap start
/work/software root# /usr/sbin/lsof -iTCP -n -P | grep java
java      6175   root   10u  IPv6 327556       TCP *:8080 (LISTEN)
java      6175   root   12u  IPv6 327557       TCP *:8443 (LISTEN)
java      6175   root   21u  IPv6 327562       TCP *:8009 (LISTEN)
java      6175   root   22u  IPv6 327565       TCP 127.0.0.1:8005 (LISTEN)
</pre>
</td>
</table>
<p>
Tomcat is now built and running.  You can access it by going to:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">

http://localhost:8080
</pre>
</td>
</table>
<p>
which will redirect you to:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">

https://localhost:8443
</pre>
</td>
</table>
<p>
When you goto https://localhost:8443 you will be asked to accept the certificate.  If you have problems, make sure to clear you browser&#8217;s cache.  Now that we have Tomcat server running, we are ready to download and setup our WebGoat server.  </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# $CATALINA_HOME/bin/shutdown.sh
 root# cd /usr/local/src
/usr/local/src root# wget http://webgoat.googlecode.com/files/WebGoat-5.2.war
/usr/local/src root# /usr/bin/openssl sha1 WebGoat-5.2.war
SHA1(WebGoat-5.2.war)= c5aab7c5496625777a3b9e21b9888cddee5b649c
/usr/local/src root# mv WebGoat-5.2.war /work/software/tomcat/webapps/WebGoat.war
/usr/local/src root# $CATALINA_HOME/bin/startup.sh
/usr/local/src root# ls -la /work/software/tomcat/webapps/WebGoat
/usr/local/src root# ls -la /work/software/tomcat/conf/tomcat-users.xml
</pre>
</td>
</table>
<p>
Add WebGoat users and roles to <strong>$CATALINA_HOME/conf/tomcat-users.xml</strong> file.  Start Tomcat back up.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# $CATALINA_HOME/bin/shutdown.sh
 root# vi $CATALINA_HOME/conf/tomcat-users.xml
    &lt;tomcat-users&gt;
      &lt;role rolename=&quot;webgoat_basic&quot;/&gt;
      &lt;role rolename=&quot;webgoat_admin&quot;/&gt;
      &lt;role rolename=&quot;webgoat_user&quot;/&gt;
      &lt;role rolename=&quot;tomcat&quot;/&gt;
      &lt;user password=&quot;webgoat&quot; roles=&quot;webgoat_admin&quot; username=&quot;webgoat&quot;/&gt;
      &lt;user password=&quot;basic&quot; roles=&quot;webgoat_user,webgoat_basic&quot; username=&quot;basic&quot;/&gt;
      &lt;user password=&quot;tomcat&quot; roles=&quot;tomcat&quot; username=&quot;tomcat&quot;/&gt;
      &lt;user password=&quot;guest&quot; roles=&quot;webgoat_user&quot; username=&quot;guest&quot;/&gt;
    &lt;/tomcat-users&gt;
 root# $CATALINA_HOME/bin/startup.sh
</pre>
</td>
</table>
<p>
At this point, WebGoat should be running.  Pretend you are an 18-year hacker, and use your penetration skills to break into one of the accounts.  Check out the Access Control Flaws material and the Remote Admin Access section.  Being aware of what is possible, and that the threats are real, helps motivate a person to defend against them.
</p>
<p>
Now it is time to examine the work of OWASP Summer of Code project wiki, <a href="http://www.owasp.org/index.php/OWASP_Securing_WebGoat_using_ModSecurity_Project">Securing WebGoat using ModSecurity</a>.  With a vulnerable server to test out the vulnerabilities against, we will move on to the required software that will help defend against brute force password attacks.  First step, install Lua to use with ModSecurity.</p>
<h2>Lua</h2>
<p>The <a href="http://www.lua.org/">Lua</a> language combines &#8220;simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.&#8221;
</p>
<p>
For a complete discussion of the benefits of Lua, Soumya has written an article &#8220;<a href="http://blog.taragana.com/index.php/archive/10-reasons-why-you-should-make-lua-a-new-programming-language-your-coding-friend-a-detailed-review/">10 Reasons Why You Should Make Lua (A New Programming Language) Your Coding Friend &#8211; A Detailed Review</a>.&#8221;  Erik Wrenholt has also done an <a href="http://www.timestretch.com/FractalBenchmark.html">interesting benchmark</a> again popular languages to compute the Mandelbrot.  We are focusing on Lua is because it can be used with ModSecurity.  Plus, we want to take advantage of the work done by Stephen Craig Evans and others who worked on securing web applications.
</p>
<p>
To install Lua on a linux server by source:
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd  /usr/local/src/
/usr/local/src root# wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
/usr/local/src root# md5sum lua-5.1.4.tar.gz
d0870f2de55d59c1c8419f36e8fac150  lua-5.1.4.tar.gz
/usr/local/src root#tar xzf  lua-5.1.4.tar.gz
/usr/local/src root# cd lua-5.1.4
/usr/local/src/lua-5.1.4 root# make linux
/usr/local/src/lua-5.1.4 root# make install
/usr/local/src/lua-5.1.4 root# cd /usr/local/lib
/usr/local/lib root# gcc -shared -o liblua.5.1.4.so /usr/local/lib/liblua.a
/usr/local/lib root# ln -s liblua.5.1.4.so liblua.so
</pre>
</td>
</table>
<p>
</p>
<p><h2>ModSecurity</h2>
<p>If you are running a version of ModSecurity older than version 2.5, you will need to upgrade.  As of ModSecurity 2.5, Lua can be used:<br />
<blockquote>The new SecRuleScript directive allows for the execution of Lua scripts which provide an even more flexible and powerful interface into ModSecurity. When is Lua needed? ModSecurity chained rules can easily implement AND logic to create complex rules that evaluate that specific variables are present and have certain data, however they can not easily create proper OR logic. This is where Lua can help.</p></blockquote>
<p>A previous blog post, &#8220;<a href="http://blog.securitymonks.com/2008/07/31/implementing-a-web-application-firewall-with-modsecurity/">Implementing a Web Application Firewall with ModSecurity</a>,&#8221; goes through the step of installing ModSecurity with an Apache Web Server.  Following that post, your Apache httpd.conf configuration files should load the mod_security2.so module and include the modsecurity.conf file.  It is the <strong>modsecurity.conf</strong> file where the additional rules will be added.</p>
<h2>Problem with Usernames and Passwords</h2>
<p>WebGoat demonstrates a few security issues that need to be addressed.  From OWASP&#8217;s &#8220;<a href="http://www.owasp.org/index.php/OWASP_ModSecurity_Securing_WebGoat_Section4_Sublesson_04.2">OWASP ModSecurity Securing WebGoat Section4 Sublesson 04.2</a>&#8221; Forgot Password section, the following points are made:</p>
<ul>
<li>Attackers who are attempting to enumerate valid usernames. If you submit an invalid one the html response text includes info stating as such. We can track this.</li>
<li>Once a specific valid username is identified, the attacker then starts a targeted attack to guess answers to the password hint (favorite color).</li>
<li>Attackers can initiate reverse brute force attacks – this is when an attacker cycles through different valid user accounts and submits the same common answer to the question (submitting Blue as the answer to different usernames).</li>
</ul>
<p>The OWASP ModSecurity Securing WebGoat document does such a good job outlining the security issues along with possible solutions, I am going to leave it to the reader to decide what solutions are appropriate for their systems.  If I continued stepping through to a more secure implementation, I would end up copying everything in the document.  Playing around with the rules, testing the results, is great fun in a geeky security kind of way.  Do drop down and read the reviewer&#8217;s comments.  A very good job by Stephen Craig Evans and all who worked on OWASP Summer of Code project.  Of course, a special thank to Ivan Ristic, who gave us ModSecurity.
</p>
<p>
Recently, I listened to a<a href="http://itc.conversationsnetwork.org/shows/detail3776.html"> IT Conversation podcast</a>, from the O&#8217;Reilly Media Emerging Technology Conference.  Tim O&#8217;Reilly spoke about hackers.  Not the black hatters, but those folks who work tirelessly to bring about the kind of software and services that make the Internet possible.  While the Internet may be at times a dangerous place, thanks to the efforts of these hackers who work out of love for the challenge, often with little regard to financial factors, we have these great tools that go a long way towards helping people secure their applications.
</p>
<h2>Final Thoughts</h2>
<p><a href="http://despair.com/mis24x30prin.html"><img src="http://images.despair.com/products/demotivators/mistakes.jpg" alt="" width=300 align="right" /></a>In today&#8217;s post we examined a security breach that occurred involving a major player in the Internet community.  To help understand that problem, and others, we setup WebGoat.  Sun Tzu wrote in <a href="http://en.wikipedia.org/wiki/The_Art_of_War">The Art of War</a>, &#8220;So it is said that if you know your enemies and know yourself, you will fight without danger in battles.  If you only know yourself, but not your opponent, you may win or may lose.  If you know neither yourself nor your enemy, you will always endanger yourself.&#8221;  WebGoat helps us understand the attack vectors against web applications a little better.  Once identifying a possible problems, we walked through a solution that can help reduce the risk.</p>
<p>
It is easy to find humor in an employee with administrative access using the password &#8220;happiness.&#8221;  The reaction from the Internet community to Twitter&#8217;s problems might be a little schadenfreude at play.  <a href="http://plato.stanford.edu/entries/adorno/">Theodor Adorno</a>, philosopher and sociologist, defined <strong>schadenfreude</strong> as largely unanticipated delight in the suffering of another which is cognized as trivial and/or appropriate.  Or, maybe it is more like <a href="http://www.phrases.org.uk/bulletin_board/32/messages/352.html">whistling past the graveyard</a>, where folks are a bit cheerful or joyful in the face of a situation that doesn&#8217;t warrant it.
</p>
<p>
When very public security incidents occur, companies need to take a little stock.  Not all employees will take training seriously nor follow all policies.  That includes people with important roles.  Employees make mistakes and it is difficult to guard against every possible mistake that could occur.  That is why a layered approach to security is constantly preached.  While each layer cost money, security groups at organizations are in a constant battle to monitor and prevent intrusions in a cost effective way.  Fortunately, we have the work of many hackers (the good kind), helping us develop solutions to deal with daily new challenges.  There are no guarantees.  As Albert Einstein once said, &#8220;Anyone who has never made a mistake has never tried anything new.&#8221;  Wisdom comes when we learn from these mistakes.  CIOs need to ask themselves, &#8220;how safe is my company from being next week&#8217;s security headline?&#8221;  Security groups within an organization must be able to learn and adapt.  At the end of the day, the question is how different is your company from Twitter?  Insanity is doing the same thing and expecting different results.  I&#8217;ll close this post with the wise words of <a href="http://en.wikipedia.org/wiki/Sam_Levenson">Sam Levenson</a>, “You must learn from the mistakes of others. You can’t possibly live long enough to make them all yourself.”</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2009/01/10/webgoat-lua-and-modsecurity-verses-password-guessing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RTIR:  Adding Incident Response Capabilities to RT</title>
		<link>http://blog.securitymonks.com/2008/08/07/rtir-adding-incident-response-capabilities-to-rt/</link>
		<comments>http://blog.securitymonks.com/2008/08/07/rtir-adding-incident-response-capabilities-to-rt/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 21:11:37 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[RTIR]]></category>
		<category><![CDATA[Request Tracker]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/?p=257</guid>
		<description><![CDATA[In our last post, &#8220;Request Tracker Installation (Part 2 of 2),&#8221; we implemented Request Track (RT) on an Apache web server.  As a reminder, RT is an enterprise-grade ticketing system which allows for the checking of the status of various tasks including when the tasks were requested, who requested the tasks and why, when [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.securitymonks.com/images/IMMM.jpg"><img src="/images/IMMM_small.jpg" alt="Incident Management Mind Map Image" align="left" width=250/></a>In our last post, &#8220;<a href="http://blog.securitymonks.com/2008/08/03/request-tracker-installation-part-2-of-2/">Request Tracker Installation (Part 2 of 2)</a>,&#8221; we implemented <a href="http://bestpractical.com/rt/">Request Track (<strong>RT</strong>)</a> on an <a href="http://www.apache.org/">Apache</a> web server.  As a reminder, RT is an enterprise-grade ticketing system which allows for the checking of the status of various tasks including when the tasks were requested, who requested the tasks and why, when the tasks were completed, prioritizing, etc.  It was developed by the folks over at <a href="http://www.bestpractical.com">Best Practical</a>, and is the leading open-source issue tracking system.  Best Practical has also created RT for Incident Response (<strong>RTIR</strong>), which is &#8220;<em>an Open Source incident handling system designed with the needs of CERT teams and other incident-response teams in mind</em>.&#8221;  The posting &#8220;<a href="http://bestpractical.com/rtir/comparison.html">RTIR: RT for Incident Response</a>&#8221; outlines the added features of RTIR.  Today&#8217;s post will build upon the implementation of RT and will walk through the steps to implement RTIR.  </p>
<p>
Before going any further, I did want to give credit to the Doctor, who has been good enough to post over on his <a href="http://itservicemngmt.blogspot.com/2007/05/incident-management-mind-map.html">ITIL Service Management blog</a> a <a href="http://blog.securitymonks.com/2008/03/23/mind-mapping/">mind mapping</a> of the incident management process under <a href="http://en.wikipedia.org/wiki/ITIL_v3">ITIL</a>.  That mind map is the image used in today&#8217;s blog.  While it has nothing directly to do with RTIR, it is interesting in terms of incident management and I wanted to give proper credit.
</p>
<p><h3>Installation</h3>
</p>
<p>
Below are the basic steps involved with installing RTIR.  </p>
<h4><strong>1. Download and install required Perl modules.</strong></h4>
</p>
<p>
There are several Perl packages, which are dependent on other packages, and so the cycle goes.  You can install there packages using cpan, with commands like:
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# perl -MCPAN -e 'install Business::Hours'
 /usr/local/src root# perl -MCPAN -e 'install Net::Whois::RIPE'
</pre>
</td>
</table>
<p>
</p>
<p>
Sometimes you can run into problems installing modules in that manner.  Another alternative is to pull down the package, untar, configure, compile, and install in a manner similar to:
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://search.cpan.org/CPAN/authors/\
id/M/MR/MRSAM/Net-CIDR-0.11.tar.gz
 /usr/local/src root# tar xzf Net-CIDR-0.11.tar.gz
 /usr/local/src root# cd Net-CIDR-0.11
 /usr/local/src/Net-CIDR-0.11 root# perl Makefile.PL
 /usr/local/src/Net-CIDR-0.11root# make test
 /usr/local/src/Net-CIDR-0.11 root# make install
</pre>
</td>
</table>
<p>
</p>
<p>
To make installation of RTIR as easy as possibly, you may want to make sure the following packages are installed.
</p>
<table border=1 width="90%">
<tr>
<th width=100 align=left>Package</th>
<th width=300 align=left>File</th>
</tr>
<tr>
<td>Business::Hours</td>
<td>http://search.cpan.org/CPAN/authors/id/J/JE/JESSE/\<br />
Business-Hours-0.07.tar.gz</td>
</tr>
<tr>
<td>Net::Whois::RIPE</td>
<td>http://search.cpan.org/CPAN/authors/id/P/PA/PAULG/<br />
Net-Whois-RIPE-1.23.tar.gz</td>
</tr>
<tr>
<td>Net::CIDR</td>
<td>http://search.cpan.org/CPAN/authors/id/M/MR/MRSAM/\<br />
Net-CIDR-0.11.tar.gz</td>
</tr>
<tr>
<td>Business::SLA</td>
<td>http://search.cpan.org/CPAN/authors/id/R/RU/RUZ/\<br />
Business-SLA-0.05.tar.gz</td>
</tr>
<tr>
<td>Regexp::Common::net::CIDR</td>
<td>http://search.cpan.org/CPAN/authors/id/R/RU/RUZ/\<br />
Regexp-Common-net-CIDR-0.02.tar.gz</td>
</tr>
<tr>
<td>Devel::Cycle</td>
<td>http://search.cpan.org/CPAN/authors/id/L/LD/LDS/\<br />
Devel-Cycle-1.10.tar.gz</td>
</tr>
<tr>
<td>PadWalker</td>
<td>http://search.cpan.org/CPAN/authors/id/R/RO/ROBIN/\<br />
PadWalker-1.7.tar.gz</td>
</tr>
<tr>
<td>Devel::Symdump</td>
<td>http://search.cpan.org/CPAN/authors/id/A/AN/ANDK/\<br />
Devel-Symdump-2.08.tar.gz</td>
</tr>
<tr>
<td>Pod::Coverage</td>
<td>http://search.cpan.org/CPAN/authors/id/R/RC/RCLAMP/\<br />
Pod-Coverage-0.19.tar.gz</td>
</tr>
<tr>
<td>Test::Pod::Coverage</td>
<td>http://search.cpan.org/CPAN/authors/id/P/PE/PETDANCE/\<br />
Test-Pod-Coverage-1.08.tar.gz</td>
</tr>
<tr>
<td>Test::Memory::Cycle</td>
<td>http://search.cpan.org/CPAN/authors/id/P/PE/PETDANCE/\<br />
Test-Memory-Cycle-1.04.tar.gz</td>
</tr>
<tr>
<td>Test::Taint</td>
<td>http://search.cpan.org/CPAN/authors/id/P/PE/PETDANCE/\<br />
Test-Taint-1.04.tar.gz</td>
</tr>
<tr>
<td>WWW::Mechanize</td>
<td>http://search.cpan.org/CPAN/authors/id/P/PE/PETDANCE/\<br />
WWW-Mechanize-1.34.tar.gz</td>
</tr>
<tr>
<td>Test::HTTP::Server::Simple</td>
<td>http://search.cpan.org/CPAN/authors/id/J/JE/JESSE/\<br />
Test-HTTP-Server-Simple-0.09.tar.gz</td>
</tr>
</table>
<p><h4><strong>2. Download, configure, and install RTFM.</strong></h4>
</p>
<p>
The stable RTIR package was released back to 2004, way before the most recent RT 3 release.  Pull down the most recently updated for RT 3 release of the <a href="http://www.bestpractical.com/rtfm/">RT FAQ Manager (RTFM)</a>.  To quote from the FAQ, &#8220;<em>RTFM lets you open, categorize and search for &#8216;articles.&#8217; Like RT, RTFM lets your users contribute additional information to existing articles and makes sure that each article&#8217;s full history is preserved for future inspection. RTFM makes it easy to quickly search the knowledge base and find critical information</em>.&#8221;
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://download.bestpractical.com/pub/rt/devel/\
RTIR_M3/RTFM-2.2.2.tar.gz
 /usr/local/src root# tar xzf RTFM-2.2.2.tar.gz
 /usr/local/src root# cd RTFM-2.2.2
 /usr/local/src/RTFM-2.2.2 root# perl Makefile.PL
 /usr/local/src/RTFM-2.2.2 root# make
 /usr/local/src/RTFM-2.2.2 root# make install
 /usr/local/src/RTFM-2.2.2 root# make initdb
 /usr/local/src/RTFM-2.2.2 root# cd ..
 /usr/local/src root# wget http://download.bestpractical.com/pub/rt/devel/\
RTIR_M3/RTFM-Extension-ArticleTemplates-0.01.tar.gz
 /usr/local/src root# tar xzf RTFM-Extension-ArticleTemplates-0.01.tar.gz
 /usr/local/src root# cd RTFM-Extension-ArticleTemplates-0.01
 /usr/local/src/RTFM-Extension-ArticleTemplates-0.01root# perl Makefile.PL
 /usr/local/src/RTFM-Extension-ArticleTemplates-0.01root# make
 /usr/local/src/RTFM-Extension-ArticleTemplates-0.01root# make install
 /usr/local/src/RTFM-Extension-ArticleTemplates-0.01root# cd ..
</pre>
</td>
</table>
<p>
</p>
<p><h4><strong>3. Download, configure, and install RTIR.</strong></h4>
</p>
<p>
Pull down the most recently updated for RT 3 release of RTIR.
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://download.bestpractical.com/pub/rt/devel/\
RTIR_M3/RT-IR-2.3.17.tar.gz
 /usr/local/src root# tar xzf RT-IR-2.3.17.tar.gz
 /usr/local/src root# cd RT-IR-2.3.17
 /usr/local/src/RT-IR-2.3.17 root# perl Makefile.PL
 /usr/local/src/RT-IR-2.3.17 root# make install
 </pre>
</td>
</table>
<p>
</p>
<p><h4><strong>4. Edit RT configuration file.</strong></h4>
</p>
<p>
Edit the RT configuration file /opt/rt3/etc/RT_SiteConfig.pm adding the RTIR configuration file /opt/rt3/local/plugins/RT-IR/etc/RTIR_Config.pm.
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/RT-IR-2.3.17 root#  vi /opt/rt3/etc/RT_SiteConfig.pm
</pre>
</td>
</table>
<p>
</p>
<p>
Add the lines:
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
# The RTIR config file
$RTIR_CONFIG_FILE = "/opt/rt3/local/plugins/RT-IR/etc/RTIR_Config.pm";
require $RTIR_CONFIG_FILE || die ("Couldn't load RTIR config file '$RTIR_CONFIG_FILE'\n$@");
Set(@Plugins, 'RT::FM', 'RT::IR');
</pre>
</td>
</table>
<p>
</p>
<p><h4><strong>5. Initialize the database.</strong></h4>
</p>
<p>
Update the RT database.
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/RT-IR-2.3.17 root# make initdb
</pre>
</td>
</table>
<p>
</p>
<p><h4><strong>6. Stop and restart the Apache server.</strong></h4>
</p>
<p>
For good measure, restart the Apache server.
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/RT-IR-2.3.17 root# /usr/local/apache/bin/apachectl stop
 /usr/local/src/RT-IR-2.3.17 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p>
</p>
<p><h4><strong>7. Configure RTIR.</strong></h4>
</p>
<p>
Configuration of RT and RTIR is a topic for another post; maybe even a book.  I will include below basic instructions from RTIR readme.  Please see the next section for additional documentation.</p>
<blockquote><p>
1) Using RT&#8217;s configuration interface, add the email address<br />
   of the Network Operations Team (the people who will handle<br />
   activating and removing Blocks) as AdminCC on the Blocks queue.<br />
   RT -&gt; Configuration -&gt; Queues -&gt; Blocks -&gt; Watchers</p>
<p>2) You may want to modify the email messages that are automatically<br />
   sent on the creation of Investigations and Blocks.<br />
   RT -&gt; Queues -&gt; &lt;select RTIR&#8217;s Queue&gt; -&gt; Templates.<br />
   RT -&gt; Global -&gt; Templates.</p>
<p>3) By default, RT ships with a number of global Scrips.  You should use<br />
   RT&#8217;s configuration interface to look through them, and disable any<br />
   that aren&#8217;t apropriate in your environment.<br />
   RT -&gt; Queues -&gt; &lt;/select&gt;&lt;select RTIR&#8217;s Queue&gt; -&gt; Scrips.<br />
   RT -&gt; Global -&gt; Scrips.</p>
<p>4) Add staff members who handle incidents to the DutyTeam group.<br />
   RT -&gt; Configuration -&gt; Groups -&gt; DutyTeam -&gt; Members.</p>
<p>5) You can override values in the RTIR_Config.pm in your<br />
   RT_SiteConfig.pm file. Just add your customizations after the &#8220;require&#8221;<br />
   line mentioned above.
</p></blockquote>
<h3>Additional Information</h3>
</p>
<p>
RT has a nice user interface.  In order to figure out and use the program, you need to read the documentation.  We may come back and do a post on configuration.  How you configure RTIR software depends on the environment and your plans for using the software.  Below is a listing of several information sources.</p>
<ul>
<li><a href="http://svn.bestpractical.com/cgi-bin/index.cgi/bps/view/rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/DocIndex.pod">DocIndex.pod</a> &#8211; Can also view DocIndex.pod with the command:<br />
<strong>perldoc lib/RT/IR/DocIndex.pod</strong></li>
<li><a href="http://svn.bestpractical.com/cgi-bin/index.cgi/bps/view/rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/AdministrationTutorial.pod">AdministrationTutorial.pod</a>  &#8211; Can also view AdministrationTutorial.pod with the command:<br />
<strong>perldoc lib/RT/IR/AdministrationTutorial.pod</strong></li>
<li><a href="http://svn.bestpractical.com/cgi-bin/index.cgi/bps/view/rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Config.pm">Config.pm</a> &#8211; Can also view Constituencies.pod with the command:<br />
<strong>perldoc lib/RT/IR/Config.pm</strong></li>
<li><a href="http://svn.bestpractical.com/cgi-bin/index.cgi/bps/view/rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Constituencies.pod">Constituencies.pod</a>  &#8211; Can also view Constituencies.pod with the command:<br />
<strong>perldoc lib/RT/IR/Constituencies.pod</strong></li>
<li><a href="http://svn.bestpractical.com/cgi-bin/index.cgi/bps/view/rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm">Ticket.pm</a> &#8211; Can also view Ticket.pm with the command:<br />
<strong>perldoc lib/RT/IR/Tutorial.pod</strong></li>
<li><a href="http://svn.bestpractical.com/cgi-bin/index.cgi/bps/view/rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Tutorial.pod">Tutorial.pod </a> &#8211; Can also view Tutorial.pod with the command:<br />
<strong>perldoc lib/RT/IR/Tutorial.pod</strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/08/07/rtir-adding-incident-response-capabilities-to-rt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Request Tracker Installation  (Part 2 of 2)</title>
		<link>http://blog.securitymonks.com/2008/08/03/request-tracker-installation-part-2-of-2/</link>
		<comments>http://blog.securitymonks.com/2008/08/03/request-tracker-installation-part-2-of-2/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 02:33:46 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Leopard]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[ModSecurity]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NIST]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Request Tracker]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/?p=211</guid>
		<description><![CDATA[Awhile back, I posted &#8220;Request Tracker Installation  (Part 1 of 2),&#8221; which provided information and additional links concerning Request Tracker (RT).  As a reminder, RT is an enterprise-grade ticketing system which allows for the checking of the status of various tasks including when the tasks were requested, who requested the tasks and why, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/opensource.jpg" alt="Open Source Installation" align="left"/>Awhile back, I posted &#8220;<a href="http://blog.securitymonks.com/category/request-tracker">Request Tracker Installation  (Part 1 of 2)</a>,&#8221; which provided information and additional links concerning <a href="http://bestpractical.com/rt/">Request Tracker (RT)</a>.  As a reminder, RT is an enterprise-grade ticketing system which allows for the checking of the status of various tasks including when the tasks were requested, who requested the tasks and why, when the tasks were completed, prioritizing, etc.  I delayed the second part of the post, which was to step through installation of RT, until I could add some background information.  I wanted to walk through implementing secure open source software such as <a href="http://www.apache.org/">Apache</a>, <a href="http://www.php.net">PHP</a>, <a href="http://www.mysql.com">MySQL</a>, <a href="http://www.openssl.org">OpenSSL</a>, and <a href="http://www.modsecurity.org">ModSecurity</a>.  No small task.  It is all about integration both in terms of security and the power that a software package like RT can provide your organization.  That is why I selected the image on the left of all these various open source software symbols for this post on RT.</p>
<p>
If you are going to be using RT, you need to get the &#8220;<a href="http://rtbook.bestpractical.com/">RT Essentials</a>&#8221; book written by Jesse Vincent, Robert Spier, Dave Rolsky, Darren Chamberlain, and Richard Foley.  It is a good reference and a quick read.  For up-to-date information, see the <a href="http://wiki.bestpractical.com/view/HomePage">RT Wiki</a> and the <a href="http://blog.bestpractical.com/">Best Practical Solutions blog site</a>.
</p>
<p><h3>Prerequisites</h3>
<p>To start, please review the following posts:</p>
<ol>
<li><a href="http://blog.securitymonks.com/2008/04/14/an-apache-implementation/">An Apache Implementation</a>
	</li>
<li><a href="http://blog.securitymonks.com/2008/04/24/apache-and-openssl/">Apache and OpenSSL</a></li>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-implementation/">PHP Implementation</a></li>
<ul>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-as-a-module/">PHP as a Module</a></li>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/">PHP as a CGI</a></li>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-configuration-modifications/">PHP Configuration Modifications</a></li>
</ul>
<li><a href="http://blog.securitymonks.com/2008/04/07/introduction-to-mysql/">Introduction to MySQL</a></li>
<li><a href="http://blog.securitymonks.com/2008/02/28/setting-up-and-securing-mysql-references/">Setting Up and Securing MySQL: References</a></li>
<li><a href="http://blog.securitymonks.com/2008/07/31/implementing-a-web-application-firewall-with-modsecurity/">Implementing a Web Application Firewall with ModSecurity</a></li>
</ol>
<h3>Install Software</h3>
<p>With Apache, MySQL, PHP, OpenSSL, and ModSecurity installed, we are now ready to focus on software packages required by RT.</p>
<h4><strong>1.  Installing <a href="http://expat.sourceforge.net/">expat</a>.</strong></h4>
<p>Different operating systems will vary on whether <a href="http://expat.sourceforge.net/">expat</a>, the XML parser, is installed.  Expat is needed to complete the cpan install for <a href="http://perl-rss.sourceforge.net/">XML::RSS</a>.  Check your particular operating system.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://downloads.sourceforge.net/expat/expat-2.0.1.tar.gz
 /usr/local/src root# tar xzf expat-2.0.1.tar.gz
 /usr/local/src root# cd expat-2.0.1
 /usr/local/src/expat-2.0.1 root# ./configure
 /usr/local/src/expat-2.0.1 root# make
 /usr/local/src/expat-2.0.1 root# make check
 /usr/local/src/expat-2.0.1 root# make install
</pre>
</td>
</table>
<p></p>
<h4><strong>2.  Install FastCGI</strong></h4>
<p>For RT, you can install <a href="http://perl.apache.org/">mod_perl</a> or <a href="http://www.fastcgi.com/">mod_fastcgi</a>.  In this posting, we are going to walks through the installation of FastCGI.  Information concerning mod_perl will be provided below so the reader can chose what fits best in their environment.  FastCGI is much simpler to install and allows the core Apache process to stay small in size.  With FastCGI, RT runs as a separate process from Apache allowing RT to be stopped and restarted without affecting the Apache server.  In general, FastCGI programs are easier to manage.
</p>
<p>
The Apache module mod_fastcgi allows a web server to run CGI scripts via a separate, persistent program.  PHP comes with FastCGI support compiled in by default, so nothing needs to be done to the PHP installation.
</p>
<p>
You can have the Apache program call FastCGI, and have it run as the same user as the Apache server or use suexec to have FastCGI switch to a different user.  Under some operating systems, suexec may not get compiled and installed when installing Apache.  Check if suexec is installed, and if not go back to the Apache source, compile it, and install it.  Initially, we are not going to use the suexec program.  Instead we will create the group &#8220;rt&#8221;, add user httpd to group rt, and set permissions that way.  You may choose later to use suexec.  </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# ls -la /usr/local/apache/bin/suexec
ls: /usr/local/apache/bin/suexec: No such file or directory
 root# cd /usr/local/src/httpd-2.2.8
 /usr/local/src/httpd-2.2.8 root# make suexec
 /usr/local/src/httpd-2.2.8 root# cp ./support/suexec /usr/local/apache/bin/suexec
</pre>
</td>
</table>
<p>
Now, we are ready to get mod_fastcgi installed.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
 /usr/local/src root# tar xzf mod_fastcgi-2.4.6.tar.gz
 /usr/local/src root# cd mod_fastcgi-2.4.6
 /usr/local/src/mod_fastcgi-2.4.6 root# cp Makefile.AP2 Makefile
 /usr/local/src/mod_fastcgi-2.4.6 root# make top_dir=/usr/local/apache
 /usr/local/src/mod_fastcgi-2.4.6 root# make top_dir=/usr/local/apache install
 /usr/local/src/mod_fastcgi-2.4.6 root# /usr/local/apache/bin/apachectl stop
 /usr/local/src/mod_fastcgi-2.4.6 root# vi /usr/local/apache/conf/httpd.conf
</pre>
</td>
</table>
<p>
Add the following lines to the Apache httpd.conf file:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
# Load the mod_fastcgi module.
LoadModule fastcgi_module modules/mod_fastcgi.so
</pre>
</td>
</table>
<p>
Check if installation and configuration is working.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/mod_fastcgi-2.4.6 root# /usr/local/apache/bin/apachectl configtest
Syntax OK
 /usr/local/src/mod_fastcgi-2.4.6 root# /usr/local/apache/bin/apachectl start
 /usr/local/src/mod_fastcgi-2.4.6 root# cat /var/www/logs/error_log | grep -i fastcgi
[Fri Aug 01 12:17:22 2008] [notice] FastCGI: process manager initialized (pid 15221)
[Fri Aug 01 12:17:22 2008] [notice] Apache/2.2.8 (Unix) mod_ssl/2.2.8
OpenSSL/0.9.7a mod_fastcgi/2.4.6 configured -- resuming normal operations
</pre>
</td>
</table>
<p>
For in depth coverage of mod_perl, <a href="http://stason.org/">Stas Bekman</a> and <a href="http://www.oreillynet.com/pub/au/999">Eric Cholet</a> have written the book, &#8220;<a href="http://modperlbook.org/">Practical mod_perl</a>.&#8221;  They have made the complete book available online in both <a href="http://modperlbook.org/html/index.html">HTML</a> and <a href="http://modperlbook.org/pdf/index.html">PDF</a> format under the <a href="http://creativecommons.org/">Creative Commons</a> Attributes Share-Alike License.  <a href="http://stason.org/">Stas Bekman</a> and <a href="http://www.onyxneon.com/people/jim_brandt.html">Jim Brandt</a> have also written the &#8220;<a href="http://www.amazon.com/gp/product/0977920119?ie=UTF8&#038;tag=theultimatlearna&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0977920119">mod_perl2 User&#8217;s Guide Book</a>&#8221; where 50% of the book&#8217;s proceeds go to <a href="http://www.perlfoundation.org/">The Perl Foundation</a>.
</p>
<p>
If you are installing under Mac OS X, mod_perl may complain about Perl 5.8.8 being built without threads and you will get a message about building perl with -Duserthreads.  If you are determined to use mod_perl, consider dropping back to Apache 1.3.x and using mod_perl 1.x.  While Apache 1.3.x is legacy code, and I tend to want to use the code that is being actively developed, there is an argument for using Apache 1.3.x.  One major feature of Apache 2.x is threading. On Windows, where most basic libraries are and must be threadsafe, Apache 2 is really the only choice.  <a href="http://search.cpan.org/~nwclark/perl-5.8.8/README.macosx">Earlier Mac OS X</a> releases did not include a completely thread-safe libc, so threading is still not fully supported in Perl.  This is why the Perl version that comes with Mac OS X is not compiled to use threads.  To use  Apache2.x, Perl will need to be configured to use threads.  The code is available from the <a href="http://www.perl.com/download.csp">Perl web site</a>.
</p>
<p>
Rather than getting bogged down in compiling Perl to use thread, we will move ahead and use FastCGI.  By the time this post, I will have worked on getting RT installed under Linux, Mac OS X, and FreeBSD.  Figuring out what software works best in a multi OS environment can be challenging.  </p>
<h4><strong>3. Configure RT</strong></h4>
<p>Let us start by adding the group RT.  Under many operating systems, this would be done with the simple command &#8220;<strong>groupadd rt</strong>.&#8221;  Things are always more interesting under Mac OS X, where you would have to first look at what group ids (gid), choose an unused gid, and then create the rt group using that gid.  Under Mac OS X Leopard, group rt would be created with the commands:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# dscl . list /groups PrimaryGroupID | sort -k 2,2 -n
 root# dscl . create /groups/rt gid gid-of-rt
 root# dscl . create /groups/rt passwd '*'
 root# dscl . read /groups/rt
AppleMetaNodeLocation: /Local/Default
Password: *
PrimaryGroupID: gid-of-rt
RecordName: rt
RecordType: dsRecTypeNative:groups
</pre>
</td>
</table>
<p>
RT&#8217;s primary maintenance and documentation site is <a href="http://www.bestpractical.com">http://www.bestpractical.com</a>.   Documentation can be found at the Best Practical Solutions RT Wiki located at <a href="http://wiki.bestpractical.com/view/HomePage">http://wiki.bestpractical.com/</a>. The latest TAR/GZ is located at <a href="http://download.bestpractical.com/pub/rt/release/rt.tar.gz">http://download.bestpractical.com/pub/rt/release/rt.tar.gz</a>. The lack of any version numbers means the version can be updated at any time. The latest version, as of this writing, is 3.8.0.
</p>
<p>
The following are the steps for downloading and configuring RT:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://download.bestpractical.com/pub/rt/release/rt.tar.gz
 /usr/local/src root# tar xzf rt.tar.gz
 /usr/local/src root# cd rt-3.8.0
 /usr/local/src/rt-3.6.5 root# ./configure \
  --with-web-user="httpd" \
  --with-web-group="httpd" \
  --with-rt-user="httpd" \
  --with-rt-group="rt"
</pre>
</td>
</table>
<p></p>
<h4><strong>4.  Install Apache::TEST</strong></h4>
<p>Perl module Apache::TEST will not allow you to run the test check as root. You can download the module separately as a non root user and after configuring, compiling, and testing the program, you install it as root.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# su - goofy
 ~$ cd src
 ~/src goofy$ wget http://search.cpan.org/CPAN/authors/id/P/PH/PHRED/Apache-Test-1.30.tar.gz
 ~/src goofy$ tar xzf Apache-Test-1.30.tar.gz
 ~/src goofy$ cd Apache-Test-1.30
 ~/src goofy$ perl Makefile.PL
 ~/src goofy$ make
 ~/src goofy$ make test
 ~/src goofy$ sudo su root
 root# make instal
</pre>
</td>
</table>
<p></p>
<h4><strong>5.  Run fixdeps Command and Install Perl Modules</strong></h4>
<p>Now you are ready to utilize the <strong>fixedeps</strong> utility that comes with RT to install required Perl modules.  There is also the <strong>testdeps</strong> utility to test if all dependencies are installed and RT is ready to be installed.  You may need to run fixdeps multiple times before testdeps reports that you have all required software packages.  The first time through, it can take awhile (depending on your installation).  Be aware that some perl modules may need to be installed manually.  It various depending on OS and your environment.  You will be able to tell which modules need manual installation by the final message provided by the fixdeps program.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src/rt-3.8.0
 /usr/local/src/rt-3.8.0 root# make fixdeps
 /usr/local/src/rt-3.8.0 root# make fixdeps
 /usr/local/src/rt-3.8.0 root# make testdeps
</pre>
</td>
</table>
<p></p>
<h4><strong>6.  Install RT</strong></h4>
</p>
<p>
The final installation of RT is the easy part.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# make install
</pre>
</td>
</table>
<p></p>
<h4><strong>7.  Configure RT_SiteConfig.pm</strong></h4>
<p>We now will configure /opt/rt3/etc/RT_SiteConfig.pm.  In the next step a database user and a database will be setup.  We are only adding those values to the configuration file in this step.  I am going to set up a hostname (rt.securitymonks.com) for my current machine.  Please do not copy blindly.  Change this to your environment.  We will create the hostname so it only exists locally by adding an entry into the machines /etc/hosts file.  Right now, I am only going to access the Apache server from this machine.  In other words, the client and server will be on the same box.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# vi /etc/hosts
</pre>
</td>
</table>
<p>
Add the following line, adapting it to your organization:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# vi /etc/hosts
##
127.0.0.1       localhost
10.1.218.202   rt.securitymonks.com
</pre>
</td>
</table>
<p>
We are now ready to modify the RT_SiteConfig.pm file.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# vi /opt/rt3/etc/RT_SiteConfig.pm
</pre>
</td>
</table>
<p>
At minimum, add the following linesto /opt/rt3/etc/RT_SiteConfig.pm:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
Set($rtname, 'BRORT');
Set($Organization, 'securitymonks');

Set($CorrespondAddress , 'john@securitymonks.com');
Set($CommentAddress , 'john@securitymonks.com');

Set($Timezone , 'US/Eastern'); # obviously choose what suits you

# THE DATABASE:

Set($DatabaseType, 'mysql'); # e.g. Pg or mysql

# These are the settings we used above when creating the RT database,
# you MUST set these to what you chose in the section above.

Set($DatabaseUser , 'rtuser');
Set($DatabasePassword , 'secret');
Set($DatabaseName , 'rtdb');

# THE WEBSERVER:

Set($WebPath , '');
Set($WebBaseURL , 'https://rt.securitymonks.com');

# Logging
Set($LogToSyslog, '');
Set($LogToFile, 'debug');
Set($LogDir, '/opt/rt3/var/log');
Set($LogToFileNamed, "rt.log");
</pre>
</td>
</table>
<p></p>
<h4><strong>8.  Initialize the Database</strong></h4>
<p>RT needs to create the rtdb database, the rt db users, and initialize some tables.  This can be done with the command <strong>initialize-database</strong>, which should be run only once.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# make initialize-database
 /usr/local/bin/perl sbin/rt-setup-database --action init --dba root --prompt-for-dba-password
In order to create or update your RT database, this script needs to connect to your mysql
instance on localhost as root.  Please specify that user's database password below. If the
user has no database

password, just press return.

Password:
Working with:
Type:   mysql
Host:   localhost
Name:   rtdb
User:   rtuser
DBA:    root
Now creating a mysql database rtdb for RT.
Done.
Now populating database schema.
Done.
Now inserting database ACLs
Granting access to rtuser@'localhost' on rtdb.
Done.
Now inserting RT core system objects
Done.
Now inserting data
Done inserting data
Done.
</pre>
</td>
</table>
<p>
Check the MySQL database out.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# mysql -u rtuser -p
mysql> use rtdb;
</pre>
</td>
</table>
<p>
</p>
<h4><strong>9.  Modify Apache Configuration File</strong> </h4>
<p>Edit the /usr/local/apache/conf/httpd.conf file.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# /usr/local/apache/bin/apachectl stop
 /usr/local/src/rt-3.8.0 root# vi /usr/local/apache/conf/httpd.conf
</pre>
</td>
</table>
<p>
We are going to have the RT server run under our secure web server.  Find the &#8220;<strong>&#60virtualhost _default_:443&#62</strong>&#8221; line, change it to &#8220;<strong>&#60virtualhost 10.1.218.202:443&#62</strong>&#8220;.  Add the following lines to that section (adjusting to your environment):</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
   ServerName rt.securitymonks.com
   DocumentRoot /opt/rt3/share/html
   ErrorLog /usr/local/apache/logs/rt.error
   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   CustomLog /usr/local/apache/logs/rt.access_log combined
   AddHandler fastcgi-script fcgi
   ScriptAlias / /opt/rt3/bin/mason_handler.fcgi/
</pre>
</td>
</table>
<p>
Add the user the Apache server runs as (httpd by default), to the RT group.  For non Mac OS X, modify group membership by editing the file /etc/group (<strong>vi /etc/group</strong>).  Mac OS X users need to user the dscl command.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# dscl . append /groups/rt GroupMembership httpd
 root# dscl . read /groups/rt
</pre>
</td>
</table>
<p>
Change the group and permission on the log area if you have told RT to log to /opt/rt3/var/log. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# chgrp rt /opt/rt3/var/log
 root# chmod g+w /opt/rt3/var/log
</pre>
</td>
</table>
<p>
Test the configuration of the file, and if everything checks out start up Apache. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# /usr/local/apache/bin/apachectl configtest
Syntax OK
 /usr/local/src/rt-3.8.0 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p>
 Remember there are now three files to check for problems with RT.
<ul>
<li>/opt/rt3/var/log/rt.log</li>
<li>/usr/local/apache/logs/rt.error</li>
<li>/usr/local/apache/logs/rt.access_log</li>
</ul>
<p>There are many configuration operations.  The options chosen in this post represents only the minimal to get RT running.  Please see the <a href="http://wiki.bestpractical.com/view/FastCGIConfiguration">RT Wiki&#8217;s FastCGIConfiguration</a> page for additional information.</p>
<h4><strong>10.  Access RT and Change the Default Password</strong> </h4>
<p><a href="http://blog.securitymonks.com/images/RT_login.jpg"><img align="left" width="150" title="ModifyUserImage" src="/images/RT_login.jpg"/></a>Now it is time to log in and change the default password.  Using the entry we made in our /etc/hosts file, we can now access the site by going to <strong>https://rt.securitymonks.com</strong>.  This URL should be different for your site.  You will see a login screen similar to the image on the left.</p>
<p>
Log in using the username &#8220;<strong>root</strong>&#8221; and password &#8220;<strong>password</strong>&#8220;.  Once logged in, you will see the screen similar to the image below (click on the image if you need to enlarge):<br />
<a href="http://blog.securitymonks.com/images/RT_ataglance.jpg"><img width="400" title="RT_at_a_glance" src="/images/RT_ataglance.jpg"/></a><br />
Over on the left menu bar, select &#8220;<strong>Configuration</strong>.&#8221;  That will bring you to the &#8220;RT Administration&#8221; screen:<br />
<a href="http://blog.securitymonks.com/images/RT_Administration.jpg"><img width="200" title="RT_administration" src="/images/RT_Administration.jpg"/></a><br />
Select, &#8220;<strong>Users</strong>.&#8221;  That will bring you to the &#8220;Select a user&#8221; screen:<br />
<a href="http://blog.securitymonks.com/images/RT_selectauser.jpg"><img width="300" title="RT_Select_a_User" src="/images/RT_selectauser.jpg"/></a><br />
Select the user &#8220;<strong>root</strong>,&#8221; which will bring you to the &#8220;Modify the user root&#8221; screen.  If you look at the lower left of the screen, there is a &#8220;Access Control area.&#8221;  There is a place to enter &#8220;New Password.&#8221;  Do so.  The screen looks like:<br />
<a href="http://blog.securitymonks.com/images/RT_modifyauser.png"><img width="200"  title="RT_Modify" src="/images/RT_modifyauser.png"/></a><br />
Make sure to hit the &#8220;Save Changes&#8221; button at the bottom of the screen.  With a working copy of RT, you are not ready to start adjusting configurations and working with the program.  For additional information, Please check out the “<a href="http://rtbook.bestpractical.com/">RT Essentials</a>” and the <a href="http://wiki.bestpractical.com/view/HomePage">RT Wiki</a> and the Best Practical Solutions <a href="http://blog.bestpractical.com/">blog site</a>.  Look for future posts to build upon the RT installation and database.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/08/03/request-tracker-installation-part-2-of-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementing a Web Application Firewall with ModSecurity</title>
		<link>http://blog.securitymonks.com/2008/07/31/implementing-a-web-application-firewall-with-modsecurity/</link>
		<comments>http://blog.securitymonks.com/2008/07/31/implementing-a-web-application-firewall-with-modsecurity/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 04:02:27 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Application]]></category>
		<category><![CDATA[Defense in Depth]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[ModSecurity]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Web Application]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/?p=169</guid>
		<description><![CDATA[There are a few topics I have meant to do a post on for awhile.  Sometimes having too much interest and information on a topic can be a bad thing.  Wanting to pull various postings and articles along with implementation instructions can be a bit time consuming.  Plus, in order to demonstrate [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/modsecurity.gif" alt="ModSecurity Image" align="left"/>There are a few topics I have meant to do a post on for awhile.  Sometimes having too much interest and information on a topic can be a bad thing.  Wanting to pull various postings and articles along with implementation instructions can be a bit time consuming.  Plus, in order to demonstrate why someone might be interested in implementing a web application firewall (<a href="http://www.owasp.org/index.php/Web_Application_Firewall">WAF</a>), I envisioned a post discussing the collapse of the perimeter and addressing points made by the <a href="http://www.opengroup.org/jericho/">Jericho Forum</a> (see the <a href="http://www.securitycatalyst.com/blog/2008/06/security-roundtable-for-june-2008-clarion-call-of-the-jericho-forum/">Security Roundtable</a> podcast for June 2008 for a good discussion on the topic).  <a href="http://raffy.ch/blog/">Raffael Marty</a> makes excellent points in his soon to be released book, &#8220;<a href="http://www.amazon.com/Applied-Security-Visualization-Raffael-Marty/dp/0321510100">Applied Security Visualization</a>&#8220;:</p>
<blockquote><p>The crime landscape is shifting.  Attacks are moving up the network stack.  Network-based attacks are not the prime source of security problems anymore.  The attacks today are moving into the application layer: Web 2.0, instant messenger attacks, fraud, information theft, and crime-ware are just some examples of new types of attacks that generate a load of data to be collected and analyzed.  Beware!  Applications are really chatty and generate alot of data.</p></blockquote>
<p>While my current post is not about security visualization (see earlier post &#8220;<a href="http://blog.securitymonks.com/2007/10/20/security-data-visualization/">Security Data Visualization</a>&#8220;), I would like to point out that <a href="http://davix.secviz.org">DAVIX</a>, a live CD for data analysis and visualization, is expected to be released August 6th.  That should be really cool and fun.</p>
<p>
Since application security is a topic of interest for me, I ran into the problem of having too many topics I wanted to discuss when I started trying to write a post on <a href="http://www.modsecurity.org/">ModSecurity</a>, an open source, free WAF Apache module.  Today, rather than waiting for me to integrate the information, I decided to move ahead and do the post while limiting myself to only pointing out the various sources.  The reader can follow the links for a more in-depth discussion and understanding on the topic.</p>
<h3>Why You Should Care</h3>
<p>The <a href="http://itradio.com.au/security/">Risky Business</a> podcast has come to be one of my favorite podcasts.  The host, <a href="http://itradio.com.au/security/?page_id=2">Patrick Gray</a> and regular guest <a href="http://www.zdnet.com.au/tag/munir_kotadia.htm">Munir Kotadia</a>, just cracks me up.  Plus the show is informative and features great guests.  This week&#8217;s show had an interview with <a href="http://itradio.com.au/security/?p=85">H D Moore talking about the DNS bug</a>.  Timely and informative; what else can one ask for?  The <a href="http://itradio.com.au/security/?p=81">68th episode</a>, done at the beginning of this month, had an interview with <a href="http://jeremiahgrossman.blogspot.com/">Jeremiah Grossman</a> concerning web application firewalls.  As Patrick writes in the show notes, &#8220;<em>it takes typical organizations around <strong>130 days to fix sequel injection bugs</strong> in code.  But you can mitigate these sorts of things with a Web app firewall, and you won’t even have to deal with the development team! Hooray!</em>.&#8221;
</p>
<p>
In Grossman&#8217;s blog post &#8220;<a href="http://jeremiahgrossman.blogspot.com/2008/06/can-wafs-protect-against-business-logic.html">Can WAFs protect against business logic flaws?</a>&#8220;, he pointed out that &#8220;<em>WAFs don&#8217;t defend against every logic flaw, or even every crazy form of SQLi or XSS. Just as white/black box scanners can&#8217;t identify every vulnerability and neither can expert pen-testers or source code auditors</em>.&#8221;  Stuart King, in his article, &#8220;<a href="http://www.computerweekly.com/blogs/stuart_king/2008/07/more-wafs.html">Larry David and Web Application Firewalls</a>&#8220;, builds upon this idea when he wrote:</p>
<blockquote><p>Back to the <a href="http://www.csoonline.com/article/412163/Industry_View_Web_Application_Security_Today_Are_We_All_Insane_/1">CSO article</a> where the point is made that we are sitting on a huge legacy of insecure code and that &#8220;we can&#8217;t rewrite history.&#8221; So, the argument is that a web application firewall mitigates the risk &#8211; note: does not solve the problem &#8211; until the code can be replaced.</p>
<p>How much of the risk is mitigated is open to debate, but there are lots of other things to consider too. For instance the cost of redeveloping code against the cost of purchasing and supporting a WAF. We also need to consider the value and risk profile of the product. </p></blockquote>
<p>Today&#8217;s world consist of attackers adjusting focus from network-based attacks to the application layer.  Grossman in his post &#8220;<a href="http://jeremiahgrossman.blogspot.com/2008/03/website-security-strategies-that-work.html">Website Security Strategies that Work</a>&#8221; makes the claim that &#8220;<em><strong>9 out of 10 (or more) websites have vulnerabilities</strong> as a result of being built by those who didn’t know or appreciate the severity of today’s attacks</em>.&#8221;  There is no arguing that many organizations are sitting on a huge legacy of insecure code, much of which may have been written before the discovery of prevalent vulnerabilities such as <a href="http://ha.ckers.org/xss.html">XSS</a>, <a href="http://ha.ckers.org/sqlinjection/">SQL Injection</a>, <a href="http://ha.ckers.org/blog/20080202/csrf-yup-its-real-folks/">CSRF</a>, etc.  Even worse, organization often have their security groups focused on network or system security, leaving application level security to developers.  Unfortunately, these developers are receiving little or no training, while remaining under pressure to produce code under short deadlines.
</p>
<p>
Andre Gironda series, starting with &#8220;<a href="http://www.tssci-security.com/archives/2008/06/23/week-of-war-on-wafs-day-1-top-ten-reasons-to-wait-on-wafs/">Week of War on WAF’s: Day 1 — Top ten reasons to wait on WAF’s,</a>&#8221; provides important reasons why WAFs should not be viewed as a silver bullet solution.  Rich Mogull in his post &#8220;<a href="http://securosis.com/2008/06/02/web-application-security-we-need-web-application-firewalls-to-work-better/">Web Application Security: We Need Web Application Firewalls To Work. Better</a>&#8221; makes the important point:<br />
<blockquote>With old school vulnerabilities we know the details of the specific vulnerability and (usually) exploit mechanism. With WAFs, we are trying to block vulnerability classes instead of specific vulnerabilities. This is a HUGE difference. The WAF doesn’t know the details of the application or any application-specific vulnerabilities, and thus is much more limited in what it can block.</p></blockquote>
<p>Mogull goes on to state that WAFs can:<br />
<blockquote>no longer be merely external boxes protecting against generic vulnerabilities; they need tighter integration into our applications. In the long term, I’ve branded this Application and Database Monitoring and Protection (<a href="http://securosis.com/2007/12/17/definitions-content-monitoring-and-protection-and-application-and-database-monitoring-and-protection/">ADMP</a>) as we create a dedicated application and database security stack that links from the browser on the front end, to the DB server on the back.</p></blockquote>
<p>ADMPs, or if you prefer WAFs + Database Activity Monitoring (WAFs+DAM),  would be another step in the evolution of WAFs.  As <a href="http://www.ivanristic.com/">Ivan Ristic</a>, creator of ModSecurity, points out in his blog post &#8220;<a href="http://blog.modsecurity.org/2008/05/whats-the-score.html">What&#8217;s the Score of the Game?</a>&#8220;:<br />
<blockquote>I feel that one of areas where organizations are failing, with regards to web application security, is that there is a lack of communication between the following three groups: Development teams (who are running source code reviews), InfoSec teams (who are running vulnerability scans) and Operational Security teams (who are running web application firewalls).  These three teams each have unique perspectives on the vulnerabilities of the webapps and they should share their data with each other.</p></blockquote>
<p>Nicely stated.  No one is arguing that writing secure code is not the answer.  If organization began adapting secure systems development lifecycle (<a href="https://buildsecurityin.us-cert.gov/daisy/bsi/articles/knowledge/sdlc/326-BSI.html">SDLC</a>) models into their business operation, many security problems would go away.  Building secure software will require changes in the current development culture, which will include people, processes, and technology.  No small task.
</p>
<p>
Gunnar Peterson has a nice post, &#8220;<a href="http://1raindrop.typepad.com/1_raindrop/2006/09/waf_and_xsg_ris.html">WAF and XSG Risk and Effectiveness at 20,000 feet</a>&#8221; where he discusses modeling of combination of risk and effectiveness to identify areas of focus.  As Peterson <a href="http://1raindrop.typepad.com/1_raindrop/2006/01/defense_in_dept.html">points out in another post</a>, &#8220;<em>WAFs are not as static as network firewalls&#8230;Instead WAFs collaborate much more directly with development, which is another growth opportunity for security industry</em>.&#8221;
</p>
<p>
This post is going to stay focused on WAFs.  With it taking on average 130 days to fix sequel injection bugs, organizations need something they can implement today.  WAFs have an important role to play in adding a layer of security and monitoring to a <a href="https://buildsecurityin.us-cert.gov/daisy/bsi/articles/knowledge/principles/347-BSI.html">defense in depth security approach</a>.  WAFs will evolve.  They are in the process of evolving now.  Understanding the fundamental ideas and going through the implementation of an open source solution starts us on the path of better understanding of future technologies.</p>
<h3>An Implementation Using ModSecurity</h3>
<p>Building on previous posts concerning &#8220;<a href="http://blog.securitymonks.com/2008/04/14/an-apache-implementation/">An Apache Implementation</a>&#8220;, &#8220;<a href="http://blog.securitymonks.com/2008/04/21/php-implementation/">PHP Implementation</a>&#8220;, and &#8220;<a href="http://blog.securitymonks.com/2008/04/24/apache-and-openssl/">Apache and OpenSSL</a>&#8220;, we have an Apache web server setup to build upon.  For additional details, please get Ivan Ristic&#8217;s book, &#8220;<a href="http://www.apachesecurity.net/">Apache Security</a>.&#8221;  It really is a must have book for anyone serious about running an Apache web server.   Ristic also maintains the ModSecurity <a href="http://www.modsecurity.org/">website</a> and <a href="http://blog.modsecurity.org/">blog</a>, which serves as a great source for up-to-date information on ModSecurity.
</p>
<p>
The Apache module <a href="http://httpd.apache.org/docs/2.2/mod/mod_unique_id.html">mod_unique_id</a> needs to be installed for  ModSecurity to work properly.  This module was not installed when we configured Apache.  At that time, we did not know we needed it.  While it can be somewhat inconvenient, for security reasons it is best not to install modules not needed.</p>
<h4><strong>1.  Stop Apache Server.</strong></h4>
</p>
<p><table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
# /usr/local/apache/bin/apachectl stop
</pre>
</td>
</table>
<p></p>
<h4><strong>2.  Install mod_unique_id Module.</strong></h4>
<p>For non Mac OS X, do the following:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd /usr/local/src/httpd-2.2.8
/usr/local/src/httpd-2.2.8 root# make clean
/usr/local/src/httpd-2.2.8 root# CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
./configure --prefix=/usr/local/apache \
--enable-rewrite \
--enable-so \
--disable-imap \
--disable-userdir --with-mpm=worker --enable-ssl --enable-unique-id --enable-unique-id
/usr/local/src/httpd-2.2.8 root# make
/usr/local/src/httpd-2.2.8 root# make install
</pre>
</td>
</table>
<p> <br />
For Mac OS X, please do:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd /usr/local/src/httpd-2.2.8
/usr/local/src/httpd-2.2.8 root# make clean
/usr/local/src/httpd-2.2.8 root# CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
LDFLAGS="-L/opt/local/lib -L/usr/lib" \
./configure --prefix=/usr/local/apache --enable-rewrite \
--enable-so --disable-imap --disable-userdir \
--with-mpm=worker --enable-ssl --enable-unique-id
/usr/local/src/httpd-2.2.8 root# make
/usr/local/src/httpd-2.2.8 root# make install
</pre>
</td>
</table>
<p>   </p>
<h4><strong>3.  Install <a href="http://www.pcre.org/">PCRE</a>.</strong></h4>
<p>Only under Mac OS X did I have to install Perl Compatible Regular Expressions (PCRE).  You may be able to skip this step, depending on your OS.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd /usr/local/src
/usr/local/src root# wget http://downloads.sourceforge.net/pcre/pcre-7.7.tar.gz
/usr/local/src root# tar xzf pcre-7.7.tar.gz
/usr/local/src root# cd pcre-7.7
/usr/local/src/pcre-7.7 root# CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
LDFLAGS="-L/opt/local/lib -L/usr/lib" \
./configure
/usr/local/src/pcre-7.7 root# make
/usr/local/src/pcre-7.7 root# make test
/usr/local/src/pcre-7.7 root# make install
</pre>
</td>
</table>
<p>   </p>
<h4><strong>4.  Install the latest version of <a href="http://xmlsoft.org/downloads.html">libxml2</a> or <a href="http://www.lua.org/download.html">Lua</a>.</strong></h4>
<p>To quote wikipedia, <a href="http://en.wikipedia.org/wiki/Libxml2">libxml</a> is &#8220;<em>a library for parsing XML documents</em>&#8221; and <a href="http://en.wikipedia.org/wiki/Lua_(programming_language)">Lua</a> is &#8220;<em>a lightweight, reflective, imperative and procedural programming language, designed as a scripting language with extensible semantics as a primary goal</em>.&#8221; ModSecurity requires dynamic libraries which are not built by default in the source distribution.  Binary distribution is recommended.
</p>
<p>
I will go through configuration and installation of libxml2 from source and the binary installation of lua under Mac OS X.   There is a good chance if you are running a different OS, the libraries will have already been installed. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd  /usr/local/src/
/usr/local/src root# wget ftp://xmlsoft.org/libxml2/libxml2-2.6.32.tar.gz
/usr/local/src root# tar xzf libxml2-2.6.32.tar.gz
/usr/local/src root# cd libxml2-2.6.32
/usr/local/src/cd libxml2-2.6.32 root#  CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
LDFLAGS="-L/opt/local/lib -L/usr/lib" \
/usr/local/src/cd libxml2-2.6.32 root# ./configure
/usr/local/src/cd libxml2-2.6.32 root# make
/usr/local/src/cd libxml2-2.6.32 root# make install
/usr/local/src/cd libxml2-2.6.32 root# cd ..
/usr/local/src root# wget http://luaforge.net/frs/download.php/3097/lua5_1_3_Darwin811x86_lib.tar.gz
/usr/local/src root# mkdir lua
/usr/local/src root# cd lua
/usr/local/src/lua root# tar xzf lua5_1_3_Darwin811x86_lib.tar.gz
/usr/local/src/lua root# cp liblua5.1.* /usr/local/lib
/usr/local/src/lua root# cp include/* /usr/local/include
</pre>
</td>
</table>
<p></p>
<h4><strong>5.  Download, unpack, configure, and compile <a href="http://www.modsecurity.org/download/direct.html">ModSecurity</a>.</strong></h4>
<p>If you are interested in connecting a ModSecurity sensor to the central audit log repository, you will want to build the ModSecurity Log Collector below with the command &#8220;make mlogc&#8221;.  Install instructions can be found under apache2/mlogc-src directory.  That step will not be included below.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
root# cd  /usr/local/src/
/usr/local/src root# wget http://www.modsecurity.org/download/modsecurity-apache_2.5.5.tar.gz
/usr/local/src root# tar xzf modsecurity-apache_2.5.5.tar.gz
/usr/local/src root# cd modsecurity-apache_2.5.5
/usr/local/src/modsecurity-apache_2.5.5 root# cd apache2
</pre>
</td>
</table>
<p>
For non Mac OS X, configure with the command:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# ./configure \
--with-apxs=/usr/local/apache/bin/apxs \
--with-apr=/usr/local/apache/bin \
--with-apu=/usr/local/apache/bin
</pre>
</td>
</table>
<p>
For Mac OS X, use the command:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
LDFLAGS="-L/opt/local/lib -L/usr/lib" \
./configure --with-apxs=/usr/local/apache/bin/apxs
</pre>
</td>
</table>
<p>
Continue to compile and install with the commands:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# make
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# make test
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# make install
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# ls -la /usr/local/apache/modules
</pre>
</td>
</table>
<p></p>
<h4><strong>6.  Configure Apache and ModSecurity.</strong></h4>
<p>We must now edit the httpd.conf file in order to load libxml2 or lua5.1 modules before the ModSecurity module.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# vi /usr/local/apache/conf/httpd.conf
</pre>
</td>
</table>
<p>
Add the lines for non Mac OS X:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
#
LoadFile /usr/lib/libxml2.so
LoadFile /usr/lib/liblua5.1.so
#
LoadModule security2_module modules/mod_security2.so
</pre>
</td>
</table>
<p>
For Mac OS X, add the lines:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
#
LoadFile /usr/local/lib/libxml2.2.dylib
LoadFile /usr/local/lib/liblua5.1.so
#
LoadModule security2_module modules/mod_security2.so
</pre>
</td>
</table>
<p>
Create the ModSecurity configuration file.  There is a file modsecurity.conf-minimal present in the /usr/local/src/modsecurity-apache_2.5.5 that can be used.  There is also a a Core Rule Set that was included in the /usr/local/src/modsecurity-apache_2.5.5/rules directory courtesy of Breach Security Inc.  To quote the README file, &#8220;<em>The Core Rule Set provides generic protection from unknown vulnerabilities often found in web application that are in most cases custom coded.  The Core Rule Set is heavily commented to allow it to be used as a step-by-step deployment guide for ModSecurity</em>.&#8221;  Under the rules subdirectory, there a directory &#8220;optional&#8221; which contains additional possible rules.  It is left to the reader which configuration files they may want to include, though it might be wise to start with the minimal and make sure the Apache runs without problems.  Then add configurations files as desired. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5/apache2 root# cd ..
/usr/local/src/modsecurity-apache_2.5.5 root# cp  modsecurity.conf-minimal /usr/local/apache/conf/modsecurity.conf
/usr/local/src/modsecurity-apache_2.5.5 root# cp  rules/*.conf /usr/local/apache/conf/
</pre>
</td>
</table>
<p>
Include the modsecurity.conf, and additional ModSecurity configurations file, in the Apache httpd.conf file.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5 root# vi /usr/local/apache/conf/httpd.conf
</pre>
</td>
</table>
<p>
Add the line:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
Include /usr/local/apache/conf/modsecurity.conf
#Include /usr/local/apache/conf/modsecurity_crs_10_config.conf
#Include /usr/local/apache/conf/modsecurity_crs_21_protocol_anomalies.conf
#Include /usr/local/apache/conf/modsecurity_crs_23_request_limits.conf
#Include /usr/local/apache/conf/modsecurity_crs_30_http_policy.conf
#Include /usr/local/apache/conf/modsecurity_crs_35_bad_robots.conf
#Include /usr/local/apache/conf/modsecurity_crs_40_generic_attacks.conf
#Include /usr/local/apache/conf/modsecurity_crs_45_trojans.conf
#Include /usr/local/apache/conf/modsecurity_crs_50_outbound.conf
</pre>
</td>
</table>
<p>
Edit /usr/local/apache/conf/modsecurity.conf.  The modifications will be very dependent on your environment.  See resources listed in the Additional Information section to help with configuration.  The default configuration saves the log files relative to the configuration file directory.  Change this to where the apache logs are currently being saved. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5 root# vi /usr/local/apache/conf/modsecurity.conf
</pre>
</td>
</table>
<p>
Change the values to:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
SecAuditLog /var/www/logs/modsec_audit.log
SecDebugLog /var/www/logs/modsec_debug.log
</pre>
</td>
</table>
<p>
Let&#8217;s create null files with the correct permissions for Apache.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5 root# touch  /var/www/logs/modsec_audit.log
/usr/local/src/modsecurity-apache_2.5.5 root# chown httpd.httpd /var/www/logs/modsec_audit.log
/usr/local/src/modsecurity-apache_2.5.5 root# touch  /var/www/logs/modsec_debug.log
/usr/local/src/modsecurity-apache_2.5.5 root# chown httpd.httpd /var/www/logs/modsec_debug.log
</pre>
</td>
</table>
<p></p>
<h4><strong>7.  Start Apache.</strong></h4>
<p>Check that the configuration file is correct and start up Apache.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5 root# /usr/local/apache/bin/apachectl configtest
Syntax OK
/usr/local/src/modsecurity-apache_2.5.5 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p>
Check if ModSecurity if configured into running Apache server.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
/usr/local/src/modsecurity-apache_2.5.5 root# cat /var/www/logs/error_log | grep ModSecurity
[Thu Jul 31 18:24:59 2008] [notice] ModSecurity for Apache/2.5.5 (http://www.modsecurity.org/) configured.
</pre>
</td>
</table>
<p></p>
<h3>Additional Information</h3>
<p>This post is only to get the basics down.  The above information was taken from the <a href="http://www.modsecurity.org/documentation/modsecurity-apache/2.5.5/modsecurity2-apache-reference.html#installation">ModSecurity documentation</a> install section for version 2.5.5.  A great deal more information is available at the <a href="http://blog.modsecurity.org/">ModSecurity blog site</a> and in the book &#8220;<a href="http://www.apachesecurity.net">Apache Security</a>&#8220;.  </p>
<h3>Concluding Remarks</h3>
<p>Ivan Ristic and <a href="http://blog.shezaf.com/">Ofer Shezaf</a> are working on an interesting paper, &#8220;<a href="http://blog.modsecurity.org/files/enough_with_default_allow_r2_draft.pdf">Enough With Default Allow in Web Applications!</a>&#8221;  This paper demonstrates how WAFs are evolving.  To quote the paper:</p>
<blockquote><p>The default allow deployment model, which is commonly used to implement and deploy web applications, is the cause of numerous security problems. We propose a method of modeling web applications in a platform-agnostic way to adopt a default deny model instead, removing several classes of vulnerability altogether and significantly reducing the attack surface of many others. Our approach is best adopted during development, but can be nearly as efficient as an afterthought, or when used at deployment time.  What they are looking to do is create a protection layer between the web servers and applications which would increase security and turn applications into verifiable components with external contracts that can be enforced.</p></blockquote>
<p>Ristic mentions in his post the planned release of &#8220;<em>an open source profiling tool (which I will announce next week) to help with the third use case and automate the creation of positive security models (also known as the learning feature of web application firewalls)</em>.&#8221;  Breach Security has also <a href="http://www.breach.com/news-events/press-releases/whitehat-security-and-breach-security-team-to-offer-powerful-web-application-security.html">teamed up with WhiteHat Security</a> to add the ability to their Sentinel scanning service to automatically create custom ModSecurity rules for certain classes of vulnerabilities that are found in your web applications.  This is the kind of evolution that is required in security and makes ModSecurity such an interesting software package.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/07/31/implementing-a-web-application-firewall-with-modsecurity/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Apache and OpenSSL</title>
		<link>http://blog.securitymonks.com/2008/04/24/apache-and-openssl/</link>
		<comments>http://blog.securitymonks.com/2008/04/24/apache-and-openssl/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 23:05:56 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[OpenSSL]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/2008/04/24/apache-and-openssl/</guid>
		<description><![CDATA[Adding to the previous post titled &#8220;An Apache Implementation&#8220;, today we will discuss implementing OpenSSL under Apache.  To quote from the OpenSSL site, OpenSSL is &#8220;a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/security_graphic.gif" alt="Apache and OpenSSL" align="left" />Adding to the previous post titled &#8220;<a href="http://blog.securitymonks.com/2008/04/14/an-apache-implementation/">An Apache Implementation</a>&#8220;, today we will discuss implementing <a href="http://www.openssl.org/">OpenSSL</a> under Apache.  To quote from the OpenSSL site, OpenSSL is &#8220;<em>a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a full-strength general purpose cryptography library</em>.&#8221;  Most operating system have OpenSSL installed, so do not download and install it.  Doing so could break applications that rely on the pre-installed version of OpenSSL.  Work with what you have.  After all, there is more to life than just installation.  There is configuration and certification.</p>
<p>
If you are using Apache 2.x, which is what we installed in the previous post, Apache supports SSL already with the mod_ssl module.  If you need to check if mod_ssl is part of your Apache configuration, do so with the command:
</p>
<p>
<strong>/usr/local/apache/bin/httpd -l</strong>
</p>
<p>
Having established that mod_ssl module is installed, we will now go through the steps of generating a certificate request, approving the certificate, and add to Apache configuration file required lines to create a SSL enabled Apache server.</p>
<h3>Key Generation</h3>
<p>We start off by generating a non password protected 1024 bit server private key using the <a href="http://www.linuxjournal.com/article/6826">RSA algorithm</a>.  We will have the key stored in the file <strong>server.key</strong>.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root#  cd /usr/local/apache/conf
 /usr/local/apache/conf root# mkdir ssl
 /usr/local/apache/conf root# cd ssl
 /usr/local/apache/conf/ssl root# openssl genrsa -out <strong>server.key</strong> 1024
Generating RSA private key, 1024 bit long modulus
.....................................................................++++++
....++++++
e is 65537 (0x10001)

 /usr/local/apache/conf/ssl root# cat server.key
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDS1A7eGdTo39tnYdzYI3Ifl1/sA4ZiY7PzkDU68tZoA4WzJB9n
aSJHCbd0ESG0oPiyf/yqMyNR2ECwjLUFo1m1nrON2w3QdM5zFZZv6v7jDt40u3bT
95XwdFG4FYDw+gq6liuRAkAe2+B6WM1Qv5rN3IzhmZmPA8YjV/sbPzNmzIuNHrVw
FY0WkRzrEF6P36Z6RVJQSzgzx4pDeu5rRX88HxLdTm4Uz6maiwhLsxZv0QIDAQAB
hsqZuAY7esEvSlL9xxXHxHL9Ywl/EXnXSMcJ9ktSobs/T0favkQKulgq6ov9TzIQ
v2Z2vLEABQJBANeKaGm41GgDZp3yEIuNKUp0OjwnORpkuYf/DFA+ox1AAS2OPGjV
iua7aiHYPPF6O6Knb+6SiBRFVkjB6Pz1Fl0CQFs7mxCIHrvTjGN8EcHQ038IP/iu
AoGBAMLjcFLzghM7TDBHEMVkDs0RO4SKxaESFXkjZ3F0papFB0TQMY+AakVMwB80
7vlwjDVFhqU23IF97F7H01bA590DfIxg6c11w4PdlxHVb9Kv+K7P7mve3wbJEUV+
rYr8r+Hr25Fegzwg1tfgFLDDkDoeC3u1wbQNCmL/qksSrD6hAkEA+mc0g4S92Y6S
gDQ3JU/YLaYV4aw2Xk/v5RtNmk++73QtU++azuXSFeDbHHHsZdm2tXBOdRkCQQCv
vg68hRPLa1p0VjbfUk3kgzgoa+LHfnE4TeEAXNIqu1E6j8r5v4Pt9cnnpqSqT/vn
qzTyQmTBW621ioer5A4v2QocJ2R6XhgjDwFOmKTGs0mH
-----END RSA PRIVATE KEY-----
 /usr/local/apache/conf/ssl root# chmod 400 server.key
</pre>
</td>
</table>
<h3>Certificate Signing Request (CSR)</h3>
<p>The next step is to create a <a href="http://en.wikipedia.org/wiki/Certificate_signing_request">certificate-signing request (CSR)</a>, which is used as a message sent asking a certificate authority (CA) to sign a certificate.  If you want a field to be empty, do not hit return.  That would just select the default value.  Instead, use &#8220;.&#8221;.  Below, I have left my responses off.  Enter your own appropriate values.  The generated CSR will be the file <strong>server.csr</strong>.
</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/apache/conf/ssl root# openssl req -new -key server.key -out <strong>server.csr</strong>
You are about to be asked to enter information that will be
incorporated into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:
State or Province Name (full name) [Berkshire]:
Organization Name (eg, company) [My Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
 /usr/local/apache/conf/ssl root#  cat server.csr
</pre>
</td>
</table>
<p>You can now send the CSR server.csr to your public CA.  The CA will generate and sign the certificate.  To make things more interesting, we are now going to sign our own CSR and generate a signed certificate <strong>server.crt</strong>.  You can use the command &#8220;openssl x509&#8243; to examine the certificate.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/apache/conf/ssl root# openssl x509 -req -days 365 -in server.csr \
-signkey server.key -out <strong>server.crt</strong>
Signature ok
subject=/C=US/ST=New
 Jersey/L=Princetown/O=PU/OU=RS/CN=podus.pu.edu/emailAddress=jbond@pu.edu
Getting Private key
 /usr/local/apache/conf/ssl root# openssl x509 -text -in server.crt
 /usr/local/apache/conf/ssl root# chmod 400 server.crt
</pre>
</td>
</table>
<h3>Configuration</h3>
<p>Now we are going to enable SSL on our Apache server running the server off port 443.  The  server will use the certificate generated above.  We are also going to disable SSLv2 since it has <a href="http://www.eucybervote.org/Reports/MSI-WP2-D7V1-V1.0-02.htm">some problems</a> and is disabled by default in Internet Explorer 7, Firefox 2, Opera 9, and Safari.</p>
<p>
Modify the apache configuration file:
</p>
<p>
<strong>/usr/local/apache/conf/httpd.conf</strong>
</p>
<p>
adding the lines:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
Listen 443
&lt;virtualhost _default_:443>
#   SSL Engine Switch:
SSLEngine on
# Path to the server certificcate
SSLCertificateFile "/usr/local/apache/conf/ssl/server.crt"
# Path to the server private key
SSLCertificateKeyFile "/usr/local/apache/conf/ssl/server.key"
# Allow SSLv3 only
SSLProtocol All -SSLv2
#   SSL Cipher Suite:
#   Disallow ciphers that are weak
SSLCipherSuite ALL:!EXP:!NULL:!ADH:!LOW
# Make SSL work with Internet Explorer
SetEnvIf User-Agent ".*MSIE.*" \
              nokeepalive ssl-unclean-shutdown \
              downgrade-1.0 force-response-1.0
&lt;/virtualhost>
</pre>
</td>
</table>
<p>
Depending on your requirements, you might want to run the server only over SSL.  You can do this by stopping the server from listening on port 80.  That would result in unable to connect message.  Instead, it might be better to redirect traffic coming to http over to https.  A great source of recipes for rewrite rule is the <a href="http://rewrite.drbacchus.com/">mod_rewrite Cookbook</a> site.  </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
</pre>
</td>
</table>
<p>We will also add limitations to who can access the site by limiting who access the &#8220;/&#8221; directory.  In the example below, we will limit it to 127.0.0.1.  In the httpd.conf file, after the line &#8220;&lt;Directory />&#8221; add the line:</p>
<pre class="displaycode">
SSLRequire  %{REMOTE_ADDR} =~ m/^127.0.0.1$/
</pre>
<p>Start Apache with the command:</p>
<pre>
/usr/local/apache/bin/apachectl start
</pre>
<p>You can try and access the web server with the URL:</p>
<pre class="displaycode">

http://yourhostname/
</pre>
<p>you will get the message:</p>
<pre>
Forbidden
You don't have permission to access / on this server.
</pre>
<p>Notice that the URL has changed from &#8220;http://yourhostname&#8221; to &#8220;<strong>https</strong>://yourhostname&#8221;.  Now try and access the site using:</p>
<pre class="displaycode">

http://127.0.0.1/
</pre>
<p>You will get prompted whether to accept the certificate.  Since you are accessing 127.0.0.1, it will complain about a domain name mismatch.  The host you are trying to access needs to match the entry you provided for &#8220;Common Name&#8221; in the CSR, otherwise it will complain.  If you accept the certificate, you can access the site.  </p>
<h3>Final Thoughts</h3>
<p>At this point, we have secured communication between the client and the Apache web server.  In my next post, we will discuss installing one more module, <a href="http://www.modsecurity.org">mod_security</a>.  Mod_security is a web application firewall and serves as another layer in our web defenses.  It is not meant as a replacement for implementing good security in databases, web servers, or applications.  That is why we have gone through all these additional steps first.  Remember, once, <a href="http://www.securityfocus.com/bid/5363/exploit">SSLv2</a> was thought to be secure.  Now we know otherwise.  <a href="http://www.securityfocus.com/vulnerabilities">Vulnerabilities</a> are continuously being discovered.  Good security is about building up one&#8217;s defenses.  It is a process, not a destination.  Maybe one day some company will have a security solution that will defend systems against all threats.  I know that is not today, no matter what sales folks might say.  When that day comes, you can bet before that solution makes it to market, hackers will have found a way around it.  So while we wait for the security rapture to take us to a secure promise land, implement security in layers.  It is your best defense.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/04/24/apache-and-openssl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An Apache Implementation</title>
		<link>http://blog.securitymonks.com/2008/04/14/an-apache-implementation/</link>
		<comments>http://blog.securitymonks.com/2008/04/14/an-apache-implementation/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 06:15:02 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MacPorts]]></category>
		<category><![CDATA[References]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/2008/04/14/an-apache-implementation/</guid>
		<description><![CDATA[&#8220;Clocks slay time&#8230; time is dead as long as it is being clicked off by little wheels; only when the clock stops does time come to life.&#8221; &#8212; William Faulkner

In honor of ApacheCon Europe, held this past week, we will be going over a very basic implementation of an Apache web server.  Ivan Ristic, [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;<a href="http://www.worldofquotes.com/author/William-Faulkner/1/index.html">Clocks slay time&#8230; time is dead as long as it is being clicked off by little wheels; only when the clock stops does time come to life.</a>&#8221; &#8212; <strong><a href="http://en.wikipedia.org/wiki/William_Faulkner">William Faulkner</a></strong></p>
<p>
<a href="http://despair.com/gettowork.html"><img src="/images/gettowork.jpg" alt="Time Image" align="left" width=150 /></a>In honor of <a href="http://www.eu.apachecon.com/eu2008/">ApacheCon Europe</a>, held this past week, we will be going over a very basic implementation of an <a href="http://httpd.apache.org/">Apache web server</a>.  <a href="http://blog.ivanristic.com/">Ivan Ristic</a>, author of &#8220;<a href="http://www.apachesecurity.net/">Apache Security</a>&#8221; spoke at ApacheCon where he presented &#8220;<a href="http://www.modsecurity.org/documentation/ApacheCon_Europe_2008-Web_Intrusion_Detection_with_ModSecurity.pdf">Web Intrusion Detection with ModSecurity</a>.&#8221;  Rich Bowen, author of &#8220;<a href="http://www.amazon.com/exec/obidos/asin/1590595610/drbacchus/">The Definitive Guide to Apache mod_rewrite</a>&#8221; (and a <a href="http://books.google.com/books?q=%22rich+bowen%22+author&#038;source=citation&#038;sa=X&#038;oi=print&#038;ct=title&#038;cad=bottom-3results&#038;hl=en">few other titles</a>) on his blog <a href="http://wooga.drbacchus.com/">DrBacchus Journal</a> did a post titled &#8220;<a href="http://wooga.drbacchus.com/apachecon-eu-2008-so-far">ApacheCon EU 2008 so far</a>.&#8221;  Rich had this to say about Ivan&#8217;s talk, &#8220;<em>His talk was fabulous</em>.&#8221;  He goes on to elaborate, &#8220;<em>I&#8217;m sure that everything Ivan talked about is in the docs, but his talk was amazingly valuable anyway, since it showed me things in one hour that would probably have taken me months to discover. And I&#8217;ve been using mod_security for years already, and wasn&#8217;t aware of them, or didn&#8217;t quite understand the syntax.&#8221;</em>  <a href="http://people.apache.org/~niq/">Nick Kew</a> agrees with Rich.  On Nick&#8217;s blog <a href="http://bahumbug.wordpress.com/">NIQ&#8217;s Soapbox</a>, his posting &#8220;<a href="http://bahumbug.wordpress.com/2008/04/10/putting-ones-money-where-ones-mouth-is/">Putting ones money where ones mouth is ….</a>&#8221;  had this to say, <em>&#8220;The highlight of today was Ivan Ristic’s mod_security talk: that module is getting seriously interesting.</em>&#8221;
</p>
<p>
If you are interested in hearing more about ApacheCon, the <a href="http://streaming.linux-magazin.de/events/apacheconfree/">keynote sessions</a> have been made available for free off the Linux Magazine web site.  The available presentations consist of:
<ul>
<li><a href="http://www.jimjag.com/">Jim Jagielski</a>, Chairman of the Apache Software Foundation, starts off with his talk &#8220;<a href="http://streaming.linux-magazin.de/en/program_apachecon08.htm">State of the Feather</a>.&#8221;  To  quote from the program, &#8220;<em>Join ASF Chairman Jim Jagielski for a review of events and progress over the last 12 months within the Apache Software Foundation. Jim will detail the growth of the ASF, both in members as well as projects, discuss the noteworthy achievements of the ASF during that time period, and preview what the next 12 months likely hold for the pre-eminent open source foundation.</em>&#8220;</li>
<li><a href="http://en.oreilly.com/oscon2008/public/schedule/speaker/3809">Cliff Schmidt</a>, Executive Director of <a href="http://literacybridge.org/">Literacy Bridge</a>, discusses &#8220;<a href="http://www.eu.apachecon.com/eu2008/program/talk/2625">Using Audio Technology and Open Content to Reduce Global Illiteracy</a>.&#8221;  To quote from the program, &#8220;<em>During this talk, Cliff will share his observations from Ghana and discuss Literacy Bridge&#8217;s Talking Book Project.  Literacy Bridge was founded to empower children and adults with tools for scalable knowledge sharing and literacy learning. The Talking Book Project is Literacy Bridge&#8217;s major program, developing new and affordable digital audio technology to provide vital, locally generated information and literacy training to people with limited access to either</em>.&#8221;</li>
<li><a href="http://www.merit.unu.edu/about/profile.php?id=24">Rishab Aiyer Ghosh</a>, <a href="http://www.opensource.org/">Open Source Initiative</a> Board Member, presents &#8220;<a href="http://www.eu.apachecon.com/eu2008/program/talk/2630">Apache and Steam Engines: the Magic of Collaborative Innovation</a>.&#8221;  To quote from the program, &#8220;<em>Rishab looks at collaborative model of creativity, from 18th century steam engines to the human genome project and discusses why and how collaborative creativity works. Using data from the FLOSS studies, he shows how this makes free software a continuing source of economic value and innovation around the world</em>.&#8221;</li>
<li><a href="http://www.ics.uci.edu/~fielding/">Roy Fielding</a>, Co-founder of The Apache Software Foundation, and Vice President, Apache HTTP Server, discussed &#8220;<a href="http://www.eu.apachecon.com/eu2008/program/talk/2636">Apache 3.0 (a Tall Tale)&#8221;</a>.  To quote from the program, &#8220;<em>Thirteen years ago, the Apache Group founders finished the first beta release of Apache httpd, having reached the end of their initial pile of small improvements, and began to look forward to a complete rewrite of the server architecture. Suddenly, our forward progress slowed to a trickle, mailing list traffic dropped by two-thirds, and our focus diverged&#8230;Today, we face a new chasm, and our past successes have only made it wider and deeper than before. This talk is about the other side.</em>&#8220;</li>
</ul>
<p>I am with Rich and Nick, Ivan&#8217;s work with <a href="http://www.modsecurity.org">ModSecurity</a> is extremely interesting and we will build towards implementing it.  First, we need to start simple for there are many steps in the process.  This post will provide references for setting up an Apache server, followed by a simple implementation.  For additional information, particularly in the area of security, see my previous post &#8220;<a href="http://blog.securitymonks.com/2008/02/24/securing-apache-references/">Securing Apache: References</a>.&#8221;
</p>
<p>
Some folks might ask, &#8220;why not simply install XAMPP or MAMPP (depending on your system)?&#8221;  Installing binaries is one way to go.  With something as important as the web server, taking the easiest path is not necessary the best option.  Compiling from source provides the most power and flexibility to change things according to your priorities.  You gain control over such issues as compile time options, modules, and when to upgrade (verses waiting for security patches and upgrades to come out in binary format).  While it might not be the easiest path, it is vital in learning what is going on with your system and helping avoid integration problems in the future.  </p>
<h3>Documents and Articles</h3>
<p>Below are a few documents and articles that are most helpful when setting up Apache.</p>
<ul>
<li><a href="http://www.apachesecurity.net/">Apache Security</a> by <a href="http://blog.ivanristic.com/">Ivan Ristic</a>.  When it comes to the Apache web server, Ivan is the man to listen to.  His book, truly is the complete guide to securing your Apache web server.  It is an excellent resource.</li>
<li><a href="http://httpd.apache.org/docs/2.2/install.html">Compiling and Installing</a> document created by The Apache Software Foundation.  A great deal of information on Apache is available, not surprisingly, off the Apache HTTP server site.</li>
<li><a href="http://www.securityfocus.com/infocus/1786">Securing Apache 2: Step-by-Step</a> by <a href="http://blog.ivanristic.com">Ivan Ristic</a>.  This is a shorter, more compact article appearing in SecurityFocus.</li>
<li><a href="http://httpd.apache.org/docs/2.2/misc/security_tips.html">Security Tips</a> document created by The Apache Software Foundation.  A very good source of information on securing the Apache HTTP server.  The best place to go to ensure you have the most up-to-date information on securing the server.</li>
</ul>
<h3>Benchmarks</h3>
<p><a href="http://www.cisecurity.org">The Center for Internet Security</a> is a non-profit enterprise that helps develop security configuration benchmarks.  The stated mission of CIS is to &#8220;<em>reduce the risk of business and e-commerce disruptions resulting from inadequate technical security controls</em>.&#8221;  They have created the document &#8220;<a href="http://www.cisecurity.org/bench_apache.html">CIS Level 1 &#038; 2 Benchmark and Scoring Tool for the Apache Web Server</a>.&#8221;  The document was last updated, as of this writing, on January 2008.  The download file consists of:
<ul>
<li><strong>CIS_Apache_Benchmark_v2.1.pdf</strong> &#8211; the Benchmark document contains detailed instructions for implementing the steps necessary for CIS Level 1 and Level 2 sec.</li>
<li><strong>cis_score_tool_apache_v2.10.sh.gz</strong> &#8211; a Host-based Scoring Tool scores the security of a system against the Benchmark and creates a variance report. </li>
</ul>
<p>Additional information is available off the site.  </p>
<h3>Forums and Blogs</h3>
<p>Most of the forums and blogs that I am familiar with deal with security issues involved with web servers.  See my &#8220;<a href="http://blog.securitymonks.com/2008/02/28/setting-up-and-securing-mysql-references/">Securing Apache: References</a>&#8221; post for those links. </p>
<h3>Installing Apache</h3>
<p>If Apache was not installed with your operating system, or if you wish to compile from source, you will need to download the latest Apache from the <a href="http://httpd.apache.org/">Apache web site</a>.   For this document, I will go through pulling down Apache version 2.2.  Please consult the <a href="http://httpd.apache.org/docs/2.2/install.html">Apache HTTP Server Version 2.2 Compiling and Installing documentation</a> for additional information.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://mirrors.isc.org/pub/apache/httpd/httpd-2.2.8.tar.gz
 /usr/local/src root# tar xzf httpd-2.2.8.tar.gz
</pre>
</td>
</table>
<p>
At this point, you need to check the integrity.  There as two ways to do this.  First, is by calculating the MD5 sum of the source and comparing it to the signature file.  Mac OS X users, please note use the command <strong>/sbin/md5</strong> instead of <strong>md5sum</strong>.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# md5sum httpd-2.2.8.tar.gz
39a755eb0f584c279336387b321e3dfc  httpd-2.2.8.tar.gz

 /usr/local/src root# wget -O - -q http://www.apache.org/dist/httpd/httpd-2.2.8.tar.gz.md5
39a755eb0f584c279336387b321e3dfc  httpd-2.2.8.tar.gz
</pre>
</td>
</table>
<p>
The second method, uses public-key cryptography to <a href="http://httpd.apache.org/dev/verification.html">verify the integrity of the files</a>.  This is more complicated, but more secure.  The MD5 sums can be circumvented if an intruder compromises the main distribution site and replaces the signature files.  Using public-key cryptography can be done using <a href="http://www.gnupg.org">GnuPG</a>, the free software version of the OpenPGP.  Most Unix systems has it installed by default.  The installation is fairly straight forward, no matter what OS you are using:  </p>
<ol>
<li><a href="http://www.media-art-online.org/gnupg/help/setup.html">Install GnuPG</a>.  For Mac OS X, you would want to install <a href="http://macgpg.sourceforge.net/">Mac GnuPG</a>.  For Windows, you will need <a href="http://winpt.sourceforge.net/">WinPT</a>.</li>
<li>Optionally, under Unix you might want to install a <a href="http://www.gnupg.org/related_software/frontends.en.html">graphical front-end for GnuPG</a>.</li>
<li><a href="http://www.dewinter.com/gnupg_howto/english/GPGMiniHowto-3.html">Generate</a> a pair of keys.</li>
</ol>
<p>Apache developers use their cryptographic keys to sign the distributions digitally.  We are going to download the PGP signature, fetch the GnuPG unique key ID (<strong>DE885DD3</strong>), and then check the signature.  </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# wget http://www.apache.org/dist/httpd/httpd-2.2.8.tar.gz.asc
 /usr/local/src root# gpg --keyserver pgpkeys.mit.edu --recv-key DE885DD3
gpg: requesting key DE885DD3 from HKP keyserver pgpkeys.mit.edu
gpg: trustdb created
gpg: key DE885DD3: public key "Sander Striker <striker @apache.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1

 /usr/local/src root# gpg httpd-2.2.8.tar.gz.asc
gpg: Signature made Sat Jan 18 07:21:28 2003 PST using DSA key ID DE885DD3
gpg: Good signature from "Sander Striker </striker><striker @apache.org>"
gpg:                 aka "Sander Striker </striker><striker @striker.nl>"
gpg: checking the trustdb
gpg: no ultimately trusted keys found
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Fingerprint: 4C1E ADAD B4EF 5007 579C  919C 6635 B6C0 DE88 5DD3

 /usr/local/src root# gpg --fingerprint DE885DD3
pub  1024D/DE885DD3 2002-04-10 Sander Striker </striker><striker @apache.org>
     Key fingerprint = 4C1E ADAD B4EF 5007 579C  919C 6635 B6C0 DE88 5DD3
uid                            Sander Striker </striker><striker @striker.nl>
sub  2048g/532D14CA 2002-04-10
</striker></pre>
</td>
</table>
<p>
To verify DE885DD3 was created by the real Sander Striker, download <a href="http://www.apache.org/dist/httpd/KEYS">public keys for the Apache HTTP Server developers</a> from the Apache HTTP Server Project website.  Officially, you should validate by face-to-face communication with multiple government-issued photo identification confirmations.  Trust can be a complicated issue.  For more information on determining what level of trust, please read the GNU Privacy Handbook section on <a href="http://www.gnupg.org/gph/en/manual.html#AEN335">Validating other keys on your public keyring</a>.
</p>
<p>
Let us get back to compiling Apache.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# cd httpd-2.2.8
 /usr/local/src/httpd-2.2.8 root# ./configure --prefix=/usr/local/apache
 /usr/local/src/httpd-2.2.8 root# make
 /usr/local/src/httpd-2.2.8 root# make install
</pre>
</td>
</table>
<p>
There is more to be done.  The above configuration was to help in determining the Apache modules that are compiled be default.  The following modules, should not be used unless needed:</p>
<table border=1>
<tr>
<td><a href="hthttp://httpd.apache.org/docs/2.2/mod/mod_userdir.html">mod_userdir</a></td>
<td>Allows each user to have their own website under the ~username alias.  Be careful when using this directive; for instance, &#8220;UserDir ./&#8221; would map &#8220;/~root&#8221; to &#8220;/&#8221; &#8211; which is probably undesirable. If you are running Apache 1.3 or above, it is strongly recommended that your configuration include a &#8220;UserDir disabled root&#8221; declaration. See also the <a href="http://httpd.apache.org/docs/1.3/mod/core.html#directory"><directory></directory></a> directive and the <a href="http://httpd.apache.org/docs/1.3/misc/security_tips.html">Security Tips</a> page for more information.</td>
</tr>
<tr>
<td><a href="http://httpd.apache.org/docs/2.2/mod/mod_info.html">mod_info</a></td>
<td>Provides a comprehensive overview of the server.  This module can leak sensitive information from the configuration directives of other Apache modules such as system paths, usernames/passwords, database names, etc.</td>
</tr>
<tr>
<td><a href="http://httpd.apache.org/docs/2.2/mod/mod_status.html">mod_status</a></td>
<td>Provides information on server activity and performance.  If mod_status is compiled into the server, its handler capability is available in all configuration files, including per-directory files (e.g., .htaccess). This</td>
</tr>
<tr>
<td><a href="http://httpd.apache.org/docs/2.2/mod/mod_include.html">mod_include</a></td>
<td>This module provides a filter which will process files before they are sent to the client. The processing is controlled by specially formatted SGML comments, referred to as elements. These elements allow conditional text, the inclusion of other files or programs, as well as the setting and printing of environment variables.</td>
</tr>
</table>
<p>The following modules will be require for use with later postings.  If you are sure you do not need theses modules, do not include them, and make sure not to include them in the below configuration.</p>
<table border=1>
<tr>
<td><a href="http://httpd.apache.org/docs/2.2/mod/mod_headers.html">mod_headers</a></td>
<td>This module provides directives to control and modify HTTP request and response headers. Headers can be merged, replaced or removed.</td>
</tr>
<tr>
<td><a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">mod_rewrite</a></td>
<td>This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. Even external database lookups in various formats can be used to achieve highly granular URL matching.</p>
<p>
Security concerns:
<ul>
<li>The rewrite engine may be used in .htaccess files. To enable the rewrite engine for these files you need to set &#8220;RewriteEngine On&#8221; and &#8220;Options FollowSymLinks&#8221; must be enabled. If your administrator has disabled override of FollowSymLinks for a user&#8217;s directory, then you cannot use the rewrite engine.</li>
<li>See the <a href="http://httpd.apache.org/docs/2.2/misc/security_tips.html">Apache Security Tips</a> document for details on how your security could be compromised if the directory where logfiles are stored is writable by anyone other than the user that starts the server.</li>
</ul>
</td>
</tr>
<tr>
<td><a href="http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html">mod_setenvif</a></td>
<td>The mod_setenvif module allows you to set environment variables according to whether different aspects of the request match regular expressions you specify. These environment variables can be used by other parts of the server to make decisions about actions to be taken.</td>
</tr>
<tr>
<td><a href="http://httpd.apache.org/docs/2.2/mod/mod_ssl.html">mod_ssl</a></td>
<td>Strong cryptography using the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols.  This module relies on <a href="http://www.openssl.org/">OpenSSL</a> to provide the cryptography engine.</td>
</tr>
</table>
<p>To determine which modules would be installed by default, issue the following command.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# ./httpd -l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_log_config.c
  mod_env.c
  mod_setenvif.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgi.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_so.c
</pre>
</td>
</table>
<p>
Now, we are going to change the modules that get installed.  We are going to add Secure Sockets Layer (SSL) support with the &#8220;&#8211;enable-ssl&#8221; switch.  In a later post, we will discuss how to use this cryptographic protocols to provide secure communications between clients and our web browser.  Unless you are sure you do not want SSL support, include the &#8220;&#8211;enable-ssl&#8221; switch.
</p>
<p>
For folks compiling on Mac OS X 10.5, the &#8220;&#8211;enable-ssl&#8221; switch will give you problems.  As of this writing, Leopard is using OpenSSL version 0.9.71 from September 2006.  There have been some changes made since then.  You could upgrade, but as mentioned before, you do not know what installed software is dependent on that library.  It would be nice if Apple had upgraded with the release of a new OS, but you have to play the cards Steve Jobs has dealt.  <a href="http://www.macports.org">The MacPorts Project</a> have the latest version of OpenSSL, 0.9.8g from October 2007.  In order to get Apache to compile, I would recommend using the most recent OpenSSL library.  If you need help with MacPorts, please see my posting &#8220;<a href="http://blog.securitymonks.com/2008/04/18/macports-under-mac-os-x-leopard/">MacPorts Under Mac OS X Leopard</a>.&#8221;  Special Mac OS X installation instruction follow.
</p>
<p>
For <strong>non Mac OS X</strong> operating systems, do the following to configure, compile and install Apache:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# make clean
 /usr/local/src/httpd-2.2.8 root# /bin/rm -r /usr/local/apache
 /usr/local/src/httpd-2.2.8 root# CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
./configure --prefix=/usr/local/apache \
--enable-rewrite \
--enable-so \
--disable-imap \
--disable-userdir --with-mpm=worker --enable-ssl
 /usr/local/src/httpd-2.2.8 root# make
 /usr/local/src/httpd-2.2.8 root# make install
</pre>
</td>
</table>
<p>
For <strong>Mac OS X</strong>, you need to tell the compiler which libraries to use so the more recent OpenSSL is used.  Do that with the following commands:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# make clean
 /usr/local/src/httpd-2.2.8 root# /bin/rm -r /usr/local/apache
 /usr/local/src/httpd-2.2.8 root# CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
<strong>LDFLAGS="-L/opt/local/lib -L/usr/lib"</strong> \
./configure --prefix=/usr/local/apache --enable-rewrite \
--enable-so --disable-imap --disable-userdir \
--with-mpm=worker --enable-ssl
 /usr/local/src/httpd-2.2.8 root# make
 /usr/local/src/httpd-2.2.8 root# make install
</pre>
</td>
</table>
<p></p>
<h3>Configuration</h3>
<p>It is time to configure and make the Apache server more secure.  Ivan Ristic have made available &#8220;<a href="http://www.apachesecurity.net/download/apachesecurity-ch02.pdf">Chapter 2: Installation and configuration</a>.&#8221;  Follow the chapter, do not just copy.  For demonstration purposes, I&#8217;ll be using what is written in that chapter to configure the Apache web server.  There are various configuration options and you want to configure the server for your environment.  It is very important to understand what is contained in your configuration file.
</p>
<p>
Create the user and group <strong>httpd</strong>, from which the Apache web server will run.  Under most versions of Unix (not Mac OS X), this is a simple matter of executing the following commands: </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# cd /usr/local/apache
 /usr/local/apache root# /usr/sbin/groupadd httpd
 /usr/local/apache root# /usr/sbin/useradd httpd -g httpd -d /dev/null -s /sbin/nlogin
</pre>
</td>
</table>
<p>
Under Mac OS X, there is no <strong>groupadd</strong> or <strong>useradd</strong> command.  Things are always more interesting under Mac OS X.  Prior to Leopard (10.5), you would have to determine which group ids (gid) have been used, choose an unused gid, and then create the httpd group using that gid.  This would be accomplished with the commands:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# nireport . /groups gid name
 root# nicl . -create /groups/httpd
 root# nicl . -append /groups/httpd <em>unique-gid</em>
 root# nicl . -append /groups/httpd passwd "*"
 root# nireport . /groups gid name
</pre>
</td>
</table>
<p>
Once creating the group, you would need to create a new user by finding an unused uid, create the user, fill in the user attributes, add a password, create a home area, and finally set permissions.  This would be accomplished with the commands:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# nireport / /users name uid
 root# niutil -create / /users/httpd
 root# niutil -createprop / /users/httpd uid <em>uid-from-above</em>
 root# niutil -createprop / /users/httpd gid <em>gid-from-above</em>
 root# niutil -createprop / /users/httpd realname "Web Server"
 root# niutil -createprop / /users/httpd home "/dev/null"
 root# niutil -createprop / /users/httpd shell "/sbin/nologin"
 root# niutil -createprop / /users/httpd passwd "*"
</pre>
</td>
</table>
<p>
<a href="http://en.wikipedia.org/wiki/NetInfo">NetInfo</a>, the system configuration database,  no longer exists in Mac OS X 10.5 (Leopard).  The entire structure for managing local users, groups, and other such things has been completely replaced by <a href="http://www.afp548.com/article.php?story=LeopardServerReview-LocalDirectory">Local Directory Services</a>.  In Leopard, the DirectoryService daemon does the job of the DirectoryService, lookupd, and the memberd daemons.  Please see previous posting, &#8220;<a href="http://blog.securitymonks.com/2008/02/17/backing-up-using-amanda-on-mac-os-x-leopard-part-i/">Backing Up Using Amanda on Mac OS X Leopard Part I</a>&#8221; for additional details.  There is now a command line utility <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/dscl.1.html">dscl</a> to perform some advanced functions formerly covered by NetInfo Manager.  Creating the group httpd and user httpd would be done with the following commands: </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# dscl . list /groups PrimaryGroupID | sort -k 2,2 -n
 root# dscl . create /groups/httpd gid <em>gid-of-httpd</em>
 root# dscl . create /groups/httpd passwd '*'
 root# dscl . read /groups/httpd
AppleMetaNodeLocation: /Local/Default
Password: *
PrimaryGroupID: <em>gid-of-httpd</em>
RecordName: httpd
RecordType: dsRecTypeNative:groups

 root# dscl . list /users UniqueID | sort -k 2,2 -n
 root# dscl localhost -create /Local/Default/Users/httpd
 root# dscl localhost -create /Local/Default/Users/httpd RecordName httpd
 root# dscl localhost -create /Local/Default/Users/httpd UserShell /sbin/nologin
 root# dscl localhost -create /Local/Default/Users/httpd RealName "Web Server"
 root# dscl localhost -create /Local/Default/Users/httpd UniqueID <em>a-unique-uid</em>
 root# dscl localhost -create /Local/Default/Users/httpd PrimaryGroupID <em>gid-of-httpd</em>
 root# dscl localhost -create /Local/Default/Users/httpd NFSHomeDirectory /dev/null
 root# dscl . read /users/httpd
AppleMetaNodeLocation: /Local/Default
GeneratedUID: <em>generated-unique-id</em>
NFSHomeDirectory: /dev/null
PrimaryGroupID: <em>gid-of-httpd</em>
RealName:
 Web Server
RecordName: httpd
RecordType: dsRecTypeNative:users
UniqueID: <em>a-unique-uid</em>
UserShell: /sbin/nologin
</pre>
</td>
</table>
<p>
As part of the installation, the file /usr/local/apache/conf/httpd.conf is created.  Move that configuration for safe keeping and start with an empty configuration file.  Add the required functionality to ensure only the needed directives and modules are included.  Also, adjust file permissions.  Mac OS X users note that there is no group &#8220;<strong>root</strong>.&#8221;  Please use the group &#8220;<strong>admin</strong>&#8221; instead.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# cd /usr/local/apache
 /usr/local/apache root# mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.orig
 /usr/local/apache root# chown -R root:root /usr/local/apache
 /usr/local/apache root# find /usr/local/apache -type d | xargs chmod 755
 /usr/local/apache root# find /usr/local/apache -type f | xargs chmod 644
 /usr/local/apache root# chmod u+x  /usr/local/apache/bin/*
 /usr/local/apache root# mkdir -p /var/www/logs
 /usr/local/apache root# mv /usr/local/apache/htdocs /var/www/htdocs
 /usr/local/apache root# find /var/www/ -type d | xargs chmod 755
 /usr/local/apache root# find /var/www/ -type f | xargs chmod 644
 /usr/local/apache root# chmod -R go-r /usr/local/apache/conf
 /usr/local/apache root# chmod -R go-r /usr/local/apache/logs
 /usr/local/apache root# chmod -R go-r /var/www/logs
 /usr/local/apache root# vi /usr/local/apache/conf/httpd.conf
</pre>
</td>
</table>
<p>
Create a configuration file <strong>/usr/local/apache/conf/httpd.conf</strong> similar to the following file (adjust to your requirements):</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
# Location of the web server files
ServerRoot /usr/local/apache
# Location of the wev server tree
DocumentRoot /var/www/htdocs
# Listen on which port
Listen 80
# Store the PID of the main Apache process
PidFile /var/www/logs/httpd.pid
# Do not enables DNS lookups on client IP addresses
HostNameLookups Off
#
User httpd
Group httpd
# Deny access to the complete filesystem and then allow access
# to the document root.
&lt;Directory />
Order Deny,Allow
Deny from all
Options None
AllowOverride None
&lt;/Directory>
&lt;Directory /var/www/htdocs>
Order Allow,Deny
Allow from all
&lt;/Directory>
# Enable CGI Scripts
&lt;Directory /var/www/cgi-bin>
Options ExecCGI
SetHandler cgi-script
&lt;/Directory>
# Logging
LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /var/www/logs/access_log combined
LogLevel info
ErrorLog /var/www/logs/error_log
# Setting Server Configuration Limits
# wait up to 300 seconds for slow clients
TimeOut 60
# allow connections to be reused between requests
KeepAlive On
# allow a maximum of 100 requests per connection
MaxKeepAliveRequests 100
# wait up to 15 seconds for the next
# request on an open connection
KeepAliveTimeout 15
# impose no limits on the request body
LimitRequestBody 64000
# allow up to 100 headers in a request
LimitRequestFields 100
# each header may be up to 8190 bytes long
LimitRequestFieldsize 8190
# the first line of the request can be
# up to 8190 bytes long
LimitRequestLine 8190
# limit the XML request body to 1 million bytes(Apache 2.x only)
LimitXMLRequestBody 1000000
# the maximum number of processes
ServerLimit 16
# how many processes to start with
StartServers 2
# how many threads per process to create
ThreadsPerChild 25
# minimum spare threads across all processes
MinSpareThreads 25
# maximum spare threads across all processes
MaxSpareThreads 75
# maximum clients at any given time
MaxClients 150
# Preventing Information Leaks
ServerSignature Off
ServerTokens ProductOnly
&lt;FilesMatch "(^\.ht|~$|\.bak$|\.BAK$)">
Order Allow,Deny
Deny from all
&lt;/FilesMatch>
</pre>
</td>
</table>
<p>
At this point, you are ready to bring up the Apache web server.  Clean up any unnecessary files.  </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# /bin/rm -r /usr/local/apache/cgi-bin
 /usr/local/src/httpd-2.2.8 root# /bin/rm -r /usr/local/apache/manual
 /usr/local/src/httpd-2.2.8 root# /usr/local/apache/bin/apachectl configtest
 /usr/local/src/httpd-2.2.8 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p>
If you have any problems, take a look at <strong>/var/www/logs/error_log</strong>.  This is a very basic and clean Apache web server configuration.  It is a starting point from which we will build upon in future postings.  </p>
<h3>Conclusion</h3>
<p>I started this post with a quote from William Faulkner concerning how &#8220;<em>only when the clock stops does time come to life</em>.&#8221;  Or if you prefer the <a href="http://www.despair.com">despair.com</a> quote, &#8220;<em>Get to work: You aren&#8217;t being paid to believe in the power of your dreams</em>.&#8221;  I&#8217;ll be honest with you, doing a post on Apache implementation is not my idea of an exciting post.  I would much rather jump ahead and start talking about securing web applications at a higher level.  Sometimes, one has to build up to the more exciting stuff in order to demonstrate that one is not just selling <a href="http://en.wiktionary.org/wiki/pipe_dream">pipe dreams</a> with no real way to make those ideas a reality.  That is the difference between science and science fiction.  <a href="http://en.wikipedia.org/wiki/Bernard_of_Chartres">Bernard of Chartres</a> once wrote, “<em>We are like dwarfs standing upon the shoulders of giants, and so able to see more and see farther than the ancients</em>.”  Only the hard work of the ancients has allowed us to see further and dream bigger.  At some point, to make those dreams a reality, getting to work in the annoying details of life is a requirement.  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/04/14/an-apache-implementation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Securing Apache: References</title>
		<link>http://blog.securitymonks.com/2008/02/24/securing-apache-references/</link>
		<comments>http://blog.securitymonks.com/2008/02/24/securing-apache-references/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 02:18:03 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[connective intelligence]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/2008/02/24/securing-apache-references/</guid>
		<description><![CDATA[Before beginning any project, I start by researching the topic and pulling documents.  I do have my favorite spots to look, such as O&#8217;Reilly, NIST, the Center for Internet Security Benchmarks, Safari Books Online, ISACA, SANS, OWASP, Build Security In, a few choice blogs, etc.  While preparing to write an upcoming post on [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sun.com/portal/resource/info.jpg" alt="Secure Apache" align="left" width=100 />Before beginning any project, I start by researching the topic and pulling documents.  I do have my favorite spots to look, such as <a href="http://www.oreillynet.com/">O&#8217;Reilly</a>, <a href="http://csrc.nist.gov/publications/PubsSPs.html">NIST</a>, the <a href="http://www.cisecurity.org/">Center for Internet Security Benchmarks</a>, <a href="http://safari5.bvdep.com/">Safari Books Online</a>, <a href="http://www.isaca.org">ISACA</a>, <a href="http://www.sans.org/reading_room">SANS</a>, <a href="http://www.owasp.org">OWASP</a>, <a href="https://buildsecurityin.us-cert.gov/">Build Security In</a>, a few <a href="http://www.google.com/reader/shared/04444925558149080505">choice blogs</a>, etc.  While preparing to write an upcoming post on setting up a secure Apache web server, I found several great references.  Now, you do not need to read all these documents to implement a secure web server.  But, considering how a web server is the gateway from which the outside world connects to your organization, you might want to.  Here are a few documents of interest:
<ul>
<li><a href="http://www.apachesecurity.net/">Apache Security</a> by Ivan Ristic
	</li>
<li><a href="http://www.securityfocus.com/infocus/1786">Securing Apache 2: Step-by-Step</a> by Ivan Ristic</li>
<li>Apache HTTP Server Version 2.2: <a href="http://httpd.apache.org/docs/2.2/install.html">Compiling and Installing</a></li>
<li>Apache HTTP Server Version 2.2: <a href="http://httpd.apache.org/docs/2.2/misc/security_tips.html">Security Tips</a></li>
<li>Center for Internet Security Benchmarks for<a href="http://www.cisecurity.org/bench_apache.html"> Apache Web Server v2.1</a> by Ryan Barnett</li>
<li><a href="http://www.cgisecurity.com/lib/ryan_barnett_gcux_practical.html">Securing Apache Step by Step</a> by Ryan C. Barnett</li>
<li><a href="http://www.modsecurity.org/documentation/modsecurity-apache/2.5.0/modsecurity2-apache-reference.pdf">ModSecurity Reference Manual</a></li>
<li><a href="http://csrc.nist.gov/publications/nistpubs/800-44-ver2/SP800-44v2.pdf">NIST SP 800-44 v2: Guidelines on Securing Public Web Server</a> by Miles Tracy, Wayne Jansen, Karen Scarfone, and Theodore Winograd</li>
<li><a href="http://csrc.nist.gov/publications/nistpubs/800-95/SP800-95.pdf">NIST SP 800-95: Guide to Secure Web Services</a> by Anoop Singhal, Theodore Winograd, and Karen Scarfone</li>
<li>OWASP <a href="http://www.owasp.org/index.php/Category:OWASP_WeBekci_Project">WeBekci Project</a>, a web based ModSecurity 2.x management tool.</li>
<li><a href="http://remo.netnea.com/">REMO</a>, a project to build a graphical rule editor for ModSecurity with a positive/whitelist approach.</li>
<li><a href="http://www.gotroot.com/tiki-index.php?page=mod_security+rules">Got Root</a>, the Internets largest source of intrusion prevention signatures and comment spam blacklists for webservers, over 13,000 signatures.</li>
</ul>
<p>There are two freely available tools for helping with the security of your Apache configuration:
<ul>
<li><a href="http://www.cisecurity.org/sub_form.html">The CIS Scoring Tool for Apache</a></li>
<li><a href="http://www.apachesecurity.net/download/snapshot/apache_tools-snapshot.tar.gz">Apache httpd Tools</a></li>
</ul>
<p>A coworker was complaining that the majority of information he was finding in blogs was junk.  I asked him how was he finding his information.  He was doing a regular Google search; not even a <a href="http://blogsearch.google.com/">Google Blog Search</a>.  I understood his pain.  <a href="http://www.connectivism.ca/blog/">George Siemens</a> makes a very interesting distinction between collective intelligence and connective intelligence.  <strong><a href="http://en.wikipedia.org/wiki/Collective_intelligence"></a><a href="http://connectivism.ca/blog/2008/02/collective_or_connective_intel.html">Collective intelligence</a></strong> is &#8220;<em>a form of intelligence that emerges from the collaboration and competition of many individuals</em>&#8220;.  George defines <strong>connective intelligence</strong> as &#8220;<em>individual creation of information, ideas, and concepts which are then shared with others, connected, and re-created and extended based on the interaction</em>.&#8221;  </p>
<p>
George goes on to state, &#8220;<em>simply, collective means blending together. Connective means connecting while retaining the original (though others may build on it in their own spaces)</em>.&#8221;  Put another way, &#8220;<em>the collective presents a melting pot of ideas. The connective represents a mosaic of ideas.</em>&#8221;  People are surprised when I tell them that I do not read blogs. I read Ivan Ristic, Jeremiah Grossman, Gunnar Peterson, Ryan Barnett, Dafydd Stuttard, etc.  My coworker&#8217;s problem is that he&#8217;s drowning in the melting pot of information provided by collective intelligence.  When I read an author I like or come across software I find really useful, I look to see if the authors have a blog.  I will then <a href="http://www.google.com/help/reader/tour.html">subscribe</a> to their RSS feed, allowing me to make use of connective intelligence.
</p>
<p>
A few blogs of interest for web application security:
<ul>
<li><a href="http://blog.ivanristic.com/">Ivan Ristic</a>, author of &#8220;Apache Security&#8221; and principal author of <a href="http://www.modsecurity.org/projects/modsecurity/apache/index.html">ModSecurity</a>, the open source web application firewall.</li>
<li><a href="http://jeremiahgrossman.blogspot.com/">Jeremiah Grossman</a>, author of the CIS Scoring Tool for Apache and founder and Chief Technology Officer of WhiteHat Security.</li>
<li><a href="http://www.modsecurity.org/blog/">Ryan Barnett</a>, author of &#8220;<a href="http://www.amazon.com/Preventing-Attacks-Apache-Ryan-Barnett/dp/0321321286">Preventing Web Attacks With Apache</a>&#8220;, and Director of Application Security Training for Breach Security.</li>
<li><a href="http://blog.portswigger.net/">Dafydd &#8220;PortSwigger&#8221; Stuttard</a>, co-authof of &#8220;<a href="http://www.portswigger.net/wahh/">The Web Application Hacker&#8217;s Handbook</a>&#8221; and Principal Security Consultant at NGS Software.</li>
<li><a href="http://1raindrop.typepad.com">Gunnar Peterson</a>, Software Security Architect and CTO at Arctec Group.</li>
<li><a href="http://ha.ckers.org/blog/">Robert &#8220;RSnake&#8221; Hansen</a>, CEO SecTheory.</li>
<li><a href="http://shreeraj.blogspot.com">Shreeraj Shah</a>, founder of <a href="http://www.blueinfy.com/knowledge.html">Blueinfy</a>, a company that provides application security services.</li>
<li><a href="http://www.memestreams.net/users/acidus">Billy Hoffman</a>, co-author of &#8220;<a href="http://www.amazon.com/Ajax-Security-Billy-Hoffman/dp/0321491939">Ajax Security</a>&#8221; and lead research engineer with Atlanta-based SPI Dynamics Inc.</li>
<li><a href="http://blogs.msdn.com/sdl/default.aspx">Bryan Sullivan</a>, co-author of &#8220;<a href="http://www.amazon.com/Ajax-Security-Billy-Hoffman/dp/0321491939">Ajax Security</a>&#8221; and developer and security researcher at SPI Dynamics, Microsoft.</li>
<li><a href="http://shiflett.org/">Chris Shiflett</a>, author and speaker who leads the web application security practice at <a href="http://omniti.com/">OmniTI</a>.</li>
<li><a href="http://blog.watchfire.com/">Ory Segal</a>, Security Products Architect, Rational, Application Security (Watchfire), IBM.</li>
<li><a href="http://myappsecurity.blogspot.com/">Anurag Agarwal</a>, is a senior application security consultant providing expertise on secure development lifecycle and vulnerability assessment. He also manages www.attacklabs.com and www.myappsecurity.com.</li>
</ul>
<p>I wanted to mention that I started off with the names of several web application professionals.  I wanted to include links to their names in this post.  As I searched out their names to add a little background blurb, I kept coming across postings from Anurag Agarwal.  He has done a great job profiling many of the leaders in web application security.   The above list is missing many people and that is entirely my fault.  As I stated, the list is of people that I am familiar with and is not meant to be a complete list of web application security professionals.
</p>
<p>
With these resources at our disposal, we are well positioned to start our quest to secure Apache.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/02/24/securing-apache-references/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

