<?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; Linux</title>
	<atom:link href="http://sixserv.org/category/linux/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>Memory Debugging or a &#8220;Universal Game Trainer&#8221; with Python and ptrace</title>
		<link>http://sixserv.org/2010/07/26/memory-debugging-or-a-universal-game-trainer-with-python-and-ptrace/</link>
		<comments>http://sixserv.org/2010/07/26/memory-debugging-or-a-universal-game-trainer-with-python-and-ptrace/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 13:35:22 +0000</pubDate>
		<dc:creator>apoc</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[ptrace]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=656</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/>Reading and writing other process memory can have many different purposes: besides debugging, this technique is probably most frequently known to be used by game trainers, to alter different values of a running game (like the value of health or money). Most (if not all) of the game trainers available, are developed for Windows and [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/><p>Reading and writing other process memory can have many different purposes: besides debugging, this technique is probably most frequently known to be used by game trainers, to alter different values of a running game (like the value of health or money).</p>
<p>Most (if not all) of the game trainers available, are developed for Windows and only for a specific game, but there are some universal trainers, that could be used to locate and change values in memory of any game or application and with <a href="http://kcheat.sourceforge.net/">kcheat</a> and <a href="http://www.chrishowie.com/2006/09/01/tursiops-universal-trainer-for-linux/">Tursiops</a> there are some solutions for Linux.<br />
I&#8217;ve developed a proof of concept to locate and change any byte value using python and the <a href="http://bitbucket.org/haypo/python-ptrace/overview">ptrace bindings</a>. <a href="http://en.wikipedia.org/wiki/Ptrace">ptrace</a> is a Unix system call for controlling other processes, it is for instance used by the gdb debugger.</p>
<p>The following code creates a debugging instance and attaches the other process by PID:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> ptrace.<span style="color: black;">debugger</span>.<span style="color: black;">debugger</span> <span style="color: #ff7700;font-weight:bold;">import</span> PtraceDebugger
&nbsp;
dbg = PtraceDebugger<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
process = dbg.<span style="color: black;">addProcess</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1234</span>, <span style="color: #008000;">False</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Now the <code>process</code> instance can be used to inspect and manipulate the process. To manipulate the memory it is important to know the virtual memory mappings (&#8216;areas&#8217;) of the process:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> ptrace.<span style="color: black;">debugger</span>.<span style="color: black;">memory_mapping</span> <span style="color: #ff7700;font-weight:bold;">import</span> readProcessMappings
&nbsp;
memory_mapping = readProcessMappings<span style="color: black;">&#40;</span>process<span style="color: black;">&#41;</span></pre></div></div>

<p>Now the list contains <code>MemoryMapping</code> instances, describing the virtual memory areas of the process. We are interested in their location and permission (Quickref: <code>mapping.start</code>, <code>mapping.end</code>, <code>mapping.permissions</code>). The trainer should only be searching within memory mappings with &#8220;rw&#8221; permissions.</p>
<p>Last but not least, the reading and writing from/to memory methods:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">value = process.<span style="color: black;">readBytes</span><span style="color: black;">&#40;</span>0x11223344, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># this reads 1 byte</span>
process.<span style="color: black;">writeBytes</span><span style="color: black;">&#40;</span>0x11223344, value<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># writes len(value) bytes</span></pre></div></div>

<p>After that you can close the debugger instance by:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">dbg.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>I encountered some difficulties with closing/detaching the debugging process, it seems that the process is only really detached if the script is terminated, as a workaround I forked the memory search process, to circumvent that in my proof of concept trainer.</p>
<p>That&#8217;s it! If you&#8217;re interested, you can checkout my proof of concept for a universal game trainer: <a href="http://apoc.sixserv.org/code/pycheat.py">pycheat.py</a> (GPLv3) It can locate and change byte values (<code>char</code>) in other processes memory:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">% python pycheat.py 8169
pycheat: universal game trainer v0.1
process id: 8169
highest address: 0xffffff
&nbsp;
searching for address by byte value: 23
search memory area[0x00DB8000-0x00DC0000] address[0x00DBD989] value[0x17 (023)]    
&nbsp;
found 5926 occurrences, change value to: 33
search memory area[0x00DB8000-0x00DC0000] address[0x00DBFD88] value[0x21 (033)]    
&nbsp;
found 1 occurrence! correct address for this value is 0x00C4335A
change value in memory at 0x00C4335A to: 99
done.</pre></div></div>

<p>First you enter the known value, the trainer is searching it inside the memory, chances are high, that there are many occurrences of it, so you change the value inside the game and repeat the search with the new one. After ~2-4 iterations the correct location should be found and you can manipulate it.</p>
<p><small><strong>edit</strong>: smaller changes</small></p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2010/07/26/memory-debugging-or-a-universal-game-trainer-with-python-and-ptrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Loading of SDL</title>
		<link>http://sixserv.org/2010/05/21/dynamic-loading-of-sdl/</link>
		<comments>http://sixserv.org/2010/05/21/dynamic-loading-of-sdl/#comments</comments>
		<pubDate>Fri, 21 May 2010 05:58:15 +0000</pubDate>
		<dc:creator>apoc</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=605</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_ccpp.png" width="50" height="51" alt="" title="C/C++" /><br/>If you want to use the SDL library (or any other library for that matter) in your programs, you normally would just link with the library, for instance by -lSDL (GCC). Sometimes however, it would be more flexible to dynamically load the library at runtime. With dynamic loading, if your application supports alternative libraries (e.g.: [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_ccpp.png" width="50" height="51" alt="" title="C/C++" /><br/><p>If you want to use the <a href="http://www.libsdl.org/">SDL library</a> (or any other library for that matter) in your programs, you normally would just link with the library, for instance by <code>-lSDL</code> (GCC). Sometimes however, it would be more flexible to dynamically load the library at runtime. With dynamic loading, if your application supports alternative libraries (e.g.: <strike><a href="http://www.opengl.org/resources/libraries/glut/">GLUT</a></strike> <a href="http://www.sfml-dev.org/">SFML</a> as an replacement for SDL), it can discover and use available libraries at runtime. The system your program is running on, just needs one of those libraries installed and can switch them without the need to recompile your program. This technique is probably most commonly used to load plugins into programs at runtime.</p>
<p>Theres a helpful Wikipedia article about <a href="http://en.wikipedia.org/wiki/Dynamic_loading">Dynamic loading</a>, they even describe how to load the SDL library in their examples. Besides that, theres an old discussion about that at <a href="http://lists.libsdl.org/pipermail/sdl-libsdl.org/2007-October/063161.html">lists.libsdl.org</a> and an article at eaten by a grue (<a href="http://eatenbyagrue.org/when_good_libraries_go_bad.html">when good libraries go bad</a>). However I didn&#8217;t find a complete example implementation for this, so I&#8217;m trying to <a href="http://apoc.sixserv.org/coderepo/listing.php?repname=dloadsdl">create one</a> with this article, although I&#8217;m not a very experienced C++ programmer.</p>
<p>The first thing to do is to load the library file, on POSIX/UNIX systems we do this with <code><a href="http://linux.die.net/man/3/dlopen">dlopen()</a></code>, on windows we use <code><a href="http://msdn.microsoft.com/en-us/library/ms684175%28VS.85%29.aspx">LoadLibrary</a>()</code> and for closing <code><a href="http://linux.die.net/man/3/dlclose">dlclose()</a></code> and <code><a href="http://msdn.microsoft.com/en-us/library/ms683152%28VS.85%29.aspx">FreeLibrary()</a></code> respectively. The following code snippet for open/closing the library should work on both Linux and Windows systems:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#ifdef _WIN32</span>
    <span style="color: #339900;">#include &lt;windows.h&gt;</span>
<span style="color: #339900;">#else</span>
    <span style="color: #339900;">#include &lt;dlfcn.h&gt;</span>
<span style="color: #339900;">#endif</span>
&nbsp;
<span style="color: #666666;">// [...]</span>
&nbsp;
<span style="color: #339900;">#ifdef _WIN32</span>
    HMODULE libhandle<span style="color: #008080;">;</span>
    libhandle <span style="color: #000080;">=</span> LoadLibrary<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;SDL.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#else</span>
    <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span>libhandle<span style="color: #008080;">;</span>
    libhandle <span style="color: #000080;">=</span> dlopen<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;libSDL.so&quot;</span>, RTLD_LAZY<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#endif</span>
&nbsp;
<span style="color: #666666;">// ... dlsym() and GetProcAddress() calls ...</span>
&nbsp;
<span style="color: #339900;">#ifdef _WIN32</span>
    FreeLibrary<span style="color: #008000;">&#40;</span>libhandle<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#else</span>
    dlclose<span style="color: #008000;">&#40;</span>libhandle<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#endif</span></pre></td></tr></table></div>

<p>You need to link your programs to the dl library for this to work (such as <code>-ldl</code> in gcc).</p>
<p>The returned handle can be used to retrieve symbol addresses and then to convert them to function pointers. Theres <code><a href="http://linux.die.net/man/3/dlsym">dlsym()</a></code> on POSIX and <code><a href="http://msdn.microsoft.com/en-us/library/ms683212%28VS.85%29.aspx">GetProcAddress()</a></code> on Windows machines. The following code does that cross-platform for <code><a href="http://sdl.beuc.net/sdl.wiki/SDL_SetVideoMode">SDL_SetVideoMode()</a></code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">SDL_Surface <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>p_SDL_SetVideoMode<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, Uint32<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#ifdef _WIN32</span>
    p_SDL_SetVideoMode <span style="color: #000080;">=</span> 
        <span style="color: #008000;">&#40;</span>SDL_Surface <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, Uint32<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> GetProcAddress<span style="color: #008000;">&#40;</span>libhandle, <span style="color: #FF0000;">&quot;SDL_SetVideoMode&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#else</span>
    p_SDL_SetVideoMode <span style="color: #000080;">=</span> 
        <span style="color: #008000;">&#40;</span>SDL_Surface <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, Uint32<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> dlsym<span style="color: #008000;">&#40;</span>libhandle, <span style="color: #FF0000;">&quot;SDL_SetVideoMode&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#endif</span></pre></td></tr></table></div>

<p>You need to look at the header files (<code>/usr/include/SDL/SDL_video.h</code>) for the exact declaration (return and parameter types). </p>
<p>Theres a problem here, when casting from an void pointer that is returned by <code>dlsym()</code> to a function pointer which is prohibited by the C/C++ ISO standards. I&#8217;m using a simple explicit (C-style) cast here and in practice, I not even encountered a warning with modern compilers. </p>
<p>Johan Petersson has written an article (<a href="http://www.trilithium.com/johan/2004/12/problem-with-dlsym/">When standards collide: the problem with dlsym</a>) about that problem in <a href="http://www.trilithium.com/johan/">Scatter/Gather thoughts</a>, I want to quote:</p>
<blockquote><p><em>You probably noticed that I omitted the C-style cast from my earlier example. Alas, most C and C++ compilers will allow the conversion when you use a C-style cast. You may not even get a warning, even though it&#8217;s prohibited in ISO C as well as ISO C++. This kind of conversion is a common compiler extension. So common, in fact, that many people don&#8217;t realize it&#8217;s not in the standards.</em></p></blockquote>
<p>The article is from 2004, I don&#8217;t know if the current C/C++ standards had changed any of that. </p>
<p>In the last code snippet theres an redundancy that can be resolved by using a <code>typedef</code> instead:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> SDL_Surface <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>Type_SDL_SetVideoMode<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span>, Uint32<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
Type_SDL_SetVideoMode p_SDL_SetVideoMode<span style="color: #008080;">;</span>
<span style="color: #339900;">#ifdef _WIN32</span>
    p_SDL_SetVideoMode <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>Type_SDL_SetVideoMode<span style="color: #008000;">&#41;</span> GetProcAddress<span style="color: #008000;">&#40;</span>libhandle, <span style="color: #FF0000;">&quot;SDL_SetVideoMode&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#else</span>
    p_SDL_SetVideoMode <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>Type_SDL_SetVideoMode<span style="color: #008000;">&#41;</span> dlsym<span style="color: #008000;">&#40;</span>libhandle, <span style="color: #FF0000;">&quot;SDL_SetVideoMode&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#endif</span></pre></td></tr></table></div>

<p>Thats everything you need to call that function: <code>(p_SDL_SetVideoMode)(...);</code> The major problem here is that SDL has over 200 functions that &#8220;must&#8221; be declared and addressed this way. I&#8217;ve written a <a href="http://apoc.sixserv.org/coderepo/filedetails.php?repname=dloadsdl&#038;path=%2Flibsdl_header_parser.rb">ruby script</a> for Linux that does that for the SDL headers within <code>/usr/include/SDL</code>, at first it reads the symbol names directly from the <code>libSDL.so</code> shared library utilizing <code><a href="http://linux.die.net/man/1/nm">nm</a></code>, then it parses the header files for the function declarations found by <code>nm</code> and generates the code for the pointer declaration and explicit casts (/dlsym calls) automatically.</p>
<p>I&#8217;ve created some <a href="http://apoc.sixserv.org/coderepo/listing.php?repname=dloadsdl">example code</a> that defines an abstract class <code><a href="http://apoc.sixserv.org/coderepo/filedetails.php?repname=dloadsdl&#038;path=%2FDLLoader.h">DLLoader</a></code> and an implementation <code><a href="http://apoc.sixserv.org/coderepo/filedetails.php?repname=dloadsdl&#038;path=%2FDLLoaderSDL.h">DLLoaderSDL</a></code> that includes an struct with the automatically generated function pointers etc. The test program loads the library and shows a SDL window for 3 seconds.<br />
I&#8217;ve tested the program with GCC 4.5.0 (Linux), GCC 3.4.5 (Windows MinGW) and CL 14.0 (Windows VC++). I also added Makefiles for each of those compiler suites.</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2010/05/21/dynamic-loading-of-sdl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zensursula: Teil 1 &#8211; DNS</title>
		<link>http://sixserv.org/2009/06/27/zensursula-teil-1-dns/</link>
		<comments>http://sixserv.org/2009/06/27/zensursula-teil-1-dns/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 20:40:41 +0000</pubDate>
		<dc:creator>apoc</dc:creator>
				<category><![CDATA[Censorship]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[zensursula]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=447</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_censorship.png" width="67" height="51" alt="" title="Censorship" /><br/>&#8220;Sie werden sich noch wünschen wir wären Politikverdrossen&#8221; (@343max) Ich hatte in den letzten Wochen den Eindruck, als ob die gesamte Internet-Gemeinschaft in Deutschland Sturm lief, überall gab und gibt es nur ein Thema: Die Internetzensur Bestrebungen der großen Koalition. Dabei hatte man am Ende den Eindruck gegen eine Mauer von Unkenntnis, Ignoranz aber vielleicht [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_censorship.png" width="67" height="51" alt="" title="Censorship" /><br/><blockquote><p><em style="font-size: 21px;">&#8220;Sie werden sich noch wünschen wir wären Politikverdrossen&#8221;</em> (<a href="http://twitter.com/343max/status/2228357957">@343max</a>)</p></blockquote>
<p><img src="/wp-content/uploads/2009/06/zensursula-300x292.jpg" alt="zensursula-300x292" title="zensursula-300x292" width="300" height="292" class="alignleft size-full wp-image-453" style="margin-right: 8px;" />Ich hatte in den letzten Wochen den Eindruck, als ob die gesamte Internet-Gemeinschaft in Deutschland Sturm lief, überall gab und gibt es nur ein Thema: Die Internetzensur Bestrebungen der großen Koalition. Dabei hatte man am Ende den Eindruck gegen eine Mauer von Unkenntnis, Ignoranz aber vielleicht auch einfach blanker böswilliger Berechnung einfach nichts ausrichten zu können.<br />
Besonders Enttäuschend empfand ich die Medien, überraschend war es freilich nicht dass sie praktisch ausschließlich Parteipropaganda nachplapperten und die Mainstream Meinung nach dem Willen der Regierung formten. Von investigativem Journalismus jedenfalls war in den Holzmedien nichts zu sehen, das überlässt man offenbar <a href="http://ak-zensur.de/2009/05/loeschen-funktioniert.html">anderen</a>.</p>
<p>Ein wenig Ironisch ist es schon, ist doch gerade das Internet die einzige breit zugängliche alternative Informationsquelle(wie wir eindrucksvoll sehen konnten), die mit der jetzt beschlossenen Infrastruktur möglicherweise schon bald stark eingeschränkt wird. Dabei geht es auch um die Frage ob wir der Regierung soweit vertrauen, nach der Installation einer bis dato einmaligen Infrastruktur für Zensur, bei der Sperrung von Kinderpornographischen Inhalten zu bleiben. In den letzten Jahren hat uns die große Koalition keinen Grund geliefert das zu glauben.</p>
<p>Die eigentliche Kluft wie häufig Thematisiert, liegt nicht zwischen den Internet-Natives und den &#8220;Internet-Ausdruckern&#8221; sondern vielmehr in dem Teil der Bevölkerung der sich unabhängig Informiert und dem Teil, der den großen Medien und Agenturen(auch im Internet) blind vertaut und als einzige Informationsquelle zur eigenen Meinungsbildung heranzieht, also den überwiegenden Teil der Gesellschaft.</p>
<p>Gestern nun hat die <a href="http://www.dradio.de/kulturnachrichten/200906261600/3">EU die Zensur in China gerügt</a>(so Merkwürdig wie das auch immer ist), demnach vergessen wir einfach alles was die EU-Länder sonst so treiben und beschäftigen uns nun, <b>offensichtlich im Wohlwollen der EU</b>, um die aktiven technischen Möglichkeiten der Umgehung jedweder Zensur-Infrastruktur, außerdem kann es nicht schaden die von den Zensoren eingesetzte Technologie mal etwas genauer zu beleuchten.</p>
<p><strong>In diesem ersten Teil soll es um die Zensur durch DNS Manipulationen gehen.</strong></p>
<p>Es ist noch die leichteste Form der Zensur, die Einstiegsdroge der Staaten sozusagen, denn DNS Manipulationen lassen sich Kinderleicht aushebeln was wohl schnell den Wunsch nach härteren Mitteln wecken dürfte. Bei dieser Form der Zensur installieren die ISP&#8217;s die Sperrlisten in ihren DNS-Servern, ist doch zumindest anzunehmen, das die Mehrheit der Internet Nutzer die Server ihres Providers verwenden, wobei das bei leibe nicht immer der Fall ist. So war und ist es schon immer möglich seinen eigenen DNS-Server zu betreiben. Jetzt wo man allen Grund hat den DNS-Servern der Provider zu misstrauen, ist das eine sehr praktikable Möglichkeit, zumindest für diejenigen die sich mit dem Internet auskennen.<br />
Doch der Reihe nach, im Prinzip reicht es statt eines Domain-Namens in der Adresszeile die Ip-Adresse einzugeben um diese Zensur zu umgehen, besser ist es da schon einen alternativen DNS-Server zu verwenden, vorzugsweise im Ausland, aber auch der <a href="http://ccc.de/">CCC</a> und der <a href="http://www.foebud.org/datenschutz-buergerrechte/gegen-internetsperren-in-einer-freien-gesellschaft-foebud-richtet-anti-zensur-dns-server-ein/?searchterm=DNS">Foebud</a> stellen unzensierte DNS-Server (noch) frei zur Verfügung. Listen mit freien Servern gibt es z.B. bei <a href="http://wikileaks.org/wiki/Alternative_DNS">Wikileaks</a>, dem <a href="http://ccc.de/censorship/dns-howto/">CCC</a> oder die Server des <a href="http://www.opennicproject.org/index.php?view=category&#038;id=51%3Amigrate-to-opennic&#038;option=com_content&#038;Itemid=82">Open NIC Projektes</a>.</p>
<p><strong>DNS Caching Server</strong></p>
<p>Nützlich ist auch das Einrichten eines eigenen Caching DNS-Servers der zufällig aus einer Liste, öffentliche Servern abfragt. Ich verwende dafür den <a href="http://www.phys.uu.nl/~rombouts/pdnsd/">pdnsd</a>, nicht zu verwechseln mit dem vollwertigen DNS-Server, <a href="http://powerdns.com/">PowerDNS</a>. Je nach Distribution sollte sich die Installation einfach gestalten, z.B. reicht ein <code>pacman -S pdnsd</code> um mit Arch Linux den Server zu installieren. Jetzt sollte man sich die Beispiel Konfiguration kopieren und Anpassungen vornehmen. Hier eine mögliche Beispielkonfiguration, es muss nur die server_ip angepasst werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">global <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #007800;">perm_cache</span>=<span style="color: #000000;">512000</span>; <span style="color: #666666; font-style: italic;"># cache groesse in KB (hier &quot;leicht&quot; uebertriebene 500 MB)</span>
        <span style="color: #007800;">cache_dir</span>=<span style="color: #ff0000;">&quot;/var/cache/pdnsd&quot;</span>;
        <span style="color: #007800;">run_as</span>=<span style="color: #ff0000;">&quot;nobody&quot;</span>;
        <span style="color: #007800;">server_ip</span>=10.0.0.4; <span style="color: #666666; font-style: italic;"># ANPASSEN</span>
        <span style="color: #007800;">status_ctl</span>=on;
        <span style="color: #007800;">paranoid</span>=on; <span style="color: #666666; font-style: italic;"># prevents cache poisoning</span>
        <span style="color: #007800;">query_method</span>=udp_tcp;
        <span style="color: #007800;">min_ttl</span>=15m; <span style="color: #666666; font-style: italic;"># min/max TTL</span>
        <span style="color: #007800;">max_ttl</span>=4w;
        <span style="color: #007800;">timeout</span>=<span style="color: #000000;">15</span>; <span style="color: #666666; font-style: italic;"># global timeout 15 seconds</span>
        <span style="color: #007800;">neg_rrs_pol</span>=auth;
        <span style="color: #007800;">par_queries</span>=<span style="color: #000000;">2</span>; <span style="color: #666666; font-style: italic;"># maximale parallele abfrage von servern</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
server <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #666666; font-style: italic;"># ein paar oeffentliche server (alle getestet)</span>
        label = <span style="color: #ff0000;">&quot;random&quot;</span>;
        randomize_servers = on;
        ip = 85.214.73.63, <span style="color: #666666; font-style: italic;"># foebud</span>
        204.152.184.76, <span style="color: #666666; font-style: italic;"># ISC (USA)</span>
        213.73.91.35, <span style="color: #666666; font-style: italic;"># CCC</span>
        194.95.202.198, <span style="color: #666666; font-style: italic;"># DFN</span>
        58.6.115.43, <span style="color: #666666; font-style: italic;"># Westnet (Australien)</span>
        82.229.244.191, <span style="color: #666666; font-style: italic;"># Frankreich</span>
        88.191.77.10, <span style="color: #666666; font-style: italic;"># Frankreich</span>
	216.87.84.209, <span style="color: #666666; font-style: italic;"># OpenNIC</span>
	88.191.77.10; <span style="color: #666666; font-style: italic;"># OpenNIC</span>
        <span style="color: #007800;">timeout</span>=<span style="color: #000000;">10</span>; <span style="color: #666666; font-style: italic;"># 10 sekunden maximal</span>
        <span style="color: #007800;">uptest</span>=<span style="color: #c20cb9; font-weight: bold;">ping</span>;
        <span style="color: #007800;">ping_timeout</span>=<span style="color: #000000;">400</span>; <span style="color: #666666; font-style: italic;">#ms</span>
        <span style="color: #007800;">interval</span>=30m; <span style="color: #666666; font-style: italic;"># uptest der server per ping</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Unveraendert aus Sample Conf:</span>
<span style="color: #666666; font-style: italic;"># This section is meant for resolving from root servers.</span>
server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        label = <span style="color: #ff0000;">&quot;root-servers&quot;</span>;
        root_server = on;
        randomize_servers = on; <span style="color: #666666; font-style: italic;"># Give every root server an equal chance</span>
                                <span style="color: #666666; font-style: italic;"># of being queried.</span>
        ip =    198.41.0.4
        ,       192.228.79.201
        ,       192.33.4.12
        ,       128.8.10.90
        ,       192.203.230.10
        ,       192.5.5.241
        ,       192.112.36.4
        ,       128.63.2.53
        ,       192.36.148.17
        ,       192.58.128.30
        ,       193.0.14.129
        ,       198.32.64.12
        ,       202.12.27.33
        ;
        timeout = <span style="color: #000000;">5</span>;
        uptest = query;         <span style="color: #666666; font-style: italic;"># Test availability using empty DNS queries.</span>
        interval = 30m;         <span style="color: #666666; font-style: italic;"># Test every half hour.</span>
        ping_timeout = <span style="color: #000000;">300</span>;     <span style="color: #666666; font-style: italic;"># Test should time out after 30 seconds.</span>
        purge_cache = off;
        exclude = .localdomain;
        policy = included;
        preset = off;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ganz praktisch, damit braucht man nur eine einzige hosts Datei im ganzen LAN zu pflegen:</span>
<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> 
        <span style="color: #007800;">owner</span>=localhost;
        <span style="color: #007800;">serve_aliases</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>;
        <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">file</span></span>=<span style="color: #ff0000;">&quot;/etc/hosts&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Ich habe alle DNS Server getestet. Eventuell die Konfiguration noch auf die eigenen Anforderungen anpassen, eine Dokumentation findet ihr <a href="http://www.phys.uu.nl/~rombouts/pdnsd/doc.html">hier</a>. Die /etc/resolv.conf noch auf die lokale IP-Adresse umstellen dann den Server (neu)starten. Jetzt sollte er funktionieren, testen kann man das z.B. mit nslookup oder: <code>dig 4poc.org [IP des DNS]</code>, dig zeigt auch wie lange er zum resolven brauchte.</p>
<p>Um festzustellen welche DNS-Server verwendet werden habe ich ein kleines Skript geschrieben, eigentlich passt die Thematik(siehe Anmerkung im Script) nicht direkt zum Thema aber den folgenden Artikeln sei schon mal etwas vorgegriffen: <a href="http://nstest.4poc.org/">nstest.4poc.org</a> (DNS Tester, falls jemanden einen besseren Namen dafür einfällt nur her damit.)</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2009/06/27/zensursula-teil-1-dns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ivacy VPN unter Linux: PPTP/OpenVPN und Socks5-Gateway</title>
		<link>http://sixserv.org/2009/01/24/ivacy-vpn-unter-linux-pptp-und-socks5/</link>
		<comments>http://sixserv.org/2009/01/24/ivacy-vpn-unter-linux-pptp-und-socks5/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 23:42:15 +0000</pubDate>
		<dc:creator>apoc</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ivacy]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[openvpn]]></category>
		<category><![CDATA[pptp]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[socks]]></category>
		<category><![CDATA[vpn]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=171</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/>Die VPN Provider sprießen, dank der &#8220;Sicherheits-Politik&#8221; in Europa und den USA, wie Pilze aus dem Boden. Seit Juli 2008 gibt es Ivacy, einem durchaus interessanten VPN-Anbieter über den es möglich ist sich der Vorratsdatenspeicherung Europas zu entziehen. Hier geht es mir darum zu zeigen wie man Ivacy unter Linux nutzen kann, genauer gesagt wie [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/><p>Die VPN Provider sprießen, dank der &#8220;Sicherheits-Politik&#8221; in Europa und den USA, wie Pilze aus dem Boden. Seit Juli 2008 gibt es <a href="https://pr.ivacy.com/en/auth/signup?ref2=024fa5cc800ac0f761aefc14ae5d4fd9">Ivacy</a>, einem durchaus interessanten VPN-Anbieter über den es möglich ist sich der Vorratsdatenspeicherung Europas zu entziehen. Hier geht es mir darum zu zeigen wie man Ivacy unter Linux nutzen kann, genauer gesagt wie man OpenVPN und PPTP unter Linux einrichtet, die Country-Selection Funktion von Ivacy nutzt und wie man einen Socks5 Proxy einrichtet der Verbindungen über Ivacy weiterleitet, dazu später mehr. <strong>Diese Anleitung sollte nicht nur mit Ivacy funktionieren, alle VPN-Anbieter bieten OpenVPN oder PPTP</strong>(das proprietäre VPN Protokoll von Microsoft).<br />
<strong>Update:</strong> Habe einen OpenVPN-Abschnitt eingefügt.<br />
<strong>Update 4.2.09@20:50:</strong> OpenVPN-Abschnitt überarbeitet.<br />
<strong>Update 8.2.09@22:15:</strong> Artikel nochmals überarbeitet.<br />
<strong>Update 21.4.09@22:00:</strong> Privoxy-Abschnitt eingefügt.</p>
<p><em></em>Bevor es losgeht sollte ich vielleicht noch erwähnen das es sich hierbei um keine Anleitung für Linux-Anfänger oder Ubuntu/Suse-&#8221;Profis&#8221; handelt. *g* <span id="more-171"></span></p>

<h2>0. Einleitung und Sicherheit</h2>
<p>Ich stelle die Verbindung zu Ivacy über eine extra eingerichtete Virtuelle Maschine her, die auf dem VMWare Server meiner 24/7 Kiste läuft. Darauf habe ich eine minimale Arch Linux-Installation am laufen. Dieser Server dient mir als Socks5-Gateway ins Ivacy VPN-Netz. </p>
<p>In wie weit Ivacy auch Genial ist, bleibt die Frage der Vertrauenswürdigkeit eines VPN-Dienstleisters bestehen, insbesondere wenn er so günstig wie Ivacy ist. Die Frage muss sich jeder selbst stellen und daraufhin entscheiden welche Art von Traffic er über das VPN schicken will. Ein Socks5-Gateway erlaubt es sehr viel genauer zu bestimmen und zu kontrollieren was über Ivacy ins Internet geht.</p>
<h3>0.1. NAT und DoubleVPN</h3>
<p>Bei Ivacy bekommt man keine statische oder dynamische IP. Vielmehr bekommt jeder die gleiche, per NAT werden alle Anfragen nach außen geleitet. Wenn sich so hunderte User hinter einer einzigen IP verbergen, verhilft das allen zu einem erheblichen Grad an Anonymität. Benötigt man einen offenen Port der zu einem Geforwarded wird, so kann man diesen einfach auf der Webseite anfordern und bekommt einen zufälligen zugewiesen.<br />
Außerdem ist es möglich seinen Traffic über 2 Hops von Ivacy zu leiten um so die Anonymität noch zusätzlich zu erhöhen.</p>
<h2>1. OpenVPN</h2>
<p>OpenVPN muss in einer Version >= 2.1 installiert sein(!). Je nach Distribution installieren und darauf achten das ein tun-Device entsteht. In Arch Linux muss man sich selbst um das erstellen kümmern. Im <a href="http://ivacy.com/en/doc/help/setup/winxp_openvpn">Windows XP</a>(nicht im Linux Abschnitt warum auch immer) gibt es die notwendigen Konfigurations-Dateien sowie Zertifikate(!). Die Konfigurationsdatei für OpenVPN kann praktisch übernommen werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">client
dev tun
proto udp
remote openvpn.ivacy.com <span style="color: #000000;">1194</span>
resolv-retry infinite
nobind
persist-key
persist-tun
ca <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ivacy-ca.crt
cert <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ivacy-client.crt
key <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ivacy-client.key
tls-auth <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ivacy-tls.key <span style="color: #000000;">1</span>
ns-cert-type server
comp-lzo
verb <span style="color: #000000;">3</span>
<span style="color: #666666; font-style: italic;"># Mit Passwort Datei: (geht nur wenn openvpn</span>
<span style="color: #666666; font-style: italic;"># mit &quot;--enable-password-save&quot; kompiliert wurde!):</span>
auth-user-pass <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>password
<span style="color: #666666; font-style: italic;"># sonst so:</span>
auth-user-pass
redirect-gateway
reneg-sec <span style="color: #000000;">0</span>
up <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ivacy-up.sh
down <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ivacy-down.sh</pre></div></div>

<p>Die <em>/etc/openvpn/password</em>-Datei enthält Username &#8211; neue Zeile &#8211; Password, doch wie schon erwähnt kann es sein, das dies nicht funktioniert wenn openvpn ohne &#8220;&#8211;enable-password-save&#8221; kompiliert wurde. Danach noch die Zertifikat-Dateien erstellen die es auf der oben <a href="http://ivacy.com/en/doc/help/setup/winxp_openvpn">erwähnten Seite</a> auf ivacy.com gibt und die richtigen Berechtigungen(600) geben.</p>
<p>Die up und down Scripte können wohl auch durch <em>/etc/openvpn/update-resolv.conf</em> ersetzt werden(sofern vorhanden), siehe dazu auch den <a href="http://geekosphere.org/852/ivacy-mit-openvpn-unter-linux/">Artikel auf Geekosphere</a>. Ich verwende die Scripte auch dazu um den Socks-Daemon zu starten/beenden. Hier die Scripte:</p>
<p><strong>/etc/openvpn/ivacy-up.sh:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf.last
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver 1.254.2.2&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver 1.254.2.3&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>sockd <span style="color: #660033;">-D</span></pre></div></div>

<p><strong>/etc/openvpn/ivacy-down.sh:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf.last <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf
<span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-9</span> sockd</pre></div></div>

<p>Die DNS-Server können der Tabelle unten entnommen werden, jedoch ist mir nur ein OpenVPN-Server von Ivacy bekannt, eben der in Russland, deshalb ist auch <strong>keine</strong> Country-Selection über OpenVPN möglich! (höchstens über die Double-VPN Funktion) Die OpenVPN Verbindung startet man darauf mit:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openvpn <span style="color: #660033;">--script-security</span> <span style="color: #000000;">3</span> system <span style="color: #660033;">--config</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ivacy.conf</pre></div></div>

<p>Nicht vergessen in der <em>/etc/socksd.conf</em>-Datei, &#8220;external&#8221; auf das verwendete tun-Device(tun0 z.B.) einzustellen.</p>
<h2>2. PPTP</h2>
<p>Hierfür braucht es pptp(nicht den Server, den Client!), in Arch-Linux heisst das Paket &#8220;pptp-linux&#8221; in Ubuntu &#8220;pptpclient&#8221; und auch sonst gibt es das bestimmt bei jeder Distribution als Paket. Also zuerst vergewissern wir uns das pptp installiert ist:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pptp <span style="color: #660033;">--version</span>
pptp version 1.7.2</pre></div></div>

<p>Die Konfiguration besteht nur 2 Dateien, zunächst /etc/ppp/chap-secrets:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Username<span style="color: #7a0874; font-weight: bold;">&#93;</span> PPTP <span style="color: #7a0874; font-weight: bold;">&#91;</span>Password<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>Dein Benutzername und Passwort von Ivacy eintragen. /etc/ppp/peers/ivacy</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pty <span style="color: #ff0000;">&quot;pptp pptp2.ivacy.com --nolaunchpppd&quot;</span>
name <span style="color: #7a0874; font-weight: bold;">&#91;</span>Username<span style="color: #7a0874; font-weight: bold;">&#93;</span>
remotename PPTP
require-mppe-<span style="color: #000000;">128</span>
<span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ppp<span style="color: #000000; font-weight: bold;">/</span>options.pptp</pre></div></div>

<p>Auch hier den Usernamen ändern. Die Verbindung kann mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pon ivacy debug dump logfd <span style="color: #000000;">2</span> nodetach</pre></div></div>

<p>getestet werden. Wird die local und remote IP angezeigt funktioniert alles.</p>
<h3>2.1. Country Selection</h3>
<p>Ivacy ermöglicht es den VPN-Server nach Land auszuwählen. Zur Verfügung steht USA, England und Russland. Auswählen kann man das unter Windows mit ihren Ivacy Monitor(und den anderen Programmen von Ivycy). Der PPTP-Host bestimmt das Land:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pptp2.ivacy.com	Russland
pptp3.ivacy.com	England
pptp4.ivacy.com	USA</pre></div></div>

<p>Dies also entsprechend oben anpassen, je nach aus welchem Land man ins Internet will. (VDS gilt übrigens auch in England)</p>
<p>Die wichtigsten Einstellungen, das kann sich natürlich alles ändern und man sollte das entsprechend ändern sofern ifconfig ppp0 eine andere IP zeigt:<br />
<strong>Russland:</strong><br />
<code>PPTP-Server: 213.232.208.167 (pptp2.ivacy.com)<br />
Gateway: 1.254.2.167<br />
DNS Primary: 1.254.2.2<br />
DNS Secondary: 1.254.2.3</code></p>
<p><strong>England:</strong><br />
<code>PPTP-Server: 81.222.64.214 (pptp3.ivacy.com)<br />
Gateway: 1.254.3.131<br />
DNS Primary: 1.254.3.2<br />
DNS Secondary: 1.254.3.3</code></p>
<p><strong>USA:</strong><br />
<code>PPTP-Server: 208.88.226.38 (pptp4.ivacy.com)<br />
Gateway: 1.254.4.128<br />
DNS Primary: 1.254.4.2<br />
DNS Secondary: 1.254.4.3</code></p>
<h3>2.2. Verbindung herstellen</h3>
<p>Hier ein Auszug wie das Verbinden funktionieren kann(mit pptp2.ivacy.com, IP: 213.232.208.167):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ route del <span style="color: #660033;">-net</span> default <span style="color: #666666; font-style: italic;"># Das Entfernen des Default-Gateways</span>
<span style="color: #666666; font-style: italic;"># Der PPTP-Server soll über den eben gelöschten Default-Gateway geroutet werden:</span>
$ route add <span style="color: #660033;">-host</span> 213.232.208.167 gw 10.0.0.1
$ pon ivacy <span style="color: #666666; font-style: italic;"># Die PPTP-Verbindung wird hergestellt</span>
<span style="color: #666666; font-style: italic;"># Nach ein paar Sekunden sollte die Verbindung aufgebaut sein...</span>
$ <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> ppp0
ppp0      Link encap:Point-to-Point Protocol
          inet addr:1.2.127.104  P-t-P:1.254.2.167  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:<span style="color: #000000;">1406</span>  Metric:<span style="color: #000000;">1</span>
          RX packets:<span style="color: #000000;">21</span> errors:<span style="color: #000000;">0</span> dropped:<span style="color: #000000;">0</span> overruns:<span style="color: #000000;">0</span> frame:<span style="color: #000000;">0</span>
          TX packets:<span style="color: #000000;">24</span> errors:<span style="color: #000000;">0</span> dropped:<span style="color: #000000;">0</span> overruns:<span style="color: #000000;">0</span> carrier:<span style="color: #000000;">0</span>
          collisions:<span style="color: #000000;">0</span> txqueuelen:<span style="color: #000000;">3</span>
          RX bytes:<span style="color: #000000;">2774</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2.7</span> Kb<span style="color: #7a0874; font-weight: bold;">&#41;</span>  TX bytes:<span style="color: #000000;">1189</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1.1</span> Kb<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #666666; font-style: italic;"># Die P-t-P IP wird als neuer Default-Gateway eingetragen:</span>
$ route add <span style="color: #660033;">-net</span> default gw 1.254.2.167
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver 1.254.2.2&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf <span style="color: #666666; font-style: italic;"># Eintragen der DNS Adressen:</span>
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver 1.254.2.3&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf
<span style="color: #666666; font-style: italic;"># Noch als kleiner Hint:</span>
$ route <span style="color: #660033;">-n</span>
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
213.232.208.167 10.0.0.1        255.255.255.255 UGH   <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>        <span style="color: #000000;">0</span> eth0
1.254.2.167     0.0.0.0         255.255.255.255 UH    <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>        <span style="color: #000000;">0</span> ppp0
10.0.0.0        0.0.0.0         255.255.255.0   U     <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>        <span style="color: #000000;">0</span> eth0
0.0.0.0         1.254.2.167     0.0.0.0         UG    <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>        <span style="color: #000000;">0</span> ppp0</pre></div></div>

<p>Die Verbindung sollte jetzt stehen. Ich bin ziemlich sicher das das alles viel einfacher geht, aber mir erschien dieser Weg als der logischste, natürlich schreibt man sich das alles in ein entsprechendes Shell-Skript. (Update: siehe Unten, <a href="http://apoc.sixserv.org/scripts/ivacyConnect.rb">ivacyConnect.rb</a>)<br />
Hier noch das Gegenstück, das beenden der Verbindung und umleiten der Route:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ poff ivacy
$ route add <span style="color: #660033;">-net</span> default gw 10.0.0.1 <span style="color: #666666; font-style: italic;"># Bei mir ist 10.0.0.1 der Gateway, entsp. ändern</span>
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver 10.0.0.1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf <span style="color: #666666; font-style: italic;"># Was auch immer euer DNS ist.</span></pre></div></div>

<h3>2.3. Connect Script</h3>
<p>Ich dachte ich stelle auch mal mein Script online mit dem ich die Ivacy Verbindung aufbaue: <a href="http://apoc.sixserv.org/scripts/ivacyConnect.rb">ivacyConnect.rb</a><br />
Das ganze ist ein Ruby Script, muss natürlich als root ausgeführt werden. Außerdem sollten die Werte am Anfang an das eigene Netzwerk angepasst werden. Es basiert darauf das in der /etc/ppp/peers/ivacy als Hostnamen für den PPTP-Server, &#8220;pptp.ivacy.com&#8221; eingetragen ist. Je nach Land ändert es dann die IP dieser Domain über die /etc/hosts Datei.</p>
<h2>3. Socks v5 Server</h2>
<p>Der Vorteil eines solchen Socks5 > Ivacy Gateways liegt einfach darin, das man pro Anwendung entscheiden kann ob sie über Ivacy gehen soll oder nicht. Dazu im nächsten Teil mehr, erstmal zum Einrichten des Socks5 Servers. Zum Einsatz kommt Dante, einem einfach zu konfigurierenden Socks-Server. (Bei Arch Linux ist Dante im AUR zu finden.) <em>/etc/sockd.conf:</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">logoutput: syslog stdout
internal: eth0 port = <span style="color: #000000;">1080</span>
external: ppp0 <span style="color: #666666; font-style: italic;"># -- bei OpenVPN zu tun0 oder besser gesagt tunN ändern.</span>
&nbsp;
method: none
clientmethod: none
extension: <span style="color: #7a0874; font-weight: bold;">bind</span>
&nbsp;
connecttimeout: <span style="color: #000000;">120</span>   <span style="color: #666666; font-style: italic;"># on a lan, this should be enough if method is &quot;none&quot;.</span>
iotimeout: <span style="color: #000000;">0</span> <span style="color: #666666; font-style: italic;"># or perhaps 86400, for a day.</span>
&nbsp;
client pass <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        from: 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> port <span style="color: #000000;">1</span>-<span style="color: #000000;">65535</span> to: 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
pass <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        from: 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> to: 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>
        <span style="color: #7a0874; font-weight: bold;">command</span>: <span style="color: #7a0874; font-weight: bold;">bind</span>
        log: connect error
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
pass <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        from: 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> to: 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
        <span style="color: #7a0874; font-weight: bold;">command</span>: bindreply udpreply
        log: connect error
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
pass <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        from: 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> to: 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>
        protocol: tcp udp
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Da der Server ohnehin nur in meinem LAN erreichbar ist, verzichte ich auf jedwede Authentifikation. Gestartet wird der Socks5-Dante mit:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ sockd
$ sockd <span style="color: #660033;">-d</span> <span style="color: #666666; font-style: italic;"># Debug Mode, nützlich bei fehlerhafter Konfiguration</span></pre></div></div>

<h3>3.1. Firefox</h3>
<p>Von Haus aus kann Firefox Socks Proxy verwenden. In den Netzwerk Einstellungen also die IP des VPN-Gateways und 1080 als Port einstellen. DNS-Requests werden per Default nicht über den Socks geleitet. Um dies zu aktivieren, verändert man die Config-Variable &#8220;network.proxy.socks_remote_dns&#8221; über &#8220;about:config&#8221;.<br />
Eine weitere Möglichkeit ist z.B. das <a href="https://addons.mozilla.org/de/firefox/addon/2464">FoxyProxy-AddOn</a>. Damit kann sehr schnell der Socks aktiviert werden, oder zwischen eingestellten Proxys ausgewählt werden. Wichtig ist auch hier die DNS über Socks Funktion zu aktivieren. Zu finden in den FoxyProxy Options -> Global Settings -> Use SOCKS proxy for DNS lookups.</p>
<p><img class="aligncenter size-full wp-image-185" title="FoxyProxy Firefox-Plugin" src="http://sixserv.org/wp-content/uploads/2009/01/foxy_proxy_screeny1.png" alt="FoxyProxy Firefox-Plugin" width="426" height="109" /></p>
<p>Um sich nicht durch Cookies usw. zu verraten empfiehlt es sich ein neues Profil fürs Surfen per VPN anzulegen. Praktisch ist es auch einen <a href="http://www.canfield.com/content/multiple-independent-firefox-sessions">zweiten Firefox</a> mit Proxy laufen zu lassen.</p>
<h3>3.2. TSocks</h3>
<p>Das kleine Programm tsocks erlaubt das transparente Umleiten des Traffics. Nachdem es eingerichtet ist kann man so jedes beliebige Programm über den Socks5 Ivacy Gateway laufen lassen. Nachdem man tsocks installiert hat muss noch folgende Konfigurationsdatei angelegt werden:</p>
<p><strong>/etc/tsocks.conf</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">local</span> = 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0
&nbsp;
server = 10.0.0.30
server_port = <span style="color: #000000;">1080</span>
server_type = <span style="color: #000000;">5</span></pre></div></div>

<p>Jedes beliebige Programm kann jetzt über den Socks-Server geleitet werden, auch dann wenn es selbst gar keinen Socks-Proxy unterstützt. Dazu wird einfach tsocks vorangestellt, z.B.:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tsocks <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>google.com<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Zu beachten ist, das die DNS-Aufrufe weiterhin über den in resolv.conf eingestellten DNS-Server laufen und so neben dem kleinen Anonymitätsverlust, auch die internen Ivacy-Seiten(.site) nicht aufgelöst werden können.</p>
<h3>4. Privoxy: HTTP Proxy Server</h3>
<p>Viele Anwendungen unterstützen keine Socks5 Proxys, daher ist ein gewöhnlicher HTTP-Proxy manchmal ganz praktisch. Privoxy kennen bestimmt viele in Verbindung mit Tor, für unsere VPN-Gateway VM muss lediglich die folgende Zeile in der Konfiguration(<strong>/etc/privoxy/config</strong>) geändert werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">listen-address  127.0.0.1:<span style="color: #000000;">8118</span>
ändern auf die lokale IP:
listen-address  10.0.0.30:<span style="color: #000000;">8118</span></pre></div></div>

<p><em>Das war dann schon alles zum Thema Ivacy, ich werde den Artikel auch in Zukunft überarbeiten wenn mir neues dazu einfällt. Anmerkungen und Feedback ist natürlich wie immer gern gesehn, ich hoffe einigen Linux-Usern damit geholfen zu haben.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2009/01/24/ivacy-vpn-unter-linux-pptp-und-socks5/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>xinetd: info script</title>
		<link>http://sixserv.org/2009/01/22/xinetd-info-script/</link>
		<comments>http://sixserv.org/2009/01/22/xinetd-info-script/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 18:00:29 +0000</pubDate>
		<dc:creator>apoc</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RBot]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[hddtemp]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sensors]]></category>
		<category><![CDATA[xinetd]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=142</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/>Ich wollte von unterwegs aus den Status meines Heimservers abrufen können. Dabei ging es mir vorallem um die Temperatur von CPU, Mainboard und den Festplatten. Der auf sixserv.org laufende rbot(im Freenode idled der in #sixserv) soll auf Kommando den Status anzeigen. Soweit so gut. Ein kleines Ruby-Skript das auf dem Server zuhause läuft erfasst die [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/><p>Ich wollte von unterwegs aus den Status meines Heimservers abrufen können. Dabei ging es mir vorallem um die Temperatur von CPU, Mainboard und den Festplatten. Der auf sixserv.org laufende rbot(im Freenode idled der in #sixserv) soll auf Kommando den Status anzeigen. Soweit so gut. Ein kleines Ruby-Skript das auf dem Server zuhause läuft erfasst die Temperaturen per &#8220;sensors&#8221; und &#8220;hddtemp&#8221;. Der xinetd-Daemon konfigurierte ich daraufhin so das auf einen Port das Skript gebunden wird. Es erwartet bevor es die Daten übermittelt ein Passwort, einfach zum zusätzlichen Schutz auch wenn das vielleicht gar nicht nötig ist. Jemand der einen Portscan durchführt könnte eben so informationen zum System gelangen, die Passwortabfrage verhindert dies.</p>
<p>Zunächst zu dem Ruby-Script(z.B. /opt/botinfo.rb):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
i = <span style="color:#CC00FF; font-weight:bold;">Kernel</span>.<span style="color:#CC0066; font-weight:bold;">gets</span>
<span style="color:#9966CC; font-weight:bold;">if</span> i.<span style="color:#CC0066; font-weight:bold;">chomp</span> != <span style="color:#996600;">'DASGEHEIMEPASSWORT'</span> <span style="color:#9966CC; font-weight:bold;">then</span>
	<span style="color:#008000; font-style:italic;"># puts 'Wrong Password'</span>
	<span style="color:#CC0066; font-weight:bold;">exit</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">`uptime`</span>.<span style="color:#9900CC;">lstrip</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># HDD Temps:</span>
matches = <span style="color:#996600;">`cat /proc/partitions`</span>.<span style="color:#9900CC;">scan</span> <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>s<span style="color:#006600; font-weight:bold;">|</span>h<span style="color:#006600; font-weight:bold;">&#93;</span>d<span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>
matches.<span style="color:#9900CC;">uniq</span>!
matches.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>disk<span style="color:#006600; font-weight:bold;">|</span>
	<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;#{disk}: #{`hddtemp -n /dev/#{disk}`.chomp}.0*C (#{$1}GB) &quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> 
&nbsp;
systemp = <span style="color:#996600;">`sensors`</span>
&nbsp;
temp1 = systemp.<span style="color:#9900CC;">scan</span> <span style="color:#006600; font-weight:bold;">/</span>CPU Temp:    \<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>\.0.<span style="color:#9900CC;">C</span><span style="color:#006600; font-weight:bold;">/</span>
temp2 = systemp.<span style="color:#9900CC;">scan</span> <span style="color:#006600; font-weight:bold;">/</span>M\<span style="color:#006600; font-weight:bold;">/</span>B Temp:    \<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>\.0.<span style="color:#9900CC;">C</span><span style="color:#006600; font-weight:bold;">/</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;System: #{temp2[0]}.0*C #{temp2[1]}.0*C | CPUs: #{temp1[0]}.0*C #{temp1[1]}.0*C&quot;</span></pre></td></tr></table></div>

<p>Hier muss natürlich sensors und hddtemp installiert sein, aber dieses Script kann praktisch alles mögliche an Informationen sammeln und ausgeben.<br />
Die Konfiguration von xinetd gestaltet sich sehr einfach, in dem Verzeichnis /etc/xinetd.d einfach eine neue Datei für das Script erstellen(z.B. &#8220;botinfo&#8221;):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">service botinfo
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
    disable         = no
    port            = <span style="color: #000000;">8888</span>
    socket_type     = stream
    protocol        = tcp
    <span style="color: #7a0874; font-weight: bold;">wait</span>            = no
    user            = apoc
    server          = <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>botinfo.rb
    <span style="color: #7a0874; font-weight: bold;">type</span>            = unlisted
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Den Port, User und den Skript Pfad entsprechend anpassen und xinetd neu starten. Mit netcat kann es man danach testen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ nc localhost <span style="color: #000000;">8888</span>
DASGEHEIMEPASSWORT
<span style="color: #000000;">18</span>:<span style="color: #000000;">40</span>:<span style="color: #000000;">35</span> up <span style="color: #000000;">3</span> days, <span style="color: #000000;">41</span> min,  <span style="color: #000000;">4</span> <span style="color: #c20cb9; font-weight: bold;">users</span>,  load average: <span style="color: #000000;">0.00</span>, <span style="color: #000000;">0.02</span>, <span style="color: #000000;">0.20</span>
sda: <span style="color: #000000;">30.0</span><span style="color: #000000; font-weight: bold;">*</span>C <span style="color: #7a0874; font-weight: bold;">&#40;</span>10GB<span style="color: #7a0874; font-weight: bold;">&#41;</span> sdb: <span style="color: #000000;">29.0</span><span style="color: #000000; font-weight: bold;">*</span>C <span style="color: #7a0874; font-weight: bold;">&#40;</span>10GB<span style="color: #7a0874; font-weight: bold;">&#41;</span>
System: <span style="color: #000000;">39.0</span><span style="color: #000000; font-weight: bold;">*</span>C <span style="color: #000000;">38.0</span><span style="color: #000000; font-weight: bold;">*</span>C <span style="color: #000000; font-weight: bold;">|</span> CPUs: <span style="color: #000000;">37.0</span><span style="color: #000000; font-weight: bold;">*</span>C <span style="color: #000000;">36.0</span><span style="color: #000000; font-weight: bold;">*</span>C</pre></td></tr></table></div>

<p>Der Port muss ggf. vom Router geforwarded werden damit ein Entfernter Server darauf zugreifen kann. Auch ein dyndns ist hilfreich, sofern man über keine statische IP verfügt. Ein einfaches rbot-Plugin um diese Daten vom irc aus abzufragen sieht z.B. so aus:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'socket'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> BotinfoPlugin <span style="color:#006600; font-weight:bold;">&lt;</span> Plugin
  <span style="color:#9966CC; font-weight:bold;">def</span> help<span style="color:#006600; font-weight:bold;">&#40;</span>plugin, topic=<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#996600;">'info =&gt; return system information'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> info<span style="color:#006600; font-weight:bold;">&#40;</span>m, params<span style="color:#006600; font-weight:bold;">&#41;</span>
    sock = TCPSocket.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'heimserver.dyndns.org'</span>, <span style="color:#006666;">8888</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    sock.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'DASGEHEIMEPASSWORT'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    m.<span style="color:#9900CC;">reply</span> sock.<span style="color:#9900CC;">recv</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1024</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    sock.<span style="color:#9900CC;">close</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
plugin = BotinfoPlugin.<span style="color:#9900CC;">new</span>
plugin.<span style="color:#9900CC;">map</span> <span style="color:#996600;">'info'</span></pre></td></tr></table></div>

<p>Die Daten können ebenfalls von einem PHP-Script aus abgefragt werden. Keines Beispiel:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$socket</span> <span style="color: #339933;">=</span> <span style="color: #990000;">socket_create</span><span style="color: #009900;">&#40;</span>AF_INET<span style="color: #339933;">,</span> SOCK_STREAM<span style="color: #339933;">,</span> SOL_TCP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">socket_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;heimserver.dyndns.org&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;8888&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DASGEHEIMEPASSWORT<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">socket_write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pass</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">socket_read</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2048</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Vielleicht findet das ja irgendjemand interessant <img src='http://sixserv.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2009/01/22/xinetd-info-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>opengl-background unter compiz</title>
		<link>http://sixserv.org/2008/09/19/opengl-background-unter-compiz/</link>
		<comments>http://sixserv.org/2008/09/19/opengl-background-unter-compiz/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 15:53:50 +0000</pubDate>
		<dc:creator>nks</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[compiz]]></category>
		<category><![CDATA[eye-candy]]></category>
		<category><![CDATA[mplayer]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[xscreensaver]]></category>
		<category><![CDATA[xwinwrap]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=103</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/>Eine weitere nette Spielerei für Leute mit zu viel Ressourcen Ich hab sie nicht aber das ganze läuft auch auf einem 700Mhz Duron flüssig. Ihr benötigt &#8220;xscreensaver&#8221; (und auch das Paket &#8220;fireflies&#8221; falls ihr es wie auf den Screenshots haben wollt, wobei sich &#8220;pong&#8221; auch ganz gut macht) und &#8220;xwinwrap&#8221; (xwinwrap does teh magic) nks@hydra [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/><p>Eine weitere nette Spielerei für Leute mit zu viel Ressourcen <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Ich hab sie nicht aber das ganze läuft auch auf einem 700Mhz Duron flüssig.</p>
<p>Ihr benötigt &#8220;xscreensaver&#8221; (und auch das Paket &#8220;fireflies&#8221; falls ihr es wie auf den Screenshots haben wollt, wobei sich &#8220;pong&#8221; auch ganz gut macht) und &#8220;xwinwrap&#8221; (xwinwrap does teh magic)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nks<span style="color: #000000; font-weight: bold;">@</span>hydra ~ $ <span style="color: #c20cb9; font-weight: bold;">nice</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">15</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>xwinwrap <span style="color: #660033;">-ni</span> <span style="color: #660033;">-argb</span> <span style="color: #660033;">-fs</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">-st</span> <span style="color: #660033;">-sp</span> <span style="color: #660033;">-b</span> <span style="color: #660033;">-nf</span> <span style="color: #660033;">--</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>xscreensaver<span style="color: #000000; font-weight: bold;">/</span>fireflies <span style="color: #660033;">-window-id</span> WID</pre></div></div>

<p>Das ganze sieht dann so aus:</p>
<p><a href="http://sixserv.org/wp-content/uploads/2008/09/screenshot.jpeg" rel="lightbox[103]"><img class="alignnone size-thumbnail wp-image-106" title="screenshot" src="http://sixserv.org/wp-content/uploads/2008/09/screenshot.jpeg" alt="" width="150" height="120" /></a><a href="http://sixserv.org/wp-content/uploads/2008/09/screenshot2.jpeg" rel="lightbox[103]"><img class="alignnone size-medium wp-image-107" title="screenshot2" src="http://sixserv.org/wp-content/uploads/2008/09/screenshot2.jpeg" alt="" width="149" height="120" /></a><a href="http://sixserv.org/wp-content/uploads/2008/09/screenshot3.jpeg" rel="lightbox[103]"><img class="alignnone size-thumbnail wp-image-108" title="screenshot3" src="http://sixserv.org/wp-content/uploads/2008/09/screenshot3.jpeg" alt="" width="150" height="120" /> </a></p>
<p>Für mehr Infos:</p>
<ul>
<li><a href="http://swik.net/xwinwrap">http://swik.net/xwinwrap</a></li>
</ul>
<p>Man kann neben xscreensaver auch Videos als Hintergrund laufen lassen</p>
<p>nks</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2008/09/19/opengl-background-unter-compiz/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>software-kvm mit synergy</title>
		<link>http://sixserv.org/2008/09/19/software-kvm-mit-synergy/</link>
		<comments>http://sixserv.org/2008/09/19/software-kvm-mit-synergy/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 14:54:05 +0000</pubDate>
		<dc:creator>nks</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[eee]]></category>
		<category><![CDATA[fernbedienung]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[synergy]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=98</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/>Mir ist gestern die Fernbedienung meiner Sourround-Anlage auf den Boden gefallen &#8211; jetzt ist sie unbrauchbar. Also dachte ich mir: &#8220;Hey, mach doch den eee-pc zu deiner neuen Fernbedienung!&#8221;. Also wenn ich im bett liege und die lautstärke regeln will, schnell per ssh auf den Rechner verbinden und alsamixer nutzen. Aber dafür is der eee [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_linux.png" width="50" height="51" alt="" title="Linux" /><br/><p>Mir ist gestern die Fernbedienung meiner Sourround-Anlage auf den Boden gefallen &#8211; jetzt ist sie unbrauchbar. Also dachte ich mir: &#8220;Hey, mach doch den eee-pc zu deiner neuen Fernbedienung!&#8221;.</p>
<p>Also wenn ich im bett liege und die lautstärke regeln will, schnell per ssh auf den Rechner verbinden und alsamixer nutzen. Aber dafür is der eee ja schon bisl overkill. Dann erinnerte ich mich an meine Experimente vor einem Jahr die beiden desktop-pcs miteinander zu verbinden.</p>
<p>Ich hatte es auch mit synergy versucht, aber es war ziemlich buggy. Aber die neue Version läuft wesentlich stabiler. Also schnell auf allen 3 boxen synergy gemerged und ab an die config:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># nks's synergy configuration file</span>
<span style="color: #666666; font-style: italic;"># eeerr0r is the synergy-server</span>
<span style="color: #666666; font-style: italic;"># infected and hydra are the clients</span>
&nbsp;
section: screens
infected:
hydra:
eeerr0r:
end
&nbsp;
section: links
<span style="color: #666666; font-style: italic;"># larry is to the right of moe and curly is above moe</span>
infected:
right = eeerr0r
eeerr0r:
left = infected
right = hydra
hydra:
left = eeerr0r
end
section: aliases
infected:
192.168.178.30
hydra:
192.168.178.32
eeerr0r:
192.168.178.25
end</pre></div></div>

<p>Das ganze dann auf dem System welches Tastatur und Maus bereitstellen soll unter &#8220;/etc/synergy.conf&#8221;<br />
und dann ab in die shell:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nks<span style="color: #000000; font-weight: bold;">@</span>eeerr0r ~ $ synergys <span style="color: #660033;">-f</span> <span style="color: #660033;">--config</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>synergy.conf</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nks<span style="color: #000000; font-weight: bold;">@</span>infected ~ $ synergyc <span style="color: #660033;">-f</span> eeerr0r</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nks<span style="color: #000000; font-weight: bold;">@</span>hydra ~ $ synergyc <span style="color: #660033;">-f</span> eeerr0r</pre></div></div>

<p>Und schon kann ich vom eee-pc aus beide Rechner kvm-style fernsteuern <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
das ganze funktioniert auch unter windows und mac os.</p>
<p>Besonders schön is das ganze in Kombination mit compiz weil man dann vom Bett/anywhere aus ranzoomen kann <img src='http://sixserv.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Informationen &amp; links:</p>
<ul>
<li><a href="http://synergy2.sourceforge.net/">http://synergy2.sourceforge.net/</a></li>
<li><a href="http://de.wikipedia.org/wiki/Synergy">http://de.wikipedia.org/wiki/Synergy</a></li>
</ul>
<p>ps: <a href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&amp;friendID=50002989">chase &amp; status</a> releasen demnächst ihr neues Album, zwar ziemlich die uk-kommerz schiene, aber &#8220;hurt you&#8221; und &#8220;pieces&#8221; laufen atm ja fast in jedem set, also man kann gespannt sein (wobei &#8220;hurt you&#8221; auch auf dem neuem Album ist)</p>
<p>pps:Ich hatte damals auch mit xdmx ruexperimentiert, hehe.. vll. probier ich demnächst auch wieder etwas damit rum, allerdings mit compiz etwas zu lahm, in Kombination mit <a href="http://chromium.sourceforge.net/">chromium</a> funktioniert es vll besser.</p>
<p>nks</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2008/09/19/software-kvm-mit-synergy/feed/</wfw:commentRss>
		<slash:comments>0</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>
