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

<channel>
	<title>Logi.cc</title>
	<atom:link href="http://logi.cc/en/feed/" rel="self" type="application/rss+xml" />
	<link>http://logi.cc/en</link>
	<description>Linux Technology, Web Technology, SEO Technology and more</description>
	<lastBuildDate>Fri, 24 Aug 2012 16:24:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Netfilter Log Format</title>
		<link>http://logi.cc/en/2010/07/netfilter-log-format/</link>
		<comments>http://logi.cc/en/2010/07/netfilter-log-format/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 07:16:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[netfilter]]></category>

		<guid isPermaLink="false">http://logi.cc/en/?p=31</guid>
		<description><![CDATA[Here is a quick reference for the format used by the netfilter log messages.   This is all derived from the source of the netfilter kernel modules (Linux kernel 2.4.2). Below is a hypothetical log message generated by netfilter. It is based on a real log entry but I have added all possible IP and TCP [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick reference for the format used by the netfilter log messages.   This is all derived from the source of the netfilter kernel modules (Linux kernel 2.4.2).</p>
<p>Below is a hypothetical log message generated by netfilter.  It is based on a real log entry but I have added all possible IP and TCP flags as well as a fragment offset  for illustrative purposes.</p>
<table border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td><tt>Apr 16 00:30:45 megahard kernel: </tt></td>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#d0d0ff"><tt>NF: D(I,Priv) </tt></td>
<td bgcolor="#e0ffe0"><tt>IN=eth1</tt></td>
<td><tt> </tt></td>
</tr>
</tbody>
</table>
</td>
<td bgcolor="#e0ffe0"><tt>OUT=</tt></td>
<td><tt> </tt></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#c0ffff"><tt>MAC=00:80:8c:1e:12:60:00:10:76:00:2f:c2:08:00</tt></td>
<td><tt> </tt></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#e2e2e2"><tt>SRC=211.251.142.65</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>DST=203.164.4.223</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>LEN=60</tt></td>
<td><tt> </tt></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#e2e2e2"><tt>TOS=0x00</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>PREC=0x00</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>TTL=44</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>ID=31526</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>CE</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>DF</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>MF</tt></td>
<td><tt> </tt></td>
<td bgcolor="#e2e2e2"><tt>FRAG=179</tt></td>
<td><tt> </tt></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#e2e2e2"><tt>OPT (072728CBA404DFCBA40253CBA4032ECBA403A2CBA4033ECBA40<br />
2C1180746EA18074C52892734A200)</tt></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#e2e2e2"><tt>PROTO=TCP</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>SPT=4515</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>DPT=111</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>SEQ=1168094040</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>ACK=0</tt></td>
<td><tt> </tt></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#ffffe0"><tt>WINDOW=32120</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>RES=0x03</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>URG</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>ACK</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>PSH</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>RST</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>SYN</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>FIN</tt></td>
<td><tt> </tt></td>
<td bgcolor="#ffffe0"><tt>URGP=0</tt></td>
<td><tt> </tt></td>
</tr>
</tbody>
</table>
<p><tt>OPT (020405B40402080A05E3F3C40000000001030300)</tt></p>
<p><span id="more-31"></span></p>
<p>The items are explained in sequence:</p>
<table style="height: 1110px;" border="1" cellspacing="0" cellpadding="2" width="550">
<tbody>
<tr>
<td valign="top"><tt>Apr 16 00:30:45<br />
megahard kernel: </tt></td>
<td valign="top">syslog prefix.  It is not present if you read log messages from the console.</td>
</tr>
<tr>
<td valign="top">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td bgcolor="#d0d0ff"><tt>NF: D(I,Priv) </tt></td>
</tr>
</tbody>
</table>
</td>
<td valign="top" bgcolor="#d0d0ff">Enabled with:<tt><strong> --log-prefix <em>'prefix'</em></strong></tt><br />
An arbitrary, user defined log prefix.  <strong>Including the spaces.</strong><br />
A trailing space is necessary to keep the prefix separate from the next       token; this is a bug in netfilter.</td>
</tr>
<tr bgcolor="#e0ffe0">
<td valign="top"><tt>IN=eth1</tt></td>
<td>Interface the packet was received from.  Empty value for locally generated packets.</td>
</tr>
<tr bgcolor="#e0ffe0">
<td valign="top"><tt>OUT=</tt></td>
<td>Interface the packet was sent to.  Empty value for locally received packets.</td>
</tr>
<tr bgcolor="#c0ffff">
<td valign="top"><tt>MAC=<br />
00:80:8c:1e:12:60:<br />
00:10:76:00:2f:c2:<br />
08:00</tt></td>
<td valign="top">Destination MAC=00:80:8c:1e:12:60,<br />
Source MAC=00:10:76:00:2f:c2,<br />
Type=08:00 (ethernet frame carried an IPv4 datagram)</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>SRC=211.251.142.65</tt></td>
<td>Source IP address</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>DST=203.164.4.223</tt></td>
<td>Destination IP address</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>LEN=60</tt></td>
<td>Total length of IP packet in bytes</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>TOS=0x00</tt></td>
<td>Type Of Service, &#8220;Type&#8221; field.<br />
Increasingly being replaced by <strong>DS</strong> and <strong>ECN</strong>.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>PREC=0x00</tt></td>
<td>Type Of Service, &#8220;Precedence&#8221; field.<br />
Increasingly being replaced by <strong>DS</strong> and <strong>ECN</strong>.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>TTL=44</tt></td>
<td>remaining Time To Live is 44 hops.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>ID=31526</tt></td>
<td>Unique ID for this IP datagram, shared by all fragments if fragmented.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>CE</tt></td>
<td>Presumably the &#8220;ECN CE&#8221; flag (Congestion Experienced).<br />
This seems to be wrong because according to RFC2481, the CE bit is located        in the TOS field.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>DF</tt></td>
<td>&#8220;Don&#8217;t Fragment&#8221; flag.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>MF</tt></td>
<td>&#8220;More Fragments following&#8221; flag.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>FRAG=179</tt></td>
<td>Fragment offset in units of &#8220;8-bytes&#8221;.  In this case the byte        offset for data in this packet is 179*8=1432 bytes.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>OPT (0727..A200)</tt></td>
<td>Enabled with:<tt><strong> --log-ip-options</strong></tt><br />
IP options.  This variable length field is rarely used.       Certain IP options, f.e. source routing, are often disallowed by netadmins.       Even harmless options like &#8220;Record Route&#8221; may only be allowed if the        transport protocol is ICMP, or not at all.</td>
</tr>
<tr bgcolor="#e2e2e2">
<td valign="top"><tt>PROTO=TCP</tt></td>
<td>Protocol name or number.        Netfilter uses names for TCP, UDP, ICMP, AH and ESP.         Other protocols are identified by number.       A list is in your <em>/etc/protocols</em>.  A complete       list is in the file        <a rel="nofollow" href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml"> <strong><em>protocol-numbers</em></strong></a></td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>SPT=4515</tt></td>
<td>Source port (TCP and UDP).  A list of port numbers       is in your /<em>etc/services</em>.  A complete list is in the file        <a rel="nofollow" href="http://www.iana.org/assignments/port-numbers"> <strong><em>port-numbers</em></strong></a></td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>DPT=111</tt></td>
<td>Destination port (TCP and UDP).  See SPT above.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>SEQ=1168094040</tt></td>
<td>Enabled with:<tt><strong> --log-tcp-sequence</strong></tt><br />
Receive Sequence number.  By cleverly chosing this number, a cryptographic        &#8220;cookie&#8221; can be implemented while still satisfying TCP protocol requirements.       These &#8220;<a rel="nofollow" href="http://cr.yp.to/syncookies.html">SYN-cookies</a>&#8221; defeat some        types of SYN-flooding DoS attacks and should be enabled on all systems        running public TCP servers.<br />
<tt>echo 1 &gt; /proc/sys/net/ipv4/tcp_syncookies</tt></td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>ACK=0</tt></td>
<td>Same as the Receive Sequence number, but for the other end of the TCP connection.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>WINDOW=32120</tt></td>
<td>The TCP Receive Window size.  This may be scaled by bit-shifting left by a number        of bits specified in the &#8220;Window Scale&#8221; TCP option.  If the host supports ECN, then       the TCP Receive Window size will also be controlled by that.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>RES=0x03</tt></td>
<td>Reserved bits.  The ECN flags &#8220;<strong>CWR</strong>&#8221; and &#8220;<strong>ECNE</strong>&#8221; will show up in the two        least significant bits of this field.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>URG</tt></td>
<td>Urgent flag.   See URGP below.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>ACK</tt></td>
<td>Acknowledgement flag.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>PSH</tt></td>
<td>Push flag.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>RST</tt></td>
<td>RST (Reset) flag.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>SYN</tt></td>
<td>SYN flag, only exchanged at TCP connection establishment.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>FIN</tt></td>
<td>FIN flag, only exchanged at TCP disconnection.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>URGP=0</tt></td>
<td>The Urgent Pointer allows for urgent, &#8220;out of band&#8221; data transfer.       Unfortunately not all protocol implementations agree, so this        facility is hardly ever used.</td>
</tr>
<tr bgcolor="#ffffe0">
<td valign="top"><tt>OPT (020405...300)</tt></td>
<td>enabled with:<tt><strong> --log-tcp-options</strong></tt><br />
TCP options.  This variable length field gets a lot of use.       Important options include: Window Scaling, Selective Acknowledgement        and Explicit Congestion Notification.</td>
</tr>
<tr bgcolor="#e0ffe0">
<td valign="top"><tt> </tt></td>
<td>Unfortunately the rule number in the chain which matched the packet        is for architectural reasons not available in netfilter logs.       You will have to &#8220;cook your own&#8221; by using the user-prefix feature.</td>
</tr>
</tbody>
</table>
<p>More interesting files, such as <strong><em>multicast-addresses</em></strong>, can be found in  <a rel="nofollow" href="http://www.iana.org/protocols/"> http://www.iana.org/protocols/</a>.</p>
<h3><a href="http://logi.cc/en/2010/07/netfilter-log-format-issues/">Issues with netfilter log format</a></h3>
<h2>Protocol Header Information</h2>
<h4>IP Header Format as defined in <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc791.html">RFC-791</a>:</h4>
<table style="height: 290px;" border="1" cellspacing="0" cellpadding="0" width="550">
<tbody>
<tr>
<td width="20" align="center">0</td>
<td width="20" align="center">1</td>
<td width="20" align="center">2</td>
<td width="20" align="center">3</td>
<td width="20" align="center">4</td>
<td width="20" align="center">5</td>
<td width="20" align="center">6</td>
<td width="20" align="center">7</td>
<td width="20" align="center">8</td>
<td width="20" align="center">9</td>
<td width="20" align="center">10</td>
<td width="20" align="center">11</td>
<td width="20" align="center">12</td>
<td width="20" align="center">13</td>
<td width="20" align="center">14</td>
<td width="20" align="center">15</td>
<td width="20" align="center">16</td>
<td width="20" align="center">17</td>
<td width="20" align="center">18</td>
<td width="20" align="center">19</td>
<td width="20" align="center">20</td>
<td width="20" align="center">21</td>
<td width="20" align="center">22</td>
<td width="20" align="center">23</td>
<td width="20" align="center">24</td>
<td width="20" align="center">25</td>
<td width="20" align="center">26</td>
<td width="20" align="center">27</td>
<td width="20" align="center">28</td>
<td width="20" align="center">29</td>
<td width="20" align="center">30</td>
<td width="20" align="center">31</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="4" height="30" align="center">IP Version</td>
<td colspan="4" align="center">Hdr.Length</td>
<td colspan="8" align="center" bgcolor="#c8c8c8"><strong>TOS / DS,ECN</strong></td>
<td colspan="16" align="center">Total Length</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="16" height="30" align="center">Identification</td>
<td align="center">-</td>
<td align="center">DF</td>
<td align="center">MF</td>
<td colspan="13" align="center">Fragment Offset</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="8" height="30" align="center">Time To Live</td>
<td colspan="8" align="center">Protocol Number</td>
<td colspan="16" align="center">Header Checksum</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="32" height="30" align="center">32 bit Source Address</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="32" height="30" align="center">32 bit Destination Address</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="32" height="40" align="center">Options (0 to 10 Words of 32 Bits)</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" align="center">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr bgcolor="#ffffe0">
<td height="20" align="center"></td>
</tr>
<tr bgcolor="#e0ffff">
<td height="60" align="center" valign="top">IP Payload<br />
(including header of heigher protocol)</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The header of an IP packet consists of 5 or more words of 32 bits (4 bytes) each.  The minimum header length (no options) is therefore 20 bytes.  The Version field for the shown type of packet is 4 = IPv4 (Internet Protocol version 4).  The header Length field is the header length in 32bit words, this would be 5 without options,  and at most 15 with options.  The Total Length is in bytes and includes the header.  Data length can then be calculated from the supplied values.</p>
<p><strong>TOS / DS / ECN</strong>:   This field has had an unstable history.   This is briefly explained in <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>, section 19 (near the end).</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td></td>
<td width="20" align="center">0</td>
<td width="20" align="center">1</td>
<td width="20" align="center">2</td>
<td width="20" align="center">3</td>
<td width="20" align="center">4</td>
<td width="20" align="center">5</td>
<td width="20" align="center">6</td>
<td width="20" align="center">7</td>
</tr>
<tr>
<td height="28" align="center">TOS</td>
<td colspan="3" align="center" bgcolor="#c8c8c8">Precedence</td>
<td colspan="4" align="center" bgcolor="#c8c8c8">Type</td>
<td align="center" bgcolor="#c8c8c8">-</td>
</tr>
<tr>
<td height="28" align="center">DS,ECN</td>
<td colspan="6" align="center" bgcolor="#e2e2e2">DS Codepoint</td>
<td align="center" bgcolor="#ffffe0">ECT</td>
<td align="center" bgcolor="#ffffe0">CE</td>
</tr>
</tbody>
</table>
<p>Many sites are starting to implement Differentiated Services DS  [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2474.html">RFC2474</a>]  in their routers.  DS uses <em>code-points</em> which are stored in bits 0 to 5 of the old TOS field.  The content and meaning of this field can change at network boundaries.</p>
<p>If the host is ECN  [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>] capable and the payload is a TCP packet, then up to two flag bits will be needed in the old TOS field. Bit 6 becomes the <strong>ECT</strong> (ECN-capable Transport) flag, and Bit 7 becomes the <strong>CE</strong> (Congestion Experienced) flag.</p>
<p>IP datagrams can be fragmented if the link layer cannot fit it into a single link layer data unit.  The fragment offset is specified in units of <em>8-bytes</em>,  thus allowing the available 13 bits to cover the necessary values for up to 64K of  data.</p>
<p>IP packets usually carry a higher level protocol such as TCP.  In the case of TCP, the PROTO field would be set to 6 and the  TCP <em>Protocol Data Unit</em> (PDU)  is carried in the IP Payload field of the packet.  See below.</p>
<h4>TCP Header Format (as defined in <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc793.html">RFC-793</a>):</h4>
<div style="font: normal 10px Tahoma, Geneva, sans-serif;">
<table style="height: 274px;" border="1" cellspacing="0" cellpadding="0" width="550">
<tbody>
<tr>
<td width="15" align="center">0</td>
<td width="15" align="center">1</td>
<td width="15" align="center">2</td>
<td width="15" align="center">3</td>
<td width="15" align="center">4</td>
<td width="15" align="center">5</td>
<td width="15" align="center">6</td>
<td width="15" align="center">7</td>
<td width="15" align="center">8</td>
<td width="15" align="center">9</td>
<td width="15" align="center">10</td>
<td width="15" align="center">11</td>
<td width="15" align="center">12</td>
<td width="15" align="center">13</td>
<td width="15" align="center">14</td>
<td width="15" align="center">15</td>
<td width="15" align="center">16</td>
<td width="15" align="center">17</td>
<td width="15" align="center">18</td>
<td width="15" align="center">19</td>
<td width="15" align="center">20</td>
<td width="15" align="center">21</td>
<td width="15" align="center">22</td>
<td width="15" align="center">23</td>
<td width="15" align="center">24</td>
<td width="15" align="center">25</td>
<td width="15" align="center">26</td>
<td width="15" align="center">27</td>
<td width="15" align="center">28</td>
<td width="15" align="center">29</td>
<td width="15" align="center">30</td>
<td width="15" align="center">31</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Source Port</td>
<td colspan="16" align="center">Destination Port</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" height="30" align="center">Sequence Number</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" height="30" align="center">Acknowledgement Number</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="4" height="30" align="center">Data<br />
Offset</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center"><img src="http://logi.cc/images/CWR.gif" alt="CWR" /></td>
<td align="center"><img src="http://logi.cc/images/ECNE.gif" alt="ECNE" /></td>
<td align="center"><img src="http://logi.cc/images/URG.gif" alt="URG" /></td>
<td align="center"><img src="http://logi.cc/images/ACK.gif" alt="ACK" /></td>
<td align="center"><img src="http://logi.cc/images/PSH.gif" alt="PSH" /></td>
<td align="center"><img src="http://logi.cc/images/RST.gif" alt="RST" /></td>
<td align="center"><img src="http://logi.cc/images/SYN.gif" alt="SYN" /></td>
<td align="center"><img src="http://logi.cc/images/FIN.gif" alt="FIN" /></td>
<td colspan="16" align="center">Window</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Checksum</td>
<td colspan="16" height="30" align="center">Urgent Pointer</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" height="40" align="center">Options (0 to 10 Words of 32 Bits)</td>
</tr>
<tr bgcolor="#e0ffff">
<td colspan="32" height="60" align="center">TCP Payload</td>
</tr>
</tbody>
</table>
</div>
<p>The header of a TCP packet consists of 5 or more words of 32 bits (4 bytes) each.  The minimum header length (no options) is therefore 20 bytes.  The <em>Data Offset</em> field is the header length in 32bit words, this would be 5 without options,  and at most 15 with options.</p>
<p>Explicit Congestion Notification (ECN) [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>] adds 2 new flags to the TCP header: <em>Congestion Window Reduced</em> (CWR) and  <em>ECN-Echo</em> (ECNE).  ECN also requires 1 or 2 additional flags in the IP header.</p>
<p>Commonly, the TCP header will carry options related to enhancements  of the TCP protocol.  Important options are Window Scaling, Selective  Acknowledgement (SACK) [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2018.html">RFC2018</a>, <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2883.html">RFC2883</a>]  and Explicit Congestion Notification (ECN) [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>].</p>
<p>TCP data payload length is the IP payload length minus the TCP header length.</p>
<p>TCP packets usually carry an application level data stream, f.e. HTTP, FTP, Telnet, SSH, etc.</p>
<h4>UDP Header format (as defined in <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc768.html">RFC-768</a>):</h4>
<table border="1" cellspacing="0" cellpadding="0" width="640">
<tbody>
<tr>
<td width="20" align="center">0</td>
<td width="20" align="center">1</td>
<td width="20" align="center">2</td>
<td width="20" align="center">3</td>
<td width="20" align="center">4</td>
<td width="20" align="center">5</td>
<td width="20" align="center">6</td>
<td width="20" align="center">7</td>
<td width="20" align="center">8</td>
<td width="20" align="center">9</td>
<td width="20" align="center">10</td>
<td width="20" align="center">11</td>
<td width="20" align="center">12</td>
<td width="20" align="center">13</td>
<td width="20" align="center">14</td>
<td width="20" align="center">15</td>
<td width="20" align="center">16</td>
<td width="20" align="center">17</td>
<td width="20" align="center">18</td>
<td width="20" align="center">19</td>
<td width="20" align="center">20</td>
<td width="20" align="center">21</td>
<td width="20" align="center">22</td>
<td width="20" align="center">23</td>
<td width="20" align="center">24</td>
<td width="20" align="center">25</td>
<td width="20" align="center">26</td>
<td width="20" align="center">27</td>
<td width="20" align="center">28</td>
<td width="20" align="center">29</td>
<td width="20" align="center">30</td>
<td width="20" align="center">31</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Source Port</td>
<td colspan="16" align="center">Destination Port</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Total Length</td>
<td colspan="16" height="30" align="center">Checksum (optional)</td>
</tr>
<tr bgcolor="#e0ffff">
<td colspan="32" height="60" align="center">UDP Payload</td>
</tr>
</tbody>
</table>
<p>The header of a UDP packet consists of 2 words of 32 bits (4 bytes) each.  The header length is therefore always 8 bytes.   The <em>Total Length</em> field includes the UDP header and is measured  in bytes.</p>
<p>UDP packets usually carry an application level datagram as their payload, f.e. DNS, NTP, NFS, etc.</p>
<p>You can found useful information about cancer symptoms on the  <a href="http://silcaat.com/">silcaat.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://logi.cc/en/2010/07/netfilter-log-format/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Netfilter Log Format Issues</title>
		<link>http://logi.cc/en/2010/07/netfilter-log-format-issues/</link>
		<comments>http://logi.cc/en/2010/07/netfilter-log-format-issues/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 07:00:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[netfilter]]></category>

		<guid isPermaLink="false">http://logi.cc/en/?p=32</guid>
		<description><![CDATA[Positives Netfilter logs are intuitive and easy to read by the occasional, non-expert admin. They provide much more information than f.e. ipchains, in particular about the transport protocol. Show the header of messages returned inside an ICMP packet. Consistency Issues Most items in the log use the LABEL=value format, but: flags appear on their own, [...]]]></description>
			<content:encoded><![CDATA[<h3>Positives</h3>
<ol>
<li>Netfilter logs are intuitive and easy to read by the occasional,      non-expert admin.</li>
<li>They provide much more information than f.e. ipchains, in particular      about the transport protocol.</li>
<li>Show the header of messages returned inside an ICMP packet.</li>
</ol>
<h3>Consistency Issues</h3>
<ol>
<li>Most items in the log use the <tt><strong>LABEL=value</strong></tt> format, but:<br />
flags appear on their own,<br />
options use &#8220;<tt><strong>OPT (abc..)</strong></tt>&#8220;, and<br />
<em>incomplete</em> is flagged like this:      &#8220;<tt><strong>INCOMPLETE [12 bytes]</strong></tt>&#8220;!<br />
The latter would also be much more useful if it showed the data:<br />
&#8220;<tt><strong>INCOMPLETE=0050445ACAFEAFFEEFFAEFAC</strong></tt>&#8220;.</li>
<li>The TOS field is ripped apart into &#8220;TOS&#8221; and &#8220;PREC&#8221;.  This is particularly bad      because TOS is increasingly being replaced by DS and ECN.</li>
<li>The two MAC addresses and the type-code are thrown together into      one 14 byte sequence.</li>
<li>Recursive headers are enclosed in <tt><strong>[..]</strong></tt> but the <tt><strong>[..]</strong></tt> are also used for other purposes including inside a recursive header.</li>
<li>Having a variable number of fields makes it impossible to quickly extract     specific information.  F.e. the following will fail miserably if the number      of IP options varies:<br />
<strong><tt>awk '/DPT=53 /{printf("%s %s\n", $10, $15)} logfile'</tt></strong></li>
<li>The user prefix ought not to allow white space.      Having a variable number of spaces (from different prefixes) makes it      impossible to quickly extract specific information, see previous point.</li>
</ol>
<p><span id="more-32"></span></p>
<h3>Efficiency Issues</h3>
<ol>
<li>The worst case netfilter log line would easily <strong>exceed 400 chars</strong>.</li>
<li>The sheer length of the log lines typically causes wrapping over 2      or 3 lines on a 100 column xterm.  This makes it extremely difficult      to discriminate log records and to find individual items.</li>
<li>The <tt><strong>LABEL=value</strong></tt> format with multi char labels is approximately      double the size of what it needs to be.</li>
<li>Interpreting flag bits and then printing them separately is approximately     10% as efficient as just printing the byte or word.</li>
<li>Mapping protocol numbers to names does not belong into the kernel.</li>
</ol>
<h3>Parsing Issues</h3>
<ol>
<li>Netfilter logs need a unique identifying mark.  Recognition of netfilter      logs is currently based on the <strong>hope</strong> that no other subsystem generates      the fields we are using for identification.</li>
<li>Currently, the arbitrary nature of the user prefix makes it impossible to      guarantee recognition of the start of the log record.</li>
<li>The user prefix needs to be separated from the next field by a space.     It serves no conceivable purpose to have it joined up with the      &#8220;<tt><strong>IN=</strong></tt>&#8221; field.</li>
<li>Simple extractor commands like the one below are defeated by the      variable number of fields.<br />
<strong><tt>awk '/DPT=111 /{printf("%s %s\n", $10, $15)} logfile'</tt></strong></li>
<li>The kernel code should not be burdened with providing a user interface by      interpreting flags, protocol numbers and sub-fields.</li>
<li>Header lengths need to be logged.  Since header-option logging is an iptables      option there is no way of telling if the header really did not have any      options or if they were just not logged.</li>
<li>The end of a log line needs to be reliably detectable by an unique field that     is guaranteed to be present in all records.  Relying on the EOL is unreliable     because &#8220;newline&#8221; chars <strong>do</strong> occur in mid record if logging on the console      and they can also be introduced by cut-n-paste operations.</li>
</ol>
<h3>Proposal for an alternative log format</h3>
<p>Actually, there probably should be two log formats:</p>
<ol>
<li>ipchains compatible, so existing applications can continue to be used.</li>
<li>a native format that is easy to read for a moderately experienced sysop      and also parsable without resorting to unreasonable measures.</li>
</ol>
<p>This format (with all options set) aims to make logfilter output consistent,  cuts out some expansions, adds header-length (HLEN) fields and has a terminating  mark &#8220;#&#8221;.</p>
<p><tt><strong> NF: USERPREFIX=userprefix IN=eth1 OUT= MAC=00808c1e1260,001076002fc2,0800   SRC=211.251.142.65 DST=203.164.4.223 LEN=100 TOS=0x00  TTL=44 ID=31526 FLAGS=0x4000 HLEN=60  OPT=072728CBA404DFCBA40253CBA4032ECBA403A2CBA4033ECBA402C1180746EA18074C52892734A200 PROTO=6 SPT=4515 DPT=111 SEQ=1168094040 ACK=0 WINDOW=32120  FLAGS=0x003 URGP=0 HLEN=40 OPT=020405B40402080A05E3F3C40000000001030300 # </strong></tt></p>
<p>We can already drop existing options (&#8211;log-ip-options, &#8211;log-tcp-sequence,  &#8211;log-tcp-options) but the labels need to be kept so the number of fields  remains constant.  In most cases we could also drop the &#8220;MAC=..&#8221; (keep the label).   These measures reduce the log to a more managable size:</p>
<p><tt><strong> NF: USERPREFIX=userprefix IN=eth1 OUT= MAC SRC=211.251.142.65 DST=203.164.4.223  LEN=100 TOS=0x00 TTL=44 ID=31526 FLAGS=0x4000 HLEN=60 OPT PROTO=6  SPT=4515 DPT=111 SEQ ACK WINDOW=32120 FLAGS=0x003 URGP HLEN=40 OPT # </strong></tt></p>
<p>Slightly re-ordering and shortening labels to single chars, but keeping labels  for empty fields and reverting to the well known <strong>IP:PORT</strong> notation:</p>
<p><tt><strong> NF: U=userprefix 211.251.142.65:4515 203.164.4.223:111 I=eth1 O M L=100  S=0x00 T=44 I=31526 F=0x4000 H=60 P=6 S A W=32120 F=0x003 U H=40 O # </strong></tt></p>
<h3>Other remedies</h3>
<p>Harald Welte has written a ULOG module which provides and interface for  a user-space daemon.  This facility might allow a user-space plugin to  produce customized output.  It also won&#8217;t have to go through the old, inefficient syslog mechanism.</p>
<p>Unfortunately ULOG is not part of the kernel distribution yet.  But it is  available from <a href="http://gnumonks.org/projects/" rel="nofollow">http://gnumonks.org/projects/</a> for those who are willing and able to patch the kernel.</p>
]]></content:encoded>
			<wfw:commentRss>http://logi.cc/en/2010/07/netfilter-log-format-issues/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ipchains Log Format</title>
		<link>http://logi.cc/en/2010/07/ipchains-log-format/</link>
		<comments>http://logi.cc/en/2010/07/ipchains-log-format/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 10:05:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[ipchains]]></category>

		<guid isPermaLink="false">http://logi.cc/en/?p=16</guid>
		<description><![CDATA[Here is a quick reference for the format used by the ipchains log messages. This is mostly taken from the ipchains-HOWTO A typical log message generated by ipchains: Jun 16 08:00:38 megahard kernel: Packet log: forward DENY eth1 PROTO=17 a.b.c.d:234 w.x.y.z:34567 L=78 S=0x00 I=13413 F=0x0000 T=112 (#16) The leading part is self explanatory. The remaining [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick reference for the format used by the ipchains log messages.   This is mostly taken from the <em><a rel="nofollow" href="http://tldp.org/HOWTO/IPCHAINS-HOWTO.html">ipchains-HOWTO</a></em></p>
<p>A typical log message generated by ipchains:</p>
<p><tt><strong>Jun 16 08:00:38 megahard kernel: Packet log: forward DENY </strong></tt><br />
<tt><strong>eth1 PROTO=17 a.b.c.d:234 w.x.y.z:34567 L=78 S=0x00 I=13413 </strong></tt><br />
<tt><strong>F=0x0000 T=112 (#16)</strong></tt></p>
<p>The leading part is self explanatory.  The remaining items are explained in sequence here:</p>
<table style="height: 366px;" border="1" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr bgcolor="#e0ffe0">
<td><tt>forward</tt></td>
<td>Name of the chain which was traversed by the packet</td>
</tr>
<tr bgcolor="#e0ffe0">
<td><tt>DENY</tt></td>
<td>action taken by ipchains</td>
</tr>
<tr bgcolor="#e0ffe0">
<td><tt>eth1</tt></td>
<td>interface the packet was passing through</td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>PROTO=17</tt></td>
<td>Protocol number. A list is in your <em>/etc/protocols</em>.  A complete       list is in the file        <a rel="nofollow" href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml"> <strong><em>protocol-numbers</em></strong></a></td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>a.b.c.d</tt></td>
<td>source IP address</td>
</tr>
<tr bgcolor="#ffffe0">
<td><tt>234</tt></td>
<td>source port (TCP and UDP) or the ICMP type.  A list of port numbers       is in your /<em>etc/services</em>.  A complete list is in the file        <a rel="nofollow" href="http://www.iana.org/assignments/port-numbers"> <strong><em>port-numbers</em></strong></a></td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>w.x.y.z</tt></td>
<td>destination IP address</td>
</tr>
<tr bgcolor="#ffffe0">
<td><tt>34567</tt></td>
<td>destination port (TCP and UDP) or the ICMP code.  A list of ICMP       types and codes is in the file        <a rel="nofollow" href="http://www.iana.org/assignments/icmp-parameters"> <strong><em>icmp-parameters</em></strong></a></td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>L=78</tt></td>
<td>total Length of packet in bytes</td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>S=0x00</tt></td>
<td>type of Service (TOS), only 4 bits used these days, not important for       firewall purposes</td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>I=13413</tt></td>
<td>IP-ID, increments with each packet sent</td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>F=0x0000</tt></td>
<td>Flags (3 bits) and Fragment offset (13 bits)</td>
</tr>
<tr bgcolor="#e2e2e2">
<td><tt>T=112</tt></td>
<td>Time to live (TTL) or hops remaining before packet is dropped</td>
</tr>
<tr bgcolor="#e0ffe0">
<td><tt>(#16)</tt></td>
<td>rule number in the chain which matched the packet and caused the log</td>
</tr>
</tbody>
</table>
<p>More interesting files, such as <strong><em>multicast-addresses</em></strong>, can be found in  <a rel="nofollow" href="http://www.iana.org/protocols/"> http://www.iana.org/protocols/</a>.</p>
<p><span id="more-16"></span></p>
<h2>Protocol Header Information</h2>
<p><a name="IPheader"></a></p>
<h4>IP Header Format as defined in <a rel="nofolow" href="http://www.faqs.org/rfcs/rfc791.html">RFC-791</a>:</h4>
<table style="height: 292px;" border="1" cellspacing="0" cellpadding="0" width="500">
<tbody>
<tr>
<td width="20" align="center">0</td>
<td width="20" align="center">1</td>
<td width="20" align="center">2</td>
<td width="20" align="center">3</td>
<td width="20" align="center">4</td>
<td width="20" align="center">5</td>
<td width="20" align="center">6</td>
<td width="20" align="center">7</td>
<td width="20" align="center">8</td>
<td width="20" align="center">9</td>
<td width="20" align="center">10</td>
<td width="20" align="center">11</td>
<td width="20" align="center">12</td>
<td width="20" align="center">13</td>
<td width="20" align="center">14</td>
<td width="20" align="center">15</td>
<td width="20" align="center">16</td>
<td width="20" align="center">17</td>
<td width="20" align="center">18</td>
<td width="20" align="center">19</td>
<td width="20" align="center">20</td>
<td width="20" align="center">21</td>
<td width="20" align="center">22</td>
<td width="20" align="center">23</td>
<td width="20" align="center">24</td>
<td width="20" align="center">25</td>
<td width="20" align="center">26</td>
<td width="20" align="center">27</td>
<td width="20" align="center">28</td>
<td width="20" align="center">29</td>
<td width="20" align="center">30</td>
<td width="20" align="center">31</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="4" height="30" align="center">IP Version</td>
<td colspan="4" align="center">Hdr.Length</td>
<td colspan="8" align="center" bgcolor="#c8c8c8"><strong>TOS / DS,ECN</strong></td>
<td colspan="16" align="center">Total Length</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="16" height="30" align="center">Identification</td>
<td align="center">-</td>
<td align="center">DF</td>
<td align="center">MF</td>
<td colspan="13" align="center">Fragment Offset</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="8" height="30" align="center">Time To Live</td>
<td colspan="8" align="center">Protocol Number</td>
<td colspan="16" align="center">Header Checksum</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="32" height="30" align="center">32 bit Source Address</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="32" height="30" align="center">32 bit Destination Address</td>
</tr>
<tr bgcolor="#e2e2e2">
<td colspan="32" height="40" align="center">Options (0 to 10 Words of 32 Bits)</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" align="center">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr bgcolor="#ffffe0">
<td height="20" align="center"></td>
</tr>
<tr bgcolor="#e0ffff">
<td height="60" align="center" valign="top">IP Payload<br />
(including header of heigher protocol)</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The header of an IP packet consists of 5 or more words of 32 bits (4 bytes) each.  The minimum header length (no options) is therefore 20 bytes.  The Version field for the shown type of packet is 4 = IPv4 (Internet Protocol version 4).  The header Length field is the header length in 32bit words, this would be 5 without options,  and at most 15 with options.  The Total Length is in bytes and includes the header.  Data length can then be calculated from the supplied values. <strong>TOS / DS / ECN</strong>:   This field has had an unstable history.   This is briefly explained in <a rel="nofolow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>, section 19 (near the end).Many sites are starting to implement Differentiated Services DS  [<a rel="nofolow" href="http://www.faqs.org/rfcs/rfc2474.html">RFC2474</a>]  in their routers.  DS uses <em>code-points</em> which are stored in bits 0 to 5 of the old TOS field.  The content and meaning of this field can change at network boundaries.</p>
<td valign="top">
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td></td>
<td width="20" align="center">0</td>
<td width="20" align="center">1</td>
<td width="20" align="center">2</td>
<td width="20" align="center">3</td>
<td width="20" align="center">4</td>
<td width="20" align="center">5</td>
<td width="20" align="center">6</td>
<td width="20" align="center">7</td>
</tr>
<tr>
<td height="28" align="center">TOS</td>
<td colspan="3" align="center" bgcolor="#c8c8c8">Precedence</td>
<td colspan="4" align="center" bgcolor="#c8c8c8">Type</td>
<td align="center" bgcolor="#c8c8c8">-</td>
</tr>
<tr>
<td height="28" align="center">DS,ECN</td>
<td colspan="6" align="center" bgcolor="#e2e2e2">DS Codepoint</td>
<td align="center" bgcolor="#ffffe0">ECT</td>
<td align="center" bgcolor="#ffffe0">CE</td>
</tr>
</tbody>
</table>
<p>If the host is ECN  [<a rel="nofolow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>] capable and the payload is a TCP packet, then up to two flag bits will be needed in the old TOS field. Bit 6 becomes the <strong>ECT</strong> (ECN-capable Transport) flag, and Bit 7 becomes the <strong>CE</strong> (Congestion Experienced) flag.IP datagrams can be fragmented if the link layer cannot fit it into a single link layer data unit.  The fragment offset is specified in units of <em>8-bytes</em>,  thus allowing the available 13 bits to cover the necessary values for up to 64K of  data.</p>
<p>    IP packets usually carry a higher level protocol such as TCP.  In the case of TCP, the PROTO field would be set to 6 and the  TCP <em>Protocol Data Unit</em> (PDU)  is carried in the IP Payload field of the packet.  See below.</p>
<h4>TCP Header Format (as defined in <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc793.html">RFC-793</a>):</h4>
<div style="font: normal 10px Tahoma, Geneva, sans-serif;">
<table style="height: 268px;" border="1" cellspacing="0" cellpadding="0" width="500">
<tbody>
<tr>
<td width="15" align="center">0</td>
<td width="15" align="center">1</td>
<td width="15" align="center">2</td>
<td width="15" align="center">3</td>
<td width="15" align="center">4</td>
<td width="15" align="center">5</td>
<td width="15" align="center">6</td>
<td width="15" align="center">7</td>
<td width="15" align="center">8</td>
<td width="15" align="center">9</td>
<td width="15" align="center">10</td>
<td width="15" align="center">11</td>
<td width="15" align="center">12</td>
<td width="15" align="center">13</td>
<td width="15" align="center">14</td>
<td width="15" align="center">15</td>
<td width="15" align="center">16</td>
<td width="15" align="center">17</td>
<td width="15" align="center">18</td>
<td width="15" align="center">19</td>
<td width="15" align="center">20</td>
<td width="15" align="center">21</td>
<td width="15" align="center">22</td>
<td width="15" align="center">23</td>
<td width="15" align="center">24</td>
<td width="15" align="center">25</td>
<td width="15" align="center">26</td>
<td width="15" align="center">27</td>
<td width="15" align="center">28</td>
<td width="15" align="center">29</td>
<td width="15" align="center">30</td>
<td width="15" align="center">31</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Source Port</td>
<td colspan="16" align="center">Destination Port</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" height="30" align="center">Sequence Number</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" height="30" align="center">Acknowledgement Number</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="4" height="30" align="center">Data<br />
    Offset</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">CWR</td>
<td align="center">ECNE</td>
<td align="center">URG</td>
<td align="center">ACK</td>
<td align="center">PSH</td>
<td align="center">RST</td>
<td align="center">SYN</td>
<td align="center">FIN</td>
<td colspan="16" align="center">Window</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Checksum</td>
<td colspan="16" height="30" align="center">Urgent Pointer</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="32" height="40" align="center">Options (0 to 10 Words of 32 Bits)</td>
</tr>
<tr bgcolor="#e0ffff">
<td colspan="32" height="60" align="center">TCP Payload</td>
</tr>
</tbody>
</table></div>
<p>  The header of a TCP packet consists of 5 or more words of 32 bits (4 bytes) each.  The minimum header length (no options) is therefore 20 bytes.  The <em>Data Offset</em> field is the header length in 32bit words, this would be 5 without options,  and at most 15 with options.Explicit Congestion Notification (ECN) [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>] adds 2 new flags to the TCP header: <em>Congestion Window Reduced</em> (CWR) and  <em>ECN-Echo</em> (ECNE).  ECN also requires 1 or 2 additional flags in the IP header.</p>
<p>  Commonly, the TCP header will carry options related to enhancements  of the TCP protocol.  Important options are Window Scaling, Selective  Acknowledgement (SACK) [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2018.html">RFC2018</a>, <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2883.html">RFC2883</a>]  and Explicit Congestion Notification (ECN) [<a rel="nofollow" href="http://www.faqs.org/rfcs/rfc2481.html">RFC2481</a>].</p>
<p>  TCP data payload length is the IP payload length minus the TCP header length.</p>
<p>  TCP packets usually carry an application level data stream, f.e. HTTP, FTP, Telnet, SSH, etc.</p>
<h4>UDP Header format (as defined in <a rel="nofollow" href="http://www.faqs.org/rfcs/rfc768.html">RFC-768</a>):</h4>
<table style="height: 138px;" border="1" cellspacing="0" cellpadding="0" width="500">
<tbody>
<tr>
<td width="15" align="center">0</td>
<td width="15" align="center">1</td>
<td width="15" align="center">2</td>
<td width="15" align="center">3</td>
<td width="15" align="center">4</td>
<td width="15" align="center">5</td>
<td width="15" align="center">6</td>
<td width="15" align="center">7</td>
<td width="15" align="center">8</td>
<td width="15" align="center">9</td>
<td width="15" align="center">10</td>
<td width="15" align="center">11</td>
<td width="15" align="center">12</td>
<td width="15" align="center">13</td>
<td width="15" align="center">14</td>
<td width="15" align="center">15</td>
<td width="15" align="center">16</td>
<td width="15" align="center">17</td>
<td width="15" align="center">18</td>
<td width="15" align="center">19</td>
<td width="15" align="center">20</td>
<td width="15" align="center">21</td>
<td width="15" align="center">22</td>
<td width="15" align="center">23</td>
<td width="15" align="center">24</td>
<td width="15" align="center">25</td>
<td width="15" align="center">26</td>
<td width="15" align="center">27</td>
<td width="15" align="center">28</td>
<td width="15" align="center">29</td>
<td width="15" align="center">30</td>
<td width="15" align="center">31</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Source Port</td>
<td colspan="16" align="center">Destination Port</td>
</tr>
<tr bgcolor="#ffffe0">
<td colspan="16" height="30" align="center">Total Length</td>
<td colspan="16" height="30" align="center">Checksum (optional)</td>
</tr>
<tr bgcolor="#e0ffff">
<td colspan="32" height="60" align="center">UDP Payload</td>
</tr>
</tbody>
</table>
<p>  The header of a UDP packet consists of 2 words of 32 bits (4 bytes) each.  The header length is therefore always 8 bytes.   The <em>Total Length</em> field includes the UDP header and is measured  in bytes.</p>
<p>UDP packets usually carry an application level datagram as their payload,  f.e. DNS, NTP, NFS, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://logi.cc/en/2010/07/ipchains-log-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux Firewalls</title>
		<link>http://logi.cc/en/2010/07/linux-firewalls/</link>
		<comments>http://logi.cc/en/2010/07/linux-firewalls/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 08:58:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://logi.cc/en/?p=9</guid>
		<description><![CDATA[Packet filtering firewall: Linux ipchains implement a packet filtering firewall and can be considered medium security if implemented properly.  A packet filtering firewall looks at each packet individually, it does not (can not) consider any previous packets which may be part of a multiple packet transaction.  In other words, a packet filtering firewall is stateless. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Packet filtering firewall:</strong></p>
<blockquote><p>Linux ipchains implement a <strong>packet filtering firewall</strong> and can be considered medium security if implemented properly.  A packet filtering firewall looks at each packet individually, it does not (can not) consider any previous packets which may be part of a multiple packet transaction.  In other words, a packet filtering firewall is stateless.</p></blockquote>
<p><span id="more-9"></span></p>
<h4>ipchains firewall (minimal survival rules):</h4>
<blockquote><p>No time to do it properly?  Want to get on-line fast?  Here is a <strong><a href="http://logi.cc/linux/minimalIPChainsRules.txt">minimal ipchains rule-set</a></strong> for Linux kernels 2.2.x.   But don&#8217;t trust me!  Once you have it installed, test it <a href="http://logi.cc/en/2010/07/what-is-the-difference-between-reject-and-deny/"> here</a>.  At the time of writing the latest kernel was 2.2.16, the information provided here has been tested with this kernel.The intention of providing this rule-set is to allow you to get on-line quickly while providing you with basic security until you have had time to implement something better.</p>
<p>No attempt has been made to optimize the rule-set.  It is quite conceiveable that you can re-order the rules or even reduce the number of rules &#8211; feel free to do that if you want to.  However, ipchains are quite efficient.  Each rule only takes a few micro seconds to traverse, so there is not much to be gained unless you have lots of rules, e.g. hundreds.</p>
<p>I am planning on putting <strong>a more elaborate ruleset</strong> here (the one I use on my own firewall) once I get around to cleaning it up.    <img src='http://enlogicc.s3.amazonaws.com/en/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p></blockquote>
<h4>Stateful Firewalls:</h4>
<blockquote><p>A more secure solution can be provided by a <strong>stateful firewall.</strong> Such a firewall knows about many different protocols and it can look at the context of each packet and then filter according to that.Linux kernels 2.4.x have <strong><a rel="nofollow" href="http://www.netfilter.org/">Netfilter</a></strong> which allows you to implement a stateful firewall.</p>
<p>A commercial, stateful firewall with an usable, free, limited edition is the <strong><a rel="nofollow" href="http://www.gnatbox.com/">Gnatbox</a></strong>.</p>
<p>A <strong>proxy server</strong> does essentially the same thing as a stateful firewall for the protocol it is designed for, but the design motivation for a proxy server may not be security.  It could be performance (squid)  or to block obnoxious material (junkbuster).  &#8220;Socks&#8221; is a proxy server designed as a security measure; I found it to be unsatisfactory on my system, but YMMV.</p></blockquote>
<h4>Layered security:</h4>
<blockquote><p>It is common knowledge that several layers of security are better than one.  What sometimes is not so clear is that more of the same is not necessarily better, e.g. two identical firewalls are not much more secure than a single firewall.  The basic idea of multiple layers is to have something like this:</p>
<table width="85%">
<tbody>
<tr>
<td valign="top">1st layer:</td>
<td valign="top">Packet filtering firewall.  Non essential services removed.</td>
</tr>
<tr>
<td valign="top">2nd layer:</td>
<td valign="top">Logging to a separate host or a printer (hardcopy).  Intrusion detection installed.</td>
</tr>
<tr>
<td valign="top">3rd layer:</td>
<td>Where appropriate, servers installed in a <span style="text-decoration: underline;">chroot</span>ed &#8220;jail&#8221;.  Telnet, ftp and other programs which transmit passwords in clear text eliminated or tunneled through a secure channel.</td>
</tr>
<tr>
<td valign="top">4th layer:</td>
<td valign="top">Security conscious installation of client software, e.g. no suid-root clients.</td>
</tr>
</tbody>
</table>
<p>Do I use all of those?  No, only about two thirds of this.  It is up to you to judge how much security is appropriate and if the effort and cost is worth the benefit for you.</p></blockquote>
<h4>Firewall Related Links</h4>
<blockquote><dl>Cut-down versions of Linux.  Optimized as routers and/or firewalls:
<dl>
<li><a href="http://www.zelow.no/floppyfw/index.html" rel="nofollow">Floppy Firewall</a></li>
<li><a href="http://www.toms.net/rb/" rel="nofollow">Tom&#8217;s rtbt</a> not a firewall, but a single floppy Linux system, links to similar systems.</li>
</dl>
<dt> Hardening system for various Linux distros:</dt>
<dl>
<li> <a href="http://bastille-linux.sourceforge.net/" rel="nofollow">Bastille Linux</a></li>
</dl>
<dt> A commercial firewall, and a limited but still useful, no-cost version:</dt>
<dl>
<li> <a href="http://www.gnatbox.com/" rel="nofollow">GNAT Box &#8211; The Simple Powerful and Affordable Firewall</a></li>
</dl>
<dt> <a name="port-scanning-services"></a>Port Scanning Services:</dt>
<dl>
<li> <a href="http://security.symantec.com/sscv6/home.asp" rel="nofollow">Norton Online Systems</a> (good)</li>
</dl>
<dt> Intrusion Detection:</dt>
<dl>
<li> <a href="http://tripwire.org/" rel="nofollow">Tripwire</a></li>
<li> <a href="http://www.snort.org/" rel="nofollow">Snort!</a></li>
</dl>
<dt>Secure Servers and Clients:</dt>
<p> Get rid of telnet and ftp.  Use ssh, scp, rsync instead.
<dl>
<li><a href="http://www.openssh.com/" rel="nofollow">OpenSSH</a> Excellent implementation of ssh1 and ssh2.</li>
<li><a href="http://www.samba.org/rsync/" rel="nofollow">rsync</a> can be used  with ssh.  It is a <strong>really useful</strong> utility to keep directories  on a remote hosts in synch with the local version, or vice versa.   Also uses conpression and does incremental updates.  <strong>Hint</strong>:  explore ssh-agent (part of ssh).</li>
</dl>
<dt> Other useful information:</dt>
<dl>
<li> <a href="http://www.allwhois.com/">Allwhois.com &#8211; Search any domain name in the world!</a></li>
</dl>
</dl>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://logi.cc/en/2010/07/linux-firewalls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is the difference between REJECT and DENY?</title>
		<link>http://logi.cc/en/2010/07/what-is-the-difference-between-reject-and-deny/</link>
		<comments>http://logi.cc/en/2010/07/what-is-the-difference-between-reject-and-deny/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 08:23:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[deny]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[reject]]></category>

		<guid isPermaLink="false">http://logi.cc/en/?p=10</guid>
		<description><![CDATA[With ipchains you can ACCEPT, REJECT or DENY a packet.  What ACCEPT does is self-explainatory, but nearly everybody  asks what the difference between REJECT and DENY is and which one is better.  And how does nmap see the ports? Below is my attempt at explaining the differences.  The example transactions were captured with tcpdump. REJECT [...]]]></description>
			<content:encoded><![CDATA[<p>With <strong><tt>ipchains</tt></strong> you can <em>ACCEPT</em>, <em>REJECT</em> or <em>DENY</em> a packet.  What <em>ACCEPT</em> does is self-explainatory, but nearly everybody  asks what the difference between <em>REJECT</em> and <em>DENY</em> is and which one is better.  And how does <strong><tt>nmap</tt></strong> see the ports?</p>
<p>Below is my attempt at explaining the differences.  The example transactions were captured with <strong><tt>tcpdump</tt></strong>.</p>
<p style="text-align: left;"><span id="more-10"></span></p>
<h2><span style="color: #000099;">REJECT</span></h2>
<blockquote><p>means that for every packet received an <strong>ICMP port unreachable</strong> packet is sent to the source address.  Of course this tells the remote host that your system is up and running and that you are running a firewall.For the identd service (port 113) read the identd section further down.</p>
<p><strong><span style="color: #ff6600;">Example: </span></strong> Port <tt>23</tt> is set to REJECT:</p>
<p><tt>08:29:33.908826 reddwarf.xix.com.2876 &gt; megahard.xix.com.23: S</tt></p>
<p><tt> 611071769:611071769(0) win 32120</tt></p>
<p><tt> &lt;mss 1460,sackOK,timestamp 8136624[|tcp]&gt; (DF) [tos 0x10]</tt></p>
<p><tt>08:29:33.908826 megahard.xix.com &gt; reddwarf.xix.com:</tt></p>
<p><tt> icmp: megahard.xix.com tcp port 23 unreachable [tos 0xd0]</tt></p>
<p>The response to the syn-packet (S) is an ICMP port &#8220;unreachable&#8221;;.</p></blockquote>
<h2><span style="color: #000099;">DENY</span></h2>
<blockquote><p>means the packet is discarded, dropped to the floor, assigned to oblivion.  No reply packet of any kind is sent.  (In the new <strong><tt>iptables</tt></strong> for <strong>Linux 2.4</strong>, this is now called <strong><em>DROP</em></strong>, which is clearer than <strong><em>DENY</em></strong>).If you set a rule which matches a particular source address and a rule-target of <em>DENY</em>, then your computer may as well be turned off as far as that source address is concerned.  However, if you <em>DENY</em> some port ranges, say ports below 1024, and allow others, then it is also obvious that you are running a firewall.</p>
<p>For the identd service (port 113) read the identd section further down.</p>
<p><span style="color: #ff6600;"><strong>Example:</strong> </span>Port <tt>24</tt> is set to DENY:</p>
<p><tt>08:29:36.138037 reddwarf.xix.com.2877 &gt; megahard.xix.com.24: S</tt></p>
<p><tt> 621695306:621695306(0) win 32120</tt></p>
<p><tt> &lt;mss 1460,sackOK,timestamp 8136847[|tcp]&gt; (DF) [tos 0x10]</tt></p>
<p>There is no response to the syn-packet (S) and <tt>reddwarf</tt> keeps trying a few more times.</p></blockquote>
<h2><span style="color: #000099;">ACCEPT  (or no firewall)</span></h2>
<blockquote><p>There are two cases here.  Either there is a service listening on that port or not.<span style="color: #ff6600;"><strong>Example:</strong> </span> Port <tt>12345</tt> with <strong>no service</strong> listening:</p>
<p><tt>08:43:11.386320 reddwarf.xix.com.1302 &gt; megahard.xix.com.12345: S</tt></p>
<p><tt> 1961263534:1961263534(0) win 32120</tt></p>
<p><tt> &lt;mss 1460,sackOK,timestamp 7858375[|tcp]&gt; (DF) [tos 0x10]</tt></p>
<p><tt>08:43:11.386320 megahard.xix.com.12345 &gt; reddwarf.xix.com.1302: R</tt></p>
<p><tt> 0:0(0) ack 1961263535 win 0 [tos 0x10]</tt></p>
<p>The response to the syn-packet (S) is a connection reset (R).  This is <strong><span style="text-decoration: underline;">clearly different</span></strong> from what you get from an ipchains firewall.</p>
<p><span style="color: #ff6600;"><strong>Example:</strong> </span> Port <tt>22</tt> with <strong><tt>sshd</tt></strong> listening:</p>
<p><tt>08:41:27.840998 reddwarf.xix.com.2878 &gt; megahard.xix.com.22: S</tt></p>
<p><tt> 1377668429:1377668429(0) win 32120</tt></p>
<p><tt> &lt;mss 1460,sackOK,timestamp 8208017[|tcp]&gt; (DF)</tt></p>
<p><tt>08:41:27.840998 megahard.xix.com.22 &gt; reddwarf.xix.com.2878: S</tt></p>
<p><tt> 1362603816:1362603816(0) ack 1377668430 win 32120</tt></p>
<p><tt> &lt;mss 1460,sackOK,timestamp 62682656[|tcp]&gt; (DF)</tt></p>
<p><tt>08:41:27.840998 reddwarf.xix.com.2878 &gt; megahard.xix.com.22: .</tt></p>
<p><tt> ack 1 win 32120 &lt;nop,nop,timestamp 8208017 62682656&gt; (DF)</tt></p>
<p>A successfully established TCP connection.  The hosts have exchanged and acknowleged their respective syn-packets (S).</p></blockquote>
<hr />
<h2><span style="color: #000099;">How does nmap see these ports?</span></h2>
<blockquote><p>As before, port 21 is not used (it has nothing listening on it).</p>
<p>Port 22 is open with ssh listening.</p>
<p>Ports 23 and 24 have these ipchains rules:</p>
<p><tt>megahard:# ipchains -I input -i eth0 -p tcp --dport 23 -j REJECT</tt></p>
<p><tt>megahard:# ipchains -I input -i eth0 -p tcp --dport 24 -j DENY</tt><tt>reddwarf:# nmap -sT -p 21-24 megahard</tt></p>
<p><tt>Starting nmap V. 2.12 by Fyodor (fyodor@dhp.com, www.insecure.org/nmap/)</tt></p>
<p><tt>Interesting ports on megahard (192.168.1.1):</tt></p>
<p><tt>Port    State       Protocol  Service</tt></p>
<p><tt>22      open        tcp        ssh</tt></p>
<p><tt>23      filtered    tcp        telnet</tt></p>
<p><tt>24      filtered    tcp        priv-mail</tt></p>
<p><tt>Nmap run completed -- 1 IP address (1 host up) scanned in 1 second</tt></p>
<p><strong>nmap has no trouble recognising both firewalled ports as filtered!</strong></p>
<p>Presumably, it classes the DENYed port as filtered because there was a response from other ports at the same IP address.</p></blockquote>
<hr />
<h2><span style="color: #000099;">Which one is better?</span></h2>
<h3>LAN:</h3>
<blockquote><p>REJECT is appropriate for UDP packets you don&#8217;t want to accept, it causes an ICMP <strong><em>port unreachable</em></strong> reply.  The correct response to unwanted TCP packets is a <strong><em>reset</em></strong>, unfortunately ipchains is not capable of sending a TCP <strong><em>reset</em></strong>.   Sending port unreachable ICMP messages in response to a TCP packet (as REJECT does) is useless and is disregarded by many protocol stacks.  A viable option is to use DENY, which sends no reply.  Alternatively you can use a package such as <strong><a rel="nofollow" href="http://web.archive.org/web/20070206224106/http://www.bellamy.co.nz/section5.html">return-rst</a></strong> in conjunction with ipchains to produce the correct response.</p></blockquote>
<h3>Internet:</h3>
<p>I believe in making it unpleasant for people who have no business connecting to my system, so those rules use DENY.   I have also observed that once I changed most of my ipchains rules from REJECT to DENY,  the number of connection attempts has dropped to a fraction of what it used to be.</p>
<p>More recently (December 2000), I have changed back to REJECT for UDP and I use <strong><a rel="nofollow" href="http://web.archive.org/web/20070206224106/http://www.bellamy.co.nz/section5.html">return-rst</a></strong> for TCP.   For other protocols I use DENY.   Within a few days, the number of firewall hits has increased by at least a factor of two!  I&#8217;ll keep watching this for a while.</p>
<h4>identd / authd:</h4>
<blockquote><p>Some servers will attempt to establish your identity before proceeding with your connection.  If you don&#8217;t run an identd or authd, a TCP <strong><em>reset</em></strong> is normally returned and everything is fine.If you firewall port 113 with REJECT or DENY,  you are likely to experience inconvenient delays.  My recommendation is therefore to leave that port open and to make sure you don&#8217;t run a server there.  Or if you do run an identd, make sure you picked an up-to-date one with a good reputation.</p></blockquote>
<h4>Revealing the existence of a firewall?</h4>
<p>I have heard the argument that DENY gives away the presence of a firewall and REJECT does not.  The above examples prove this argument to be nonsense. It is possible to make your system look like it has not got a firewall, at least on first inspection.   Use REJECT for all UDP, and for TCP, implement a means of sending <strong><em>reset</em></strong> packets, for example with <strong><a rel="nofollow" href="http://web.archive.org/web/20070206224106/http://www.bellamy.co.nz/section5.html">return-rst</a></strong>.  Other protocols should be DENYed.</p>
]]></content:encoded>
			<wfw:commentRss>http://logi.cc/en/2010/07/what-is-the-difference-between-reject-and-deny/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Content Delivery Network via Amazon Web Services: S3: enlogicc.s3.amazonaws.com

Served from: logi.cc @ 2013-05-22 22:48:04 -->