<?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>sixserv blog &#187; security</title>
	<atom:link href="http://sixserv.org/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixserv.org</link>
	<description>A Blog about Linux, Networking, Development and Security.</description>
	<lastBuildDate>Tue, 27 Jul 2010 16:45:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Zensursula: Teil 2 &#8211; Cleanfeed, DNS, DPI</title>
		<link>http://sixserv.org/2009/10/05/zensursula-teil-2-cleanfeed-dns-dpi/</link>
		<comments>http://sixserv.org/2009/10/05/zensursula-teil-2-cleanfeed-dns-dpi/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 15:32:52 +0000</pubDate>
		<dc:creator>apoc</dc:creator>
				<category><![CDATA[Censorship]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[vpn]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=500</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_censorship.png" width="67" height="51" alt="" title="Censorship" /><br/>Die mit Lügen und Erpressung der Provider gegen alle Vernunft durchgepeitschte, grundgesetzwidrige unkontrollierbare deutsche Zensurinfrastruktur wird gerade vom &#8220;zuständigen&#8221; BKA in aller Heimlichkeit geplant und wird genauso heimlich von den Providern implementiert werden. Das die erstmals angedachten DNS-Sperren vollständig wirkungslos sind, darüber sind sich wohl alle einig, genauso eindeutig ist es wohl das die DNS-Sperren [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_censorship.png" width="67" height="51" alt="" title="Censorship" /><br/><p>Die mit Lügen und Erpressung der Provider gegen alle Vernunft durchgepeitschte, grundgesetzwidrige unkontrollierbare deutsche Zensurinfrastruktur wird gerade vom &#8220;zuständigen&#8221; BKA in aller <a href="http://www.heise.de/netze/meldung/Umsetzungsvorgaben-fuer-Web-Sperren-sollen-geheim-bleiben-Update-753549.html">Heimlichkeit geplant</a> und wird genauso heimlich von den Providern implementiert werden. Das die erstmals angedachten DNS-Sperren vollständig wirkungslos sind, darüber sind sich wohl alle einig, genauso eindeutig ist es wohl das die DNS-Sperren nur den Einstieg hin zur Schaffung eines ausgefeilten Zensursystems mit Vorbild der <a href="http://www.greatfirewallofchina.org/">Great Firewall of China</a> sein wird. Schon jetzt vermuten einige das ein <a href="http://en.wikipedia.org/wiki/Cleanfeed_%28content_blocking_system%29">Cleanfeed</a> Modell nach britischen Vorbild <a href="http://www.netzpolitik.org/2009/zensursula-richtlinie-fuer-web-sperren-sollen-geheim-bleiben/">geplant ist</a>.<br />
Die Befristung auf 3 Jahre hilft natürlich auch nicht, entweder nach 3 Jahren stellt sich heraus, das es nur wenig gegen &#8220;Kinderpornographie&#8221; geholfen hat, dann muss noch mehr und tief greifender gesperrt werden, oder die Verbrechensstatistik (die im übrigen ohnehin vom BKA &#8220;erstellt&#8221; wird) geht zurück, dann war es ein Erfolg und muss genauso weitergeführt werden.</p>
<div id="attachment_504" class="wp-caption alignleft" style="width: 310px"><a href="/wp-content/uploads/2009/10/URL_Filtering.png" rel="lightbox[500]"><img class="size-medium wp-image-504" title="URL_Filtering" src="/wp-content/uploads/2009/10/URL_Filtering-300x51.png" alt="bla" width="300" height="51" /></a><p class="wp-caption-text">Cleanfeed - Bildquelle: <a href='http://en.wikipedia.org/wiki/File:URL_Filtering_%282%29.svg'>Wikimedia Commons</a></p></div>
<p>Das <strong>Cleanfeed</strong> System wird von Providern in England eingesetzt um z.B.: bestimmte <a href="http://www.redorbit.com/news/technology/1607705/uk_blocks_wikipedia_page_over_child_image/">Wikipedia Artikel zu blockieren</a>. Welche wahrscheinlich regimekritischen Seiten noch so alles gesperrt werden weiß man natürlich nicht, da die geheimen Listen(der <a href="http://en.wikipedia.org/wiki/Internet_Watch_Foundation">IWF</a>), natürlich nicht unabhängig kontrolliert werden. Cleanfeed filtert nach der IP und URL, was durch eine Kombination aus konventionellen IP-Filtern und Proxy-Servern ermöglicht wird. Zunächst wird der Traffic nur nach IP-Adressen gefiltert, bestimmte Verbindungen werden schon hier blockiert, andernfalls wird der fragwürdige Traffic durch ein Arsenal an transparenten Proxy-Servern geleitet(<a href="http://de.wikipedia.org/wiki/Man-in-the-middle-Angriff">Man-in-the-middle-Angriff</a> auf HTTP) die mit einer Blacklist ausgerüstet bestimmte URLs blockieren.</p>
<p>In China z.B. wird noch einen Schritt weiter gegangen, so wird jedes IP-Paket von DPI-Hardware genau untersucht, enthält es unerwünschte Suchbegriffe oder Inhalte wird von dem zensierenden Backbone TCP-RST-Pakete gesendet, die so die fragliche TCP-Verbindung sofort beendet. So implementiert die chinesische Suchmaschine <a href="http://de.wikipedia.org/wiki/Baidu">Baidu</a> dies bereits auf Server-Seite. Wer auf <a href="http://www.baidu.com/">Baidu.com</a> nach &#8220;Falun Gong&#8221; sucht, dessen Verbindung wird für einige Minuten gesperrt.<br />
Beim <strong><a href="http://en.wikipedia.org/wiki/Deep_packet_inspection">Deep Packet Inspection</a></strong> wird jedes vorbeikommende Paket auseinandergenommen, so kann beispielsweise festgestellt werden ob es sich um eine HTTP Verbindung handelt und welche URL angefordert wird oder welche Daten gesendet werden. Das allein ist natürlich ein krasser verstoß gegen die Netzneutralität sowie gegen jedes noch so aufgeweichtes Fernmeldegeheimnis. Zum Vergleich, das wäre wie wenn die Post jeden Brief unbemerkt öffnet und nach bestimmten Stichworten durchsucht. Wenn es schon unbedingt DPI seien muss, dann wenigstens Open Source, dachten sich wahrscheinlich die Entwickler des <a href="http://www.opendpi.org/">OpenDPI</a> Projektes <img src='http://sixserv.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Im letzten <a href="http://sixserv.org/2009/06/27/zensursula-teil-1-dns/">Zensursula-Artikel</a> habe ich mich mit den DNS-Filtern beschäftigt, insbesondere wie man einen eigenen DNS-Cache-Server betreibt der die Zensur über DNS verhindert. Wie erwähnt handelt es sich dabei nur um den Einstieg, die Einführung von Cleanfeed/DPI kann die Zensur wieder akut werden lassen, selbst mit eigenem DNS-Server. Wie es technisch geht hat jüngst <a href="http://www.zdnet.de/sicherheit_in_der_praxis_sperre_von_freien_dns_servern_so_umgeht_man_die_blockade_story-39001543-41502966-1.htm">Vodafone in ihrem UMTS Netz</a> gezeigt, sie fangen jede Anfrage über Port 53 ab und leiten sie an ihre eigenen DNS-Server weiter.</p>
<p>Das Einzige wirksame Mittel gegen diese fortgeschrittenen Zensur Bemühungen, ist es den eigenen Traffic möglichst zu verschleiern, im einfacheren Fall seinen Traffic verschlüsselt über Rechner im Ausland zu leiten, bspw. über <strong>HTTP oder Socks4/5-Proxy-Server</strong>. Die Meisten Zensur-Regime sperren deshalb ebenfalls bekannte Ausländische Proxy bzw. Anonymisierungs-Dienste(Socks, VPN-Dienstleister oder Tor-Nodes) auf IP-Ebene.<br />
Mittlerweile gibt es eine ganze Flut von VPN-Providern die bezahlte Zugänge zu Ausländischen VPN-Servern bereitstellen, <a href="http://sixserv.org/2009/01/24/ivacy-vpn-unter-linux-pptp-und-socks5">Ivacy war hier auch schon Thema</a>. Explizit erwähnen will ich hier außerdem <a href="http://www.perfect-privacy.com/">Perfect-Privacy</a> die zwar etwas teurer sind, aber dafür sehr schnell und Zugriff zu über 20 weltweit verteilten Servern bieten. </p>
<p>Auf <a href="http://filesharefreak.com/2008/10/18/total-anonymity-a-list-of-vpn-service-providers/">FileShareFreak</a> und <a href="http://www.daten-speicherung.de/index.php/test-internet-anonymisierungsdienste/">Daten-Speicherung.de</a> gibt es Listen von VPN-Providern. Wem es statt einer Zensur zu umgehen, um wirkliche Anonymität geht, reichen diese Anbieter nicht aus. Nur ein <a href="http://de.wikipedia.org/wiki/Onion_Routing">Onion Routing</a> kann wirkliche Anonymität gewährleisten, z.B.: <a href="http://de.wikipedia.org/wiki/Tor_(Netzwerk)">Tor</a> oder <a href="http://de.wikipedia.org/wiki/Java_Anon_Proxy">JAP/JonDo</a>. Diese haben natürlich den Nachteil, extrem Langsam und unzuverlässig zu sein. Daneben gibt es mit <a href="https://xerobank.com/">Xerobank</a> einen Bezahl-Anbieter für schnelles Onion Routing.</p>
<p><strong>Update:</strong> Auf ZDNet gibt es einen guten <a href="http://www.zdnet.de/sicherheits_analysen_internet_per_umts_so_faelschen_deutsche_provider_webinhalte_story-39001544-41515603-1.htm">Artikel</a> darüber, wie weit die DPI-Manipulationen bei den UMTS-Anbietern, wie Vodafone mittlerweile gehen. (<a href="http://www.netzpolitik.org/2009/dpi-so-faelschen-deutsche-provider-webinhalte/">via Netzpolitik</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2009/10/05/zensursula-teil-2-cleanfeed-dns-dpi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>kernel mode sockets part 2 (the clean way)</title>
		<link>http://sixserv.org/2008/08/30/kernel-mode-sockets-part-2-the-clean-way/</link>
		<comments>http://sixserv.org/2008/08/30/kernel-mode-sockets-part-2-the-clean-way/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 00:34:27 +0000</pubDate>
		<dc:creator>nks</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=10</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/>Version 0.3 -  23.01.2009 Willkommen zu teil 2 der linux kernel mode socket Serie. Nun befassen wir uns mit einem sauberem weg der socketcalls vom kernel aus. Auch hierfür gibt es noch andere Wege. In einem der nächsten Teile bauen wir uns eine socket()-Funktion selber, aber nun zum sauberem socket Auch hier müssen wir wieder [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/><p>Version 0.3 -  23.01.2009</p>
<p>Willkommen zu teil 2 der linux kernel mode socket Serie. Nun befassen wir uns mit einem sauberem weg der socketcalls vom kernel aus. Auch hierfür gibt es noch andere Wege. In einem der nächsten Teile bauen wir uns eine socket()-Funktion selber, aber nun zum sauberem socket <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Auch hier müssen wir wieder set_fs/get_fs (man kann sie auch weglassen, aber in diesem Fall garantiere ich für NICHTS, bzw das Modul lässt sich kompilieren aber die Funktion funktioniert im besten Fall nicht&#8230;) nutzen da file-Operationen im kernelmode nicht gestattet sind, der Zugriff auf sockets ist ein Dateizugriff. Die Funktion inet_addr müssen wir uns nicht extra schreiben, hab ich zwischenzeitlich herausgefunden in der &#8220;linux/inet.h&#8221; gibt es in_aton() <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Die Hauptschwierigkeit besteht in den neuen Strukturen <a href="http://docs.sun.com/app/docs/doc/819-2257/iovec-9s?a=view">iovec</a> und <a href="http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/structmsghdr.html">msghdr</a>. Die ich allerdings anhand von Kommentaren erklären werde, soweit wichtig, bzw unter den beiden links steht alles was man wissen muss (obwohl es nicht spezifisch um die linux Strukturen geht).</p>
<p>Ab an den Code:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
 * lkm_clean_socket.c - nks
 */</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/module.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/kernel.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/socket.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/net.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/in.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/inet.h&gt;</span>
<span style="color: #339933;">#include &lt;net/sock.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/uaccess.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> init_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">struct</span> socket <span style="color: #339933;">*</span>socket<span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> sockaddr_in saddr<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> errno<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> msghdr msg<span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> iovec iov<span style="color: #339933;">;</span>
	mm_segment_t old_fs<span style="color: #339933;">;</span>
&nbsp;
	printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;#sixserv/sixserv.org presents:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;simple &amp; clean kernel mode socket - nks<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>errno <span style="color: #339933;">=</span> sock_create<span style="color: #009900;">&#40;</span>PF_INET<span style="color: #339933;">,</span>SOCK_STREAM<span style="color: #339933;">,</span>IPPROTO_TCP<span style="color: #339933;">,&amp;</span>socket<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is up ...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
	saddr.<span style="color: #202020;">sin_addr</span>.<span style="color: #202020;">s_addr</span> <span style="color: #339933;">=</span> in_aton<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;79.140.33.153&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	saddr.<span style="color: #202020;">sin_port</span> <span style="color: #339933;">=</span> htons<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	saddr.<span style="color: #202020;">sin_family</span> <span style="color: #339933;">=</span> AF_INET<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>errno <span style="color: #339933;">=</span> socket<span style="color: #339933;">-&gt;</span>ops<span style="color: #339933;">-&gt;</span>connect<span style="color: #009900;">&#40;</span>socket<span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> sockaddr<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>saddr<span style="color: #339933;">,</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>saddr<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is up an connected...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
	iov.<span style="color: #202020;">iov_base</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;GET / HTTP/1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	iov.<span style="color: #202020;">iov_len</span> <span style="color: #339933;">=</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET / HTTP/1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	msg.<span style="color: #202020;">msg_iov</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>iov<span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_iovlen</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_control</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_controllen</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_name</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_namelen</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_flags</span>	<span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
	old_fs <span style="color: #339933;">=</span> get_fs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	set_fs<span style="color: #009900;">&#40;</span>KERNEL_DS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>errno <span style="color: #339933;">=</span> sock_sendmsg<span style="color: #009900;">&#40;</span>socket<span style="color: #339933;">,&amp;</span>msg<span style="color: #339933;">,</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET / HTTP/1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is sending stuff...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>	
&nbsp;
	iov.<span style="color: #202020;">iov_base</span> <span style="color: #339933;">=</span> buffer<span style="color: #339933;">;</span>
	iov.<span style="color: #202020;">iov_len</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1024</span><span style="color: #339933;">;</span>
&nbsp;
	msg.<span style="color: #202020;">msg_iov</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>iov<span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_iovlen</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_control</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_name</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	msg.<span style="color: #202020;">msg_namelen</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
	old_fs <span style="color: #339933;">=</span> get_fs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	set_fs<span style="color: #009900;">&#40;</span>KERNEL_DS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>errno <span style="color: #339933;">=</span> sock_recvmsg<span style="color: #009900;">&#40;</span>socket<span style="color: #339933;">,&amp;</span>msg<span style="color: #339933;">,</span><span style="color: #0000dd;">1024</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is recieving stuff...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Recieved: %s..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> cleanup_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;Goodbye world.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
MODULE_LICENSE<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GPL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ein weiteres mal passen wir unsere Makfeile an:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">obj-m += lkm_clean_socket.o
&nbsp;
all:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> modules
&nbsp;
clean:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> clean</pre></div></div>

<p>Nach einem make ist das modul fertig und liegt unter dem namen &#8220;lkm_clean_socket.ko&#8221; im aktuellem verzeichnis.<br />
Wenn alles geklappt hat machen wir folgendes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># modinfo lkm_clean_socket.ko</span>
filename:       lkm_clean_socket.ko
license:        GPL
depends:
vermagic:       2.6.25-gentoo-r7 SMP mod_unload PENTIUM4
<span style="color: #666666; font-style: italic;"># insmod lkm_clean_socket.ko</span>
<span style="color: #666666; font-style: italic;"># dmesg</span>
....
&nbsp;
++ Kernel Mode Socket is up ...
++ ERRNO: 0..
++ Kernel Mode Socket is up an connected...
++ ERRNO: 0..
++ Kernel Mode Socket is sending stuff...
++ ERRNO: 19..
++ Kernel Mode Socket is recieving stuff...
++ ERRNO: 1024..
++ Recieved: HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span> <span style="color: #000000;">200</span> OK
Date: Sat, <span style="color: #000000;">30</span> Aug <span style="color: #000000;">2008</span> 00:<span style="color: #000000;">18</span>:<span style="color: #000000;">58</span> GMT
Server: Apache
X-Powered-By: PHP<span style="color: #000000; font-weight: bold;">/</span>5.2.0-<span style="color: #000000;">8</span>+etch11
X-Pingback: http:<span style="color: #000000; font-weight: bold;">//</span>sixserv.org<span style="color: #000000; font-weight: bold;">/</span>xmlrpc.php
Connection: close
Content-Type: text<span style="color: #000000; font-weight: bold;">/</span>html; <span style="color: #007800;">charset</span>=UTF-<span style="color: #000000;">8</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;!</span>DOCTYPE html PUBLIC <span style="color: #ff0000;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #ff0000;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&lt;</span>html <span style="color: #007800;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">dir</span></span>=<span style="color: #ff0000;">&quot;ltr&quot;</span> <span style="color: #007800;">lang</span>=<span style="color: #ff0000;">&quot;de-DE&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #007800;">profile</span>=<span style="color: #ff0000;">&quot;http://gmpg.org/xfn/11&quot;</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&lt;</span>title<span style="color: #000000; font-weight: bold;">&gt;</span>sixserv blog<span style="color: #000000; font-weight: bold;">&lt;/</span>title<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>meta http-equiv=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #007800;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>meta <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;description&quot;</span> <span style="color: #007800;">content</span>=<span style="color: #ff0000;">&quot;welcome to teh #sixserv!&quot;</span> <span style="color: #000000; font-weight: bold;">/&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&lt;</span>meta <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;generator&quot;</span> <span style="color: #007800;">content</span>=<span style="color: #ff0000;">&quot;WordPress 2.6.1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;!</span>-- leave this <span style="color: #000000; font-weight: bold;">for</span> stats please --<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">link</span> <span style="color: #007800;">href</span>=<span style="color: #ff0000;">&quot;http://sixserv.org/wp-content/themes/journalist/style.css&quot;</span> <span style="color: #007800;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">type</span></span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #007800;">media</span>=<span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">link</span> <span style="color: #007800;">rel</span>=<span style="color: #ff0000;">&quot;alternate&quot;</span> <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">type</span></span>=<span style="color: #ff0000;">&quot;application/rss+xml&quot;</span> <span style="color: #007800;">title</span>=<span style="color: #ff0000;">&quot;sixserv blog RSS Feed&quot;</span> <span style="color: #007800;">href</span>=<span style="color: #ff0000;">&quot;http://sixserv.org/feed/&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">link</span> <span style="color: #007800;">rel</span>=<span style="color: #ff0000;">&quot;shortcut icon&quot;</span> <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">type</span></span>=<span style="color: #ff0000;">&quot;image/x-png&quot;</span> <span style="color: #007800;">href</span>=<span style="color: #ff0000;">&quot;http://sixserv.org/wp-content/the
....
# rmmod lkm_clean_socket.ko</span></pre></div></div>

<p>Wie man sehen kann ist unser buffer ein wenig zu klein, und die errnos kann man sich eigtl. auch sparen wenn kein Fehler auftritt.</p>
<p>Seid gespannt auf den nächsten teil der kernel mode Serie <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>nks</p>
<p>quellen:</p>
<blockquote>
<ul>
<li><a href="http://mail.nl.linux.org/kernelnewbies/2001-10/msg00079.html">http://mail.nl.linux.org/kernelnewbies/2001-10/msg00079.html</a></li>
<li><a href="http://docs.sun.com/app/docs/doc/819-2257/iovec-9s?a=view">http://docs.sun.com/app/docs/doc/819-2257/iovec-9s?a=view</a></li>
<li><a href="http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/structmsghdr.html">http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/structmsghdr.html</a></li>
<li><a href="http://qos.ittc.ku.edu/netlink/html/node7.html">http://qos.ittc.ku.edu/netlink/html/node7.html</a></li>
<li><a href="http://google.com/codesearch?hl=de&amp;q=show:ZmG4IsUMEpU:6VNQw9NOang:byMdVv2i9V8&amp;sa=N&amp;ct=rd&amp;cs_p=http://kernel.org/pub/linux/kernel/v2.4/linux-2.4.34.1.tar.bz2&amp;cs_f=linux-2.4.34.1/net/khttpd/sockets.c">linux-2.4.34.1/ net/ khttpd/*</a></li>
<li>include/linux/net.h</li>
<li>/usr/src/linux/*</li>
</ul>
</blockquote>
<p>ps:<br />
<a href="javascript:window.external.AddSearchProvider(&quot;http://www.cuil.com/static/plugin.xml&quot;);">cuil.com</a> und <a href="javascript:window.sidebar.addSearchEngine(&quot;http://www.metager2.de/mozilla/metager2.src&quot;,&quot;http://www.metager2.de/mozilla/metager2.gif&quot;,&quot;MetaGer2&quot;,&quot;deutschsprachige%20Meta-Suchmaschine&quot;);">metager2.de</a> lassen sich beide in die Suchleiste integrieren (klickt einfach auf den namen dann fragt euch FF). Nach einigem testen gefällt mir metager2 wesentlich besser weil es VIEL mehr findet. Allerdings gefällt mir die Aufmachung von cuil.com, ich sehe noch einiges an potenzial.</p>
<p>pps:<br />
Mal wieder ein musikalischer Tipp:<br />
<a href="http://www.myspace.com/blue_nine">http://www.myspace.com/blue_nine</a></p>
<p>edit: Unterschiede zu Version 0.1 haben nur mit der Rechtschreibung zu tun!</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2008/08/30/kernel-mode-sockets-part-2-the-clean-way/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>kernel mode sockets part 1 (the dirty way)</title>
		<link>http://sixserv.org/2008/08/29/kernel-mode-sockets-part-1-the-dirty-way/</link>
		<comments>http://sixserv.org/2008/08/29/kernel-mode-sockets-part-1-the-dirty-way/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 23:38:53 +0000</pubDate>
		<dc:creator>nks</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=8</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/>Version 0.3 &#8211; 23.01.2009 Kernel mode sockets sind hoch-interessant. Im ersten teil befasse ich mich mit einer einfachen Implementierung eines ziemlich simplen kernel mode sockets, das ist nicht der Weg wie man es machen sollte allerdings hilft es erstmal dem grundsätzlichem Verständnis von lkm &#8211; also kernel modulen unter linux. Es ist natürlich trotzdem möglich [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/><p>Version 0.3 &#8211; 23.01.2009</p>
<p>Kernel mode sockets sind hoch-interessant. Im ersten teil befasse ich mich mit einer einfachen Implementierung eines ziemlich simplen kernel mode sockets, das ist nicht der Weg wie man es machen sollte allerdings hilft es erstmal dem grundsätzlichem Verständnis von lkm &#8211; also kernel modulen unter linux.</p>
<p>Es ist natürlich trotzdem möglich diesen Code in einem rootkit zu verwenden etc. aber ich finde das dieser Code nichts in einem produktiven Umfeld zu suchen hat, man öffnet keine Dateien aus derm kernel mode.</p>
<p>Wir beginnen mit den Basics eines lkm.</p>
<p>Zu erst das klassische &#8220;Hello world.&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
*  lkm_hello_world.c
*/</span>
<span style="color: #339933;">#include &lt;linux/module.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/kernel.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> init_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;Hello world.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> cleanup_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;Goodbye world.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Zum kompilieren des Moduls legen wir nun ein Makefile an:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">obj-m += lkm_hello_world.o
&nbsp;
all:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> modules
&nbsp;
clean:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> clean</pre></div></div>

<p>Vielleicht hat der ein oder andere versucht die sys/socket.h (etc.) einzubinden, aber das geht nicht. man sollte das auch nicht machen da das user-mode includes sind. Also machen wir weiter, wir erstellen wir einen simplen (dirty) socket im kernel mode. Ich hab mich dazu entschieden das wir den socket über den syscall &#8220;socketcall()&#8221; erstellen. Um syscalls aus dem kernel aufrufen zu können gab es bis kernel 2.6.19 die syscall macros (für alle mit einem neuerem kernel habe ich einen kleinen header mit den macros hoch geladen), allerdings kann man eigtl keine syscalls vom kernel aus machen, damit wir das können müssen wir aus dem kernel-space Adressraum in den user space Adressraum, das geschieht hier per set_fs(). und schon kann man userspace calls ausführen.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
*  lkm_dirty_socket.c - nks
*/</span>
<span style="color: #339933;">#include &quot;syscall_macros.h&quot; /* auskommentieren wenn die kernel version</span>
unter 2.6.19<span style="color: #339933;">/</span><span style="color: #0000dd;">18</span> ist<span style="color: #339933;">!</span> <span style="color: #339933;">*/</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/module.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/kernel.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/socket.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/net.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/in.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/ip.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/netdevice.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/init.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/syscalls.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/uaccess.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/unistd.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> errno<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* needed by socketcall() */</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
int socketcall(int call, unsigned long *args);
wie wir sehen koennen werden der funktion socketcall() 2 call uebergeben,
also benutzen wir das _syscall2-makro:
*/</span>
<span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">inline</span> _syscall2<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #339933;">,</span> socketcall<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #339933;">,</span> call<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> <span style="color: #339933;">*,</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> init_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> socket<span style="color: #339933;">;</span>
        mm_segment_t old_fs<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> sockaddr_in addr<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> sockaddr_in saddr<span style="color: #339933;">;</span>
&nbsp;
        printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;#sixserv/sixserv.org presents:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;simple kernel mode socket - nks<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        old_fs <span style="color: #339933;">=</span> get_fs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* die argumente fuer socketcall vorbereiten*/</span>
        arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> PF_INET<span style="color: #339933;">;</span>
        arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> SOCK_STREAM<span style="color: #339933;">;</span>
        arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
        set_fs<span style="color: #009900;">&#40;</span>KERNEL_DS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>socket <span style="color: #339933;">=</span> socketcall<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> arg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// SYS_SOCKET = 1</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is up ...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> cleanup_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;Goodbye world.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>nun muessen wir die Makefile an das neue modul anpassen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">obj-m += lkm_dirty_socket.o
&nbsp;
all:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> modules
&nbsp;
clean:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> clean</pre></div></div>

<p>Nun können wir mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># make</span>
<span style="color: #666666; font-style: italic;">#insmod lkm_dirty_socket</span></pre></div></div>

<p>das Modul bauen und laden, mit dmesg sollte man dann die Meldungen sehen ob es geklappt hat sieht man wenn der folgende text in der debug Ausgabe erscheint:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">++ Kernel Mode Socket is up …</pre></div></div>

<p>Aber nur ein socket alleine ist ja bekanntlich ziemlich langweilig <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
Also verbinden wir uns mit einem http Server. Hierfür müssen wir noch ein paar Anpassungen an unserem bestehendem Code tätigen:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
*  lkm_dirty_socket.c - nks
*/</span>
<span style="color: #339933;">#include &quot;syscall_macros.h&quot; /* auskommentieren wenn die kernel version unter 2.6.19/18 ist! */</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/module.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/kernel.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/socket.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/net.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/in.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/ip.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/netdevice.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/init.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/syscalls.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/uaccess.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/unistd.h&gt;</span>
<span style="color: #993333;">int</span> errno<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* needed by socketcall() */</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
int socketcall(int call, unsigned long *args);
wie wir sehen koennen werden der funktion socketcall() 2 parameter uebergeben,
also benutzen wir das _syscall2-makro:
*/</span>
<span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">inline</span> _syscall2<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #339933;">,</span> socketcall<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #339933;">,</span> call<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> <span style="color: #339933;">*,</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> init_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> socket<span style="color: #339933;">;</span>
        mm_segment_t old_fs<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> sockaddr_in addr<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> sockaddr_in saddr<span style="color: #339933;">;</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> arg1<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;#sixserv/sixserv.org presents:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;simple kernel mode socket - nks<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        old_fs <span style="color: #339933;">=</span> get_fs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> PF_INET<span style="color: #339933;">;</span>
        arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> SOCK_STREAM<span style="color: #339933;">;</span>
        arg<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
        set_fs<span style="color: #009900;">&#40;</span>KERNEL_DS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>socket <span style="color: #339933;">=</span> socketcall<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> arg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// SYS_SOCKET = 1</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is up ...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        saddr.<span style="color: #202020;">sin_addr</span>.<span style="color: #202020;">s_addr</span> <span style="color: #339933;">=</span> inet_addr<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;79.140.33.153&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        saddr.<span style="color: #202020;">sin_port</span> <span style="color: #339933;">=</span> htons<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        saddr.<span style="color: #202020;">sin_family</span> <span style="color: #339933;">=</span> AF_INET<span style="color: #339933;">;</span>
        <span style="color: #808080; font-style: italic;">/* argumente fuer connect():
            int connect(int sockfd, struct sockaddr *serv_addr, int addrlen );
        */</span>
        arg1<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> socket<span style="color: #339933;">;</span>
        arg1<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>saddr<span style="color: #339933;">;</span>
        arg1<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>saddr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>socketcall<span style="color: #009900;">&#40;</span>SYS_CONNECT<span style="color: #339933;">,</span> arg1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is up an connected...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* argumente fuer send():
            send(int s, const void *buf, size_t len, int flags);
        */</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> socket<span style="color: #339933;">;</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;GET / HTTP/1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET / HTTP/1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>socketcall<span style="color: #009900;">&#40;</span>SYS_SEND<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is sending stuff...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* argumente fuer recv():
            int recv(int s, void *buf, size_t len, int flags);
        */</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> socket<span style="color: #339933;">;</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> buffer<span style="color: #339933;">;</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1024</span><span style="color: #339933;">;</span>
        args<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>socketcall<span style="color: #009900;">&#40;</span>SYS_RECV<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;-- Kernel Mode Socket ERROR...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Kernel Mode Socket is recieving stuff...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ ERRNO: %d..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;++ Recieved: %s..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
       set_fs<span style="color: #009900;">&#40;</span>old_fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> cleanup_module<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;Goodbye world.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> inet_addr<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> a<span style="color: #339933;">,</span>b<span style="color: #339933;">,</span>c<span style="color: #339933;">,</span>d<span style="color: #339933;">;</span>
        <span style="color: #993333;">char</span> arr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        sscanf<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;%d.%d.%d.%d&quot;</span><span style="color: #339933;">,&amp;</span>a<span style="color: #339933;">,&amp;</span>b<span style="color: #339933;">,&amp;</span>c<span style="color: #339933;">,&amp;</span>d<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        arr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> a<span style="color: #339933;">;</span> arr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span> arr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> c<span style="color: #339933;">;</span> arr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> d<span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>arr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Wieder ist eine neue Funktion hinzugekommen inet_addr, aber viel interessanter sind die neuen socketcalls, beim lesen kann man anhand des call-Arguments gut sehen welche socket-Funktion nun aufgerufen wird. zur Übergabe der Parameter verwenden wir ein char array bzw zwei da recv und send jeweils 4 Argumente haben.</p>
<p>Die syscall macros hab ich für euch <a href="http://sixserv.org/wp-content/uploads/2008/08/syscall_macros.h">hochgeladen</a></p>
<p>quellen:</p>
<blockquote>
<ul>
<li><a href="http://www.linuxjournal.com/node/8110/print">http://www.linuxjournal.com/node/8110/print</a></li>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-system-calls/">http://www.ibm.com/developerworks/linux/library/l-system-calls/</a></li>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-lkm/">http://www.ibm.com/developerworks/linux/library/l-lkm/</a></li>
<li><a href="http://www.gnugeneration.com/mirrors/kernel-api/book1.html">http://www.gnugeneration.com/mirrors/kernel-api/book1.html</a></li>
<li><a href="http://www.tldp.org/LDP/lkmpg/2.6/html/">http://www.tldp.org/LDP/lkmpg/2.6/html/</a></li>
<li><a title="inet_addr code" href="http://www.ussg.iu.edu/hypermail/linux/kernel/0303.2/2007.html">http://www.ussg.iu.edu/hypermail/linux/kernel/0303.2/2007.html</a> (inet_addr())<a title="inet_addr code" href="http://www.ussg.iu.edu/hypermail/linux/kernel/0303.2/2007.html"><br />
</a></li>
<li><a href="http://google.com/codesearch/">http://google.com/codesearch/</a></li>
<li><a href="http://lkml.org">http://lkml.org</a></li>
<li><a href="http://kerneltrap.org">http://kerneltrap.org</a></li>
<li>/usr/src/linux/*</li>
<li><a href="http://sixserv.org/wp-content/uploads/2008/08/syscall_macros.h">syscall_macros.h</a></li>
</ul>
</blockquote>
<p>Bei fragen etc. kommt doch einfach ins irc (#nullserv/#sixserv im freenode)</p>
<p>nks</p>
<p>ps:<br />
benutzt öfters mal google-alternativen.. <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   <a href="http://cuil.com">http://cuil.com</a> oder <a href="http://metager2.de">http://metager2.de</a></p>
<p>pps:<br />
chillig, und wie ich finde sehr geil: <a href="http://www.myspace.com/17thboulevard">http://www.myspace.com/17thboulevard</a><br />
bin gespannt auf das album&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2008/08/29/kernel-mode-sockets-part-1-the-dirty-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
