<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.iis.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:cs="http://blogs.iis.net/"><channel><title>Nazim&amp;#39;s IIS Security Blog : SQL injection</title><link>http://blogs.iis.net/nazim/archive/tags/SQL+injection/default.aspx</link><description>Tags: SQL injection</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Using the new rules configuration in UrlScan v3.0 Beta (Part 2)</title><link>http://blogs.iis.net/nazim/archive/2008/06/30/using-the-new-rules-configuration-in-urlscan-v3-0-beta-part-2.aspx</link><pubDate>Mon, 30 Jun 2008 20:41:00 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2457686</guid><dc:creator>naziml</dc:creator><slash:comments>26</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2457686</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/06/30/using-the-new-rules-configuration-in-urlscan-v3-0-beta-part-2.aspx#comments</comments><description>&lt;H3&gt;&lt;FONT color=#008080&gt;Dissecting the SQL injection sample in the walkthrough&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;I will spend some time dissecting the SQL injection rule posted in the walkthrough for UrlScan. Before I do so, I want to re-iterate the fact that &lt;FONT color=#ff0000&gt;&lt;STRONG&gt;SQL injection is a web application issue, and hence the right place to fix it is in the web application&lt;/STRONG&gt;&lt;/FONT&gt;. Sometimes when you are the victim of a SQL storm, it is less than ideal to go figure out all the places your web application might be susceptible. That's where UrlScan comes in and offers a stop gap solution till you can fix the apps, without taking any downtime hit on your site. The one issue here is that of false positives ... and these are hard to predict because different web applications have different requirements and semantics. Nonetheless, UrlScan can offer substantial protection in the face of a SQL Storm at the cost of a some false positives that will cause valid requests to be rejected.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color=#800080&gt;&lt;STRONG&gt;[SQL Injection] &lt;BR&gt;&lt;/STRONG&gt;AppliesTo=.asp,.aspx &lt;BR&gt;DenyDataSection=SQL Injection Strings &lt;BR&gt;ScanUrl=0 &lt;BR&gt;ScanAllRaw=0 &lt;BR&gt;ScanQueryString=1 &lt;BR&gt;ScanHeaders= &lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#800080&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#800080&gt;&lt;STRONG&gt;[SQL Injection Strings] &lt;BR&gt;&lt;/STRONG&gt;-- &lt;BR&gt;%3b ; a semicolon &lt;BR&gt;/* &lt;BR&gt;@ ; also catches @@ &lt;BR&gt;char ; also catches nchar and varchar &lt;BR&gt;alter &lt;BR&gt;begin &lt;BR&gt;cast &lt;BR&gt;create &lt;BR&gt;cursor &lt;BR&gt;declare &lt;BR&gt;delete &lt;BR&gt;drop &lt;BR&gt;end &lt;BR&gt;exec ; also catches execute &lt;BR&gt;fetch &lt;BR&gt;insert &lt;BR&gt;kill &lt;BR&gt;open &lt;BR&gt;select &lt;BR&gt;sys ; also catches sysobjects and syscolumns &lt;BR&gt;table &lt;BR&gt;update &lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So this is the first bit. Notice that the only thing we are scanning here is the query string, not the URL or any headers. This will give us a little more leeway with our strings list. But even so, there are a lot of chances for false positives. For example if were to have "podcast" in my query string, I would trip the filter because of "cast". So the best thing to do is copy this over and do quick testing to make sure your apps still work. The other thing to do is keep an eye on the log files to see what it is catching.&lt;/P&gt;
&lt;P&gt;The obvious gap in the rule above is the fact that the only thing I am checking is the query string. What about the rest of the request? The parts of interest for SQL injection really depend on your web application ... but there are definitely some headers that seem important, like the Cookie header (popular candidate for script injection as well).&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color=#800080&gt;&lt;STRONG&gt;[SQL Injection Headers]&lt;/STRONG&gt; &lt;BR&gt;AppliesTo=.asp,.aspx &lt;BR&gt;DenyDataSection=SQL Injection Headers Strings &lt;BR&gt;ScanUrl=0 &lt;BR&gt;ScanAllRaw=0 &lt;BR&gt;ScanQueryString=0 &lt;BR&gt;ScanHeaders=Cookie: &lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#800080&gt;&lt;STRONG&gt;[SQL Injection Headers Strings]&lt;/STRONG&gt; &lt;BR&gt;-- &lt;BR&gt;@ ; also catches @@ &lt;BR&gt;alter &lt;BR&gt;cast &lt;BR&gt;convert &lt;BR&gt;create &lt;BR&gt;declare &lt;BR&gt;delete &lt;BR&gt;drop &lt;BR&gt;exec ; also catches execute &lt;BR&gt;fetch &lt;BR&gt;insert &lt;BR&gt;kill &lt;BR&gt;select&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For folks who have been following this, you will notice that an older version was looking at ScanAllRaw. Even with a trimmed down list, there were a lot of things breaking. Like /* with the Accept-Encoding header and 'cast' in User-Agent strings that had things like 'broadcast'. So I followed my own advice and reduced the scope a little more.&lt;/P&gt;
&lt;P&gt;Another part of the request that folks missed was the request entity, but the explanation for that deviated from this topic sufficiently to warrant its own blog &lt;A href="http://blogs.iis.net/nazim/archive/2008/06/30/urlscan-v3-0-filtering-based-on-request-entity.aspx" mce_href="http://blogs.iis.net/nazim/archive/2008/06/30/urlscan-v3-0-filtering-based-on-request-entity.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2457686" width="1" height="1"&gt;</description><category domain="http://blogs.iis.net/nazim/archive/tags/SQL+injection/default.aspx">SQL injection</category><category domain="http://blogs.iis.net/nazim/archive/tags/UrlScan/default.aspx">UrlScan</category><category domain="http://blogs.iis.net/nazim/archive/tags/IIS6/default.aspx">IIS6</category><category domain="http://blogs.iis.net/nazim/archive/tags/IIS7/default.aspx">IIS7</category><category domain="http://blogs.iis.net/nazim/archive/tags/HTTP/default.aspx">HTTP</category></item><item><title>SQL Injection Demo</title><link>http://blogs.iis.net/nazim/archive/2008/04/30/sql-injection-demo.aspx</link><pubDate>Wed, 30 Apr 2008 22:12:00 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2330990</guid><dc:creator>naziml</dc:creator><slash:comments>37</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2330990</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/04/30/sql-injection-demo.aspx#comments</comments><description>&lt;P&gt;SQL injection seems to have faded from prominence lately and has become just a buzz word. To make things a little more real I put together a quick demo for it, to demonstrate that you don't necessarily have to go out of your way to make your web application exploitable.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the ingredients for this demo:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;ASP.NET application using System.Data.SqlClient to access a SQL database. 
&lt;LI&gt;SQLExpress (or any other db) with some tool to directly author to the database. &lt;/LI&gt;&lt;/OL&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;CAUTION: This is a sample to demo SQLInjection and is hence insecure. Do not use this sample as the basis for a web application.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color=#008080&gt;Setting up the Database&lt;/FONT&gt;&lt;/H3&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used SQLExpress for my demo, but you can use whatever is available. Just be sure to update the connection string in your ASP.Net application.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Enable the sa account and gave it a password. 
&lt;LI&gt;Connect to the database with this account to make sure it works. You can use &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&amp;amp;displaylang=en"&gt;SQL Server Management Studio Express (SSMSE)&lt;/A&gt; to do this. 
&lt;LI&gt;Create a database called WebApp and create tables as follows. &lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/db_design_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/db_design_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=db_design src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/db_design_thumb.jpg" width=276 height=118 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/db_design_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Populate the tables with sample data. 
&lt;LI&gt;Try running a few queries against through SSMSE to make sure things work, eg: &lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV align=left&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;SELECT&lt;/SPAN&gt; * &lt;SPAN class=kwrd&gt;FROM&lt;/SPAN&gt; Users; &lt;SPAN class=kwrd&gt;SELECT&lt;/SPAN&gt; * &lt;SPAN class=kwrd&gt;From&lt;/SPAN&gt; Orders;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;
&lt;STYLE type=text/css&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color=#008080&gt;Setting up a Web Application on your Server&lt;/FONT&gt;&lt;/H3&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used IIS 7.0 and ASP.NET 2.0, but you could use other tools as well.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Make sure IIS is running and that you can access the default page. 
&lt;LI&gt;Under the same directory you can add the following ASP.NET page (SQLLoginUnsafe.aspx) and the code-behind file (SQLLoginUnsafe.aspx.cs) 
&lt;LI&gt;Here is the sample ASP.NET page, &lt;STRONG&gt;SqlLoginUnsafe.aspx&lt;/STRONG&gt;. &lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;&amp;lt;!--&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;    SQLLoginUnsafe.aspx&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;    Author: Nazim Lala&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;--&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=asp&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="SQLLoginUnsafe.aspx.cs" 
    Inherits="SQLLoginUnsafe" %&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;!&lt;/SPAN&gt;&lt;SPAN class=html&gt;DOCTYPE&lt;/SPAN&gt; &lt;SPAN class=attr&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;PUBLIC&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/SPAN&gt; 
    &lt;SPAN class=kwrd&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Untitled Page&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="form1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
        This is the Unsafe SQL Login Page.&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        Username:&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:TextBox&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="TextBoxUsername"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200px"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:TextBox&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    Password:&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:TextBox&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="TextBoxPassword"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200px"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:TextBox&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    Result:&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:Label&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="LabelResult"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="-"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:Label&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:Button&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ButtonLogin"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;onclick&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ButtonLogin_Click"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Login"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:Label&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="LabelData"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Here is your Order history"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;Visible&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="False"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:Label&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:GridView&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="GridView1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Visible&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="False"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:GridView&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:Button&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ButtonLogout"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;onclick&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ButtonLogout_Click"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Logout"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Visible&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="False"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;br&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;UL&gt;
