<?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>SuperHac.com &#187; LIBIPQ</title>
	<atom:link href="http://www.superhac.com/?feed=rss2&#038;cat=4" rel="self" type="application/rss+xml" />
	<link>http://www.superhac.com</link>
	<description>Hacking on a whole new level</description>
	<lastBuildDate>Thu, 30 Oct 2008 23:10:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>LIBIPQ example Code</title>
		<link>http://www.superhac.com/?p=28</link>
		<comments>http://www.superhac.com/?p=28#comments</comments>
		<pubDate>Wed, 13 Feb 2008 14:15:40 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Netfiliter]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=28</guid>
		<description><![CDATA[I had a request for a working example of using libipq. It contains enough to get anyone started. Functions include: getting src/dst ip address, src/dst ports, identifing IP protocol(udp/tcp), get the payload, etc&#8230; There is a README in the archive on how to compile and run the example. Download]]></description>
			<content:encoded><![CDATA[<p>I had a request for a working example of using libipq.  It contains enough to get anyone started.  Functions include: getting src/dst ip address, src/dst ports, identifing IP protocol(udp/tcp), get the payload, etc&#8230;  There is a README in the archive on how to compile and run the example.</p>
<h3><a href="http://superhac.com/wp-content/uploads/2008/02/libipq_exampletar.gz" onclick="return false;" title="Direct link to file">Download</a></h3>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=28</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling LIBIPQ Examples</title>
		<link>http://www.superhac.com/?p=10</link>
		<comments>http://www.superhac.com/?p=10#comments</comments>
		<pubDate>Thu, 12 May 2005 21:10:20 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=10</guid>
		<description><![CDATA[You need the following library headers to compile the LIPIPQ examples on this page: #include &#60;linux/netfilter.h&#62; #include &#60;libipq.h&#62; #include &#60;netinet/tcp.h&#62; #include &#60;netinet/ip.h&#62;]]></description>
			<content:encoded><![CDATA[<p>You need the following library headers to compile the LIPIPQ examples on this page:</p>
<p>#include &lt;linux/netfilter.h&gt;<br />
#include &lt;libipq.h&gt;<br />
#include &lt;netinet/tcp.h&gt;<br />
#include &lt;netinet/ip.h&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=10</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining the IP protocol of a packet from LIBIPQ</title>
		<link>http://www.superhac.com/?p=11</link>
		<comments>http://www.superhac.com/?p=11#comments</comments>
		<pubDate>Thu, 03 Feb 2005 21:12:47 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Netfiliter]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=11</guid>
		<description><![CDATA[When you recieved the ipq_packet_msg structure from LIBIPQ you need to determine what IP protocol (TCP, UDP, etc) is contained after the IP header. Below is a simple fuction to determine what IP protocol is contained within the packet. int identify_ip_protocol (ipq_packet_msg_t *msg) { int protocol=0; /* 6 = TCP, 16 = UDP */ /* [...]]]></description>
			<content:encoded><![CDATA[<p>When you recieved the ipq_packet_msg structure from LIBIPQ you need to determine what IP protocol (TCP, UDP, etc) is contained after the IP header. Below is a simple fuction to determine what IP protocol is contained within the packet.</p>
<p class="code">  int identify_ip_protocol (ipq_packet_msg_t *msg)<br />
{<br />
int protocol=0;  /* 6 = TCP, 16 = UDP */</p>
<p>/* Cast the IP Header from the raw packet */<br />
struct iphdr *iph = ((struct iphdr *) msg-&gt;payload);</p>
<p>/* get the protocol identifier from the ip header */<br />
protocol = iph-&gt;protocol;</p>
<p>return(protocol);</p>
<p>}</p>
<p>Once you determine the protocol you can then cast out the next header. Like this for TCP:</p>
<p class="code">   /* Cast the TCP Header from the raw packet */<br />
struct tcphdr *tcp = (struct tcphdr *)(m-&gt;payload + (iph-&gt;ihl &lt;&lt; 2));</p>
<p>or like this for UDP:</p>
<p class="code"> /* Cast the UDP Header from the raw packet */<br />
struct udphdr *udp = (struct udphdr *) (msg-&gt;payload + (iph-&gt;ihl &lt;&lt; 2));</p>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=11</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LIBIPQ udp packet parsing</title>
		<link>http://www.superhac.com/?p=12</link>
		<comments>http://www.superhac.com/?p=12#comments</comments>
		<pubDate>Mon, 31 Jan 2005 21:14:19 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Netfiliter]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=12</guid>
		<description><![CDATA[Here&#8217;s another snippet of code for calculating and parsing a UDP packet with LIBIPQ. This function gets the first two bytes of the UDP packet payload(data). &#62; &#62; __u16 get_udp_two_payload_bytes(ipq_packet_msg_t *msg) &#62; { &#62; &#62; unsigned int udp_header_size = 8; /* UDP always has an 8 byte header! */ &#62; __u16 fist_two_bytes; &#62; &#62; /* [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another snippet of code for calculating and parsing a UDP packet      with LIBIPQ. This function gets the first two bytes of the UDP packet      payload(data).<br />
&gt;<br />
&gt;</p>
<p class="code">       __u16 get_udp_two_payload_bytes(ipq_packet_msg_t *msg)<br />
&gt; {<br />
&gt;<br />
&gt;        unsigned int udp_header_size = 8; /* UDP always has an 8 byte header! */<br />
&gt;        __u16 fist_two_bytes;<br />
&gt;<br />
&gt; /* Cast the IP Header from the raw        packet */<br />
&gt; struct iphdr *iph = ((struct iphdr *) msg-&gt;payload);<br />
&gt;<br />
&gt;        /* Cast the UDP Header from the raw packet */<br />
&gt; struct udphdr *udp =        (struct udphdr *) (msg-&gt;payload + (iph-&gt;ihl 2));<br />
&gt;<br />
&gt; /*        get the payload offset from within the raw packet */<br />
&gt; int unsigned        payload_offset = ( udp_header_size + (iph-&gt;ihl 2) );<br />
&gt;<br />
&gt; /*        calculate the length of the UDP payload */<br />
&gt; int unsigned        payload_length = ntohs(udp-&gt;len) &#8211; udp_header_size;</p>
<p class="code">&nbsp;</p>
<p class="code"> /*        get the first two bytes of the payload */<br />
if(payload_length)<br />
first_two_bytes = *(__u16 *) (msg-&gt;payload + payload_offset);<br />
else /* There was no payload&#8230; */<br />
printf(&#8220;ERROR: Payload is        zero&#8230;.\n&#8221;);<br />
return(first_two_bytes);<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=12</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ipq_packet_msg structure</title>
		<link>http://www.superhac.com/?p=13</link>
		<comments>http://www.superhac.com/?p=13#comments</comments>
		<pubDate>Wed, 05 Jan 2005 21:15:50 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[Kernel]]></category>
		<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=13</guid>
		<description><![CDATA[Just a dump of the ipq_packet_msg structure. ipq_packet_msg structure defined in /usr/include/linux/netfilter_ipv4/ip_queue.h: typedef struct ipq_packet_msg { unsigned long packet_id; /* ID of queued packet */ unsigned long mark; /* Netfilter mark value */ long timestamp_sec; /* Packet arrival time (seconds) */ long timestamp_usec; /* Packet arrvial time (+useconds) */ unsigned int hook; /* Netfilter hook [...]]]></description>
			<content:encoded><![CDATA[<p>Just a dump of the ipq_packet_msg structure.</p>
<p>ipq_packet_msg structure defined in /usr/include/linux/netfilter_ipv4/ip_queue.h:</p>
<p class="code">  typedef struct ipq_packet_msg {<br />
unsigned long packet_id;	/* ID of queued packet */<br />
unsigned long mark;		/* Netfilter mark value */<br />
long timestamp_sec;		/* Packet arrival time (seconds) */<br />
long timestamp_usec;		/* Packet arrvial time (+useconds) */<br />
unsigned int hook;		/* Netfilter hook we rode in on */<br />
char indev_name[IFNAMSIZ];	/* Name of incoming interface */<br />
char outdev_name[IFNAMSIZ];	/* Name of outgoing interface */<br />
unsigned short hw_protocol;	/* Hardware protocol (network order) */<br />
unsigned short hw_type;		/* Hardware type */<br />
unsigned char hw_addrlen;	/* Hardware address length */<br />
unsigned char hw_addr[8];	/* Hardware address */<br />
size_t data_len;		/* Length of packet data */<br />
unsigned char payload[0];	/* Optional packet data */<br />
} ipq_packet_msg_t;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=13</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netfilter hooks, and the skb structure (sk_buff.h)</title>
		<link>http://www.superhac.com/?p=8</link>
		<comments>http://www.superhac.com/?p=8#comments</comments>
		<pubDate>Fri, 24 Dec 2004 21:06:50 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[Kernel]]></category>
		<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Netfiliter]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=8</guid>
		<description><![CDATA[How to use Netfilter hooks written by Owen Klan, presents a general overview of Netfilter and covers the basics of kernel module development. I also found a resource on the sk_buff structure, which holds packets passing through the network stack. You can find it here: skb &#8211; Linux network buffers]]></description>
			<content:encoded><![CDATA[<p><a href="http://uqconnect.net/%7Ezzoklan/documents/netfilter.html">How to use Netfilter hooks</a>   written by Owen Klan, presents a general overview of Netfilter and covers the basics of kernel module development.</p>
<p>I also found a resource on the sk_buff structure, which holds packets passing through the network stack.  You can find it here: <a href="http://gnumonks.org/ftp/pub/doc/skb-doc.html">skb &#8211; Linux network buffers</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=8</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LIBIPQ Packet Processing</title>
		<link>http://www.superhac.com/?p=14</link>
		<comments>http://www.superhac.com/?p=14#comments</comments>
		<pubDate>Thu, 16 Dec 2004 21:17:03 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[Kernel]]></category>
		<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Netfiliter]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=14</guid>
		<description><![CDATA[For those that are not familiar with LIBIPQ, it&#8217;s a library for receving packets from the Netfilter framework in user space applications. You can use this library to grab packets before they leave the stack, and make decisions on what to do with them. For instance you can Accept, Reject, or even mangle packets. It [...]]]></description>
			<content:encoded><![CDATA[<p>For those that are not familiar with LIBIPQ, it&#8217;s a library for receving packets from the Netfilter framework in user space applications. You can use this library to grab packets before they leave the stack, and make decisions on what to do with them. For instance you can Accept, Reject, or even mangle packets. It uses the IP_QUEUE module which you may have seen used with IPTABLES.</p>
<p>For example: <strong># iptables -A OUTPUT -j QUEUE </strong></p>
<p>This tells netfilter to route all out going packets orginating from your machine to the QUEUE.</p>
<p>Developing with LIBIPQ requires the iptables-devel package to be installed. You can then compile your programs by linking them to the LIBIPQ library as shown below:</p>
<p><strong># gcc yourapp.c -lipq</strong></p>
<p>You need to be root to run any program that uses LIBIPQ.  Also if you recieve an error like, <strong>&#8220;passer: Failed to send netlink message: Connection refused&#8221;</strong> you need to load the ip_queue module.  Just issue: <strong># modprobe ip_queue</strong>.</p>
<p>I would like to thank Ulysses, Srinivas, Henrik, Maarteen for all their help.  If I forgot anyone else thank you too!</p>
<p>Below is a code snippet for parsing out the raw packet found in the structure ipq_packet_msg_t(ipq_packet_msg_t-&gt;payload). This snippet fits into the example from <a href="http://www.crhc.uiuc.edu/%7Egrier/projects/libipq.html">Quick Intro to libipq</a>.  This is very useful for people just getting started with LIBIPQ since documentation on this is scarce.</p>
<p>case IPQM_PACKET:<br />
{<br />
ipq_packet_msg_t *m = ipq_get_packet(buf);</p>
<p>__u16 first_two_bytes = 0; /* hold the first two bytes from payload */</p>
<p>/* Cast the IP Header from the raw packet */<br />
struct iphdr *iph = ((struct iphdr *)m-&gt;payload);</p>
<p>/* Cast the TCP Header from the raw packet */<br />
struct tcphdr *tcp = (struct tcphdr *)(m-&gt;payload + (iph-&gt;ihl &lt;&lt; 2));</p>
<p>/* get the payload offset from with the raw packet */<br />
int unsigned payload_offset = ((iph-&gt;ihl &lt;&lt; 2) + (tcp-&gt;doff &lt;&lt; 2));</p>
<p>/* calculate the length of the payload */<br />
int unsigned payload_length = (unsigned int) ntohs(iph-&gt;tot_len) &#8211;  				((iph-&gt;ihl &lt;&lt; 2) + (tcp-&gt;doff &lt;&lt; 2));</p>
<p>/* Calculate the size of the IP  Header.  iph-&gt;ihl contains the number of 32 bit<br />
words that represent the header size.  Therfore to get the number of bytes<br />
multiple this number by 4 */<br />
int iphdr_size = (iph-&gt;ihl &lt;&lt; 2);</p>
<p>/* Calculate the size of the TCP Header.  tcp-&gt;doff contains the number of 32 bit<br />
words that represent the header size.  Therfore to get the number of bytes<br />
multiple this number by 4 */<br />
int tcphdr_size = (tcp-&gt;doff &lt;&lt; 2);</p>
<p>/* get the destination port of the packet */<br />
int port = ntohs(tcp-&gt;dest);</p>
<p>/* Get the first two bytes of the payload if a payload is present*/<br />
if(payload_length)<br />
first_two_bytes = *(__u16 *) (m-&gt;payload + payload_offset);</p>
<p>/* example code */<br />
if (port == 9555) /* Check for a port match */<br />
{<br />
printf(&#8220;Matched a packet\n&#8221;);</p>
<p>if(payload_length)<br />
printf(&#8220;First two bytes: 0x%x\n&#8221;, first_two_bytes); /* prints in HEX */</p>
<p>printf(&#8220;IP Header size: %d\n&#8221;, iphdr_size);<br />
printf(&#8220;TCP Header size: %d\n&#8221;, tcphdr_size);<br />
printf(&#8220;Payload Size : %d\n&#8221;, payload_length);<br />
printf(&#8220;TOTAL IP Packet size: %d\n&#8221;, ntohs(iph-&gt;tot_len));<br />
printf(&#8220;\n&#8221;);</p>
<p>status = ipq_set_verdict(h, m-&gt;packet_id, NF_ACCEPT, 0, NULL);</p>
<p>}<br />
else<br />
{<br />
status = ipq_set_verdict(h, m-&gt;packet_id, NF_ACCEPT, 0, NULL);<br />
if (status &lt; 0)<br />
die(h);<br />
}<br />
break;<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=14</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting to Develop Linux Kernel Modules</title>
		<link>http://www.superhac.com/?p=9</link>
		<comments>http://www.superhac.com/?p=9#comments</comments>
		<pubDate>Wed, 24 Nov 2004 21:09:35 +0000</pubDate>
		<dc:creator>SuperHac</dc:creator>
				<category><![CDATA[Kernel]]></category>
		<category><![CDATA[LIBIPQ]]></category>
		<category><![CDATA[Netfiliter]]></category>

		<guid isPermaLink="false">http://superhac.com/?p=9</guid>
		<description><![CDATA[I have begun the jounery of understanding Linux module development. Currently I am using the following reference to build my knowledge: The Linux Kernel Module Programming Guide (2.6) by Peter Jay Salzman The reason I am looking at developing a kernel module is to utilize the Netfilter framework. The Netfilter framework is used for filtering [...]]]></description>
			<content:encoded><![CDATA[<p>I have begun the jounery of understanding Linux module development. Currently I am using the following reference to build my knowledge:</p>
<p><a href="http://tldp.org/LDP/lkmpg/2.6/html/index.html">The Linux Kernel Module Programming Guide (2.6)</a> by Peter Jay Salzman</p>
<p>The reason I am looking at developing a kernel module is to utilize the <a href="http://www.netfilter.org/">Netfilter framework</a>. The Netfilter framework is used for filtering packets within the kernel. The user-space program IPTABLES uses the Netfilter framework for creating packet filters, which allow you to create Linux Firewalls. What I am trying to do is develop a module for application layer filtering. The framework is documented in a HOWTO titled, <a href="http://www.netfilter.org/documentation/HOWTO//netfilter-hacking-HOWTO.html">Netfilter Hacking HOWTO</a>.  Its a little dated, but should be enough to point me in the right direction.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.superhac.com/?feed=rss2&amp;p=9</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
