<?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>drewke.net</title>
	<atom:link href="http://drewke.net/dnwp/feed/" rel="self" type="application/rss+xml" />
	<link>http://drewke.net/dnwp</link>
	<description>drewke.net::Andreas Drewke</description>
	<lastBuildDate>Mon, 01 Apr 2013 20:48:20 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Injections</title>
		<link>http://drewke.net/dnwp/injections/</link>
		<comments>http://drewke.net/dnwp/injections/#comments</comments>
		<pubDate>Mon, 17 Dec 2012 21:44:13 +0000</pubDate>
		<dc:creator>Andreas Drewke</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[code injection]]></category>
		<category><![CDATA[html injection]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql injections]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://drewke.net/dnwp/?p=141</guid>
		<description><![CDATA[In last time i saw more often security holes in web applications from web developers that actually do create web applications and run them &#8211; SQL injections. I do not understand that, because avoiding them is actually no voodoo. 1. &#8230; <a href="http://drewke.net/dnwp/injections/">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In last time i saw more often security holes in web applications from web developers that actually do create web applications and run them &#8211; SQL injections.</p>
<p>I do not understand that, because avoiding them is actually no voodoo.</p>
<p><strong>1. Understanding SQL injections</strong></p>
<p style="padding-left: 30px;">Its easy. You instruct a mysql server to do things with SQL commands. At the application level these are normal strings consisting of a human readable syntax.<br />
So this is actually where exactly the injection can happen.</p>
<p style="padding-left: 30px;">Usually you will not write harmful SQL code on your own, so where do they really come from?</p>
<p style="padding-left: 30px;">This query does not look harmful:</p>
<p style="padding-left: 60px;"><em>$sql = &#8216;SELECT `id`, `name` FROM `accounts`&#8217;;</em></p>
<p style="padding-left: 30px;">This query does:</p>
<p style="padding-left: 60px;"><em>$sql = &#8216;SELECT `id`, `name` FROM `accounts` WHERE `id` = &#8216; . $id;</em></p>
<p style="padding-left: 60px;">Just depending where your $id does come from.</p>
<p style="padding-left: 60px;">Consider the following code:</p>
<p style="padding-left: 90px;"><em>$aid = $_GET['aid']; // read account id from GET parameter</em><br />
<em> $sql = &#8216;SELECT `id`, `name` FROM `accounts` WHERE `id` = &#8216; . $aid;</em><br />
<em> mysql_query($sql);</em><br />
&#8230;</p>
<p style="padding-left: 60px;">This can lead to a SQL injection, as I could do the following</p>
<p style="padding-left: 90px;"><em>curl &#8220;http://yourwebapplicationhost/account.php?id=0%3B%20DROP%20TABLE%20%60accounts%60%3B&#8221;</em></p>
<p style="padding-left: 90px;">The above code just means I can directly manipulate the SQL command.<br />
I just need to end the SQL &#8220;SELECT&#8221; and add a SQL &#8220;DROP TABLE `accounts`;&#8221;</p>
<p style="padding-left: 90px;">Its the same like:</p>
<p style="padding-left: 90px;"><em>$aid = &#8217;0; DROP TABLE `accounts`&#8217;;</em><br />
<em> $sql = &#8216;SELECT `id`, `name` FROM `accounts` WHERE `id` = &#8216; . $aid;</em><br />
<em> mysql_query($sql);</em><br />
&#8230;</p>
<p style="padding-left: 60px;">I could give more examples. But the idea should be clear now.<br />
No. Magic quotes is not a fix. Its rather a mess and deprecated. Just qoogle that.</p>
<p><strong>2. How to prevent SQL injections</strong></p>
<p style="padding-left: 30px;"><strong>2.1 Escaping</strong></p>
<p style="padding-left: 60px;">A key to success could be escaping. In easy words escaping means that &#8220;user input&#8221; data will be prepared to be safely used in a SQL query.<br />
If tied to old functional mysql API you just need to do it with <a title="mysql_real_escape_string()" href="http://de1.php.net/manual/en/function.mysql-real-escape-string.php" target="_blank">mysql_real_escape_string()</a>. If using PDO just have a look at: <a title="PDO::quote()" href="http://php.net/manual/en/pdo.quote.php" target="_blank">PDO::quote()</a></p>
<p style="padding-left: 60px;">So our code could be fixed like:</p>
<p style="padding-left: 90px;"><em>$aid = $_GET['aid']; // read account id from GET parameter</em><br />
<em> $sql = &#8216;SELECT `id`, `name` FROM `accounts` WHERE `id` = &#8216; . mysql_real_escape_string($aid);</em><br />
<em> mysql_query($sql);</em><br />
&#8230;</p>
<p style="padding-left: 30px;"><strong>2.2 Prepared Statements</strong></p>
<p style="padding-left: 60px;">A better way to prevent SQL injections is to use PDO with prepared statements.<br />
Prepared statements have advantages and disadvantes too.</p>
<p style="padding-left: 60px;"><strong>2.2.1 Advantages:</strong></p>
<p style="padding-left: 90px;">Prepared statements are SQL commands without the actual parameters. They are more like templates for queries of the same type. They become compiled in the SQL server and can be reused which gives a performance gain as compiling is only required one time.</p>
<p style="padding-left: 120px;">I tested it once and if i remember right, my application speed increased by 20%<br />
Unfortunatly web application requests have a very short life time so that reusing them does not often makes that much sense.</p>
<p style="padding-left: 90px;">Well, as the parameters are not included in the SQL command you just can not tweak the SQL command but only its parameters.</p>
<p style="padding-left: 60px;"><strong>2.2.2 Disadvantages:</strong></p>
<p style="padding-left: 90px;"><strong></strong>You need one more request to the database server to set up the prepared statement.<br />
You cannot use parameter binding in SQL commands like:</p>
<p style="padding-left: 120px;"><em>SELECT `id`,`name` FROM `accounts` WHERE `id` IN(:id1, :id2)</em></p>
<p style="padding-left: 120px;">You would have to use <a title="PDO::quote()" href="http://php.net/manual/en/pdo.quote.php" target="_blank">PDO::quote()</a> again and construct your SQL like:</p>
<p style="padding-left: 150px;"><em>// set up ids</em><br />
<em> $ids = array(1,2);</em><br />
<em> // quote ids</em><br />
<em> foreach($ids as &amp;$id) $id = PDO::quote($id);</em><br />
<em> // construct SQL</em><br />
<em> $sql = &#8216;SELECT `id`,`name` FROM `accounts` WHERE `id` IN(&#8216; . implode(&#8216;,&#8217;, $ids) . &#8216;)&#8217;;</em><br />
&#8230;</p>
<p><strong>3. Conclusion:</strong></p>
<p style="padding-left: 30px;"><strong></strong>You should always be alerted if putting input data not constructed directly from or not validated of your application itself from like $_GET, $_POST, $_REQUEST, &#8230; into e.g. a SQL query and thus escape it.<br />
Its even better to have a abstract security concept which might be e.g. using prepared statements.<br />
&#8230;</p>
<p><strong>4. XSS/HTML injections</strong></p>
<p style="padding-left: 30px;">Injections mean injecting something! So injections are all similar.<br />
A simple example of a XSS or HTML injection would be:</p>
<p style="padding-left: 60px;"><em><em>$userName = $_GET['username'];</em><br />
<em> echo &#8216;Hallo &#8216; . $userName;</em></em></p>
<p style="padding-left: 30px;">So with this kind of script i can easily put HTML or Javascript on your page just by putting some HTML or Javascript into a GET parameter &#8220;username&#8221; when calling the script.</p>
<p style="padding-left: 30px;">You might want to have a look at <a title="strip_tags()" href="http://php.net/manual/de/function.strip-tags.php" target="_blank">strip_tags()</a> or using certificates.</p>
<p style="padding-left: 30px;">I think, i dont need to explain that further.</p>
<p><strong>5. Code injections</strong></p>
<p style="padding-left: 30px;">Its the same with code injections. The difference is just where you put the injected data. With PHP code injections  a candidate e.g. is:</p>
<p style="padding-left: 60px;"><em>$code = $_GET['code'];<br />
</em><em>eval($_GET['code']);</em></p>
<p><strong>6. So what?</strong></p>
<p style="padding-left: 30px;">So this article may not be complete but it should at least make up an idea about this topic in your mind.</p>
<p style="padding-left: 30px;">Please be aware that this article is about injections related to PHP, but they work the same way in other languages as well like javascript, java, &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://drewke.net/dnwp/injections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install a NetBSD 6.0 workstation on a laptop</title>
		<link>http://drewke.net/dnwp/how-to-install-a-netbsd-6-0-workstation-on-a-laptop/</link>
		<comments>http://drewke.net/dnwp/how-to-install-a-netbsd-6-0-workstation-on-a-laptop/#comments</comments>
		<pubDate>Sun, 28 Oct 2012 12:01:10 +0000</pubDate>
		<dc:creator>Andreas Drewke</dc:creator>
				<category><![CDATA[NetBSD]]></category>
		<category><![CDATA[6.0]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[laptop]]></category>
		<category><![CDATA[mc]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[netbsd]]></category>
		<category><![CDATA[pkgin]]></category>
		<category><![CDATA[scite]]></category>
		<category><![CDATA[thunderbird]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vlc]]></category>
		<category><![CDATA[wifi]]></category>
		<category><![CDATA[wlan]]></category>
		<category><![CDATA[workstation]]></category>
		<category><![CDATA[xfce4]]></category>

		<guid isPermaLink="false">http://drewke.net/dnwp/?p=76</guid>
		<description><![CDATA[How to install a NetBSD workstation on a laptop: This is a very short tutorial how to install NetBSD 6.0 on a Laptop. It installs the OS on the whole hard disc, sets ups WIFI, installs pkgin, a binary package &#8230; <a href="http://drewke.net/dnwp/how-to-install-a-netbsd-6-0-workstation-on-a-laptop/">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>How to install a NetBSD workstation on a laptop:</strong></p>
<p>This is a very short tutorial how to install NetBSD 6.0<br />
on a Laptop.<br />
It installs the OS on the whole hard disc, sets ups WIFI,<br />
installs pkgin, a binary package manager, and some basic software&#8230;</p>
<p>Grab the ISO for NetBSD 6.0 for your machine and burn it:<br />
ftp://iso.netbsd.org/pub/NetBSD/iso/6.0/</p>
<p><strong>Install NetBSD:</strong></p>
<ul>
<li>put CD into your CD-ROM drive</li>
<li>setup BIOS to boot from CD</li>
<li>reboot computer</li>
<li>NetBSD installer</li>
<ul>
<li>choose language</li>
<li>choose keyboard type</li>
<li>Install NetBSD to hard disk</li>
<li>confirm install to whole hard disk</li>
<li>press ok to confirm install to whole hard disk again</li>
<li>choose custom Installation</li>
<ul>
<li>kernel</li>
<li>kernel modules</li>
<li>base</li>
<li>/etc</li>
<li>compiler tools</li>
<li>online manual pages</li>
<li>text processing tools</li>
<li>complete X11</li>
<li>confirm disc geometry</li>
</ul>
<li>use the entire disc</li>
<li>update boot code</li>
<li>use predefined partition sizes</li>
<ul>
<li>will create swap with size of memory</li>
<li>will create root partition</li>
</ul>
<li>confirm disk name</li>
<li>confirm installation</li>
<li>use bios console</li>
<li>choose cd-rom as install media</li>
<li>choose timezone</li>
<li>change root password</li>
<li>finish configuring</li>
<li>remove cd</li>
<li>reboot</li>
</ul>
</ul>
<p><strong>Basic rc.conf setup:</strong></p>
<p style="padding-left: 30px;">vi /etc/rc.conf</p>
<p style="padding-left: 30px;">put under</p>
<p style="padding-left: 60px;">&#8220;# Add local overrides below<br />
wscons = YES&#8221;</p>
<p style="padding-left: 60px;">the following lines:</p>
<p style="padding-left: 60px;">sshd=NO<br />
postfix=NO<br />
inetd=NO</p>
<p><strong>Enable WIFI:</strong></p>
<p style="padding-left: 30px;">vi /etc/wpa_supplicant.conf</p>
<p style="padding-left: 30px;">Add the following lines:</p>
<p style="padding-left: 60px;">network={<br />
ssid=&#8221;&lt;YOUR SSID/WLAN NAME&gt;&#8221;<br />
psk=&#8221;&lt;PSK&gt;&#8221;<br />
}</p>
<p style="padding-left: 30px;">vi /etc/rc.conf</p>
<p style="padding-left: 60px;">put the following to the end of the file</p>
<p style="padding-left: 60px;"># wlan<br />
wpa_supplicant=YES<br />
wpa_supplicant_flags=&#8221;-B -i -c /etc/wpa_supplicant.conf&#8221;<br />
ifconfig_&lt;DEVICE NAME&gt;=&#8221;dhcp&#8221;<br />
dhclient=YES</p>
<p style="padding-left: 30px;">reboot</p>
<p><strong>Install pkgin:</strong></p>
<p style="padding-left: 30px;">export PKG_PATH=ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/&lt;arch&gt;/6.0/All<br />
pkg_add -v pkgin</p>
<p style="padding-left: 30px;">echo $PKG_PATH &gt; /usr/pkg/etc/pkgin/repositories.conf</p>
<p style="padding-left: 30px;">pkgin update</p>
<p><strong>Install Midnight Commander:</strong></p>
<p style="padding-left: 30px;">pkgin install mc</p>
<p><strong>Install XFCE:</strong></p>
<p style="padding-left: 30px;">pkgin install xfce4</p>
<p style="padding-left: 30px;">vi .xinitrc in your home folder and place the following line</p>
<p style="padding-left: 60px;">startxfce4</p>
<p style="padding-left: 30px;">to start x type in shell</p>
<p style="padding-left: 60px;">startx</p>
<p><strong>Install Thunderbird:</strong></p>
<p style="padding-left: 30px;">pkgin install thunderbird</p>
<p><strong>Install Firefox:</strong></p>
<p style="padding-left: 30px;">pkgin install firefox36</p>
<p style="padding-left: 30px;">if xfce asks later for browser executable just type &#8220;firefox36&#8243;</p>
<p><strong>Install VLC:</strong></p>
<p style="padding-left: 30px;">pkgin install vlc-2.0.3</p>
<p><strong>Install Scite code editor</strong></p>
<p style="padding-left: 30px;">pkgin install scite</p>
<p><strong>Add a user</strong></p>
<p style="padding-left: 30px;">useradd -m -G wheel &lt;name&gt;<br />
passwd &lt;name&gt;</p>
<p><strong>More to come:</strong></p>
<p style="padding-left: 30px;">GDM or similar<br />
Flash<br />
Java, Eclipse<br />
CodeBlocks<br />
Skype</p>
<p style="padding-left: 30px;">modular-xorg</p>
<p style="padding-left: 60px;">for hardware accelerated OpenGL- unfortunatly as of 12-10-27 it was broken with my intel GPU</p>
]]></content:encoded>
			<wfw:commentRss>http://drewke.net/dnwp/how-to-install-a-netbsd-6-0-workstation-on-a-laptop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