&lt;LI&gt;Here is the sample code-behind the ASP.Net page, &lt;STRONG&gt;SQLLoginUnsafe.aspx.cs&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE class=csharpcode&gt;&lt;BR&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;/*&lt;/SPAN&gt;
&lt;SPAN class=rem&gt; * SQLLoginUnsafe.aspx.cs&lt;/SPAN&gt;
&lt;SPAN class=rem&gt; * Author: Nazim Lala&lt;/SPAN&gt;
&lt;SPAN class=rem&gt; * &lt;/SPAN&gt;
&lt;SPAN class=rem&gt; */&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Web;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Web.UI;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Web.UI.HtmlControls;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Web.UI.WebControls;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Text;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Data;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Data.SqlClient;

&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; SQLLoginUnsafe : System.Web.UI.Page
{
    &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; _username;
    &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; _password;
    &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; _loggedIn = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;

    &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; _connString = 
        &lt;SPAN class=str&gt;@"Data Source=.\SQLEXPRESS;"&lt;/SPAN&gt;+
        &lt;SPAN class=str&gt;"Initial Catalog=WebApp;"&lt;/SPAN&gt;+
        &lt;SPAN class=str&gt;"Integrated Security=True;"&lt;/SPAN&gt;;

    &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; SqlConnection _sqlConn = &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;;

    &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; ButtonLogin_Click(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
    {
        _username = Request[&lt;SPAN class=str&gt;"TextBoxUsername"&lt;/SPAN&gt;];
        _password = Request[&lt;SPAN class=str&gt;"TextBoxPassword"&lt;/SPAN&gt;];

        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (!IsNonEmptyCredentials())
        {
            LabelResult.Text = &lt;SPAN class=str&gt;"ERROR: Cannot have empty credentials."&lt;/SPAN&gt;;
            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt;;
        }

        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (AttemptSQLLogin())
        {
            &lt;SPAN class=rem&gt;// Login succeeded&lt;/SPAN&gt;
            
            &lt;SPAN class=rem&gt;// Fill order data&lt;/SPAN&gt;
            FillOrderData();

            EnableLoggedInVisuals();

        }
        &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
        {
            DisableLoggedInVisuals();
        }

    }

    &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; IsNonEmptyCredentials()
    {
        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (_username == &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt; ||
             _username.Length == 0 ||
             _password == &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt; ||
             _password.Length == 0)
        {
            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        }
        &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
 
    }

    &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; AttemptSQLLogin()
    {
        &lt;SPAN class=kwrd&gt;try&lt;/SPAN&gt;
        {
            _sqlConn = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SqlConnection(_connString);
            _sqlConn.Open();
        }
        &lt;SPAN class=kwrd&gt;catch&lt;/SPAN&gt; (Exception ex)
        {
            LabelResult.Text = String.Format(
                &lt;SPAN class=str&gt;"ERROR: Failed to open SQL Connection: {0}"&lt;/SPAN&gt;, ex.Message);
            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        }

        SqlDataReader dataReader = &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;;

        &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; SQLQuery = String.Format(
            &lt;SPAN class=str&gt;"SELECT * FROM Users WHERE Username='{0}' AND Password='{1}'"&lt;/SPAN&gt;, 
            _username, _password);

        SqlCommand command = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SqlCommand(SQLQuery, _sqlConn);

        &lt;SPAN class=kwrd&gt;try&lt;/SPAN&gt;
        {
            dataReader = command.ExecuteReader(CommandBehavior.SingleResult);

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (dataReader.HasRows)
            {
                LabelResult.Text = String.Format(&lt;SPAN class=str&gt;"Login success"&lt;/SPAN&gt;);
                dataReader.Close();
                _loggedIn = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
            }
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
            {
                LabelResult.Text = String.Format(
                    &lt;SPAN class=str&gt;"Login failed: Invalid credentials"&lt;/SPAN&gt;);
                dataReader.Close();
                &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
            }

        }
        &lt;SPAN class=kwrd&gt;catch&lt;/SPAN&gt; (Exception ex)
        {
            LabelResult.Text = String.Format(
                &lt;SPAN class=str&gt;"ERROR: Failed to execute SQL command: {0}"&lt;/SPAN&gt;, ex.Message);
            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        }

        &lt;SPAN class=rem&gt;//return true;&lt;/SPAN&gt;
    }

    &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; FillOrderData()
    {
        SqlDataReader dataReader = &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;;

        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (!_loggedIn)
        {
            LabelResult.Text = &lt;SPAN class=str&gt;"No user logged it"&lt;/SPAN&gt;;
            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        }

        &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; SQLQuery = String.Format(
            &lt;SPAN class=str&gt;"SELECT Orders.OrderId, Orders.Amount, Orders.CreditCard "&lt;/SPAN&gt;+
            &lt;SPAN class=str&gt;"FROM Users, Orders WHERE Users.Username='{0}' "&lt;/SPAN&gt;+
            &lt;SPAN class=str&gt;"AND Users.UserId=Orders.UserId"&lt;/SPAN&gt;, _username);

        SqlCommand command = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SqlCommand(SQLQuery, _sqlConn);

        &lt;SPAN class=kwrd&gt;try&lt;/SPAN&gt;
        {
            dataReader = command.ExecuteReader(CommandBehavior.Default);

            GridView1.DataSource = dataReader;
            GridView1.DataBind();

            dataReader.Close();

            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        }
        &lt;SPAN class=kwrd&gt;catch&lt;/SPAN&gt; (Exception ex)
        {
            LabelResult.Text = String.Format(
                &lt;SPAN class=str&gt;"ERROR: Failed to execute SQL command: {0}"&lt;/SPAN&gt;, ex.Message);
            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        }
    }

    &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; ButtonLogout_Click(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
    {
        LabelResult.Text = &lt;SPAN class=str&gt;"Logged Out"&lt;/SPAN&gt;;
        _loggedIn = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        _username = &lt;SPAN class=str&gt;""&lt;/SPAN&gt;;
        _password = &lt;SPAN class=str&gt;""&lt;/SPAN&gt;;
        DisableLoggedInVisuals();
    }

    &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; EnableLoggedInVisuals()
    {
        ButtonLogin.Enabled = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        ButtonLogin.Visible = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        LabelData.Visible = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        GridView1.Enabled = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        GridView1.Visible = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        ButtonLogout.Enabled = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        ButtonLogout.Visible = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        
    }

    &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; DisableLoggedInVisuals()
    {
        ButtonLogin.Enabled = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        ButtonLogin.Visible = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        LabelData.Visible = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        GridView1.Enabled = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        GridView1.Visible = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        ButtonLogout.Enabled = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        ButtonLogout.Visible = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        
    }
}
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;
&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;Make sure you can access the website from your local machine. &lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color=#008080&gt;Making the SQL Injection Requests&lt;/FONT&gt;&lt;/H3&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now onto the fun part. Let's say we have a user 'Foo' with password 'foo' in our Users table for the purpose of this exercise.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;U&gt;Trying an invalid user/password.&lt;/U&gt;&lt;/STRONG&gt; &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Username: Unknown &lt;BR&gt;Password: unknown &lt;BR&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen1_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen1_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen1 src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen1_thumb.jpg" width=244 height=244 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen1_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;&lt;BR&gt;As expected we get a login failure. &lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;U&gt;Bypassing login for a known user. Let's say we know user 'Foo' exists.&lt;/U&gt;&lt;/STRONG&gt; &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Username: Foo'-- &lt;BR&gt;Password: junk &lt;BR&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen2_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen2_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen2 src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen2_thumb.jpg" width=262 height=434 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen2_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;By using '--' for commenting out the rest of the conditions in the query we have been able to skip password validation for user 'Foo' &lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;U&gt;Bypassing login for unknown user. Let's say we don't know any user on the site.&lt;/U&gt;&lt;/STRONG&gt; &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Username: ' OR 1=1-- &lt;BR&gt;Password: junk &lt;BR&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen3_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen3_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen3 src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen3_thumb.jpg" width=270 height=531 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen3_thumb.jpg"&gt;&lt;/A&gt;&amp;nbsp; &lt;BR&gt;&lt;BR&gt;We used a tautology (1=1) to bypass all security checks. Notice that I know have the order information for *all* users. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;U&gt;Injecting a new user. Let's say I want to add a user 'Hijack' with password 'This'.&lt;/U&gt;&lt;/STRONG&gt; &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Username: ';INSERT INTO Users VALUES (100,'Hijack','This')-- &lt;BR&gt;Password: junk &lt;BR&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4a_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4a_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen4a src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4a_thumb.jpg" width=279 height=279 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4a_thumb.jpg"&gt;&lt;/A&gt;&amp;nbsp; &lt;BR&gt;&lt;BR&gt;But now using those credentials succeeds. &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4b_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4b_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen4b src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4b_thumb.jpg" width=282 height=337 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4b_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;U&gt;Changing price of all orders to 0.01&lt;/U&gt;&lt;/STRONG&gt; &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Username: ';UPDATE Orders Set Amount=0.01-- &lt;BR&gt;Password: junk &lt;BR&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5a_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5a_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen5a src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5a_thumb.jpg" width=293 height=293 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5a_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;&lt;BR&gt;And using an earlier example to list all orders we see that all the prices have changed. &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5b_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5b_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen5b src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5b_thumb.jpg" width=296 height=685 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5b_thumb.jpg"&gt;&lt;/A&gt;&amp;nbsp; &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;U&gt;Injecting SQL users and password hashes into the Orders table and getting it to display&lt;/U&gt;&lt;/STRONG&gt; &lt;BR&gt;&lt;BR&gt;So this is a little tricky. sys.sql_logins table has the information of interest. But how do we go about displaying it. &lt;BR&gt;The answer is simple, we inject all the information into the Orders table and get the query to display it. &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Username: 'OR 1=1;INSERT INTO Orders (OrderId, UserId, Amount, CreditCard) SELECT principal_id+1000,principal_id+1000,principal_id*1.0,name FROM sys.sql_logins UNION SELECT principal_id+1000,principal_id+1000,principal_id*1.0,master.dbo.fn_varbintohexstr(password_hash) FROM sys.sql_logins-- &lt;BR&gt;Password: junk &lt;BR&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;A href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen6_2.jpg" mce_href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen6_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=Screen6 src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen6_thumb.jpg" width=588 height=596 mce_src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen6_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;&lt;BR&gt;Now that we have user names and password hashes, you could use one of several external hash cracking tools to actually get to the password. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H3&gt;&lt;FONT color=#008080&gt;Conclusion&lt;/FONT&gt;&lt;/H3&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is quite easy to see how quickly one can invade a system through the use of SQL injection. The million dollar question is "How do I protect myself "? The answer is, follow best practices.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Sanitize your input using both black lists and white lists. 
&lt;LI&gt;Use parameterized SQL and NEVER use string concatenation to generate queries. 
&lt;LI&gt;Protect your database resources wisely and use the notion of "least privilege" to access information. &lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helped in making SQL injection a more concrete issue to protect your applications against, rather than a buzz word.&lt;/P&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2330990" width="1" height="1"&gt;</description><category domain="http://blogs.iis.net/nazim/archive/tags/SQL+injection/default.aspx">SQL injection</category><category domain="http://blogs.iis.net/nazim/archive/tags/HTTP/default.aspx">HTTP</category><category domain="http://blogs.iis.net/nazim/archive/tags/ASP_2F00_ASP.NET/default.aspx">ASP/ASP.NET</category></item><item><title>Filtering SQL injection from Classic ASP</title><link>http://blogs.iis.net/nazim/archive/2008/04/28/filtering-sql-injection-from-classic-asp.aspx</link><pubDate>Mon, 28 Apr 2008 18:53:00 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2325776</guid><dc:creator>naziml</dc:creator><slash:comments>1727</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2325776</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/04/28/filtering-sql-injection-from-classic-asp.aspx#comments</comments><description>&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;SQL injection may be over a decade old, but even the best of us need a reminder once in a while. You should always validate input to your applications! There isn’t a ‘one size fits all’ solution to sanitizing input, so I will attempt to show what a general solution might look like for classic ASP (using VBScript). Remember, you need to keep in mind the specifics of your web application and add/remove things in the sample accordingly. &lt;/FONT&gt;&lt;FONT size=3 face=Calibri&gt;So even though I am focusing on SQL injection here, input validation needs to be done to even prevent cross-site scripting attacks, among others. Check &lt;A href="http://support.microsoft.com/kb/252985/" mce_href="http://support.microsoft.com/kb/252985/"&gt;this article&lt;/A&gt; on how to prevent XSS to give you an idea of other sorts of validation that would need to be done on user input to secure a web application. If you are looking for something for ASP.NET check out &lt;A href="http://forums.asp.net/t/1254125.aspx"&gt;this post&lt;/A&gt; from Stefan on the ASP.NET team. &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;STRONG&gt;Now that UrlScan v3.0 (&lt;/STRONG&gt;&lt;A href="http://iis.net/1697/ItemPermalink.ashx"&gt;&lt;STRONG&gt;x86&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;, &lt;/STRONG&gt;&lt;A href="http://iis.net/1698/ItemPermalink.ashx"&gt;&lt;STRONG&gt;x64&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;) is out I would highly recommend using that instead of this script. There is also a &lt;/STRONG&gt;&lt;A href="http://learn.iis.net/page.aspx/473/using-urlscan"&gt;&lt;STRONG&gt;walk-through&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt; for it on implementing &lt;/STRONG&gt;&lt;A href="http://learn.iis.net/page.aspx/476/common-urlscan-scenarios/"&gt;&lt;STRONG&gt;SQL injection blocking configuration&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT color=#ff0000 size=3 face=Calibri&gt;&lt;U&gt;&lt;STRONG&gt;Please note:&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT color=#ff0000&gt;&lt;FONT size=3 face=Calibri&gt;The purpose of this sample is to get folks off the ground and up and running. This is not intended to be a long-term solution to solving SQL injection attacks against your application. &lt;/FONT&gt;&lt;FONT size=3 face=Calibri&gt;Using black lists like in the sample tend to give a lot of false positives that make many applications unusable. Increasing complexity in the list to avoid this leads to performance issues. Also, such simplistic signatures can be worked around by determined hackers. Consider UN/**/ION for example.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;FONT color=#ff0000&gt;You want to use white lists and rules to sanitize input. You should restrict your web application to &lt;/FONT&gt;&lt;A href="http://support.microsoft.com/kb/q164485/"&gt;&lt;FONT color=#ff0000&gt;using stored procedures and calling them using parameterized SQL APIs&lt;/FONT&gt;&lt;/A&gt;&lt;FONT color=#ff0000&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;The way this sample is constructed is that I have a script that checks certain inputs against a ‘black list’ of strings, and if I find a match I redirect to an error page. This script can then be ‘included’ into all public facing application scripts that process user input. There are 3 pieces to this solution: the script with the filtering logic, a sample application that will ‘include’ the filtering script and an error page we would forward to. I have added comments to the scripts themselves, so you have the reminders in front of you. Several folks asked about a send email script, so I have included a sample script for that as well. You will need to incorporate it into your application appropriately. Make sure you read the comments in the code as well for all the assumptions. The right way to do db access from web applications is to use parameterized SQL. Check out Neil&amp;nbsp; Carpenter's blog &lt;A href="http://blogs.technet.com/neilcar/archive/2008/05/21/sql-injection-mitigation-using-parameterized-queries.aspx"&gt;here&lt;/A&gt; on what this looks like.&lt;/FONT&gt;&lt;/P&gt;
&lt;H1 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;
&lt;P&gt;&lt;FONT color=#17365d size=5 face=Calibri&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;/H1&gt;
&lt;H1 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;&lt;FONT size=5&gt;&lt;FONT color=#17365d&gt;&lt;FONT face=Calibri&gt;SqlCheckInclude.asp 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;This is the code that does the main filtering. Copy the code below into an ASP file and modify according to your needs. The main things you need to add/modify for your needs are the BlackList array and the ErrorPage you want to forward to. Deploy this file in a location that will be accessible to all your web applications. Make sure that the path to your error page is correct. Use a full path here if possible, since this code will get ‘included’ into several applications that may all reside in different physical directories.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&amp;lt;% 
&lt;SPAN class=rem&gt;'  SqlCheckInclude.asp&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Author: Nazim Lala&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  This is the include file to use with your asp pages to &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  validate input for SQL injection.&lt;/SPAN&gt;


&lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; BlackList, ErrorPage, s

&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Below is a black list that will block certain SQL commands and &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  sequences used in SQL injection will help with input sanitization&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  However this is may not suffice, because:&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  1) These might not cover all the cases (like encoded characters)&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  2) This may disallow legitimate input&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Creating a raw sql query strings by concatenating user input is &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  unsafe programming practice. It is advised that you use parameterized&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  SQL instead. Check http://support.microsoft.com/kb/q164485/ for information&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  on how to do this using ADO from ASP.&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Moreover, you need to also implement a white list for your parameters.&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  For example, if you are expecting input for a zipcode you should create&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  a validation rule that will only allow 5 characters in [0-9].&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;

