<?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>TBNL &#187; security</title>
	<atom:link href="http://www.tibobeijen.nl/blog/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tibobeijen.nl</link>
	<description>...another view on the web and how it's built</description>
	<lastBuildDate>Wed, 06 Jul 2011 19:28:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>SQL injection &amp; the Kaspersky hack</title>
		<link>http://www.tibobeijen.nl/blog/2009/02/11/sql_injection-and-the-kaspersky-hack/</link>
		<comments>http://www.tibobeijen.nl/blog/2009/02/11/sql_injection-and-the-kaspersky-hack/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 18:38:50 +0000</pubDate>
		<dc:creator>Tibo Beijen</dc:creator>
				<category><![CDATA[miscellaneous]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.tibobeijen.nl/?p=137</guid>
		<description><![CDATA[Last week I read an article on webwereld titled &#8216;2008 was year of the SQL injection attack&#8216;. It was based on an article with the same title on networkworld.com. Apparently SQL injection has taken over the lead from XSS. Not surprisingly the first user-comment stated that almost 100% of the exploits were certainly in PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I read an article on webwereld titled &#8216;<a href="http://webwereld.nl/article/comments/id/54694">2008 was year of the SQL injection attack</a>&#8216;. It was based on an <a href="http://www.networkworld.com/news/2009/020209-sql-injection-attack.html">article with the same title on networkworld.com</a>. Apparently SQL injection has taken over the lead from XSS. Not surprisingly the first user-comment stated that almost 100% of the exploits were certainly in PHP applications written by would-be programmers. With things so obvious it&#8217;s of course unneccessary to provide factual data backing up such a statement. So, nothing to win in that discussion. Three days ago news came that <a href="http://www.theregister.co.uk/2009/02/08/kaspersky_compromise_report/">a customer database of Kaspersky was hacked</a>. By using SQL injection. On <a href="http://usa.kaspersky.com/about-us/news-press-releases.php?smnr_id=900000208">a PHP website</a>. Could commenter X be right?<br />
<span id="more-137"></span><br />
It <em>is</em> true that PHP allows novice as well as experienced programmers to achieve &#8216;what they want&#8217;. And the novice might adopt some very bad practices. But does that make PHP an insecure programming language? Compare it to driving a car. Yes, you can drive around like a maniac and wreak havoc on the unaware. But does that make a car an unsecure vehicle?  The PHP platform offers enough techniques to rule out SQL injection attacks:</p>
<ul>
<li>Prepared statements. There&#8217;s no need to concat potentially harmful data in SQL statements. Provide them as a parameter when executung a prepared statement. More efficient too.</li>
<li>ORM. If you think SQL should be behind an abstraction layer, you can do so. <a href="http://propel.phpdb.org/">Propel</a> and <a href="http://www.doctrine-project.org/">Doctrine</a> are the best known solutions for PHP.</li>
<li>Well structured programming. If, for some reason, you want to build queries the old way you can force upon yourself (or your team) some good practices. See example below.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dataTainted</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'un'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'un'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dataTainted</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pw'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pw'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// escape all array values using a custom function of some sort</span>
<span style="color: #000088;">$dataSafe</span> <span style="color: #339933;">=</span> mysqlEscapeValues<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dataTainted</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;SQL
SELECT
  *
FROM
  users
WHERE
  un = &quot;{$dataSafe['un']}&quot;
AND
  pw = SHA1(&quot;{$dataSafe['pw']}&quot;)
SQL</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s just the coding part of the story. In the area of application design a lot can be done to minimize the consequences of an exploit. For example, different database users can be set up that have different levels of access. Only parts of a website needing customer data then use the credentials that do provide such access.</p>
<p>So, for PHP there are good practices and solutions aplenty. For more information on SQL injection one can start at <a href="http://www.owasp.org/index.php/Guide_to_SQL_Injection">OWASP</a> or <a href="http://en.wikipedia.org/wiki/SQL_injection#Real-world_examples">Wikipedia</a>. And finally, the subject isn&#8217;t non-existent in <a href="http://msdn.microsoft.com/en-us/magazine/cc163917.aspx">.NET</a> and <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=585ac720">JSP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tibobeijen.nl/blog/2009/02/11/sql_injection-and-the-kaspersky-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

