<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/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>Neil Carpenter's Blog : Tool</title><link>http://blogs.technet.com/neilcar/archive/tags/Tool/default.aspx</link><description>Tags: Tool</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>SQL Injection Hijinks</title><link>http://blogs.technet.com/neilcar/archive/2008/10/31/sql-injection-hijinks.aspx</link><pubDate>Fri, 31 Oct 2008 23:07:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3145432</guid><dc:creator>neilcar</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/neilcar/comments/3145432.aspx</comments><wfw:commentRss>http://blogs.technet.com/neilcar/commentrss.aspx?PostID=3145432</wfw:commentRss><description>&lt;P&gt;&lt;I&gt;or Why I Keep Harping On Blacklisting&lt;/I&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Summary:&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;An incident reveals attempts to get around blacklisting by manipulating behavior in ASP, illustrating the weakness of blacklist approaches.&lt;/P&gt;
&lt;P&gt;A new version of &lt;A href="http://blogs.iis.net/wadeh/archive/2008/10/31/urlscan-3-1.aspx" mce_href="http://blogs.iis.net/wadeh/archive/2008/10/31/urlscan-3-1.aspx"&gt;UrlScan is shipping today&lt;/A&gt; with a change specifically to address this.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Discussion:&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;I was working with a colleague on an incident last week that looked like a garden-variety SQL injection drive-by except for something interesting.&lt;/P&gt;
&lt;P&gt;While looking through the IIS logs from the affected server, I saw this:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;abc=120364DEC%LARE%20@S%20VAR%CHAR(4000)%3BS%ET%20@S%...&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As I looked at this, "DEC%LARE", "VAR%CHAR", and "BS%ET" immediately stood out to me.&amp;nbsp; Obviously, the percent sign is usually used to escape something in a URL (like the %20's in there, which are spaces); however, this naked percent sign thrown in there didn't seem to have any purpose and should have caused SQL to not execute the code in question.&lt;/P&gt;
&lt;P&gt;When I see somebody do something like this, it's usually for a purpose so I took another look at it.&amp;nbsp; I realized that, if ASP silently stripped that percent sign out of there, then this would be an efficient way to bypass a lot of blacklist-based filters.&lt;/P&gt;
&lt;P&gt;I wrote a quick test ASP page(1) and found that my guess was right on -- ASP drops a percent sign from the query string if it isn't followed by two valid hex characters(0-9, A-F) when it actually interprets it via Request.QueryString.&amp;nbsp; This means that any filter that inspects raw headers using Request.ServerVariables is going to miss "DEC%LARE" if it is looking for "DECLARE" but, on the other hand, the ASP app that actually consumes that string using Request.QueryString("abc") is going to get it without the percent sign.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Conclusion:&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;As this incident illustrates, a blacklist approach to SQL injection only works for as long as nobody finds a way around your blacklist.&amp;nbsp; As soon as somebody finds a way around it (and experience suggests that attackers are motivated to do so), the value of your blacklist is zero.&lt;/P&gt;
&lt;P&gt;The right approach is to fix the actual vulnerability in the code using parameterized queries.&amp;nbsp; See the articles below for more information and examples.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A title=http://msdn.microsoft.com/en-us/library/cc676512.aspx href="http://msdn.microsoft.com/en-us/library/cc676512.aspx" mce_href="http://msdn.microsoft.com/en-us/library/cc676512.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc676512.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title="SQL Injection Mitigation- Using Parameterized Queries" href="http://blogs.technet.com/neilcar/archive/2008/05/21/sql-injection-mitigation-using-parameterized-queries.aspx" mce_href="http://blogs.technet.com/neilcar/archive/2008/05/21/sql-injection-mitigation-using-parameterized-queries.aspx"&gt;SQL Injection Mitigation- Using Parameterized Queries&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title="SQL Injection Mitigation- Using Parameterized Queries part 2 (types and recordsets)" href="http://blogs.technet.com/neilcar/archive/2008/05/23/sql-injection-mitigation-using-parameterized-queries-part-2-types-and-recordsets.aspx" mce_href="http://blogs.technet.com/neilcar/archive/2008/05/23/sql-injection-mitigation-using-parameterized-queries-part-2-types-and-recordsets.aspx"&gt;SQL Injection Mitigation- Using Parameterized Queries part 2 (types and recordsets)&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The IIS team is releasing an update to UrlScan today that includes changes to address this in their filtering product.&amp;nbsp; Of course, as I've said over and and over, no filter-based approach is going to be perfect, but UrlScan is still an excellent defense-in-depth tool and a way to mitigate SQL injection vulns in the short term while your developers fix them.&lt;/P&gt;
&lt;P&gt;For more information on the UrlScan update, Wade Hilmo has all the details:&amp;nbsp; &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://blogs.iis.net/wadeh/archive/2008/10/31/urlscan-3-1.aspx" mce_href="http://blogs.iis.net/wadeh/archive/2008/10/31/urlscan-3-1.aspx"&gt;http://blogs.iis.net/wadeh/archive/2008/10/31/urlscan-3-1.aspx&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(1)&lt;/P&gt;
&lt;P&gt;&amp;lt;HTML&amp;gt; &lt;BR&gt;QUERY_STRING = &amp;lt;%= Request.ServerVariables("QUERY_STRING") %&amp;gt; &amp;lt;BR&amp;gt;&amp;nbsp; &lt;BR&gt;test =&amp;lt;%= Request.QueryString("test") %&amp;gt; &amp;lt;BR&amp;gt; &lt;BR&gt;&amp;lt;/HTML&amp;gt;&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3145432" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/neilcar/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.technet.com/neilcar/archive/tags/Incident+Response/default.aspx">Incident Response</category><category domain="http://blogs.technet.com/neilcar/archive/tags/SQL/default.aspx">SQL</category><category domain="http://blogs.technet.com/neilcar/archive/tags/ASP/default.aspx">ASP</category><category domain="http://blogs.technet.com/neilcar/archive/tags/Tool/default.aspx">Tool</category></item><item><title>PASSGEN</title><link>http://blogs.technet.com/neilcar/archive/2008/10/22/passgen.aspx</link><pubDate>Wed, 22 Oct 2008 21:52:02 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3140463</guid><dc:creator>neilcar</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.technet.com/neilcar/comments/3140463.aspx</comments><wfw:commentRss>http://blogs.technet.com/neilcar/commentrss.aspx?PostID=3140463</wfw:commentRss><description>&lt;p&gt;Occasionally, I see a security incident where one of the things that went wrong was that all of the customer's machines have the same password for the built-in administrator's account.&amp;#160; Whenever this happens, I suggest the PASSGEN tool that was included with the book &lt;a href="http://www.amazon.com/dp/0321336437"&gt;&amp;quot;Protect Your Windows Network&amp;quot;&lt;/a&gt; by &lt;a href="http://blogs.technet.com/steriley"&gt;Steve Riley&lt;/a&gt; and &lt;a href="http://msinfluentials.com/blogs/jesper/"&gt;Jesper Johansson&lt;/a&gt;.&amp;#160; Obviously, most people don't want to run to the bookstore in the middle of a security incident but, fortunately, it was available on their website.&lt;/p&gt;  &lt;p&gt;Unfortunately, the website disappeared recently and I had to scramble around to find it.&amp;#160; If you're looking for PASSGEN (and you should be if you have the same password for local admin across a number of machines), you can find it in two places:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://blogs.technet.com/steriley/archive/2008/09/29/passgen-tool-from-my-book.aspx"&gt;The Windows Server 2008 Resource Kit&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.technet.com/steriley/archive/2008/09/29/passgen-tool-from-my-book.aspx"&gt;Steve's blog&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3140463" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/neilcar/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.technet.com/neilcar/archive/tags/Tool/default.aspx">Tool</category></item><item><title>Err</title><link>http://blogs.technet.com/neilcar/archive/2008/08/12/err.aspx</link><pubDate>Wed, 13 Aug 2008 05:10:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3104496</guid><dc:creator>neilcar</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/neilcar/comments/3104496.aspx</comments><wfw:commentRss>http://blogs.technet.com/neilcar/commentrss.aspx?PostID=3104496</wfw:commentRss><description>&lt;p&gt;I might be the last person to know this but one of my favorite internal Microsoft tools is now external.&amp;nbsp; Err.exe is a command-line tool that looks up error codes and spits out possible matches from various header files.&amp;nbsp; This is invaluable when you're reading through a log and run across something like "Failed, err 0x80070003" -- just run err and you'll find out what this possibly means:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;C:\Users\Neilcar\Downloads\Err&amp;gt;err 0x80070003&lt;br&gt;# for hex 0x80070003 / decimal -2147024893 :&lt;br&gt;&amp;nbsp; COR_E_DIRECTORYNOTFOUND&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; corerror.h&lt;br&gt;# MessageText:&lt;br&gt;# The specified path couldn't be found.&lt;br&gt;# 1 matches found for "0x80070003" &lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The download for err is available at &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=be596899-7bb8-4208-b7fc-09e02a13696c&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?familyid=be596899-7bb8-4208-b7fc-09e02a13696c&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?familyid=be596899-7bb8-4208-b7fc-09e02a13696c&amp;amp;displaylang=en&lt;/a&gt;.&amp;nbsp; Download it and extract it to somewhere in %PATH% so that it's only a command prompt away. &lt;br&gt;&lt;/p&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3104496" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/neilcar/archive/tags/Tool/default.aspx">Tool</category></item><item><title>SQLInjectionFinder</title><link>http://blogs.technet.com/neilcar/archive/2008/05/27/sqlinjectionfinder.aspx</link><pubDate>Tue, 27 May 2008 20:51:23 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3061755</guid><dc:creator>neilcar</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/neilcar/comments/3061755.aspx</comments><wfw:commentRss>http://blogs.technet.com/neilcar/commentrss.aspx?PostID=3061755</wfw:commentRss><description>&lt;p&gt;My colleague &lt;a href="http://www.codeplex.com/site/users/view/GCTech"&gt;Greg&lt;/a&gt;, who has forgotten more about command line scripting than I will ever know, put together a sample on CodePlex that automates finding SQL injection attacks from the ongoing &lt;a href="http://blogs.technet.com/neilcar/archive/2008/03/14/anatomy-of-a-sql-injection-incident.aspx"&gt;mass SQL injection attack&lt;/a&gt; (&amp;quot;SQL Storm&amp;quot;, as I saw it dubbed today).&amp;#160; This is a fairly convenient approach to searching logfiles on an IIS server.&amp;#160; &lt;/p&gt;  &lt;h3&gt;&lt;a href="http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=WSUS&amp;amp;ReleaseId=13436"&gt;SQLInjectionFinder&lt;/a&gt; -- &lt;a title="http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=WSUS&amp;amp;ReleaseId=13436" href="http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=WSUS&amp;amp;ReleaseId=13436"&gt;http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=WSUS&amp;amp;ReleaseId=13436&lt;/a&gt;&lt;/h3&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3061755" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/neilcar/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.technet.com/neilcar/archive/tags/Incident+Response/default.aspx">Incident Response</category><category domain="http://blogs.technet.com/neilcar/archive/tags/SQL/default.aspx">SQL</category><category domain="http://blogs.technet.com/neilcar/archive/tags/Tool/default.aspx">Tool</category></item></channel></rss>