BlackList = Array(&lt;SPAN class=str&gt;"--"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;";"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"/*"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"*/"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"@@"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"@"&lt;/SPAN&gt;,_
                  &lt;SPAN class=str&gt;"char"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"nchar"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"varchar"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"nvarchar"&lt;/SPAN&gt;,_
                  &lt;SPAN class=str&gt;"alter"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"begin"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"cast"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"create"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"cursor"&lt;/SPAN&gt;,_
                  &lt;SPAN class=str&gt;"declare"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"delete"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"drop"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"end"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"exec"&lt;/SPAN&gt;,_
                  &lt;SPAN class=str&gt;"execute"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"fetch"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"insert"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"kill"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"open"&lt;/SPAN&gt;,_
                  &lt;SPAN class=str&gt;"select", &lt;/SPAN&gt;&lt;SPAN class=str&gt;"sys"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"sysobjects"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"syscolumns"&lt;/SPAN&gt;,_
                  &lt;SPAN class=str&gt;"table"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"update"&lt;/SPAN&gt;)

&lt;SPAN class=rem&gt;'  Populate the error page you want to redirect to in case the &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  check fails.&lt;/SPAN&gt;

ErrorPage = &lt;SPAN class=str&gt;"/ErrorPage.asp"&lt;/SPAN&gt;
               
