<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>
<channel>
	<title>G-Loaded Journal &#187; Audit</title>
	<atom:link href="http://www.g-loaded.eu/tag/audit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Mon, 05 Dec 2011 19:55:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>High traffic on the email server</title>
		<link>http://www.g-loaded.eu/2007/06/23/high-traffic-on-the-email-server/</link>
		<comments>http://www.g-loaded.eu/2007/06/23/high-traffic-on-the-email-server/#comments</comments>
		<pubDate>Sat, 23 Jun 2007 16:15:41 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Resolved]]></category>
		<category><![CDATA[Servers]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2007/06/23/high-traffic-on-the-email-server/</guid>
		<description><![CDATA[I don&#8217;t know if 260000+ rejected attempts to relay email through an email server within a week should be considered an attack or just a considerable amount of bad traffic, but for my small server with the limited bandwidth this was an incident that I wouldn&#8217;t like to face on a regular basis. This article [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know if 260000+ rejected attempts to relay email through an email server within a week should be considered an attack or just a considerable amount of bad traffic, but for my small server with the limited bandwidth this was an incident that I wouldn&#8217;t like to face on a regular basis. This article includes some statistical information about that high-traffic week, some info about my actions and a conclusion I made after it ended.<br />
<span id="more-409"></span><br />
First of all, I use <a href="http://www.postfix.org/">postfix</a> as an SMTP server, which is configured to reject requests, if they do not meet several criteria (postfix internal restrictions), prior to sending email data to the spam and virus filters. Until now, I had never encountered high traffic on the email server.</p>
<p>A week ago, there have been many thousands of requests which were constantly rejected by the smtp service. The weird thing was that, even though it was clear (proper error codes) to the bots that the email could not be relayed through the server, they continued to try.</p>
<p>The following graph shows the <strong>number of the rejected requests</strong> during the last week:</p>
<p><a href="http://www.flickr.com/photos/maxshots/581155616/" title="Rejected Requests - week"><img src="http://farm2.static.flickr.com/1199/581155616_a012c37c6b_o.png" width="637" height="220" alt="Rejected Requests - week" /></a></p>
<p>The following graph shows the <strong>inbound/outbound traffic on the router</strong> on a random day during the last week:</p>
<p><a href="http://www.flickr.com/photos/maxshots/581155626/" title="Router Traffic"><img src="http://farm2.static.flickr.com/1106/581155626_f90829640a_o.png" width="597" height="255" alt="Router Traffic" /></a></p>
<p>The following graph shows the <strong>DNS failures</strong> on a random day during the last week:</p>
<p><a href="http://www.flickr.com/photos/maxshots/581155556/" title="DNS failures"><img src="http://farm2.static.flickr.com/1194/581155556_6665b9ee60_o.png" width="597" height="227" alt="DNS failures" /></a></p>
<h4>Actions</h4>
<p>Actually, I decided not to commit any action in order to stop the bots. Despite the continuous rejections, they kept on trying and trying.</p>
<p>I let them go for a week and they gave me 10000+ IPs. These IPs belong to hosts from which those requests were originating. After a week, I added all these IPs in the postfix access table in a way that those hosts were denied access, for example:</p>
<pre class="codesnp">XXX.YYY.ZZZ.CCC REJECT</pre>
<p>Within the following 30 minutes <strong>the number of requests dropped to a minimum!</strong> The following graph confirms that:</p>
<p><a href="http://www.flickr.com/photos/maxshots/582695093/" title="After using access control in postfix"><img src="http://farm2.static.flickr.com/1314/582695093_c25bb4f36a_o.png" width="637" height="220" alt="After using access control in postfix" /></a></p>
<p>This clearly shows that those bots are not designed to consider a rejection due to a HELO/recipient/sender etc restriction as a reason to stop trying, but they only stop when they are denied access. This makes sense in a way, as the &#8220;access denied&#8221; error means that the administrator is aware of what the remote host was trying to do, but, on the other hand, I don&#8217;t quite understand the logic behind keeping on trying despite all the <strong>non</strong>-access-denied rejections.</p>
<p>My conclusion is that <strong>the MTA&#8217;s access control mechanism is by far more important than I had initially thought</strong>. At least, postfix&#8217; access control facility provides all the flexibility one would need.</p>
<p>Anyway, I love logs. The maillogs are being archived and I will have them further analyzed whenever I have the time.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2007/06/23/high-traffic-on-the-email-server/">High traffic on the email server</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2007/12/07/email-notifications-from-a-linux-system/" rel="bookmark">Email Notifications from a Linux System</a></li>
<li><a href="http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/" rel="bookmark">Check Server HTTP Headers with CURL</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/12/free-personal-email-certificates-program-discontinued-by-thawte/" rel="bookmark">Free Personal Email Certificates Program discontinued by Thawte</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/" rel="bookmark">Issues with the feeds are now resolved</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/ssh-with-keys/" rel="bookmark">Setup the SSH server to use keys for authentication</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2007/06/23/high-traffic-on-the-email-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>SELinux audit reports script</title>
		<link>http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/</link>
		<comments>http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/#comments</comments>
		<pubDate>Wed, 20 Dec 2006 09:52:53 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Cron]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SELinux]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/</guid>
		<description><![CDATA[Those who use a SELinux enabled distribution &#8211; more specifically those who have set the SELinux security layer to enforcing mode &#8211; will most probably know about the auditd daemon (part of the audit package in Fedora Core). By default, all SELinux messages are recorded to the syslog, but when auditd is running, then all [...]]]></description>
			<content:encoded><![CDATA[<p>Those who use a SELinux enabled distribution &#8211; more specifically those who have set the SELinux security layer to <strong>enforcing</strong> mode &#8211; will most probably know about the <strong>auditd</strong> daemon (part of the <strong>audit</strong> package in Fedora Core). By default, all SELinux messages are recorded to the syslog, but when auditd is running, then all messages are kept in <code>/var/log/audit/audit.log</code>.<br />
<span id="more-296"></span><br />
The audit package, apart from the audit daemon, includes some very interesting utilities, <strong>aureport</strong> and <strong>ausearch</strong>, which are two great assistants in the procedure of locating the events that need investigation in the endless log files. <code>aureport</code> produces the report it has been asked for and <code>ausearch</code> is used to search the logs for a given event number. Enough said, now on to the script.</p>
<p><code>aureport</code> has a shortcoming. It can only display one report at a time. So, in order to have daily SELinux reports in our inbox aureport needs to be called several times from within a cron job. This is why <strong>aureportgen.py</strong> was written. It can be configured to execute aureport several times collecting the pre-defined reports for a given period of time and then print a concatenation of these reports to the stdout.</p>
<h4>Configuration</h4>
<p>Open the <code>aureportgen.py</code> script in a text editor and scroll down to the configuration section. The available options are:</p>
<p>The path to the aureport executable:</p>
<pre class="codesnp">aureportpath = "/sbin/aureport"</pre>
<p>The list of the reports to collect:</p>
<pre class="codesnp">reports = ["a", "mf", "ms", "lf", "ls"]</pre>
<p>The line above might be a little cryptic so here is the convention on how to specify the report names:</p>
<ol>
<li>Each report name may consist of up to <em>two letters</em>. The <strong>first</strong>, which is mandatory, specifies the report type and the <strong>second</strong>, which is optional, specifies whether a successes or a failures report will be returned.</li>
<li>All the aureport command line switches that specify a report type can be used as the first letter.</li>
<li>Either the letter &#8220;<strong>f</strong>&#8221; or &#8220;<strong>s</strong>&#8221; can be used as the second letter to indicate a success-only or failure-only report.</li>
<li>If the second letter is omitted, then a report that contains both successful and failed events is returned.</li>
</ol>
<p>By using the configuration above, the following reports will be returned:</p>
<ol>
<li>AVC denials (successes or failures not applicable to this report)</li>
<li>Account modification failures</li>
<li>Account modification successes</li>
<li>Login failures</li>
<li>Login successes</li>
</ol>
<h4>Usage</h4>
<p>This script was written in order to be called from within a cron job. It is mandatory to specify the number of days in the past the reports will be generated for. This is done with the <strong>&#8211;days</strong> command line option.</p>
<p>An example daily cron script is listed below:</p>
<pre class="codesnp">
#! /bin/bash
python /path/to/aureportgen.py --days 1 | mail -s "SELinux Reports by aureport" root
exit 0
</pre>
<p>The same as a cronjob would be:</p>
<pre class="codesnp">
0 0 * * *    root    python /path/to/aureportgen.py --days 1 | mail -s "SELinux Reports by aureport" root
</pre>
<p>This will scan the audit logs and the pre-defined reports will be generated for the last 24 hours. The output will be emailed to root.</p>
<p><strong>WARNING</strong>: It should be possible to run this script directly on the CLI and have multiple reports displayed in the standard output, but if the login shell&#8217;s locale is different than the crn job&#8217;s, then there could be a problem. In such cases, you will still be able to run it from the CLI without errors by setting the extra configuration option <code>fix_date</code> to <strong>True</strong>:</p>
<pre class="codesnp">fix_date = True</pre>
<h4>License</h4>
<p>This project is released under the terms of the <a href="http://www.g-loaded.eu/licenses/GPL">GNU General Public License</a>.</p>
<h4>Download</h4>
<p>You can download this script from the following link:<br />
<a href="http://www.g-loaded.eu/packages/aureportgen/aureportgen-0.1.tar.gz">aureportgen-0.1.tar.gz</a></p>
<p>Note that this is an alpha version, it is released without any warranties or support.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/">SELinux audit reports script</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/" rel="bookmark">Script for Apache Error Report</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/30/selinux-setenforce-mode/" rel="bookmark">Using setenforce to switch SELinux mode wisely</a></li>
<li><a href="http://www.g-loaded.eu/2005/12/15/get-my-kernel-headers-script/" rel="bookmark">Get my kernel headers script</a></li>
<li><a href="http://www.g-loaded.eu/2007/12/07/email-notifications-from-a-linux-system/" rel="bookmark">Email Notifications from a Linux System</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Check Server HTTP Headers with CURL</title>
		<link>http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/</link>
		<comments>http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/#comments</comments>
		<pubDate>Fri, 06 Oct 2006 03:17:55 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/</guid>
		<description><![CDATA[As you may have noticed, I&#8217;ve changed my web site&#8217;s domain recently. Therefore, I had to redirect all requests to the new address. This has been done and it works as expected, but how about taking a closer look at the HTTP responses the web server returns to the client if an old URL is [...]]]></description>
			<content:encoded><![CDATA[<p>As you may have noticed, I&#8217;ve changed my web site&#8217;s domain recently. Therefore, I had to redirect all requests to the new address. This has been done and it works as expected, but how about taking a closer look at the HTTP responses the web server returns to the client if an old URL is requested?<br />
<span id="more-286"></span><br />
This is where <a href="http://curl.haxx.se/">CURL</a> comes handy once again. CURL&#8217;s command line options include two very useful switches, <code>-I</code> and <code>-L</code>:</p>
<ul>
<li><strong>-I</strong> : when used, CURL prints only the server response&#8217;s HTTP headers, instead of the page data.</li>
<li><strong>-L</strong> : if the initial web server response indicates that the requested page has moved to a new location (redirect), CURL&#8217;s default behaviour is not to request the page at that new location, but just print the HTTP error message. This switch instructs CURL to make another request asking for the page at the new location whenever the web server returns a 3xx HTTP code.</li>
</ul>
<p>The combination of the above two switches results in having all the server responses&#8217; headers printed to the terminal, until CURL receives a code other than 3xx.</p>
<p>So, here is a real-life example. I have made two major changes to my web site so far; one included a URL structure modification when I moved from a pure HTML web site to WordPress, while the second was a domain change from the free domain <code>raoul.shacknet.nu</code> to the current paid domain name. So, this makes at least two permanent redirections. I say &#8220;at least&#8221;, because other necessary redirections could take place as well, for example, redirections of the <code>example.org</code> version of the domain to the <code>www.example.org</code> version, or redirections required for permalinks.</p>
<p>So, here is CURL&#8217;s output when I requested an old page of my web site:</p>
<pre class="console">$ curl -I -L http://raoul.shacknet.nu/servers/vnc.html</pre>
<pre class="codesnp">
HTTP/1.1 301 Moved Permanently
Date: Fri, 06 Oct 2006 01:49:06 GMT
Server: Apache/2.2.2
Location: http://www.raoul.shacknet.nu/servers/vnc.html
Connection: close
Content-Type: text/html; charset=iso-8859-1
HTTP/1.1 301 Moved Permanently
Date: Fri, 06 Oct 2006 01:49:06 GMT
Server: Apache/2.2.2
Location: http://www.g-loaded.eu/servers/vnc.html
Connection: close
Content-Type: text/html; charset=iso-8859-1
HTTP/1.1 301 Moved Permanently
Date: Fri, 06 Oct 2006 01:49:06 GMT
Server: Apache/2.2.2
Location: http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/
Connection: close
Content-Type: text/html; charset=iso-8859-1
HTTP/1.1 200 OK
Date: Fri, 06 Oct 2006 01:49:06 GMT
Server: Apache/2.2.2
X-Powered-By: PHP/5.1.4
X-Pingback: http://www.g-loaded.eu/xmlrpc.php
Status: 200 OK
Connection: close
Content-Type: text/html; charset=UTF-8
</pre>
<p>The above output shows that the client has to send 4 HTTP requests and receive 4 respective responses from the server in order to reach that old page&#8217;s final location:</p>
<ol>
<li>The first server response informs the client that the page has been permanently moved to the www version of the old domain.</li>
<li>The second response indicates that the page has been permanently moved to the www version of the new domain using the old URL structure.</li>
<li>The third indicates a permanent move to the new URL structure.</li>
<li>The final response informs the client with a 200 OK code that it has reached the page&#8217;s <a href="http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/">final location</a>.</li>
</ol>
<p>In this example, CURL provides a clear view of what situation a browser, a search engine bot or any other HTTP client encounters when it tries to reach an old page.</p>
<p>I am not an expert, but I guess that too many redirects are not a good thing, not only by considering the small increase of the server load, but also that search engine bots might not like them very much. On the other hand, redirections are a necessary evil if you want links from other websites pointing to your old domain or your old URL structure to continue to be valid, which in fact adds &#8220;value&#8221; to your website, as search engine experts would say. So it&#8217;s a matter of choice.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/">Check Server HTTP Headers with CURL</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2005/10/13/http-headers/" rel="bookmark">HTTP headers</a></li>
<li><a href="http://www.g-loaded.eu/2006/04/07/http-status-codes/" rel="bookmark">HTTP Status Codes</a></li>
<li><a href="http://www.g-loaded.eu/2005/10/19/the-if-modified-since-http-header/" rel="bookmark">The If-Modified-Since HTTP Header</a></li>
<li><a href="http://www.g-loaded.eu/2007/09/15/use-wget-or-curl-to-download-from-rapidshare-premium/" rel="bookmark">Use wget or curl to download from RapidShare Premium</a></li>
<li><a href="http://www.g-loaded.eu/2008/12/02/set-up-an-anonymous-ftp-server-with-vsftpd-in-less-than-a-minute/" rel="bookmark">Set up an anonymous FTP server with vsftpd in less than a minute</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>How to integrate seaudit-report in logwatch</title>
		<link>http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/</link>
		<comments>http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/#comments</comments>
		<pubDate>Mon, 25 Sep 2006 18:01:57 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Logwatch]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Tips]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/</guid>
		<description><![CDATA[Today, I revised my logwatch configuration and I decided to use an external parser for the SELinux audits. Logwatch includes such a parser (/usr/share/logwatch/scripts/services/audit script), but i tend to prefer seaudit-report, part of the setools-gui package in Fedora. Don&#8217;t let the package name confuse you, seaudit-report is a CLI tool. There are two ways that [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I revised my <a href="http://www.logwatch.org/">logwatch</a> configuration and I decided to use an external parser for the SELinux audits. Logwatch includes such a parser (<code>/usr/share/logwatch/scripts/services/audit</code> script), but i tend to prefer <code>seaudit-report</code>, part of the <code>setools-gui</code> package in Fedora. Don&#8217;t let the package name confuse you, <code>seaudit-report</code> is a CLI tool.<br />
<span id="more-261"></span><br />
There are two ways that this integration can be achieved:</p>
<ol>
<li>completely override the default audit script by placing one with the same name in <code>/etc/logwatch/scripts/services/</code></li>
<li>create a new custom service for <code>seaudit-report</code></li>
</ol>
<p>I decided to follow the second way. The <a href="http://oss.tresys.com/projects/setools">setools</a> source package contains the necessary files for logwatch, but they needed some customization to reflect my setup. I use the <code>auditd</code> service to collect SELinux related messages, which are saved in <code>/var/log/audit/audit.log</code>.</p>
<p>The file that contains information about which log files should logwatch analyze is named <strong>seaudit-report-group.conf</strong> and needs to be put in the <code>/etc/logwatch/conf/logfiles/</code> directory. As I mentioned previously, the logged audits are written in <code>/var/log/audit/audit.log</code>, but <code>/var/log/messages</code> still keeps some info about SELinux, eg policy reloads etc. So, the logwatch log-group configuration file should contain the following lines:</p>
<pre class="codesnp">
LogFile = audit/audit.log
Archive = audit/audit.log.*.gz
LogFile = messages
Archive = messages.*.gz
</pre>
<p>The logwatch service configuration file, <strong>seaudit-report-service.conf</strong>, should be put in <code>/etc/logwatch/conf/services/</code> and should contain the following:</p>
<pre class="codesnp">
Title = "SELinux Audit"
LogFile = seaudit-report-group
</pre>
<p>The <code>seaudit-report</code> utility, by default, does not accept input from stdin, so a wrapper script must be used in order to launch this utility with the proper options. The setools source package contains such a script, <strong>seaudit-report-service</strong>, which should be put in the <code>/etc/logwatch/scripts/services/</code> directory. The following code is the same as the original script, apart from the line that sets <code>seaudit-report</code>&#8216;s location. In some systems this utility is located in <code>/usr/bin/</code> and in others, like mine, in <code>/usr/sbin/</code> etc:</p>
<pre class="codesnp">
#!/bin/sh
SEAUDITREPORT=$(which seaudit-report)
OPTS="--stdin --malformed"
echo "Date Range: $LOGWATCH_DATE_RANGE"
echo "Detail Level: $LOGWATCH_DETAIL_LEVEL"
echo "Temp Dir: $LOGWATCH_TEMP_DIR"
echo "Debug Level: $LOGWATCH_DEBUG"
${SEAUDITREPORT} ${OPTS}
if [ $? -ne 0 ]; then
    RC=$?
    echo >&#038;2 "Failed while executing seaudit-report.\n"
    exit $RC
fi
exit 0
</pre>
<p>It is also needed to set the executable bit on this script:</p>
<pre class="console"># chmod u+x /etc/logwatch/scripts/services/seaudit-report-service</pre>
<p>By issuing the following command, the SELinux report should be printed to stdout:</p>
<pre class="console"># logwatch --service seaudit-report-service --range all --print</pre>
<p>Finally, it is possible to disable logwatch&#8217;s default SELinux analysis service (<code>audit</code>) by adding the following line in <code>/etc/logwatch/conf/logwatch.conf</code>:</p>
<pre class="codesnp">
Service = "-audit"
</pre>
<p>From now on, the logwatch report should contain, among others, only the report produced by <code>seaudit-report</code>.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/">How to integrate seaudit-report in logwatch</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/09/25/logwatch-and-dovecot-1x-series-in-fc5/" rel="bookmark">Logwatch and Dovecot 1.x series in FC5</a></li>
<li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/" rel="bookmark">Script for Apache Error Report</a></li>
<li><a href="http://www.g-loaded.eu/2005/10/14/a-real-time-log-viewer/" rel="bookmark">A real-time log viewer</a></li>
<li><a href="http://www.g-loaded.eu/2007/12/07/email-notifications-from-a-linux-system/" rel="bookmark">Email Notifications from a Linux System</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Logwatch and Dovecot 1.x series in FC5</title>
		<link>http://www.g-loaded.eu/2006/09/25/logwatch-and-dovecot-1x-series-in-fc5/</link>
		<comments>http://www.g-loaded.eu/2006/09/25/logwatch-and-dovecot-1x-series-in-fc5/#comments</comments>
		<pubDate>Mon, 25 Sep 2006 10:37:56 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Logwatch]]></category>
		<category><![CDATA[Resolved]]></category>
		<category><![CDATA[Tips]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2006/09/25/logwatch-and-dovecot-1x-series-in-fc5/</guid>
		<description><![CDATA[Logwatch is the preferred tool in order to get summaries of the various service logs in Fedora Core 5. It needs very little customization, which mainly summarizes in overriding some of the log file locations. The only issue I have encountered so far is that it cannot parse the Dovecot log entries correctly. This happens [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.logwatch.org/">Logwatch</a> is the preferred tool in order to get summaries of the various service logs in Fedora Core 5. It needs very little customization, which mainly summarizes in overriding some of the log file locations. The only issue I have encountered so far is that it cannot parse the <a href="http://www.dovecot.org/">Dovecot</a> log entries correctly.<br />
<span id="more-260"></span><br />
This happens because of two reasons:</p>
<ol>
<li>Fedora 5 includes dovecot v1.x, which has some differences in its log output format compared to older versions,</li>
<li>the stock logwatch package in Fedora contains a dovecot log parser that supports dovecot up to the 0.99.x version.</li>
</ol>
<p>This issue&#8217;s resolution is rather simple.</p>
<p>First of all, get the updated dovecot log parser from the <a href="http://www2.cvs.logwatch.org:8080/index.cgi/logwatch/scripts/services/dovecot">logwatch CVS repository</a>. I used the latest revision, 1.4 at the moment of writing. Create a <code>services/</code> directory inside the <code>/etc/logwatch/scripts/</code> directory, put the updated parser in there and set its executable bit:</p>
<pre class="console"># chmod u+x /etc/logwatch/scripts/services/dovecot</pre>
<p>This script will be the one to parse the Dovcecot log file instead of the default one.</p>
<p>Next, it is required to override a setting in the dovecot service&#8217;s configuration file. So, create a text file, named <code>dovecot.conf</code>, in <code>/etc/logwatch/conf/services/</code> and write the following line:</p>
<pre class="codesnp">*OnlyService = (imap-login|pop3-login|dovecot)</pre>
<p>Now, test if it works:</p>
<pre class="console"># logwatch --service dovecot --range yesterday --detail 10 --print</pre>
<p>This will print the dovecot report to stdout.</p>
<p>There are some things that you should take a note of. The logwatch Dovecot report will work only if dovecot is configured to record its log entries to the system log (syslog), which in turn moves these entries to <code>/var/log/maillog</code>. If you have configured Dovecot to record its log entries to a separate file, other than syslog, then it is very unlikely that the whole thing will work for any Dovecot version. This is because of the different way log entries are written to the separate log.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2006/09/25/logwatch-and-dovecot-1x-series-in-fc5/">Logwatch and Dovecot 1.x series in FC5</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li>
<li><a href="http://www.g-loaded.eu/2005/10/30/creative-pc-cam-750/" rel="bookmark">Creative PC-CAM Series webcams in linux</a></li>
<li><a href="http://www.g-loaded.eu/2005/10/14/a-real-time-log-viewer/" rel="bookmark">A real-time log viewer</a></li>
<li><a href="http://www.g-loaded.eu/2005/10/30/fedora-sound-recording-problems-solved/" rel="bookmark">Fedora sound recording problems&#8230; solved</a></li>
<li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2006/09/25/logwatch-and-dovecot-1x-series-in-fc5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>ModSecurity Overview</title>
		<link>http://www.g-loaded.eu/2006/08/24/modsecurity-overview/</link>
		<comments>http://www.g-loaded.eu/2006/08/24/modsecurity-overview/#comments</comments>
		<pubDate>Wed, 23 Aug 2006 22:22:11 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[mod_security]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Web]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2006/08/24/modsecurity-overview/</guid>
		<description><![CDATA[<a href="http://www.modsecurity.org/">ModSecurity</a> is an <a href="http://httpd.apache.org/">Apache</a> module which adds an extra layer of security by analyzing client requests before they are processed by Apache and, furthermore, by analyzing server responses after a request has been processed. This article intends to be a <em>ModSecurity</em> overview and to provide the reader with the basic knowledge about the most important directives. For detailed information refer to the <a href="http://www.modsecurity.org/documentation/">ModSecurity Documentation</a>.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.modsecurity.org/">ModSecurity</a> is an <a href="http://httpd.apache.org/">Apache</a> module which adds an extra layer of security by analyzing client requests before they are processed by Apache and, furthermore, by analyzing server responses after a request has been processed. This article intends to be a <em>ModSecurity</em> overview and to provide the reader with the basic knowledge about the most important directives. For detailed information refer to the <a href="http://www.modsecurity.org/documentation/">ModSecurity Documentation</a>.<br />
<span id="more-246"></span><br />
<a id="How_ModSecurity_Works"></a></p>
<h4> How ModSecurity Works </h4>
<p>A definition of <b>ModSecurity</b>, as it appears in the <a href="http://www.modsecurity.org/" class="external text" title="http://www.modsecurity.org/" rel="nofollow">official website</a>, would be:</p>
<blockquote><p><b>ModSecurity</b>(TM) is an open source intrusion detection and prevention engine for web applications. It can also be called a web application firewall. It operates embedded into the web server, acting as a powerful umbrella, shielding applications from attacks.</p></blockquote>
<p>The analysis of the client request and the server response is performed in stages:</p>
<ol>
<li> In the first stage, the request&#8217;s format is analyzed by a series of built-in checks (<i>implicit validations</i>). These checks can be controlled using configuration directives.</li>
<li> In the second stage, the request goes through a series of user-defined <b>input-filters</b>. Whenever there is a match, a list of user-defined actions is performed.</li>
<li> The request is processed by Apache.</li>
<li> If <i>output filtering</i> is enabled, then the output goes through a series of user-defined <b>output-filters</b>. If there is a match, then the specified actions are performed.</li>
</ol>
<p><a id="Installation_2"></a></p>
<h4> Installation </h4>
<p>Install the <code>mod_security</code> Apache module as you install every other package. On Fedora, for example, you can use <code>yum</code>:</p>
<pre class="codesnp"># yum install mod_security</pre>
<p><a id="Basic_Configuration"></a></p>
<h4> Basic Configuration </h4>
<p>Ususally, there is a separate configuration file for each Apache module, which is imported into the main Apache configuration. On Fedora, <i>ModSecurity&#8217;</i>s configuration file exists in <code>/etc/httpd/conf.d/mod_security.conf</code>.<br />
The basic configuration would be:</p>
<pre class="codesnp">
&lt;IfModule mod_security.c&gt;
    SecFilterEngine On
    SecAuditEngine RelevantOnly
    SecAuditLog logs/audit_log
    # Default action list
    SecFilterDefaultAction &quot;deny,log,status:406&quot;
    # Implicit validations
    SecFilterCheckURLEncoding On
    SecFilterCheckUnicodeEncoding On
    SecFilterForceByteRange 1 255
    SecFilterNormalizeCookies On
    #SecFilterCookieFormat 1
    # POST Payload scanning
    SecFilterScanPOST On
    # Output Filtering
    #SecFilterScanOutput On
    #SecFilterOutputMimeTypes &quot;(null) text/html text/plain&quot;
&lt;/IfModule&gt;
</pre>
<p>All the directives that are used in the above block of code are called &#8220;<strong>Configuration Directives</strong>&#8221; in ModSecurity terminology. Below, there is some brief explanation for each one of them:</p>
<ul>
<li> <em>General configuration directives</em>: ModSecurity&#8217;s operation involves two engines that work independently, the <strong>filter</strong> engine and the <strong>audit</strong> engine. Both engines can be turned <b>On</b> or <b>Off</b>.
<dl>
<dt> SecFilterEngine&nbsp;</dt>
<dd> Turn the filtering engine <b>On</b> or <b>Off</b>.</dd>
<dt> SecAuditEngine&nbsp;</dt>
<dd> Turn the audit engine <b>On</b> or <b>Off</b>. This can be done on a <i>per-server</i> (<code>virtualhost</code> context in the Apache configuration) or on a <i>per-directory</i> basis (<code>directory</code> or <code>.htaccess</code> context in the Apache configuration). If this directive is set explicitly to <b>On</b>, all requests will be logged. If it is set to <b>RelevantOnly</b>, only those requests that were matched by a filter are logged. This is the recommended setting.</dd>
<dt> SecAuditLog&nbsp;</dt>
<dd> The path to the <i>audit</i> log file.</dd>
</dl>
</li>
</ul>
<ul>
<li> Everytime a filter matches a request, an action is performed. These actions can be defined on a <i>per-rule</i> basis, but also a general default action can be specified.
<dl>
<dt> SecFilterDefaultAction&nbsp;</dt>
<dd> This directive sets the default action to be performed when a filter catches a request. The general syntax of actions is used, but some actions cannot be set in this directive (see ModSecurity Documentation). For example, the default action above will configure the engine to log each rule match and reject the request with status code 406.</dd>
</dl>
</li>
</ul>
<ul>
<li> General request validations (URL encoding, Unicode encoding, cookie format, byte range checks) can be performed by some configuration directives. These are built-in checks and are called <b>implicit validations</b> in ModSecurity terminology. Note, that in case you want to run ModSecurity in <em>detect-only</em> mode without rejecting any requests, for example by setting all the <em>per-filter</em> primary actions to <code>pass</code>, it is also required to set the default action to one that will not reject the request (eg <code>pass</code>), so that, even if the request fails to pass through these validations, the request analysis can continue on to the checks defined by the filters. An alternative for <em>detect-only</em> operation would be to explicitly turn off these built-in validations. For normal operation though, it is highly recommended that these validations are turned on:
<dl>
<dt> SecFilterCheckURLEncoding&nbsp;</dt>
<dd> Make sure that URL encoding is valid (<b>On</b>|<b>Off</b>).</dd>
<dt> SecFilterCheckUnicodeEncoding&nbsp;</dt>
<dd> Make sure that Unicode encoding is valid (<b>On</b>|<b>Off</b>).</dd>
<dt> SecFilterForceByteRange&nbsp;</dt>
<dd> Performs byte range checks. Only bytes that are in the specified range will be allowed in the request. Usually, the 1-255 range is accepted, but if you need to make it even more strict, you can set it to allow only bytes in the 32-126 range, for example: <code>SecFilterForceByteRange 32 126</code></dd>
<dt> SecFilterNormalizeCookies&nbsp;</dt>
<dd> By default, ModSecurity will not try to normalize cookie names and values. Some web applications encode the cookie content, but that can be normalized by setting this directive to <b>On</b>. The directive <b>SecFilterCheckCookieFormat</b> is completely deprecated in <code>v1.9.x</code> and has no effect.</dd>
<dt> SecFilterCookieFormat&nbsp;</dt>
<dd> By default, ModSecurity supports normalization on cookies that are in Netscape format. It can be configured though to support <i>version 1</i> cookies (as defined in <a href="http://rfc.net/rfc2965.html" class="external text" title="http://rfc.net/rfc2965.html" rel="nofollow">RFC-2965</a>). To enable <i>version 1</i> cookie support set this directive to <b>1</b>.</dd>
</dl>
</li>
</ul>
<ul>
<li> By default, <i>ModSecurity</i> can scan only <code>GET</code> variables. Scanning <code>POST</code> variables (<i>POST Payload</i>) is disabled by default.
<dl>
<dt> SecFilterScanPOST&nbsp;</dt>
<dd> By setting this directive to <b>On</b> the <i>post payload</i> can also be scanned.</dd>
</dl>
</li>
</ul>
<ul>
<li> By default, <i>ModSecurity</i> does not perform <i>output filtering</i>.
<dl>
<dt> SecFilterScanOutput&nbsp;</dt>
<dd> Set this configuration directive to <b>On</b> in order to enable <i>output filtering</i> (only Apache 2.x). Note that, when output filtering is enabled, only responses that have no content type, or whose content type is <code>text/plan</code> or <code>text/html</code> will be scanned. This behaviour can be modified with the <b>SecFilterOutputMimeTypes</b> directive.</dd>
<dt> SecFilterOutputMimeTypes&nbsp;</dt>
<dd> Set which content types will be scanned in <i>output filtering</i>.</dd>
</dl>
</li>
</ul>
<p><a id="Specifying_Actions"></a></p>
<h4> Specifying Actions </h4>
<p>Whenever a filter catches a request, then an action, or better, a <i>list of actions</i> is performed. The general syntax for action lists is (no spaces are allowed between actions):</p>
<pre class="codesnp">"primary_action,secondary_actions,flow_action or parameter:value action"</pre>
<p>For example:</p>
<pre class="codesnp">SecFilterDefaultAction "deny,log,status:406"
</pre>
<p>Action lists can be defined in three places:</p>
<ol>
<li> <b>SecFilterDefaultAction</b> directive: Whenever a user-defined rule, which follows this directive, is matched, then these <i>default actions</i> are performed, unless they are overridden by a <i>per-ruleset</i> or <i>per-rule</i> action list (see below).</li>
<li> <b>SecFilterSignatureAction</b> directive: This directive may appear several times in the configuration and is used in order to specify a <i>per-ruleset action list</i>. A <i>ruleset</i> consists of all the rules that immediately follow the <b>SecFilterSignatureAction</b> directive. Action lists that are defined in this directive are merged with the <i>default action list</i>. Note that this merging procedure may result in action overriding. It depends on the type of the actions used. See the documentation for more information on this. Also, note that <i><b>this action list will not be inherited by child contexts</b></i>.</li>
<li> <b>SecFilter</b> and <b>SecFilterSelective</b> directives: These directives accept an optional action list to be performed whenever the rule is matched. These are <i>per-rule actions</i>. Actions defined in these directives are merged with the actions that are defined in the other two directives above. Note that this merging procedure may result in action overriding. It depends on the type of the actions used. See the documentation for more information on this.</li>
</ol>
<p>Another action-related directive is <b>SecFilterActionsRestricted</b>. When it is set to <b>On</b>, all the <i>per-rule actions</i>, except for the metadata actions (id, msg, rev, severity), are ignored. This is particularly useful when importing 3rd party rules, which also contain <em>per-rule</em> action lists, but you want to define your own action-list to be performed when any of these rules is matched.</p>
<p>In short, the <i>most commonly used actions</i> and what they actually do on a filter match are outlined below:</p>
<dl>
<dt> pass</dt>
<dd> Do nothing and continue on with the next rule. Useful when running <i>ModSecurity</i> in <i>detect-mode</i>.</dd>
<dt> allow</dt>
<dd> Allow the request, but <b>do not</b> continue the request or server-response analysis.</dd>
<dt> deny</dt>
<dd> Deny the request and return the error document which corresponds to the defined status code (see below).</dd>
<dt> log</dt>
<dd> Log to the Apache error log and to the adit log if the audit engine is enabled.</dd>
<dt> nolog</dt>
<dd> Log nothing to the Apache error log or to the audit log.</dd>
<dt> status</dt>
<dd>(<code>status:CODE</code>): Specifies the HTTP error code that will be returned if the request is rejected.</dd>
<dt> redirect</dt>
<dd>(<code>redirect:URL</code>): Redirect to specified page. <i>Always overrides</i> the <b>status</b> and <b>deny</b> actions.</dd>
<dt> exec</dt>
<dd>(<code>exec:/path/to/script</code>): Execute the specified script. This action is always performed in addition to the primary action (if one is defined). The script <b>must</b> write its output to <code>stdout</code>.</dd>
</dl>
<p>Also, a <b>flow action</b>, which affects the order in which the rules are processed, may be defined:</p>
<dl>
<dt> skipnext</dt>
<dd>(<code>skipnext:N</code>): Skips next <b>N</b> rules on filter match.</dd>
<dt> chain</dt>
<dd> Combine two or more filters together. The last filter is the one that will affect the request, but in order to reach the last filter, all previous chained filters must be matched.</dd>
</dl>
<p>One of the most useful features of <i>ModSecurity</i> is that <b>metadata</b> (<i>rule id</i>, <i>revision number</i>, <i>a text message</i>, <i>severity information</i>) may be defined for each filter. This metadata is defined as <code>parameter:value</code>, where action can be one of <b>id</b>, <b>rev</b>, <b>msg</b>, <b>severity</b>. For example:</p>
<pre class="codesnp">SecFilter ".*admin.*" id:3,severity:1</pre>
<p>Finally, a filter or a chain of filters can be explicitly marked for inheritance in child contexts with the <b>mandatory</b> action. For example:</p>
<pre class="codesnp">SecFilter ".*admin.*" mandatory</pre>
<p>or</p>
<pre class="codesnp">
SecFilter ".*admin.*" mandatory,chain
SecFilter ".*login.*"
</pre>
<p>For more information refer to the <i>ModSecurity</i> documentation.</p>
<p><a id="Specifying_Filters"></a></p>
<h4> Specifying Filters </h4>
<p><i>Modsecurity</i> supports writing filters in the ways outlined below. For further information refer to the documentation.</p>
<ul>
<li> Simple Input Filter Syntax:</li>
</ul>
<pre class="codesnp">SecFilter KEYWORD [ACTIONS]
SecFilter&nbsp;!KEYWORD [ACTIONS]
</pre>
<ul>
<li> Advanced Input Filter Syntax:</li>
</ul>
<pre class="codesnp">SecFilterSelective LOCATION KEYWORD [ACTIONS]
SecFilterSelective LOCATION&nbsp;!KEYWORD [ACTIONS]
</pre>
<ul>
<li> Advanced Output Filter Syntax:</li>
</ul>
<pre class="codesnp">SecFilterSelective OUTPUT KEYWORD [ACTIONS]
SecFilterSelective OUTPUT&nbsp;!KEYWORD [ACTIONS]
</pre>
<dl>
<dt> KEYWORD&nbsp;</dt>
<dd> is a regular expression.</dd>
<dt>&nbsp;!&nbsp;</dt>
<dd> means that the regular expression is inverted, like the <b>NOT</b> logical operator.</dd>
<dt> LOCATION&nbsp;</dt>
<dd> is a <em>location identifiers</em> or a list of <em>location identifiers</em> separated with the pipe <b>|</b> symbol. The <em>location identifiers</em> might be for example, the remote party&#8217;s IP (<code>REMOTE_ADDR</code>) or hostname (<code>REMOTE_HOST</code>) etc. For a detailed list of all the possible location identifiers refer to the &#8220;<em>Advanced Filtering</em>&#8221; section of the <i>ModSecurity</i> documentation.</dd>
<dt> OUTPUT&nbsp;</dt>
<dd> indicates that the request will first be processed by Apache and the output will be checked against this filter. Requires that the directive <b>SecFilterScanOutput</b> has been set to <b>On</b>.</dd>
</dl>
<p>A special usage of advanced filtering is when the <b>ARGS</b> and the <b>ARGS_someformfield</b> are used. In this case, <b>ARGS_someformfield</b> supports inverted usage, so that all form fields are checked, except for the field that is defined in the <b>ARGS_someformfield</b> statement. For example:</p>
<pre class="codesnp">SecFilterSelective "ARGS|!ARG_firstname" "Jack"</pre>
<p>This one checks if any of the form fields, except for field &#8220;<em>firstname</em>&#8220;, is set to &#8220;Jack&#8221;.</p>
<p><a id="Filter_Inheritance"></a></p>
<h4> Filter Inheritance </h4>
<p>The filter inheritance scheme in ModSecurity follows the rules outlined below.</p>
<ul>
<li>By default, all filters, together with their <em>per-rule</em> action lists, are inherited by child contexts.</li>
<li>The <em>default</em> action list is also inherited by child contexts.</li>
<li>Action lists, defined in the <strong>SecFilterSignatureAction</strong> directive (<em>per-ruleset</em> actions), are never inherited by child contexts.</li>
</ul>
<p>It is possible to customize this scheme by using one or more of the directives <strong>SecFilterInheritance</strong>, <strong>SecFilterInheritanceMandatory</strong>, <strong>SecFilterImport</strong>, <strong>SecFilterRemove</strong> or by setting the <em>per-rule</em> action &#8220;<strong>mandatory</strong>&#8221; on a specific filter or filter chain.</p>
<p>Here are some notes about these directives:</p>
<p><strong>SecFilterInheritance</strong><br />
Controls the inheritance of rules from the parent context. By default, its value is <strong>On</strong>. By setting it to <strong>Off</strong> in a context, eg virtualhost, none of the filters defined in parent contexts is inherited. This directive needs to be explicitly set in every context in which you do not want to inherit any rules. For example:</p>
<pre class="codesnp">
&lt;Directory /path/to/some/dir&gt;
    SecFilterInheritance Off
&lt;/Directory&gt;
</pre>
<p><strong>SecFilterImport</strong><br />
This directive works in conjuction with <strong>SecFilterInheritance</strong> and has a meaning only if the latter has been set to <strong>Off</strong> in a particular context. It accepts a space-delimited list of rule IDs and can be used to explicitly import filters from parent contexts. For example:</p>
<pre class="codesnp">
&lt;Directory /path/to/some/dir&gt;
    SecFilterInheritance Off
    SecFilterImport 1001 1002 1003
&lt;/Directory&gt;
</pre>
<p><strong>SecFilterRemove</strong><br />
This directive is the exact opposite of <strong>SecFilterImport</strong>. It has a meaning only if <strong>SecFilterInheritance</strong> has not been disabled in a particular context and works only for filters that have not been marked for mandatory inheritance (see below). It accepts a space-delimited list of rule IDs and can be used to explicitly disable inherited filters. For example:</p>
<pre class="codesnp">
&lt;Directory /path/to/some/dir&gt;
    SecFilterRemove 10 11 12
&lt;/Directory&gt;
</pre>
<p><strong>SecFilterInheritanceMandatory</strong><br />
Controls the inheritance of rules for the child contexts. By default, its value is <strong>Off</strong>. By setting it to <strong>On</strong> in a context, eg virtualhost, all of the filters defined in this particular context will be inherited by force by child contexts, despite the fact that filter inheritance might be disabled in those child contexts. This directive needs to be explicitly set in every context whose filters need to be always in-effect in subcontexts. For example:</p>
<pre class="codesnp">
&lt;Virtualhost 192.168.0.1:80&gt;
	SecFilterInheritanceMandatory On
	SecFilter ".*admin.*" "id:10"
	&lt;Directory /path/to/some/dir/in/this/vhost&gt;
		SecFilterRemove 10
	&lt;/Directory&gt;
&lt;/Virtualhost&gt;
</pre>
<p>In the above example, the filter with ID 10 will still be in effect in the directory context, because all rules have been marked for mandatory inheritance in its parent context.</p>
<p>Some times, it is needed to mark only specific rules for mandatory inheritance and not all of the current context&#8217;s rules. This can be achieved by using the <strong>mandatory</strong> action in a <em>per-rule</em> action list. For example:</p>
<pre class="codesnp">
&lt;Virtualhost 192.168.0.1:80&gt;
	SecFilter ".*admin.*" "id:10,mandatory"
&lt;/Virtualhost&gt;
</pre>
<p>The rule with ID 10 will always be inherited by child contexts.</p>
<p>It is recommended that some critical filters are marked for mandatory inheritance, especially in environments where there is no trust between the users.</p>
<p><a id="Per-Virtualhost_ModSecurity_Logging"></a></p>
<h4> Per-Virtualhost ModSecurity Logging </h4>
<p>It is possible to use Apache&#8217;s custom logging feature in order to log requests, which matched a <i>ModSecurity</i> filter, on a <em>per-virtualhost</em> basis. The key for this to work is the fact that <i>ModSecurity</i> defines the environment variable <b>mod_security-relevant</b> whenever a rule is matched.</p>
<p>So, by adding the following statement in the virtualhost context, Apache will record information about ModSecurity&#8217;s activity for the specific virtualhost. This statement is taken from the official documentation:</p>
<pre class="codesnp">&lt;IfModule mod_security.c&gt;
    CustomLog /path/to/logs/modsec_custom_log \
        "%h %l %u %t \"%r\" %&gt;s %b %{mod_security-message}i" \
        env=mod_security-relevant
&lt;/IfModule&gt;
</pre>
<p><a id="Recommended_Filters"></a></p>
<h4> Recommended Filters </h4>
<p><strong>Accepted Encoding Types</strong><br />
As it is stated in the docs, <i>ModSecurity</i> supports two encoding types for the request body:</p>
<ol>
<li> <code>application/x-www-form-urlencoded</code> &#8211; used to transfer form data</li>
<li> <code>multipart/form-data</code> – used for file transfers</li>
</ol>
<dl>
<dd>In order to be sure that the web server will only accept requests with these two encoding types, a <i>selective filter</i> can be added. Note that <b>GET</b> requests are excluded from this rule because some (automated) clients supply &#8220;<code>text/html</code>&#8221; as <code>Content-Type</code>. Also, keep in mind that some web applications make use of the XMLRPC libraries in order to perform inter-application communication (communication between different web sites), send pingbacks/trackbacks for example. In this case, these features will not work, unless the <code>text/xml</code> encoding is accepted by ModSecurity.</dd>
</dl>
<pre class="codesnp"># Accepted encoding types for request
SecFilterSelective REQUEST_METHOD "!^GET$" chain
SecFilterSelective HTTP_Content-Type "!(^$|^application/x-www-form-urlencoded|^multipart/form-data|^text/xml)"
</pre>
<p><strong>Chunked Transfer Encoding</strong><br />
Reject requests whose body is delivered in chunks. This will not affect the server&#8217;s ability to send responses using the chunked transfer encoding (<i>Rule taken from the ModSecurity Documentation</i>):</p>
<pre class="codesnp"># Reject Requests With Chunked Transfer Encoding
SecFilterSelective HTTP_Transfer-Encoding "!^$"
</pre>
<p><strong>Missing User-Agent or Host Headers</strong><br />
Reject requests on which the <code>User-Agent</code> or <code>Host</code> headers are empty. This will only reject poorly made bots that do not define a user-agent string. Note that bots can easily use a fake user-agent string so to pretend that are common internet browsers. Nothing can be done to prevent this ability.</p>
<pre class="codesnp"># Require HTTP_USER_AGENT and HTTP_HOST headers
SecFilterSelective "HTTP_USER_AGENT|HTTP_HOST" "^$"
</pre>
<p><strong>Missing Content-Length Header</strong><br />
Reject POST requests that do not provide the <code>Content-Length</code> header (<i>Rule taken from the default</i> <code>mod_security.conf</code> <i>supplied on Fedora</i>):</p>
<pre class="codesnp"># Require Content-Length to be provided with every POST request
SecFilterSelective REQUEST_METHOD "^POST$" chain
SecFilterSelective HTTP_Content-Length "^$"
</pre>
<p><strong>Path Traversal Attacks</strong><br />
Reject requests which attempt to confuse the web server and make it traverse system paths and possibly execute shell commands. Note that this general filter might break the normal operation of web applications which use shell commands:</p>
<pre class="codesnp"># Reject Path Traversal attacks
SecFilter "\.\./"
</pre>
<p><strong>Cross-Site-Scripting Attacks (weak rule)</strong><br />
This filter rejects Cross-Site-Scripting Attacks (XSS) by preventing the usage of javascript statements (Javascript injection). This rule is safe to use, unless your application uses javascript in GET/POST request variables, which is very unlikely. (<i>Rule taken from the default</i> <code>mod_security.conf</code> <i>supplied on Fedora</i>):</p>
<pre class="codesnp"># Weak rule to reject Cross-Site-Scripting Attacks (XSS) using javascript
SecFilter "&lt;( |\n)*script"
</pre>
<p><strong>Cross-Site-Scripting Attacks (stronger rule)</strong><br />
This filter rejects XSS Attacks by preventing HTML and Javascript injection attempts. This filter is a lot more general and stronger than the above and its usage is not recommended for most content management and web-forum systems, as there is a high possibility that it wll break their normal operation. (<i>Rule taken from the default</i> <code>mod_security.conf</code> <i>supplied on Fedora</i>):</p>
<pre class="codesnp"># Stronger rule to reject XSS Attacks (HTML/Javascript)
SecFilter "&lt;(.|
)+&gt;"
</pre>
<p><a id="ModSecurity_Resources"></a></p>
<h4> ModSecurity Resources </h4>
<p>There are many web sites that offer ready <em>ModSecurity</em> rulesets for various web applications. In the following links you can find some very useful <strong>general</strong> rulesets, but keep in mind that they need a bit of customization in order to work with your web application.</p>
<p>Some rule resources:</p>
<ul>
<li> <a href="http://www.modsecurity.org/projects/rules/index.html" class="external free" title="http://www.modsecurity.org/projects/rules/index.html" rel="nofollow">http://www.modsecurity.org/projects/rules/index.html</a></li>
<li> <a href="http://www.gotroot.com/tiki-index.php?page=mod_security+rules" class="external free" title="http://www.gotroot.com/tiki-index.php?page=mod_security+rules" rel="nofollow">http://www.gotroot.com/tiki-index.php?page=mod_security+rules</a></li>
</ul>
<p>Useful information about the attacks:</p>
<ul>
<li> <a href="http://www.modsecurity.org/db/resources/" class="external free" title="http://www.modsecurity.org/db/resources/" rel="nofollow">http://www.modsecurity.org/db/resources/</a></li>
</ul>
<h4>Further Reading</h4>
<p>The official documentation was used as a base for this overview and, in my opinion, is the best resource for help when coniguring ModSecurity. Everything is written in great detail in there:</p>
<ol>
<li><a href="http://www.modsecurity.org/documentation/">The ModSecurity documentation</a></li>
</ol>
<p>Also, you might want to have a look at a web interface that aims to provide great help when writing filters for ModSecurity. This is <a href="http://leavesrustle.com/tools/modsecurity/">available here</a>. </p>
<h4>Notes</h4>
<p>I only recently started using <code>mod_security</code>. The first things that need to be done in order to be able to create effective filters that actually protect a web application is to study the application itself. Setting non-fatal actions for certain filters and checking the audit logs regularly is a good start. The goal is to protect the web application from being mis-used, but without breaking its normal operation.</p>
<p>This document is the second revision of the article, but it is still a draft. It needs to be enhanced with more examples. I also intend to write two extra articles related to this document, which will contain custom filter sets for <a href="http://www.wordpress.org/">WordPress</a> and <a href="http://mediawiki.org/">MediaWiki</a>, which are the web applications I use. Links to those articles will appear in the &#8220;<em>Further Reading</em>&#8221; section of this document.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2006/08/24/modsecurity-overview/">ModSecurity Overview</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2008/05/10/use-mod_deflate-to-compress-web-content-delivered-by-apache/" rel="bookmark">Use mod_deflate to Compress Web Content delivered by Apache</a></li>
<li><a href="http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/" rel="bookmark">Check Server HTTP Headers with CURL</a></li>
<li><a href="http://www.g-loaded.eu/2005/12/04/configure-awstats/" rel="bookmark">A quick AWstats guide</a></li>
<li><a href="http://www.g-loaded.eu/2007/02/21/htaccess-cheat-sheet/" rel="bookmark">.htaccess Cheat Sheet</a></li>
<li><a href="http://www.g-loaded.eu/2007/06/23/high-traffic-on-the-email-server/" rel="bookmark">High traffic on the email server</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2006/08/24/modsecurity-overview/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Track &#8216;em Down!</title>
		<link>http://www.g-loaded.eu/2006/04/07/track-em-down/</link>
		<comments>http://www.g-loaded.eu/2006/04/07/track-em-down/#comments</comments>
		<pubDate>Thu, 06 Apr 2006 23:57:30 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2006/04/07/track-em-down/</guid>
		<description><![CDATA[I&#8217;ve been checking the web server logs lately seeking for a way to track down the remote hosts that regularly submit, or try to submit, spam comments massively. Grep-ing the logs is no fun at all, so I wrote a small BASH script to do the dirty work for me. Well, this one was written [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been checking the web server logs lately seeking for a way to track down the remote hosts that regularly submit, or try to submit, spam comments massively. Grep-ing the logs is no fun at all, so I wrote a small BASH script to do the dirty work for me. Well, this one was written for my own apache log rotation setup, so it may be totally useless for you.<br />
<span id="more-184"></span></p>
<h4>How It Works For Me</h4>
<p>The script is written around the logic that a normal comment submitter usually posts a rational number of comments in a 30-day period. All blog owners have an idea of the comment traffic on their blogs. At least on this blog, most people won&#8217;t post more than 2-3 comments during a month. Even if they do not fill all the required fields on the comment form and they have to re-submit, which is almost rare, the number of the POST HTTP requests they send is not greater than 10 or 12.</p>
<p>On the other hand, a spammer, or better a spambot, usually tries to do more than that. After doing some research myself, I have concluded to the following: Even if they use dynamic IP addresses, which is a fact in most cases, the number of the POST HTTP requests they send during a 30-day period to the <code>wp-comments-post.php</code> file is by far greater than the most regular commenter&#8217;s POST requests on this blog. And I&#8217;m talking about 40-60 or even more POST HTTP requests from the same remote host in a month. This sounds like a spambot to me (correct me if I&#8217;m wrong).</p>
<h4>The Script</h4>
<p>This script, although it was written for my own use, contains some configuration parameters, so to be customized for different setups. You direct it to the directory that contains the rotated apache log files and it searches for the POST HTTP requests in all of them. My logs are rotated daily, but recycled monthly. Every day&#8217;s log file is also kept in my main apache log archive (yes, I keep everything). So, this script will give me a report for a whole month.</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##############################################################</span>
<span style="color: #666666; font-style: italic;"># Configuration BEGIN</span>
<span style="color: #666666; font-style: italic;">####################</span>
<span style="color: #666666; font-style: italic;"># The minimum number of POST HTTP requests a remote host</span>
<span style="color: #666666; font-style: italic;"># may have sent, without getting into this list.</span>
<span style="color: #666666; font-style: italic;"># ADJUST ACCORDING TO YOUR BLOG'S COMMENT TRAFFIC</span>
<span style="color: #666666; font-style: italic;"># 20 is just an example!!</span>
<span style="color: #007800;">MinPostReq</span>=<span style="color: #000000;">20</span>
<span style="color: #666666; font-style: italic;"># Where to send the report</span>
<span style="color: #007800;">MailTo</span>=<span style="color: #ff0000;">&quot;me@example.com&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Which hosts to exclude. Separate each host with an escaped |, eg \|</span>
<span style="color: #007800;">fexclude</span>=<span style="color: #ff0000;">&quot;desktop.example.com\|server.example.com&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The directory path that contains the Apache Logs</span>
<span style="color: #666666; font-style: italic;"># NO TRAILING SLASH</span>
<span style="color: #007800;">path</span>=<span style="color: #ff0000;">&quot;/path/to/rotated/apache/logs&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The page that accepts the comments. For WordPress, this is the following:</span>
<span style="color: #007800;">page</span>=<span style="color: #ff0000;">&quot;/wp-comments-post.php&quot;</span>
<span style="color: #666666; font-style: italic;"># Set it to empty &quot;&quot; to see the remote hosts that have sent POST requests on</span>
<span style="color: #666666; font-style: italic;"># any page of your web site (you will be amazed!)</span>
<span style="color: #666666; font-style: italic;">#page=&quot;&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">################</span>
<span style="color: #666666; font-style: italic;"># Configuration END</span>
<span style="color: #666666; font-style: italic;">#############################################################</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$fexclude</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># If no hosts are excluded, then set it to a random value,</span>
    <span style="color: #666666; font-style: italic;"># else grep -v will excude everything</span>
    <span style="color: #007800;">fexclude</span>=<span style="color: #ff0000;">&quot;dfahjgf32eDFSDFaFaD&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#40;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Req    Remote Host<span style="color: #000099; font-weight: bold;">\n</span>====================================================&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$path</span><span style="color: #000000; font-weight: bold;">/</span>access_log.<span style="color: #000000; font-weight: bold;">*</span>.gz; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #c20cb9; font-weight: bold;">zcat</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'&quot;POST '</span><span style="color: #007800;">$page</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'^\('</span><span style="color: #007800;">$fexclude</span><span style="color: #ff0000;">'\)'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1 }'</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-rg</span> \r
    <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ if(int($1)&gt;'</span><span style="color: #007800;">$MinPostReq</span><span style="color: #ff0000;">') { printf(&quot; %-5s %s\n&quot;,$1,$2) } }'</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Report Of Potential Spammers&quot;</span> <span style="color: #007800;">$MailTo</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>
<h4>Configuration</h4>
<p>Here is some info about the configuration options:</p>
<ul>
<li><strong>MinPostReq</strong> : The number of POST HTTP requests a remote host has sent to the <code>/wp-comments-post.php</code> file. This is the most critical option. Adjust it according to your blog&#8217;s comment submission traffic. For example if the most regular commenter posts 5 comments/month, set this a lot higher, eg 20 or more. Setting a good number here can reduce the error.</li>
<li><strong>MailTo</strong> : The email to send the report.</li>
<li><strong>fexclude</strong> : Which hosts to exclude. For example you can put all the hosts from which you administer WordPress. Make sure you separate them with an escaped | , eg: <strong>|</strong></li>
<li><strong>path</strong> : the path to the directory that contains the rotated apache logs. All log files of the form: <code>access_log.#.gz</code> will be searched.</li>
<li><strong>page</strong> : The WordPress page where the comments are submitted to. This is the <code>/wp-comments-post.php</code> file. You can set this option to nothing in order to see which hosts have sent POST HTTP requests and the total number of these requests. You will be amazed with the result.</li>
</ul>
<h4>The Report</h4>
<p>This script will send a report to your email address, which contains a list of the remote hosts that have sent POST HTTP requests to the <code>/wp-comments-post.php</code> and the number of these requests.</p>
<p>These <strong>MAY NOT</strong> be all spammers. Some of them could be readers who have submitted a lot of comments relevant to your blog. This report is just an overview of the POST HTTP requests towards WordPress and it will take further investigation to determine if a remote host has actually spammed you or tried to.</p>
<h4>Read The Following Section At Least 10 Times</h4>
<p><strong>THIS REPORT IS NOT A LIST OF SPAMMERS.<br />
You have been warned! Make sure you don&#8217;t accuse your innocent readers/commenters!! This will be your own mistake and not this script&#8217;s or my fault.</strong></p>
<p><strong>By using the above script or part of it, you explicitely accept the above statement.</strong></p>
<h4>What You Can Do</h4>
<p>If, after your own investigation, you are 100% sure that a remote host has spammed you, you can use any <strong>whois</strong> service to find the remote host&#8217;s internet provider and send them the relevant parts of your apache log files, the contents of the comments and any other information you have collected that proves that you were spammed from this address at a specific time. And remember: be polite. These people have no other relation to the spammer, apart from the fact that the latter is their client.</p>
<h4>What If It Does Not Work?</h4>
<p>Consider this script as a note you have seen. This is no release! I do not even care if it works or not. I&#8217;ve already stated that all this may be totally useless for you or for your setup. If this is the case, write a script for your own setup.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2006/04/07/track-em-down/">Track &#8216;em Down!</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li>
<li><a href="http://www.g-loaded.eu/2007/04/25/bbpress-for-wordpress/" rel="bookmark">bbPress for WordPress</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/" rel="bookmark">Script for Apache Error Report</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/mass-download/" rel="bookmark">Mass download</a></li>
<li><a href="http://www.g-loaded.eu/2007/06/23/high-traffic-on-the-email-server/" rel="bookmark">High traffic on the email server</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2006/04/07/track-em-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>A quick AWstats guide</title>
		<link>http://www.g-loaded.eu/2005/12/04/configure-awstats/</link>
		<comments>http://www.g-loaded.eu/2005/12/04/configure-awstats/#comments</comments>
		<pubDate>Sun, 04 Dec 2005 11:19:39 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[AWStats]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Traffic]]></category>
		<category><![CDATA[Web]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2005/11/25/configure-awstats/</guid>
		<description><![CDATA[AWstats is a free, popular log analyzer, released under the GPL. It can generate advanced graphical statistics from web, streaming, ftp or mail server log files. This document is not intended to be a review, but rather a quick installation and configuration guide for a specific web site, in order to have as accurate statistical data as possible for use in your traffic analysis reports.]]></description>
			<content:encoded><![CDATA[<p>AWstats is a free, popular log analyzer, released under the GPL. It can generate advanced graphical statistics from web, streaming, ftp or mail server log files. This document is not intended to be a review, but rather a quick installation and configuration guide for a specific web site, in order to have as accurate statistical data as possible for use in your traffic analysis reports.<br />
<span id="more-104"></span><br />
AWstats is actually a Perl script (<strong>awstats.pl</strong>), which parses your server&#8217;s log files and generates reports either dynamically, when used as a CGI script through the web browser, or by creating static HTML pages, when used directly from the command line or through cron. It also comes with some other helper Perl scripts to make this task even easier.</p>
<h4>Article Goals</h4>
<p>The goals of this document are to:</p>
<ol>
<li>Install AWstats in a custom location as a normal user. Although it is possible to have a system-wide installation, I chose this approach for completeness. The differences between the two methods are just the scripts&#8217; locations. The rest of the configuration stays the same.</li>
<li>Create a configuration file for our web site (Apache Virtual Host) for as accurate statistics as possible.</li>
<li>Parse this host&#8217;s log file and create a database with statistical data.</li>
<li>Use this statistical data to generate web site traffic reports. We will focus on the creation of static HTML reports, but some info on how to use <code>awstats.pl</code> as a CGI is also provided.</li>
<li>Make a quick introduction to user-defined charts.</li>
</ol>
<h4>Prerequisites</h4>
<p>This document assumes that:</p>
<ul>
<li>Our web site is configured to have its own log file.</li>
<li>The log file is written in the &quot;<strong>combined</strong>&quot; format (NCSA combined/XLF/ELF log format)</li>
<li>You have configured the Apache web server to do reverse DNS lookups (<code>HostnameLookups On</code>). This means that the log files contain the visitors&#8217; hostnames instead of their IP addresses in the HOST field. This is not necessary though.</li>
<li>We have access to the log file.</li>
</ul>
<p>Actually, <strong>only the last one is a necessity</strong>, as awstats can be configured to generate statistics even from heavily customized log formats. For this article we will use an apache log file in the &quot;<strong>combined</strong>&quot; format.</p>
<h4>Custom installation in our Home directory</h4>
<p>We will install the AWstats package in our Home directory. So, download the latest awstats version from the <a href="http://awstats.sourceforge.net/" title="Link to the AWstats Project page">Project Page</a> and extract it:</p>
<pre class="console"># tar -xzvf awstats-X.X.tar.gz -C /home/jsmith/</pre>
<p>A new directory (<code>awstats-X.X</code>) is created in our Home. This is where all scripts and other supplemental files are installed. You may want to rename this to just <code>awstats</code>:</p>
<pre class="console"># mv awstats-X.X awstats</pre>
<p>We will need to create two more directories, one for the awstats <strong>statistical data</strong> and one for the <strong>traffic reports</strong> (static HTML pages). So, we create the first one inside the awstats installation directory:</p>
<pre class="console"># mkdir /home/jsmith/awstats/statdata</pre>
<p>The directory which will hold the traffic reports can be located inside our web site&#8217;s root directory, so that they are accessible from a web browser. Assuming that our <code>DocumentRoot</code> is <code>/home/jsmith/public_html/</code>, we create a new directory in there:</p>
<pre class="console"># mkdir /home/jsmith/public_html/traffic</pre>
<p>Using this installation scheme, we avoid exposing the awstats scripts to the internet. Only the traffic reports will be accessible through a web browser. This means that it will not be possible to use <code>awstats.pl</code> as a CGI script to generate reports dynamically (directly from our statistical data), but this behaviour can easily be changed.</p>
<p>We also need to copy some <strong>images</strong>, which are used in the HTML or PDF traffic reports, to the <code>traffic</code> directory:</p>
<pre class="console"># cp -R /home/jsmith/awstats/wwwroot/icon/ /home/jsmith/public_html/traffic/</pre>
<p>The last part of the installation process is to set the appropriate permissions to the AWstats directories and files. So, we set the mode to 0755 for directories and 0644 for all files. Because the Perl scripts (*.pl files) need to be executable, we set their mode to 0755. The following lines do all this:</p>
<pre class="console"># find /home/jsmith/awstats/ -type d | xargs chmod 0755
# find /home/jsmith/awstats/ -type f | xargs chmod 0644
# find /home/jsmith/awstats/ -type f -name *.pl | xargs chmod 0755</pre>
<p>We also need to set the appropriate permissions to the directory which will hold the reports and which will be accessible from the internet:</p>
<pre class="console"># find /home/jsmith/public_html/traffic/ -type d | xargs chmod 0705
# find /home/jsmith/public_html/traffic/ -type f | xargs chmod 0604</pre>
<p>That&#8217;s enough with the installation.</p>
<h4>Configuration</h4>
<p>We need to create a configuration file for our web site. This file will be read by <code>awstats.pl</code> in order to generate the statistical data or the traffic reports. There is a sample configuration file in the <code>/home/jsmith/awstats/wwwroot/cgi-bin/</code> directory, named <code>awstats.model.conf</code>. We make a copy of this file in the same directory and replace the &quot;<em>model</em>&quot; part of the name with one that will represent our web site:</p>
<pre class="console"># cp awstats.model.conf awstats.mysite.conf</pre>
<p>We will work on the copy. Although, modifying only a few basic directives, such as the logfile path and the statistical data directory path, would be enough, we will modify some more, so that our statistics are as accurate as possible and our reports look the way we want.</p>
<p>Open the <code>awstats.mysite.conf</code> file in your favourite text editor and let&#8217;s start customizing it.</p>
<p><em>Note</em>: I would suggest that you do not use relative paths whenever needed, but rather absolute ones.</p>
<pre class="codesnp">LogFile=&quot;/home/jsmith/logs/access_log&quot;
LogType=W
LogFormat=1
LogSeparator=&quot; &quot;</pre>
<p>These are log file specific directives. If your log file is in the &quot;<code>combined</code>&quot; format, all you have to modify is its path.</p>
<pre class="codesnp">SiteDomain=&quot;www.mysite.com&quot;
HostAliases=&quot;mysite.com&quot;</pre>
<p>Here we set our web site&#8217;s URL and all the aliases that can be used to reach the site with a web browser. Separate all aliases with a &quot;space&quot;.</p>
<pre class="codesnp">DNSLookup=0</pre>
<p>By setting this directive to <strong>0</strong>, no reverse DNS lookup requests will be sent to the nameserver. I have set the Apache web server to do these lookups, so a value of <strong>0</strong> is the proper one. You can set this to <strong>1</strong>, which will lead to numerous lookup requests to the nameserver, or <strong>2</strong>, which will make awstats do the resolving by examining a DNS cache file, if it exists. Keep in mind that having awstats do the reverse DNS lookups will slow the statistics update process dramatically.</p>
<pre class="codesnp">DirData=&quot;/home/jsmith/awstats/statdata&quot;</pre>
<p>Set the directory where awstats will keep its statistical data. This is one of the directories we had created in the installation process.</p>
<pre class="codesnp">DirCgi=&quot;/home/jsmith/awstats/wwwroot/cgi-bin&quot;</pre>
<p>This is the directory that contains the <code>awstats.pl</code> script.</p>
<pre class="codesnp">DirIcons=&quot;icon&quot;</pre>
<p>Remember that we had previously copied the awstats icons to the directory which will hold our reports? That&#8217;s why we do not need to specify an absolute path for these. Just set it to <code>icon</code>.</p>
<pre class="codesnp">CreateDirDataIfNotExists=0</pre>
<p>If you had previously created the directory which will hold the statistical data, then a value of <strong>0</strong> will do. Otherwise set it to <strong>1</strong> to have the directory you have specified in the <code>DirData</code> directive created.</p>
<pre class="codesnp">KeepBackupOfHistoricFiles=1</pre>
<p>It&#8217;s a good habit to have awstats keep a backup of the historic data during the update process.</p>
<pre class="codesnp">DefaultFile=&quot;index.php&quot;</pre>
<p>Here we define the <em>index</em> file for our web site. In other words, our home page. This depends on your site.</p>
<pre class="codesnp">SkipHosts=&quot;OUR OWN PCs' HOSTNAMES&quot;</pre>
<p>This is a very important directive ragarding the accuracy of the statistics. Usually, we are our web site&#8217;s most regular visitor and it&#8217;s obvious that we do not want to be counted as a visitor. This directive can take IP addresses <strong>or</strong> hostnames as values, separated with a <code>space</code>. Regular expressions can be used in the form of <code>REGEX[value]</code>. IP addresses cannot be mixed with hostnames, so, if the DNS lookups take place at the web server level, then we have to use hostnames as values, otherwise we have to use IP addresses. Usually we need to set the IPs or hostnames of all our LAN computers or computers we use to edit the website, so that they are ignored. Below are some <strong>examples</strong>:</p>
<pre class="codesnp">SkipHosts=&quot;localhost REGEX[^.*\.example\.dyndns\.org$] test.mysite.com windowspc1&quot;
<strong>OR</strong>
SkipHosts=&quot;127.0.0.1 REGEX[^192\.168\.] REGEX[^10\.]&quot;</pre>
<p></p>
<pre class="codesnp">SkipUserAgents=&quot;&quot;</pre>
<p>If you use any custom spiders or bots to test or analyze your web site, but you don&#8217;t want their access to be included in the stats, then you should add their &quot;User Agent String&quot; as a value to this directive. Again, regular expressions can be used in the form of <code>REGEX[value]</code>.</p>
<pre class="codesnp">NotPageList=&quot;css js class gif jpg jpeg png bmp ico swf&quot;</pre>
<p>This is another important directive. Here we set what file extensions will not be counted as <em>Page Views</em> or <em>Downloads</em>, but only as <em>Hits</em>. Usually, this list includes files that are part of a web page (images, stylesheets, flash animations, java applets etc.).</p>
<pre class="codesnp">URLWithQuery=0
URLWithQueryWithOnlyFollowingParameters=&quot;&quot;
URLWithQueryWithoutFollowingParameters=&quot;&quot;
URLReferrerWithQuery=0
</pre>
<p>These do not need to be modified, unless you want the query string to be included in the web page URLs or Referrer URLs in the traffic reports. Enabling the <code>URLWithQuery</code> directive is important in the case your web page URLs are of the form <code>/index.php?p=10</code>, so that it is clear in the traffic reports which page was viewed. On the other hand, if your page URLs are of the above form, but you use permalinks, then it&#8217;s not needed to modify the default values for these directives.<br />
Including the query string in the referrer URLs is not important, in fact it can lead to lengthy meaningless referrer lists, which is not so convenient. I just provide this info here for completeness.</p>
<pre class="codesnp">LevelForWormsDetection=2</pre>
<p>By default, the detection of worms that have crawled your web site is disabled. You may want to enable this by setting the above directive&#8217;s value to <strong>2</strong>.</p>
<pre class="codesnp">Lang=&quot;en&quot;</pre>
<p>If you need the reports to be in a specific language, set it here. A list of supported languages exists in the configuration file.</p>
<pre class="codesnp">ShowAuthenticatedUsers=PHBL</pre>
<p>If your reports are <strong>private</strong>, you may set this directive&#8217;s value to <strong>PHBL</strong> (details about what each letter represents can be found inside the conf file), so that a section with details about your web site&#8217;s authenticated users is included in the reports.</p>
<pre class="codesnp">ShowWormsStats=HBL</pre>
<p>If you had previously enabled the worm detection, then you may want to include a detailed section about worms in the reports.</p>
<pre class="codesnp">IncludeInternalLinksInOriginSection=1</pre>
<p>By setting this to <strong>1</strong>, a summary of how many links to another internal page have been followed from your site&#8217;s pages is included in the reports.</p>
<pre class="codesnp">MaxNbOfDomain = 10
MaxNbOfHostsShown = 10
MaxNbOfLoginShown = 10
MaxNbOfRobotShown = 10
MaxNbOfPageShown = 10
MaxNbOfOsShown = 10
MaxNbOfBrowsersShown = 10
MaxNbOfRefererShown = 10
MaxNbOfKeyphrasesShown = 10
MaxNbOfKeywordsShown = 10
</pre>
<p>Here follows some info about the reports. You can create only one main page with a summary of the web site&#8217;s traffic, but you can also generate some supplemental pages which have full lists of the visited pages, referrers, countries, search engines etc. Each section in the main page includes a predefined number of entries that are displayed. For example, it displays by default the top 10 referrers. This number can be customized by modifying the directives above.</p>
<pre class="codesnp">ShowLinksOnUrl=1</pre>
<p>By default, each URL shown in the reports is a clickable hyperlink. If you do not want them to be actual hyperlinks, then set this to <strong>0</strong>.</p>
<pre class="codesnp">MaxRowsInHTMLOutput=1000
DetailedReportsOnNewWindows=1</pre>
<p>With these directives you set the number of entries each of the supplemental reports can have and if you want these supplemental reports to be opened in a new browser window.</p>
<pre class="codesnp">LoadPlugin=&quot;tooltips&quot;
LoadPlugin=&quot;decodeutfkeys&quot;</pre>
<p>The AWstats package includes some <strong>plugins</strong> you can enable. I found the above two to be helpful. The first one enables the display of some descriptive tooltips and the second one makes it possible to show keywords and keyphrases correctly using national characters.<br />
There are some other interesting plugins inside the awstats package, but also some more from other contributors. You can find the latter at the project&#8217;s web site. Keep in mind, that each plugin may require certain Perl modules to be installed.</p>
<h4>Update the statistics database</h4>
<p>Now that we have finished customizing our web site&#8217;s configuration file, we can finally have <code>awstats.pl</code> parse our log file and create statistical data:</p>
<pre class="console"># perl /home/jsmith/awstats/wwwroot/cgi-bin/awstats.pl -config=mysite -update -showcorrupted</pre>
<p>Notice that we do not use the whole configuration file&#8217;s filename (<code>awstats.mysite.conf</code>) to define our configuration, but only the part between <code>awstats.</code> and <code>.conf</code>.</p>
<p>The <code>-showcorrupted</code> option is not necessary. A total number of corrupted records would be displayed anyway. This just provides detailed info.</p>
<p>It would be convenient if you set cron to execute the above command on a daily or hourly basis. Here is a small BASH script that can be run through cron:</p>
<pre class="codesnp">#! /bin/bash
# Update the statistics database
perl /home/jsmith/awstats/wwwroot/cgi-bin/awstats.pl -config=mysite -update -showcorrupted
# Calculate Total Visits for all months
TotVisits=$(grep ^TotalVisits /home/jsmith/awstats/statdata/*.txt | sed 's/^.*awstats.*TotalVisits.//' | awk '{sum += $1} END {print sum}')
# Export a small GIF image with the number of total visits
text2gif -t &quot;$TotVisits&quot; > /home/jsmith/public_html/traffic/counter.gif
# Set proper permissions on the GIF image
chmod 0604 /home/jsmith/public_html/traffic/counter.gif
exit 0</pre>
<p>This small script updates the statistical data, calculates the total visits for all months and exports a small B&amp;W GIF image which can be used as our custom counter in our web site. It&#8217;s not a real-time counter, but it&#8217;s better than nothing&#8230; Anyway, this just an example. The <code>text2gif</code> utility is part of the <code>libungif-progs</code> package.</p>
<h4>Generate traffic reports</h4>
<p>There are two methods to generate reports. Either by using <strong>awstats.pl</strong> directly or by using a helper script, named <strong>awstats_buildstaticpages.pl</strong>.</p>
<p>To generate the main report for November 2005 using <code>awstats.pl</code>, you can issue the following command:</p>
<pre class="console"># perl /home/jsmith/awstats/wwwroot/cgi-bin/awstats.pl -config=mysite -month=11 -year=2005 -output -staticlinks > /home/jsmith/public_html/traffic/awstats.mysite.200511.html</pre>
<p>If the options <code>-month</code> and <code>-year</code> are omitted, then the report is generated for the current month. You can also generate a report for a whole year, by setting these two options to <strong>-month=all</strong> and <strong>-year=2005</strong>.</p>
<p>You can view the page with your web browser at:<br />
<code>http://www.mysite.com/traffic/awstats.mysite.200511.html</code></p>
<p>Furthermore, you can create supplemental reports (lengthy lists of referrers, countries etc.) or even apply filters. This info is covered in detail in the awstats documentation. See the relevant section <a href="http://awstats.sourceforge.net/docs/awstats_setup.html#READ" title="Link to AWstats Documentation page">here</a>.</p>
<p>A quick way to create full reports (main and supplemental pages) is to use the helper script, <strong>awstats_buildstaticpages.pl</strong>. This can be used in the following way:</p>
<pre class="console"># perl /home/jsmith/awstats/tools/awstats_buildstaticpages.pl -configdir=/home/jsmith/awstats/wwwroot/cgi-bin -config=mysite -awstatsprog=/home/jsmith/awstats/wwwroot/cgi-bin/awstats.pl -dir=/home/jsmith/awstats/statdata -month=11 -year=2005 -builddate=200511</pre>
<p>Here is an explanation for some of the options:<br />
<strong>-configdir</strong>: Sets the path of the directory which contains the configuration files.<br />
<strong>-awstatsprog</strong>: Sets the path to the <code>awstats.pl</code> script.<br />
<strong>-dir</strong>: Sets the directory where the report files should be saved.<br />
<strong>-builddate</strong>: Adds month and year info in the report&#8217;s filename.</p>
<p>Again, if the options <code>-month</code> and <code>-year</code> are omitted, then the report is generated for the current month and year.</p>
<p>Other options that can be used are:<br />
<strong>-update</strong>: Updates the awstats statistics database before generating any reports.<br />
<strong>-buildpdf</strong>: Creates a PDF file, after the generation of the HTML pages is done.</p>
<p>In order to generate PDF files, the package <strong>htmldoc</strong> needs to be installed in the system.</p>
<p>It would be more convenient if you set cron to execute the above command.</p>
<h4>AWstats Extra Section Configuration</h4>
<p>AWstats can be configured to include user-defined charts in the reports. These are defined in the &quot;<strong>Extra Section</strong>&quot; in the <code>awstats.mysite.conf</code> file. An explanation for each directive is included withing the conf file. Here I provide two examples that work together with some notes, just to get you started with custom charts.</p>
<p>Keep in mind the following two things:</p>
<ol>
<li>Every time you define a new extra chart, you have to increment the number in the name of each directive. For example, for the first extra chart the directive that defines the chart&#8217;s name would be <strong>ExtraSectionName1</strong>, for the second extra chart it would be <strong>ExtraSectionName2</strong> etc.</li>
<li>Every time you define a new extra chart, but you want it to include info from already parsed log files, you have to recreate the awstats historical statistical data. You can simply delete the contents of the <code>/home/jsmith/awstats/statdata</code> directory and parse all your log files again.</li>
</ol>
<p>At least a basic knowledge of Regular Expressions is required in order to configure extra charts.</p>
<h5>Top 50 RPM Downloads</h5>
<p>This user-defined chart displays the Top 50 RPM package downloads (used for the current web site):</p>
<pre class="codesnp">ExtraSectionName1=&quot;Top 50 RPM Downloads&quot;
ExtraSectionCodeFilter1=&quot;200 304&quot;
ExtraSectionCondition1=&quot;&quot;
ExtraSectionFirstColumnTitle1=&quot;Package Name&quot;
ExtraSectionFirstColumnValues1=&quot;URL,\/packages\/(.*)\.rcn.*\.rpm$&quot;
ExtraSectionFirstColumnFormat1=&quot;%s&quot;
ExtraSectionStatTypes1=HB
ExtraSectionAddAverageRow1=0
ExtraSectionAddSumRow1=1
MaxNbOfExtra1=50
MinHitExtra1=1</pre>
<h5>Top 100 Referrers by Domain</h5>
<p>This user-defined chart displays the Top 100 Referrers by Domain. It also merges referrer URLs of the form <code>www.domain.com</code> and <code>domain.com</code> to just <code>domain.com</code>.</p>
<pre class="codesnp">ExtraSectionName2=&quot;Top 100 Referrers by Domain&quot;
ExtraSectionCodeFilter2=&quot;200 304&quot;
ExtraSectionCondition2=&quot;&quot;
ExtraSectionFirstColumnTitle2=&quot;Referring Domain&quot;
ExtraSectionFirstColumnValues2=&quot;REFERER,^http:\/\/www\.([^\/]+)\/||REFERER,^http:\/\/([^\/]+)\/&quot;
ExtraSectionFirstColumnFormat2=&quot;%s&quot;
ExtraSectionStatTypes2=PHBL
ExtraSectionAddAverageRow2=0
ExtraSectionAddSumRow2=1
MaxNbOfExtra2=100
MinHitExtra2=1</pre>
<h5>Some notes</h5>
<p>User-defined charts add much more flexibility to AWstats. Sometimes, even non-professional webmasters need to &quot;dig&quot; into the server logs for some special info about their web site. This can be perfectly achieved by using custom scripts, but the extra charts are a better way of doing this.</p>
<p>Three are the most important directives in the extra chart configuration:</p>
<ul>
<li><strong>ExtraSectionCodeFilter</strong>: This filters the log entries according to the HTTP code that the web server returned after a page or file request.</li>
<li><strong>ExtraSectionCondition</strong>: With this we can set some rules that define which entries will pass or not. The rules are of the form &quot;<code>URL, regular expression</code>&quot; and they can be separated with &quot;<code>||</code>&quot;, which means &quot;<code>OR</code>&quot;. Instead of the <code>URL</code> field, other fields like the <em>User Agent</em> string or the <em>Referrer</em> URL can be checked. These are documented in the configuration file&#8217;s comments. This directive can be left blank</li>
<li><strong>ExtraSectionFirstColumnValues</strong>: This defines what is the value that will be displayed in the custom chart. This is the same as the <code>ExtraSectionCondition</code>, but it could be considered as a third level of filtering. This directive cannot be left blank. An important thing to take a note of is that you need to specify a group in the regular expression. This means that a part or all of the regular expression must be in parenthesis. Whatever this group matches will be the value in the chart.</li>
</ul>
<p>It&#8217;s clear that the knowledge of regular expressions is the absolute key in configuring an extra chart. This document is not intended to be a REGEX guide. I am not an expert on this anyway, so it would be pointless. Some helpful links can be found in the &quot;<em>Further Reading</em>&quot; section of this document.</p>
<h4>Apache Configuration (optional)</h4>
<p>Using this AWstats installation and configuration guide, there is no need for any special configuration at the web server level.</p>
<p>But, if you have not created the directory that holds the traffic reports (<code>/home/jsmith/public_html/traffic</code>) inside your <code>DocumentRoot</code>, then adding an <code>Alias</code> in your Apache VirtualHost configuration is necessary. For example, if you have created the <code>traffic</code> directory in <code>/home/jsmith/traffic</code>, then the following <code>Alias</code> must be added in your Apache or Virtual Host configuration file, so that the reports are accessible from a web browser:</p>
<pre class="codesnp">Alias /traffic /home/jsmith/traffic
&lt;Directory /home/jsmith/traffic&gt;
	AllowOverride AuthConfig
	Options None
&lt;/Directory&gt;</pre>
<p>Access control directives can be added inside the <code>&lt;Directory&gt;</code> tags or in an <code>.htaccess</code> file, but this will not be covered in this document.</p>
<p>On the other hand, if you want to use <code>awstats.pl</code> as a CGI script in order to create the traffic reports dynamically from the web browser, then the addition of a <code>ScriptAlias</code> in your Apache or Virtual Host configuration is necessary. Assuming that you have followed the custom installation instructions of this guide, then this <code>ScriptAlias</code> could be:</p>
<pre class="codesnp">ScriptAlias /traffic-bin/ &quot;/home/jsmith/awstats/wwwroot/cgi-bin/&quot;
&lt;Directory &quot;/home/jsmith/awstats/wwwroot/cgi-bin&quot;&gt;
	AllowOverride None
	Options None
	Order allow,deny
	Allow from all
&lt;/Directory&gt;</pre>
<p>Now, point your web browser at:</p>
<p><code>http://www.mysite.com/traffic-bin/awstats.pl?config=mysite</code></p>
<p>All the <code>awstats.pl</code> options, except for <code>-staticlinks</code>, are supported, so you can try the following:</p>
<p><code>http://www.mysite.com/traffic-bin/awstats.pl?config=mysite&amp;month=08&amp;year=2005</code></p>
<p>Using <code>awstats.pl</code> as a CGI script, the reports are created in real-time from the statistical data, so it might be slow. This adds unnecessary load on the server. Furthermore, AWstats had some security related issues in the past, so using it as a CGI script is not recommended, unless you are sure that these problems have been solved or you implement access restrictions.</p>
<h4>Further Reading</h4>
<p>Here are some documents you might find useful:</p>
<ol>
<li><a href="http://awstats.sourceforge.net/docs/index.html">The AWstats Documentation</a></li>
<li><a href="http://awstats.sourceforge.net/docs/awstats_faq.html">The AWstats FAQ</a></li>
<li><a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP Status Code Definitions</a></li>
<li><a href="http://www.amk.ca/python/howto/regex/regex.html">Regular Expression HOWTO</a></li>
<li><a href="http://perldoc.perl.org/perlre.html">Syntax of regular expressions in Perl (Perl Documentation)</a></li>
<li><a href="http://fedoranews.org/tchung/htmldoc/">How to build HTMLDOC RPM package for Fedora Core by Thomas Chung</a></li>
</ol>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2005/12/04/configure-awstats/">A quick AWstats guide</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/04/07/track-em-down/" rel="bookmark">Track &#8216;em Down!</a></li>
<li><a href="http://www.g-loaded.eu/2008/11/27/maxminds-geoip-dat-gz-location-change/" rel="bookmark">Maxmind&#8217;s GeoIP.dat.gz location change</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/mass-download/" rel="bookmark">Mass download</a></li>
<li><a href="http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/" rel="bookmark">Check Server HTTP Headers with CURL</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/red-hat-rpm-guide/" rel="bookmark">Red Hat RPM Guide</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2005/12/04/configure-awstats/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>A real-time log viewer</title>
		<link>http://www.g-loaded.eu/2005/10/14/a-real-time-log-viewer/</link>
		<comments>http://www.g-loaded.eu/2005/10/14/a-real-time-log-viewer/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 08:17:08 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Tips]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=52</guid>
		<description><![CDATA[It&#8217;s very useful, when testing things, to have syslog messages appear in real-time on the screen. This way there is no need to check /var/log/messages all the time. It&#8217;s really simple to set up something like this. You only need to append the following line to your /etc/syslog.conf: *.* /dev/tty9 Remember to use tabs instead [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s very useful, when testing things, to have syslog messages appear in real-time on the screen. This way there is no need to check <em>/var/log/messages</em> all the time.<br />
<span id="more-52"></span><br />
It&#8217;s really simple to set up something like this. You only need to append the following line to your <em>/etc/syslog.conf</em>:</p>
<pre class="codesnp">*.*                /dev/tty9</pre>
<p>Remember to use <strong>tabs</strong> instead of spaces. Then <strong>save</strong> and <strong>restart</strong> the syslog service:</p>
<pre class="console"># service syslog restart</pre>
<p>From now on, by pressing <strong>Ctrl-Alt-F9</strong> you can watch all the info that goes to syslog in real-time.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2005/10/14/a-real-time-log-viewer/">A real-time log viewer</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2007/02/24/creative-commons-v30-licenses-launched/" rel="bookmark">Creative Commons v3.0 Licenses Launched</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/25/logwatch-and-dovecot-1x-series-in-fc5/" rel="bookmark">Logwatch and Dovecot 1.x series in FC5</a></li>
<li><a href="http://www.g-loaded.eu/2006/05/16/namespace-declarations-with-celementtree/" rel="bookmark">Namespace Declarations With cElementTree</a></li>
<li><a href="http://www.g-loaded.eu/2006/11/01/bot-allow-content-and-cc-configurator-plugin-updates/" rel="bookmark">Bot-Allow-Content and CC-Configurator plugin updates</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2005/10/14/a-real-time-log-viewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>System Information using the console</title>
		<link>http://www.g-loaded.eu/2005/10/14/system-information-using-the-console/</link>
		<comments>http://www.g-loaded.eu/2005/10/14/system-information-using-the-console/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 07:34:35 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Tips]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=51</guid>
		<description><![CDATA[There are some really useful commands that can give information about the system directly from the console. Some of them are: See a list of all the running processes using standard syntax: # ps ax &#124; less See a list of all the running processes using BSD syntax: # ps aux &#124; less See real-time [...]]]></description>
			<content:encoded><![CDATA[<p>There are some really useful commands that can give information about the system directly from the console. Some of them are:<br />
<span id="more-51"></span><br />
See a list of all the running processes using standard syntax:</p>
<pre class="console"># ps ax | less</pre>
<p>See a list of all the running processes using BSD syntax:</p>
<pre class="console"># ps aux | less</pre>
<p>See real-time information about running processes:</p>
<pre class="console"># top</pre>
<p>Pressing the <strong>L</strong>, <strong>T</strong>, <strong>M</strong> keys while top is running you can toggle the display of <em>Average Load</em>, <em>CPU</em> and <em>Memory</em> usage respectively. The <strong>Space</strong> key refreshes the display and <strong>Q</strong> key quits the program. There are a lot more, so you should check the man page.</p>
<p>Memory and SWAP space usage:</p>
<pre class="console"># free -m</pre>
<p>Use the <strong>-m</strong> parameter to show the amount of memory in MB instead of bytes.</p>
<p>Check if a program is running:</p>
<pre class="console"># ps ax | grep PROGRAM | grep -v grep</pre>
<p>Show filesystem and disk space usage:</p>
<pre class="console"># df -h</pre>
<p>Show disk usage under the current directory</p>
<pre class="console"># du -hs</pre>
<p>The <strong>-h</strong> parameter shows sizes in human readable formats (eg MB, GB) and the <strong>-s</strong> gives only a total. If it&#8217;s not used, then information about each subdirectory is shown.</p>
<p>There are a lot more. I&#8217;ll add more commands to this post in a future update. Stay tuned!</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2005/10/14/system-information-using-the-console/">System Information using the console</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2005/09/30/change-the-console-resolution/" rel="bookmark">Change the console resolution</a></li>
<li><a href="http://www.g-loaded.eu/2006/05/17/epiphany-python-console-open-new-tab/" rel="bookmark">Epiphany Python Console &#8211; Open New Tab</a></li>
<li><a href="http://www.g-loaded.eu/2005/09/30/change-console-font-in-fedora/" rel="bookmark">Change console font in Fedora</a></li>
<li><a href="http://www.g-loaded.eu/2008/12/09/making-a-directory-writable-by-the-webserver/" rel="bookmark">Making a directory writable by the webserver</a></li>
<li><a href="http://www.g-loaded.eu/2005/10/03/search-a-string-in-multiple-files/" rel="bookmark">Search for a string in multiple files</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2005/10/14/system-information-using-the-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.142 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-07 07:36:20 -->

