<?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>Simon Whatley &#187; exploit</title>
	<atom:link href="http://www.simonwhatley.co.uk/tag/exploit/feed" rel="self" type="application/rss+xml" />
	<link>http://www.simonwhatley.co.uk</link>
	<description>The opposite of every great idea is another great idea</description>
	<lastBuildDate>Wed, 02 Nov 2011 09:28:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Preventing SQL Injection in an AIR Application</title>
		<link>http://www.simonwhatley.co.uk/preventing-sql-injection-in-an-air-application</link>
		<comments>http://www.simonwhatley.co.uk/preventing-sql-injection-in-an-air-application#comments</comments>
		<pubDate>Mon, 01 Sep 2008 10:41:20 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Adobe Integrated Runtime]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[online repositories]]></category>
		<category><![CDATA[relational database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[United States]]></category>
		<category><![CDATA[vulnerability]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=959</guid>
		<description><![CDATA[SQLite is a mostly ACID-compliant relational database management system contained in a relatively small (~500kB) C programming library. The Adobe AIR runtime includes the SQLite embedded database for use by Adobe AIR applications. This allows applications to run and store data locally and or synchronise the datastore with online repositories.]]></description>
			<content:encoded><![CDATA[<p>SQLite is a mostly <a href="http://en.wikipedia.org/wiki/ACID" title="Wikipedia: ACID" target="_blank" rel="nofollow">ACID</a>-compliant relational database management system contained in a relatively small (~500kB) C programming library. The Adobe <acronym title="Adobe Integrated Runtime">AIR</acronym> runtime includes the SQLite embedded database for use by Adobe <acronym title="Adobe Integrated Runtime">AIR</acronym> applications. This allows applications to run and store data locally and or synchronise the datastore with online repositories.</p>
<p>Applications that depend on user input to create a <abbr title="Structured Query Language">SQL</abbr> statement &#8212; concatenating the user input to the SQL query &#8212; can become vulnerable to <a href="http://en.wikipedia.org/wiki/SQL_injection" title="Wikipedia: SQL Injection" target="_blank" rel="nofollow">SQL Injection</a> attacks, much like those common to web applications.</p>
<p><abbr title="Structured Query Language">SQL</abbr> Injection is a technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in <abbr title="Structured Query Language">SQL</abbr> statements or user input is not strongly typed and thereby unexpectedly executed.</p>
<p>Fortunately, there is a simple solution to the problem: use parameterised <abbr title="Structured Query Language">SQL</abbr> Statements. Parameterised statements not only make your applications more secure and run more efficiently, but they also enable you to use objects, rather than literal values, in your queries. <abbr title="Structured Query Language">SQL</abbr> injection can&#8217;t happen because the parameter values are treated explicitly as substituted values, rather than becoming part of the literal statement text.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Parameters in a <abbr title="Structured Query Language">SQL</abbr> statement can be either <em>named</em> or <em>unnamed</em>. Below are examples of both types of statement in ActionScript and JavaScript.</p>
<h3>Named Parameters</h3>
<p>A named parameter has a specific name that is used to match the parameter value to its placeholder location in the <abbr title="Structured Query Language">SQL</abbr> statement text. A parameter name consists of the colon (:) or an at (@) character followed by the variable&#8217;s name:</p>
<p><strong>ActionScript 3</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> conn<span style="color: #000000; font-weight: bold;">:</span>SQLConnection = <span style="color: #0033ff; font-weight: bold;">new</span> SQLConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> stmt<span style="color: #000000; font-weight: bold;">:</span>SQLStatement = <span style="color: #0033ff; font-weight: bold;">new</span> SQLStatement<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
stmt.sqlConnection = conn;
stmt.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;INSERT INTO user VALUES(@title, @firstname, @lastname)&quot;</span>;
stmt.<span style="color: #004993;">parameters</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;@title&quot;</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;Mr&quot;</span>;
stmt.<span style="color: #004993;">parameters</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;@firstname&quot;</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;Simon&quot;</span>;
stmt.<span style="color: #004993;">parameters</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;@lastname&quot;</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;Whatley&quot;</span>;
stmt.execute<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p><strong>JavaScript</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> conn <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> air.<span style="color: #660066;">SQLConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> stmt <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> air.<span style="color: #660066;">SQLStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">sqlConnection</span> <span style="color: #339933;">=</span> conn<span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">text</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;INSERT INTO user VALUES(@title, @firstname, @lastname)&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">parameters</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;@title&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Mr&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">parameters</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;@firstname&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Simon&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">parameters</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;@lastname&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Whatley&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h3>Unnamed Parameters</h3>
<p>As an alternative to using explicit named parameters, you can also use implicit unnamed parameters. To use an unnamed parameter you simply designate a parameter in the <abbr title="Structured Query Language">SQL</abbr> statement using a question mark (?) character. Each parameter is assigned a numeric index, according to the order in which the parameters appear in the <abbr title="Structured Query Language">SQL</abbr> statement, <em>starting with index 0 (zero)</em> for the first parameter.</p>
<p><strong>ActionScript 3</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> conn<span style="color: #000000; font-weight: bold;">:</span>SQLConnection = <span style="color: #0033ff; font-weight: bold;">new</span> SQLConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> stmt<span style="color: #000000; font-weight: bold;">:</span>SQLStatement = <span style="color: #0033ff; font-weight: bold;">new</span> SQLStatement<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
stmt.sqlConnection = conn;
stmt.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;INSERT INTO address VALUES(?, ?, ?, ?)&quot;</span>;
stmt.<span style="color: #004993;">parameters</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;123 Main Street&quot;</span>;
stmt.<span style="color: #004993;">parameters</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;Sometown&quot;</span>;
stmt.<span style="color: #004993;">parameters</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;12345&quot;</span>;
stmt.<span style="color: #004993;">parameters</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;USA&quot;</span>;
stmt.execute<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p><strong>JavaScript</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> conn <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> air.<span style="color: #660066;">SQLConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> stmt <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> air.<span style="color: #660066;">SQLStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">sqlConnection</span> <span style="color: #339933;">=</span> conn<span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">text</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;INSERT INTO address VALUES(?, ?, ?, ?)&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">parameters</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;123 Main Street&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">parameters</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Sometown&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">parameters</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;12345&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">parameters</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;USA&quot;</span><span style="color: #339933;">;</span>
stmt.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Note: Use <code>clearParameters()</code> to empty the statement parameters array; e.g. <code>stmt.clearParameters()</code>.</p>
<h3>Advantages</h3>
<ol>
<li><strong>Performance</strong> &#8211; A <abbr title="Structured Query Language">SQL</abbr> statement that uses parameters can execute more efficiently compared to one that dynamically creates the <abbr title="Structured Query Language">SQL</abbr> text each time it executes. The performance improvement is because the statement is prepared once and then executed multiple times using different parameter values, without needing to recompile the <abbr title="Structured Query Language">SQL</abbr> statement. A comparison can be draw with database stored procedures.</li>
<li><strong>Data Typing</strong> &#8211; Parameters are used to allow for typed-substitution of values that are unknown at the time the <abbr title="Structured Query Language">SQL</abbr> statement is constructed. The use of parameters is the only way to guarantee the type (storage class) for a value passed to the database. Using paramters therefore, implies better performance and security. When parameters are not used, the runtime attempts to convert all values from their text representation to a type based on the associated column&#8217;s type.</li>
<li><strong>Security</strong> &#8211; The <acronym title="Adobe Integrated Runtime">AIR</acronym> application is not vulnerable to <abbr title="Structured Query Language">SQL</abbr> injections so common to web applications.</li>
</ol>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/preventing-sql-injection-in-an-air-application/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