&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''               &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  This function does not check for encoded characters&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  since we do not know the form of encoding your application&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  uses. Add the appropriate logic to deal with encoded characters&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  in here &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt; CheckStringForSQL(str) 
  &lt;SPAN class=kwrd&gt;On&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Error&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Resume&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt; 
  
  &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; lstr 
  
  &lt;SPAN class=rem&gt;' If the string is empty, return true&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; ( IsEmpty(str) ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
    CheckStringForSQL = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;Exit&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;ElseIf&lt;/SPAN&gt; ( StrComp(str, &lt;SPAN class=str&gt;""&lt;/SPAN&gt;) = 0 ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
    CheckStringForSQL = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;Exit&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
  
  lstr = LCase(str)
  
  &lt;SPAN class=rem&gt;' Check if the string contains any patterns in our&lt;/SPAN&gt;
  &lt;SPAN class=rem&gt;' black list&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;For&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Each&lt;/SPAN&gt; s &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; BlackList
  
    &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; ( InStr (lstr, s) &amp;lt;&amp;gt; 0 ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
      CheckStringForSQL = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;Exit&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
  
  &lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt;
  
  CheckStringForSQL = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;
  
&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt; 


&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Check forms data&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;For&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Each&lt;/SPAN&gt; s &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; Request.Form
  &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; ( CheckStringForSQL(Request.Form(s)) ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
  
    &lt;SPAN class=rem&gt;' Redirect to an error page&lt;/SPAN&gt;
    Response.Redirect(ErrorPage)
  
  &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt;

&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Check query string&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;For&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Each&lt;/SPAN&gt; s &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; Request.QueryString
  &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; ( CheckStringForSQL(Request.QueryString(s)) ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
  
    &lt;SPAN class=rem&gt;' Redirect to error page&lt;/SPAN&gt;
    Response.Redirect(ErrorPage)

    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
  
&lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt;


&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Check cookies&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;For&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Each&lt;/SPAN&gt; s &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; Request.Cookies
  &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; ( CheckStringForSQL(Request.Cookies(s)) ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
  
    &lt;SPAN class=rem&gt;' Redirect to error page&lt;/SPAN&gt;
    Response.Redirect(ErrorPage)

  &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
  
&lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt;


&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Add additional checks for input that your application&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  uses. (for example various request headers your app &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  might use)&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;

%&amp;gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;
&lt;/P&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;&lt;FONT size=5&gt;&lt;FONT color=#17365d&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;&lt;FONT size=5&gt;&lt;FONT color=#17365d&gt;&lt;FONT face=Calibri&gt;TestPage.asp &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;&lt;FONT size=5&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;This is a sample that shows how to ‘include’ the script above in my application. Make sure the path to your include file is correct. The example below is for the application and the include file being in the same directory. Make sure you modify the path if these 2 are not in the same directory.&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=3 face=Calibri&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;PRE class=csharpcode&gt;&amp;lt;% 
&lt;SPAN class=rem&gt;'  TestPage.asp&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Author: Nazim Lala&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  This is a file to test the SQLCheckInclude file. The idea here is that you add&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  the include file to the beginning of every asp page to get SQL injection &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  input validation&lt;/SPAN&gt;


%&amp;gt;

&amp;lt;!--#include file=&lt;SPAN class=str&gt;"SqlCheckInclude.asp"&lt;/SPAN&gt;--&amp;gt;
&amp;lt;%
Response.Write(&lt;SPAN class=str&gt;"Welcome to the Test Page."&lt;/SPAN&gt;)
Response.Write(&lt;SPAN class=str&gt;"If you are seeing this page then SQL validation succeeded."&lt;/SPAN&gt;)
%&amp;gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;H1 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;&lt;FONT size=5&gt;&lt;FONT color=#17365d&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H1&gt;
&lt;H1 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-fareast-font-family: 'Times New Roman'"&gt;&lt;FONT size=5&gt;&lt;FONT color=#17365d&gt;&lt;FONT face=Calibri&gt;ErrorPage.asp 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;If a ‘black list’ string is found in any input, this is the page you will be forwarded to. You can reuse any custom error page that you already have for this. I am including this only for the sake of completeness. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&amp;lt;% 
&lt;SPAN class=rem&gt;'  ErrorPage.asp&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Author: Nazim Lala&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  This is the error page that users will be redirected to if the input cannot&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  be validated&lt;/SPAN&gt;

%&amp;gt;
&amp;lt;%Response.Write(&lt;SPAN class=str&gt;"ERROR: Invalid Input"&lt;/SPAN&gt;)%&amp;gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color=#17365d size=5 face=Calibri&gt;SendEmail.asp&lt;/FONT&gt;&lt;/H3&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;This script sends email via a remote SMTP server that uses credentials. You will need to integrate this into your application at the right place to get error reporting via email.&lt;/FONT&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&amp;lt;% 

&lt;SPAN class=rem&gt;'  SendEmail.asp&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;'  Author: Nazim Lala&lt;/SPAN&gt;
    
&lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt; SendEmail(email, msg) 
  &lt;SPAN class=kwrd&gt;On&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Error&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Resume&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Next&lt;/SPAN&gt; 
  
  &lt;SPAN class=rem&gt;' If the string is empty, return false&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; ( IsEmpty(email) ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
    SendEmail = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;Exit&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;ElseIf&lt;/SPAN&gt; ( StrComp(email, &lt;SPAN class=str&gt;""&lt;/SPAN&gt;) = 0 ) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
    SendEmail = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;Exit&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
  

  &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; cdoConfig = CreateObject(&lt;SPAN class=str&gt;"CDO.Configuration"&lt;/SPAN&gt;)  

  &lt;SPAN class=kwrd&gt;With&lt;/SPAN&gt; cdoConfig.Fields  
      .Item(cdoSendUsingMethod) = cdoSendUsingPort  
      &lt;SPAN class=rem&gt;' Fill in server name for remote SMTP server and&lt;/SPAN&gt;
      &lt;SPAN class=rem&gt;' credentials&lt;/SPAN&gt;
      .Item(cdoSMTPServer) = &lt;SPAN class=str&gt;"smtpserver.foo.com"&lt;/SPAN&gt;  
      .Item(cdoSMTPAuthenticate) = 1  
      .Item(cdoSendUsername) = &lt;SPAN class=str&gt;"username"&lt;/SPAN&gt;  
      .Item(cdoSendPassword) = &lt;SPAN class=str&gt;"password"&lt;/SPAN&gt;  
      .Update  
  &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;With&lt;/SPAN&gt; 

  &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; cdoMessage = CreateObject(&lt;SPAN class=str&gt;"CDO.Message"&lt;/SPAN&gt;)  

  &lt;SPAN class=kwrd&gt;With&lt;/SPAN&gt; cdoMessage 
    &lt;SPAN class=rem&gt;'Fill in sender information&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; .Configuration = cdoConfig 
    .From = &lt;SPAN class=str&gt;"me@myself.com"&lt;/SPAN&gt; 
    .&lt;SPAN class=kwrd&gt;To&lt;/SPAN&gt; = email 
    .Subject = &lt;SPAN class=str&gt;"Test Email"&lt;/SPAN&gt; 
    .TextBody = msg 
    .Send 
  &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;With&lt;/SPAN&gt; 

  &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; cdoMessage = &lt;SPAN class=kwrd&gt;Nothing&lt;/SPAN&gt;  
  &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; cdoConfig = &lt;SPAN class=kwrd&gt;Nothing&lt;/SPAN&gt;  
  
  SendEmail = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;
  
&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt; 


%&amp;gt;


&amp;lt;FORM VERB=POST METHOD=&lt;SPAN class=str&gt;"POST"&lt;/SPAN&gt;&amp;gt; 
Test page &lt;SPAN class=kwrd&gt;for&lt;/SPAN&gt; checking input &lt;SPAN class=kwrd&gt;with&lt;/SPAN&gt; possible SQL injection.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
Email: &amp;lt;INPUT NAME=Email&amp;gt;&amp;lt;/INPUT&amp;gt;&amp;lt;BR&amp;gt;
Message: &amp;lt;INPUT NAME=Message&amp;gt;&amp;lt;/INPUT&amp;gt;&amp;lt;BR&amp;gt;
Sent: &amp;lt;% = SendEmail(Request(&lt;SPAN class=str&gt;"Email"&lt;/SPAN&gt;),Request(&lt;SPAN class=str&gt;"Message"&lt;/SPAN&gt;)) %&amp;gt;&amp;lt;BR&amp;gt; 
&amp;lt;BUTTON TYPE=SUBMIT&amp;gt;Submit&amp;lt;/BUTTON&amp;gt; 
&amp;lt;/FORM&amp;gt; &lt;/PRE&gt;
&lt;STYLE type=text/css&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Hope this helps. If folks are averse to VBScript I can cook up something for Jscript if there is demand.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2325776" width="1" height="1"&gt;</description><category domain="http://blogs.iis.net/nazim/archive/tags/SQL+injection/default.aspx">SQL injection</category><category domain="http://blogs.iis.net/nazim/archive/tags/HTTP/default.aspx">HTTP</category><category domain="http://blogs.iis.net/nazim/archive/tags/ASP_2F00_ASP.NET/default.aspx">ASP/ASP.NET</category></item></channel></rss>