<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Casaba Security &#187; Development</title>
	<atom:link href="http://www.casaba.com/blog/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.casaba.com/blog</link>
	<description>Building and breaking software and robots</description>
	<lastBuildDate>Wed, 11 Jan 2012 18:08:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Porting Watcher checks to ModSecurity rules!</title>
		<link>http://www.casaba.com/blog/2012/01/porting-watcher-checks-to-modsecurity-rules/</link>
		<comments>http://www.casaba.com/blog/2012/01/porting-watcher-checks-to-modsecurity-rules/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 23:55:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Security Testing]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[ModSecurity]]></category>
		<category><![CDATA[Watcher]]></category>

		<guid isPermaLink="false">http://www.casaba.com/blog/?p=381</guid>
		<description><![CDATA[Earlier this year, Ryan Barnett at TrustWave&#8217;s Spiderlabs started porting some of Watcher&#8217;s checks to ModSecurity.   After we chatted about this, I decided to get involved.  We always liked the idea of a server-side scanner watching the Web traffic, and since ModSecurity sits right in the sweet spot it all made sense to focus [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this year, Ryan Barnett at <a href="http://blog.spiderlabs.com/">TrustWave&#8217;s Spiderlabs</a> started <a href="http://blog.spiderlabs.com/2011/05/modsecurity-advanced-topic-of-the-week-passive-vulnerability-scanning-part-2-watcher-checks.html">porting some of Watcher&#8217;s checks to ModSecurity</a>.   After we chatted about this, I decided to get involved.  We always liked the idea of a server-side scanner watching the Web traffic, and since ModSecurity sits right in the sweet spot it all made sense to focus some effort there.</p>
<p>So over the past few months we&#8217;ve been working to port more of <a title="Watcher passive Web application scanner" href="http://websecuritytool.codeplex.com">Watcher&#8217;s </a>passive Web scanning checks to the<a title="ModSecurity" href="http://modsecurity.org/">ModSecurity </a>open source Web Application Firewall.  It seems to be working out, as some of the rules have made it into the latest release of <a title="Watcher and ModSecurity" href="http://blog.spiderlabs.com/2011/12/announcing-release-of-owasp-modsecurity-core-rule-set-v223.html">ModSecurity&#8217;s Core Rule Set v2.2.3</a> as well as some earlier rule sets.  There&#8217;s more to come.  Please send any feedback to me or Ryan, and look for more rules to be added very soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2012/01/porting-watcher-checks-to-modsecurity-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft &#8220;Roslyn&#8221; based REPL injection.</title>
		<link>http://www.casaba.com/blog/2011/12/microsoft-roslyn-based-repl-injection/</link>
		<comments>http://www.casaba.com/blog/2011/12/microsoft-roslyn-based-repl-injection/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 18:05:12 +0000</pubDate>
		<dc:creator>John Hernandez</dc:creator>
				<category><![CDATA[Code Review]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[Security Testing]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.casaba.com/blog/?p=277</guid>
		<description><![CDATA[Microsoft recently released their new Compiler API codename &#8220;Roslyn&#8221;. If you haven&#8217;t checked it out yet you should. Here&#8217;s the link: http://msdn.microsoft.com/en-us/roslyn/. I wanted to get my hands a little dirty and play with the new API. I&#8217;ve been meaning to look into Managed DLL injection for a while to get code execution for process [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft recently released their new Compiler API codename &#8220;Roslyn&#8221;. If you haven&#8217;t checked it out yet you should. Here&#8217;s the link: http://msdn.microsoft.com/en-us/roslyn/.</p>
<p>I wanted to get my hands a little dirty and play with the new API. I&#8217;ve been meaning to look into Managed DLL injection for a while to get code execution for process interrogation. There are times when we&#8217;re testing that we want to interrogate a process for framework level information. For whatever reasons we sometimes can&#8217;t compile the target with hooks. So it would be nice to have a way to execute code. Roslyn’s CSX files look like a great way to accomplish this so that&#8217;s what I&#8217;m trying to expose. </p>
<p>Currently this only works on 32 bit processes.  </p>
<p>Let&#8217;s start by describing the architecture as there are 3 things going on. The major components are the Injector, Unmanaged Injectee and Managed Injectee. The injector is the controller in this scenario; he&#8217;s responsible for the injection into the managed process and communication between the components. Communication is handled via named pipes. </p>
<p>The injector uses a well-documented dll injection technique via CreateRemoteThread and LoadLibrary. This loads the unmanaged dll into the Managed process. The unmanaged DLL actually handles the Managed DLL injection. I wont go into unmanaged dll injection as it&#8217;s pretty well document technique. I assume the reader understands these concepts. </p>
<p>From this point I assume the unmanaged DLL has been injected into the managed process. </p>
<p>After the unmanaged DLL is injected I need to make sure the correct version of the CLR is loaded. To accomplish this use the CLR hosting API’s to determine the version of the CLR that is loaded by the process (Provided there is one loaded). The host process must be running .Net 4.0 to support the Roslyn API. Because the early versions of the hosting API&#8217;s are deprecated I need to check to see if the .net 4.0 mscoree is loaded &#8220;msvcr100_clr0400.dll&#8221;. I check via a GetModuleHandle. If it exists we know we are running .Net 4.0 and know the CLR is already running. Two birds down with a single stone. </p>
<pre>
hMod = GetModuleHandle(L"msvcr100_clr0400.dll");
</pre>
<p>Once we know the CLR is loaded and it’s 4.0 we can get a handle to the CLSID_CLRMetaHost via:</p>
<pre>
hr = CLRCreateInstance( CLSID_CLRMetaHost,
IID_ICLRMetaHost,
(LPVOID*)&amp;pMetaHost );
</pre>
<p>From the meta host we can get a handle to the running RunTimeHost via:</p>
<pre>
ICLRRuntimeHost *pClrHost = NULL;
runTimeInfo-&gt;GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&amp;pClrHost);
</pre>
<p>This will return a handle to the current RuntimeHost (Or load the runtime if it isn’t running). The next call is to load my Managed DLL plus call the entry method.</p>
<pre>
pClrHost-&gt;ExecuteInDefaultAppDomain(L"InjectedManagedDll_Net_4.dll", L"InjectedManagedDll_Net_4.InjectedClass", L"Test", L"TestArg" , &amp;ret);
</pre>
<p>This loads the Managed DLL into the process. Once the Managed DLL’s Test method is called I create a managed thread.</p>
<pre>
public static int Test(string param)
{
new Thread(new ThreadStart(ThreadFunc)).Start();
return 666;
}
</pre>
<p>This thread then generates a few more threads and sets up the NamedPipe communication pipe and reports to the server things are setup.</p>
<pre>
static void ThreadFunc()
{
try
{
PipeClient.Instance.Start("CNIPipe");
}
catch (Exception e)
{
PipeClient.Instance.LogMessageToServer(e.Message);
}
}
</pre>
<p>I then expose some simple messages back and forth between the injector and injectee and expose a simple REPL loosely based on this guy’s implementation: http://visualstudiomagazine.com/articles/2011/11/16/the-roslyn-scripting-api.aspx.</p>
<pre>
private ScriptHost()
{

HashSetassemblys = new HashSet();
assemblys.Add(Assembly.GetCallingAssembly());
assemblys.Add(Assembly.GetEntryAssembly());
assemblys.Add(Assembly.GetExecutingAssembly());

Listnamespaces = new List() { "System", "System.Collections", "System.Collections.Generic" };

ScriptEngine = new ScriptEngine(assemblys.ToList(), namespaces);

Session = Session.Create(this);
}

public object Execute(string code)
{
return ScriptEngine.Execute(code, Session);
}
</pre>
<p>This gets you a basic REPL inside another process. Next steps include making sure the communication API between the host and injectee are more well formed and able to handle both 32 and 64 bit processes. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2011/12/microsoft-roslyn-based-repl-injection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>X5S V2.0&#8230;. its coming!</title>
		<link>http://www.casaba.com/blog/2011/01/x5s-v2-0-its-coming/</link>
		<comments>http://www.casaba.com/blog/2011/01/x5s-v2-0-its-coming/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 16:59:22 +0000</pubDate>
		<dc:creator>John Hernandez</dc:creator>
				<category><![CDATA[Code Review]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Nebulous]]></category>
		<category><![CDATA[Security Testing]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://www.casaba.com/blog/?p=233</guid>
		<description><![CDATA[So, It&#8217;s been awhile since we&#8217;ve done any public updates to X5S. Over the last year, I&#8217;ve improved the algorithm and process significantly. Be on the look out, it should be released within the next couple of weeks (Sometime in Jan. 11). Some of the improvements include: * Better Algorithms for doing checks * Better [...]]]></description>
			<content:encoded><![CDATA[<p>So, It&#8217;s been awhile since we&#8217;ve done any public updates to X5S. Over the last year, I&#8217;ve improved the algorithm and process significantly. Be on the look out, it should be released within the next couple of weeks (Sometime in Jan. 11).</p>
<p>Some of the improvements include:<br />
* Better Algorithms for doing checks<br />
* Better output format .. Now uses a tree view.. Going to add better support for reporting too..<br />
* Cleaner UI (Easier to use)<br />
* Re-factored the code to be cleaner/make more sense and easier to maintain. It&#8217;s much easier to understand/work with.. before was mostly prototyped code/ Alpha code.<br />
* Changed how test cases are defined for more control over the types of injects<br />
* Added a fuzzing mode that will take data from a file and inject it where canaries would normally be injected. (This can be slow with lots of injections)<br />
* Added a replay from Fiddler capture.. (Replays the capture while fuzzing/injecting on the requests). </p>
<p>* many many more minor/significant changes..  =)</p>
<p>Check back soon for a release date!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2011/01/x5s-v2-0-its-coming/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Microsoft CCI Framework for Deobfuscating .Net binaries. (Part 3)</title>
		<link>http://www.casaba.com/blog/2010/02/microsoft-cci-framework-for-deobfuscating-net-binaries-part-3/</link>
		<comments>http://www.casaba.com/blog/2010/02/microsoft-cci-framework-for-deobfuscating-net-binaries-part-3/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 18:04:51 +0000</pubDate>
		<dc:creator>John Hernandez</dc:creator>
				<category><![CDATA[Code Review]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Malware]]></category>
		<category><![CDATA[Nebulous]]></category>
		<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[Babel]]></category>
		<category><![CDATA[CCI]]></category>
		<category><![CDATA[Deobfuscation]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.casabasecurity.com/blog/?p=188</guid>
		<description><![CDATA[Renaming parts of the assembly. So I promised this last week, but I&#8217;ve been busy on a new project. Below is some code that shows renaming of methods. This is a solution to renaming classes within namespaces. It iterates over each namespace renaming classes from class1 -&#62; classN. This is more useful for human readability [...]]]></description>
			<content:encoded><![CDATA[<p>Renaming parts of the assembly.</p>
<p>So I promised this last week, but I&#8217;ve been busy on a new project. Below is some code that shows renaming of methods. This is a solution to renaming classes within namespaces. It iterates over each namespace renaming classes from class1 -&gt; classN. This is more useful for human readability and tracing logic. I leave it as an exercise to the reader to figure out how to rename other parts of the assembly. But hey if you really need it an get stuck, let me know!</p>
<p>I&#8217;ll be posting a tool at some point that does all these different actions for you. Hopefully I&#8217;ll have a early release out by mid next month. I&#8217;m currently learning WPF well enough to build in visulalizations of the control flow graph. That way after a mutator is applied you can visually see the results.</p>
<p>There is a dictionary in the mutator class that uses the namespace string as a key in order to know which class # i left off at. I test on the string length &lt; 2 because the obfuscators I&#8217;ve seen that do this trick tend to just rename everything to some obscure unicode code point of length 1. Just a easy stop condition. You can use any stop condition that suits your needs.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p188code2'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1882"><td class="code" id="p188code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> NamespaceTypeDefinition Visit<span style="color: #008000;">&#40;</span>NamespaceTypeDefinition namespaceTypeDefinition<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #6666cc; font-weight: bold;">string</span> key <span style="color: #008000;">=</span> namespaceTypeDefinition<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainingUnitNamespace</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>classDict<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span><span style="color: #008000;">&#40;</span>key<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
     classDict<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>key, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>namespaceTypeDefinition<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
     <span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> classDict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
     namespaceTypeDefinition<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">host</span><span style="color: #008000;">.</span><span style="color: #0000FF;">NameTable</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetNameFor</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Class{0}&quot;</span>, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     i<span style="color: #008000;">++;</span>
     classDict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Visit</span><span style="color: #008000;">&#40;</span>namespaceTypeDefinition<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2010/02/microsoft-cci-framework-for-deobfuscating-net-binaries-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft CCI Framework for Deobfuscating .Net binaries.</title>
		<link>http://www.casaba.com/blog/2010/02/microsoft-cci-framework-for-deobfuscating-net-binaries/</link>
		<comments>http://www.casaba.com/blog/2010/02/microsoft-cci-framework-for-deobfuscating-net-binaries/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 20:01:51 +0000</pubDate>
		<dc:creator>John Hernandez</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Malware]]></category>
		<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[Babel]]></category>
		<category><![CDATA[CCI]]></category>
		<category><![CDATA[Deobfuscation]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.casabasecurity.com/blog/?p=152</guid>
		<description><![CDATA[We had an issue recently crop up with an obfuscated .Net binary. I’ve been meaning to spend more time reversing .Net protected binaries so I start looking in it. Unfortunately everything I was reading on the forums and internet seemed difficult. Having recently read a little about Microsoft’s CCI framework, I thought this might be [...]]]></description>
			<content:encoded><![CDATA[<p>We had an issue recently crop up with an obfuscated .Net binary. I’ve been meaning to spend more time reversing .Net protected binaries so I start looking in it. Unfortunately everything I was reading on the forums and internet seemed difficult. Having recently read a little about Microsoft’s CCI framework, I thought this might be the best solution to the problem. Using a hex editor and looking for patterns seems hokey and a bit impractical.</p>
<p>So the first thing I decided to try was removing the SuppressIldasmAttribute attribute.  Below is some example code doing just that using CCI and rewriting the file. This produces an executable that works and doesn’t require just hex editing out the attribute leaving an executable that doesn’t run.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p152code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1524"><td class="code" id="p152code4"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
     var host <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PeReader<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultHost</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     var module <span style="color: #008000;">=</span> host<span style="color: #008000;">.</span><span style="color: #0000FF;">LoadUnitFrom</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> IModule<span style="color: #008000;">;</span>
     var attributeRemover <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> AttributeRemover<span style="color: #008000;">&#40;</span>host<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     module <span style="color: #008000;">=</span> attributeRemover<span style="color: #008000;">.</span><span style="color: #0000FF;">Visit</span><span style="color: #008000;">&#40;</span>module<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     Stream peStream <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>module<span style="color: #008000;">.</span><span style="color: #0000FF;">Location</span> <span style="color: #666666;">&quot;.fixed&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     PeWriter<span style="color: #008000;">.</span><span style="color: #0000FF;">WritePeToStream</span><span style="color: #008000;">&#40;</span>module, host, peStream<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     Console<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Out</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Finished&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/*
* Removes the static attribute atm SuppressIldasmAttribute.. can be modified to remove any attribute.
*/</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> AttributeRemover <span style="color: #008000;">:</span> MetadataMutator
<span style="color: #008000;">&#123;</span>
&nbsp;
     PlatformType pt<span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #0600FF; font-weight: bold;">public</span> AttributeRemover<span style="color: #008000;">&#40;</span>IMetadataHost host<span style="color: #008000;">&#41;</span>
                              <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span>host<span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
         pt <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PlatformType<span style="color: #008000;">&#40;</span>host<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
     <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> List<span style="color: #008000;">&lt;</span>ICustomAttribute<span style="color: #008000;">&gt;</span> Visit<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>ICustomAttribute<span style="color: #008000;">&gt;</span> customAttributes<span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
          <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> customAttributes<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span>  <span style="color: #008000;">&#41;</span>
          <span style="color: #008000;">&#123;</span>
               <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>customAttributes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;System.Runtime.CompilerServices.SuppressIldasmAttribute&quot;</span><span style="color: #008000;">&#41;</span>
               <span style="color: #008000;">&#123;</span>
                    customAttributes<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveAt</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
               <span style="color: #008000;">&#125;</span>
          <span style="color: #008000;">&#125;</span>
          <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Visit</span><span style="color: #008000;">&#40;</span>customAttributes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>As you can see it requires very little code. Anyways that’s enough for this post. I also have some more code I’ll be posting that uses CCI to rename methods/class/methods from their “mangled names” and code that removes invalid OpCodes so reflector works at the IL level. I’m still working on code that goes through creates a optimized methods to remove the invalid jumps such that C# code can hopefully be reconstructed. We’ll see how that goes.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2010/02/microsoft-cci-framework-for-deobfuscating-net-binaries/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Getting Around Conditionally Banned APIs When Using Microsoft&#8217;s banned.h Header File</title>
		<link>http://www.casaba.com/blog/2009/12/getting-around-conditionally-banned-apis-when-using-microsofts-banned-h-header-file/</link>
		<comments>http://www.casaba.com/blog/2009/12/getting-around-conditionally-banned-apis-when-using-microsofts-banned-h-header-file/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 23:42:28 +0000</pubDate>
		<dc:creator>Ramsey Dow</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SDL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This code sample makes use of banned.h, a Microsoft-supplied header file that deprecates dangerous CRT functions. Microsoft also poisons these functions on UNIX if you include banned.h there. This is a Good Thing, but what about the fact that they banned strlen? The banned API page states: For critical functions, such as those accepting anonymous [...]]]></description>
			<content:encoded><![CDATA[<p>This code sample makes use of <a href="http://download.microsoft.com/download/2/e/b/2ebac853-63b7-49b4-b66f-9fd85f37c0f5/banned.h" target="new"><code>banned.h</code></a>, a Microsoft-supplied header file that deprecates dangerous CRT functions. Microsoft also poisons these functions on UNIX if you include <code>banned.h</code> there. This is a Good Thing, but what about the fact that they banned <a href="http://msdn.microsoft.com/en-us/library/78zh94ax%28VS.71%29.aspx" target="new"><code>strlen</code></a>? The <a href="http://msdn.microsoft.com/en-us/library/bb288454.aspx" target="new">banned API page</a> states:</p>
<p><em>For critical functions, such as those accepting anonymous Internet connections, <code>strlen</code> must also be replaced.</em></p>
<p>That&#8217;s good advice for cases where you want to operate on untrusted data. In those cases they tell you that you should use <a href="http://msdn.microsoft.com/en-us/library/z50ty2zh.aspx" target="new"><code>strnlen_s</code></a>. The problem is, <code>banned.h</code> straight out bans <code>strlen</code>. There is no way to tell it that hey, this particular invocation is safe because I control the buffer in all aspects. Nope, sorry. You can&#8217;t use <code>strlen</code>. Or can you?</p>
<p>Here is a code sample that uses <code>banned.h</code> to deprecate unsafe APIs, yet still manages to invoke <code>strlen</code> when necessary. The sample works in both <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx" target="new">Visual Studio</a> on Windows and <a href="http://gcc.gnu.org/" target="new">GCC</a> on UNIX.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p5code6'); return false;">View Code</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p56"><td class="code" id="p5code6"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">//</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  banned_test.c</span>
<span style="color: #666666; font-style: italic;">//  20091208 ramsey@casabasecurity.com</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//  A sample program that illustrates how to &quot;grandfather in&quot; banned APIs</span>
<span style="color: #666666; font-style: italic;">//  for use when they are marked deprecated (Windows) or poisoned (UNIX)</span>
<span style="color: #666666; font-style: italic;">//  by the compiler.</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//  to compile on Windows:</span>
<span style="color: #666666; font-style: italic;">//  cl /GS /W4 /WX banned_test.c</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//  to compile on UNIX:</span>
<span style="color: #666666; font-style: italic;">//  gcc -Wall -Werror banned_test.c</span>
&nbsp;
<span style="color: #339933;">#if defined _WIN32</span>
&nbsp;
<span style="color: #339933;">#include &lt;windows.h&gt;</span>
<span style="color: #339933;">#endif    // _WIN32</span>
&nbsp;
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
<span style="color: #339933;">#if defined _WIN32</span>
&nbsp;
size_t my_strlen<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  size_t len<span style="color: #339933;">;</span>
  <span style="color: #339933;">#pragma warning(push)</span>
  <span style="color: #339933;">#pragma warning(disable:4995)</span>
  len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">#pragma warning(pop)</span>
  <span style="color: #b1b100;">return</span> len<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">#else</span>
<span style="color: #339933;">#define my_strlen strlen</span>
<span style="color: #339933;">#endif    // _WIN32</span>
&nbsp;
<span style="color: #339933;">#include &quot;banned.h&quot;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> ac<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>av<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;foo&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">#if defined _WIN32</span>
  UNREFERENCED_PARAMETER<span style="color: #009900;">&#40;</span>ac<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  UNREFERENCED_PARAMETER<span style="color: #009900;">&#40;</span>av<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">#endif    // _WIN32</span>
  <span style="color: #339933;">#if defined _WIN32</span>
  <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;len is %Id<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">#else</span>
  <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;len is %zd<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">#endif    // _WIN32</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Note that this code requires the use of Microsoft&#8217;s <code>banned.h</code> header file, which can be downloaded <a href="http://download.microsoft.com/download/2/e/b/2ebac853-63b7-49b4-b66f-9fd85f37c0f5/banned.h" target="new">here</a>. Stick it in the same directory as the above source file.</p>
<p>To compile the sample in Windows from a Visual Studio Command Prompt:</p>
<pre>

cl banned_test.c /GS /W4 /WX
</pre>
<p>As expected, this program will generate an error when run:</p>
<pre>

banned_test.c

banned_test.c(50) : error C2220: warning treated as error - no 'object' file generated

banned_test.c(50) : warning C4995: 'strlen': name was marked as #pragma deprecated
</pre>
<p>Now edit <code>banned_test.c</code> and change the <code>strlen</code> on line 50 to <code>my_strlen</code> and recompile:</p>
<pre>

cl banned_test.c /GS /W4 /WX
</pre>
<p>It should compile without error. Now run it and you should see:</p>
<pre>

len is 3
</pre>
<p>Nifty.</p>
<p>The same code works without change on UNIX (tested on NetBSD):</p>
<pre>

gcc -Wall -Werror banned_test.c
</pre>
<p>As with the Windows example, running the program will generate an error, as expected:</p>
<pre>

banned_test.c:52:31: error: attempt to use poisoned "strlen"
</pre>
<p>Again, change the occurrence of <code>strlen</code> (this time on line 52) to <code>my_strlen</code> and recompile. It will work and when run, it will say:</p>
<pre>

len is 3
</pre>
<p>What&#8217;s going on here is simple. While we are banning use of the <code>strlen</code> function, we are still allowing its use selectively through a wrapper that we have &#8220;grandfathered in.&#8221; This is easy to accomplish in UNIX: we simply
<pre>#define my_strlen strlen</pre>
<p> prior to including <code>banned.h</code> and use that function call entry point instead. Problem solved. This is not as easy to accomplish with Windows, however, as <code>cl.exe</code> has no notion of &#8220;grandfathering in&#8221; deprecated APIs. So what we do is wrap <code>strlen</code> in another function. We ignore the deprecation warning that occurs where we make the call to <code>strlen</code> through the judicious application of some Visual Studio-specific <code>pragma</code> instructions. Now all need to do is call in to our new function entry point. We&#8217;re good to go. The Windows solution requires a little more work up front, but turns out to be not so hard to accomplish after all.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2009/12/getting-around-conditionally-banned-apis-when-using-microsofts-banned-h-header-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing Security Development Errors: Lessons Learned at Windows Live by Using ASP.NET MVC</title>
		<link>http://www.casaba.com/blog/2009/11/preventing-security-development-errors-lessons-learned-at-windows-live-by-using-asp-net-mvc/</link>
		<comments>http://www.casaba.com/blog/2009/11/preventing-security-development-errors-lessons-learned-at-windows-live-by-using-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 21:42:45 +0000</pubDate>
		<dc:creator>Chris Weber</dc:creator>
				<category><![CDATA[Code Review]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Casaba had the opportunity to contribute to a new Microsoft paper regarding ASP.NET MVC security. It&#039;s online through the SDL pages, and here&#39;s the paper&#39;s direct link. A short summary of the paper follows. The SDL preaches &#039;secure by default&#039;. When Windows Live moved to ASP.Net MVC, they used that opportunity to build mitigations into [...]]]></description>
			<content:encoded><![CDATA[<p>Casaba had the opportunity to contribute to a new Microsoft paper regarding ASP.NET MVC security.  It&#039;s online through the <a href="http://www.microsoft.com/security/sdl/"> SDL pages</a>, and here&#39;s the paper&#39;s <a href="http://go.microsoft.com/?linkid=9695423">direct link</a>.  A short summary of the paper follows.</p>
<p>The SDL preaches &#039;secure by default&#039;. When Windows Live moved to ASP.Net MVC, they used that opportunity to build mitigations into the framework that prevent developers from making accidental errors which result in security flaws. Specifically, they targeted these three security issues – XSRF, Open redirects and JSON hijacking. </p>
<p>For XSRF, the mitigation was that all HTTP requests are checked for a canary by default except for HTTP GET requests. Developers can also opt-out specific pages or functionality. This automatic ‘on-by-default’ canary checking prevents accidental errors which lead to XSRF. </p>
<p>For Open redirects, Windows Live added a wrapper around the Redirect result in ASP.Net MVC which checks a list of approved domains. This way when a developer called Redirect and forgot to ensure it was safe, the wrapper would cover them automatically. </p>
<p>For JSON hijacking, they ensure that the JSON result included a canary check by default.  This prevented developers from being able to return JSON without a canary, thus preventing JSON hijacking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2009/11/preventing-security-development-errors-lessons-learned-at-windows-live-by-using-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the Importance of Good Developer Documentation</title>
		<link>http://www.casaba.com/blog/2009/11/on-the-importance-of-good-developer-documentation/</link>
		<comments>http://www.casaba.com/blog/2009/11/on-the-importance-of-good-developer-documentation/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 19:01:27 +0000</pubDate>
		<dc:creator>Ramsey Dow</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SDL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Programmers rely on documentation. It&#039;s how we learn to use APIs. Misusing APIs is a leading source of vulnerability. You might think that documentation is a cure to this ailment. Unfortunately, as someone who has been in software development for a long time, I can tell you that documentation quality is not always what it [...]]]></description>
			<content:encoded><![CDATA[<p>Programmers rely on documentation. It&#039;s how we learn to use APIs. Misusing APIs is a leading source of vulnerability. You might think that documentation is a cure to this ailment. Unfortunately, as someone who has been in software development for a long time, I can tell you that documentation quality is not always what it should be. API documentation serves as a reference. I have yet to meet the programmer who can recall every nuance about every API for all the languages they program in. (Were such a programmer to exist, its name might well be <a href="http://en.wikipedia.org/wiki/Robby_the_Robot">Robby the Robot</a>.) </p>
<p>Recently I was converting strings using the <a href="http://msdn.microsoft.com/en-us/library/eyktyxsx.aspx">mbstowcs_s</a> and <a href="http://msdn.microsoft.com/en-us/library/s7wzt4be.aspx">wcstombs_s</a> functions. (These are from from the bounds checking extensions to the C Library specified in ISO/IEC TR 24731-1.) These functions allow you to convert multibyte character sequences to and from wide character sequences. These functions are available to C and C++ programmers using Microsoft&#039;s Visual Studio compiler. (I am not yet aware of any UNIX compatible compiler that supports the draft TR 24731-1 standard.)</p>
<p>Since these two functions convert strings, it is worth looking at the parameters they expect. (Not doing so is a sure fire way to do something stupid, like enable a buffer overflow.) Looking at the relevant parameters for these two functions, we see:</p>
<p><strong>mbstowcs_s</strong>:<br />
[in] <em>sizeInWords</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The size of the wcstr buffer in words.<br />
[in] <em>count</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The maximum number of wide characters to store in the wcstr buffer, not including the terminating null, or <a href="http://msdn.microsoft.com/en-us/library/ms175769.aspx">_TRUNCATE</a>.</p>
<p><strong>wcstombs_s</strong>:<br />
[in] <em>sizeInBytes</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The size in bytes of the mbstr buffer.<br />
[in] <em>count</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The maximum number of bytes to be stored in the mbstr buffer, or <a href="http://msdn.microsoft.com/en-us/library/ms175769.aspx">_TRUNCATE</a>.</p>
<p>Does count in wcstombs_s account for the terminating NULL or not? Failure to account for this could introduce an off-by-one error which, in turn, may lead to an exploitable condition, such as a buffer overflow. How can we determine this from the documentation? Well, in its current state, we can&#039;t. This is what we call a &#8220;doc bug.&#8221;</p>
<p>Luckily, Microsoft includes the source code for the C Runtime with most Visual Studio SKUs. Assuming you installed Visual Studio in Program Files, you should be able to find the CRT source code in Program Files\Microsoft Visual Studio 9.0\VC\crt\src. CRT source code is included with all Visual Studio SKUs except for the Express Editions. Luckily for Express Edition users, the forthcoming Visual Studio 2010 release finally opens up the CRT sources to Express Edition users. If you are using an Express Edition of VS2008 or earlier, consider grabbing the VS2010 Express beta from <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx">here</a>.</p>
<p>In any case, if you have the CRT source code, it is easy to track down the source for wcstombs_s and check to see if the terminating NULL is intended to be accounted for or not. Looking into wcstombs.c we discover this bit of text in the comment for the wcstombs_s function:<br />
<code><br />
size_t n = maximum number of bytes to store in s (not including the terminating NULL)<br />
</code></p>
<p>Clearly, the terminating NULL is not meant to be included. This is as we suspected, but now we have verified it instead of blindly assuming that it would be the case. As security practitioners we should be careful not to make assumptions. Verify instead!</p>
<p>This documentation bug has been reported to Microsoft. With any luck it will get addressed prior to the VS 2010 release on March 22, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2009/11/on-the-importance-of-good-developer-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use the Source, Luke!</title>
		<link>http://www.casaba.com/blog/2009/10/use-the-source-luke/</link>
		<comments>http://www.casaba.com/blog/2009/10/use-the-source-luke/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:35:13 +0000</pubDate>
		<dc:creator>Ramsey Dow</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SDL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[If there&#039;s one thing that I&#039;ve learned throughout the years as a programmer, it is not always safe to trust the documentation. In fact, there is an old saying, &#8220;Use the source, Luke!&#8221; When possible, you should do just that. While looking over the CERT Secure C Coding Standard I noticed the following recommendation: ERR30-C. [...]]]></description>
			<content:encoded><![CDATA[<p>If there&#039;s one thing that I&#039;ve learned throughout the years as a programmer, it is not always safe to trust the documentation. In fact, there is an old saying, &#8220;Use the source, Luke!&#8221; When possible, you should do just that.</p>
<p>While looking over the <a href="http://www.cert.org/">CERT</a> <a href="https://www.securecoding.cert.org/confluence/display/seccode/CERT+C+Secure+Coding+Standard">Secure C Coding Standard</a> I noticed the following recommendation: <a href="https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=6619179">ERR30-C. Set <code>errno</code> to zero before calling a library function known to set <code>errno</code>, and check <code>errno</code> only after the function returns a value indicating failure</a>. CERT goes on to write, &#8220;[s]ome functions lack documentation regarding <code>errno</code> in the C99 standard.&#8221; They follow this up with an example for Windows: &#8220;[i]n this compliant solution, <code>errno</code> is not checked because <code>fopen()</code> makes no promise of setting it.&#8221; This would be fine, were it true. However, it is false. Let us take a closer look.</p>
<p>It is true that the symbol, <code>errno</code>, appears nowhere in the MSDN documentation for <a href="http://msdn.microsoft.com/en-us/library/yeby3zcb%28VS.71%29.aspx">fopen</a>. However, one need only look to <code>fopen.c</code> (included with all commercial Visual C implementations) to see that <code>errno.h</code> is <code>#include</code>&#039;d and <code>errno</code> is indeed set for locked streams, bad names (e.g., empty string), et al.</p>
<p>The use of <code>errno</code> is not as robust in the case of Microsoft&#039;s <code>fopen</code> implementation as it is in the implementation on my <a href="http://www.netbsd.org/">NetBSD</a> box, but that&#039;s not the point. The point is that CERT stated something was true based on documentation when in fact, it was not true. The lesson here is that one cannot simply rely on assumptions based on documentation, one must also look to the source to see what is happening.</p>
<p>In the case of Microsoft&#039;s C and secure C runtimes, the source code is available for you to look at, provided you have Visual Studio installed. (Caveat: you don&#039;t get the CRT source code if you install Visual C++ Express.) I found the code living on my box under Program Files at Microsoft Visual Studio 9.0\VC\crt\src.</p>
<p>Of course, if you&#039;re programming on Windows you should prefer <a href="http://msdn.microsoft.com/en-us/library/z5hh6ee9%28VS.80%29.aspx"><code>fopen_s</code></a> to <code>fopen</code> anyway. For the record, the MSDN documentation for <code>fopen_s</code> clearly states that it returns an <code>errno_t</code>, which is the <a href="http://msdn.microsoft.com/en-us/library/8ef0s5kh%28VS.80%29.aspx">Secure CRT</a>&#039;s answer to <code>errno</code>.</p>
<p>Update: I just found out from a source inside the Visual Studio team at Microsoft that Visual Studio 2010 Beta 2&#039;s Express Edition SKU contains the CRT source code. That&#039;s good news. You can get more information on Visual Studio 2010 Beta 2 <a href="http://blogs.msdn.com/webdevtools/archive/2009/10/21/web-tools-beta-2-overview.aspx">here</a>, and you can download it <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2009/10/use-the-source-luke/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Vim plugin for highlighting APIs banned by the Microsoft SDL</title>
		<link>http://www.casaba.com/blog/2009/08/a-vim-plugin-for-highlighting-apis-banned-by-the-microsoft-sdl/</link>
		<comments>http://www.casaba.com/blog/2009/08/a-vim-plugin-for-highlighting-apis-banned-by-the-microsoft-sdl/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 01:03:46 +0000</pubDate>
		<dc:creator>Ramsey Dow</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SDL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I do a lot of programming, so I live in my editor. I use Vim. If you also use Vim then I&#039;ve got something to share with you: a new syntax plugin that highlights function calls banned by Microsoft&#039;s Security Development Lifecycle (SDL). You can obtain the banned.vim syntax plugin from the Vim script archive. [...]]]></description>
			<content:encoded><![CDATA[<p>I do a lot of programming, so I live in my editor. I use <a target="new" href="http://www.vim.org/">Vim</a>. If you also use Vim then I&#039;ve got something to share with you: a new syntax plugin that highlights function calls banned by Microsoft&#039;s <a target="new" href="http://msdn.microsoft.com/en-us/security/cc448177.aspx">Security Development Lifecycle</a> (SDL). You can obtain the <strong>banned.vim</strong> syntax plugin from the <a target="new" href="http://www.vim.org/scripts/script.php?script_id=2753">Vim script archive</a>.</p>
<p>The <strong>banned.vim</strong> syntax plugin will highlight C function calls that have been banned by the SDL. It adds functionality to the existing C and C++ Vim syntax plugins. Banned APIs, such as <code>strcpy</code> and others, will appear visually in Vim as if they were errors. It is my hope that this extra attention will cause you to reconsider using the banned API and replace it instead with a safer alternative. Although many of these banned function calls are Windows-specific, there are quite a few that are also available in UNIX and should be avoided. Details on the APIs banned by Microsoft&#039;s SDL can be found on <a target="new" href="http://msdn.microsoft.com/en-us/library/bb288454.aspx">Microsoft&#039;s site</a>.</p>
<p>Here&#039;s a screen shot of <strong>banned.vim</strong> in action. In this case we&#039;re editing <code>str_cat.c</code>, one of the entries from the <a target="new" href="http://www.sans-ssi.org/resources/Winners_of_insecure_coding_contest_20080721.pdf">2008 SANS Awards for Finding Coding Books with Secure programming Flaws</a>. Notice the banned APIs in the code below?</p>
<p><img alt="banned.vim in action" height="362" width="541" style="display: block; margin-left: auto; margin-right: auto" src="http://www.casabasecurity.com/images/banned.png" /></p>
<p>Installing <strong>banned.vim</strong> is easy. First, you need to know what your <em>runtimepath</em> is, which varies from operating system to operating system. If you don&#039;t know what your <em>runtimepath</em> is, check the <a target="new" href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27runtimepath%27">Vim documentation</a>. Second, create the directory structure <code>after/syntax</code> in your <em>runtimepath</em> directory if it doesn&#039;t already exist. Third, copy <strong>banned.vim</strong> into <code><em>runtimepath</em>/after/syntax</code> as both <code>c.vim</code> and <code>cpp.vim</code>. That&#039;s all there is to installation. There is no need to edit your <code>.vimrc</code> or anything.</p>
<p>I would like to thank Rob Mooney for suggesting this plugin in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2009/08/a-vim-plugin-for-highlighting-apis-banned-by-the-microsoft-sdl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let me see that certificate a little more closely. Part 1 &#8211; Validating the Server&#8217;s Certificate</title>
		<link>http://www.casaba.com/blog/2008/06/let-me-see-that-certificate-a-little-more-closely-part-1-validating-the-servers-certificate/</link>
		<comments>http://www.casaba.com/blog/2008/06/let-me-see-that-certificate-a-little-more-closely-part-1-validating-the-servers-certificate/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 01:42:04 +0000</pubDate>
		<dc:creator>Brian Lewis</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Security Testing]]></category>
		<category><![CDATA[Certificate]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[If you are developing a client to a server service that communicates over SSL such as a Web Service then it is your job to ensure your server is the &#34;real deal&#34; and not some rouge server or man-in-the-middle. How do you do that? Validate the server&#39;s certificate. Make sure the certificate is for the [...]]]></description>
			<content:encoded><![CDATA[<p>If you are developing a client to a server service that communicates over SSL such as a Web Service then it is your job to ensure your server is the &quot;real deal&quot; and not some rouge server or man-in-the-middle.  How do you do that?  Validate the server&#39;s certificate.   Make sure the certificate is for the domain you are accessing, make sure the certificate chain is valid, and make sure the certificate is signed by a trusted certificate authority (CA).  Sound like a pain?  Well it isn&#39;t.  You get a lot for a little with the right API calls. </p>
<p>WinHttpReceiveResponse in C++ will return FALSE if the certificate has one of the following errors:</p>
<p><strong>WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED</strong></p>
<p>Certification<br />
revocation checking has been enabled, but the revocation check failed to verify<br />
whether a certificate has been revoked. The server used to check for revocation<br />
might be unreachable. </p>
<p><strong>WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT </strong></p>
<p>SSL certificate is invalid.</p>
<p><strong>WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED</strong></p>
<p>SSL certificate was revoked.</p>
<p><strong>WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA</strong></p>
<p>The function is unfamiliar with the Certificate Authority that generated the server&#39;s certificate.</p>
<p><strong>WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID</strong></p>
<p>SSL certificate common name (host name field) is incorrect, for example, if you entered <a href="http://www.microsoft.com" title="www.microsoft.com">www.microsoft.com</a> and the common name on the certificate says <a href="http://www.msn.com" title="www.msn.com">www.msn.com</a>.</p>
<p><strong>WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID</strong></p>
<p>SSL certificate date that was received from the server is bad. The certificate is expired.</p>
<p><strong>WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR</strong></p>
<p>The application experienced an internal error loading the SSL libraries.</p>
<p>However, <strong>WinHttpReceiveResponse</strong> does not return these errors directly as a call to GetLastError() will only return <strong>ERROR_WINHTTP_SECURE_FAILURE</strong> if there is a problem with the server&#39;s certificate.  You must use the CallBack <strong>WINHTTP_STATUS_CALLBACK</strong> to access the specific errors listed above.</p>
<p><code><br />
 public WINHTTP_STATUS_CALLBACK myOwnAsyncCallback( __in HINTERNET hInternet,<br />
	__in DWORD_PTR dwContext,<br />
	__in DWORD dwInternetStatus,<br />
	__in LPVOID lpvStatusInformation,<br />
	__in DWORD dwStatusInformationLength)<br />
	{<br />
		if (dwInternetStatus == WINHTTP_CALLBACK_STATUS_SECURE_FAILURE)<br />
		// We have a certificate issue but which one? Take action before each break. This function must be thread safe and reentrant.<br />
		switch(*(DWORD*)lpvStatusInformation)<br />
		{<br />
			case WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED:<br />
			break;<br />
			case WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT:<br />
			break;<br />
			case WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED:<br />
			break;<br />
			case WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA:<br />
			break;<br />
			case WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID:<br />
			break;<br />
			case WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID:<br />
			break;<br />
			case WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR:<br />
			break;<br />
		}<br />
	}<br />
	HINTERNET hSession = WinHttpOpen(L"A WinHTTP Example Program/1.0",<br />
	WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,<br />
	WINHTTP_NO_PROXY_NAME,<br />
	WINHTTP_NO_PROXY_BYPASS, 0);<br />
	WINHTTP_STATUS_CALLBACK isCallback = WinHttpSetStatusCallback( hSession, WINHTTP_STATUS_CALLBACK)myOwnAsyncCallback,WINHTTP_CALLBACK_FLAG_SECURE_FAILURE,<br />
	NULL);<br />
	//The rest of your code including call WinHttpReceiveResponse<br />
</code></p>
<p>For more information see<br />
<a href="http://msdn.microsoft.com/en-us/library/cc185684(VS.85).aspx">http://msdn.microsoft.com/en-us/library/cc185684(VS.85).aspx</a><br />
<a href="http://msdn.microsoft.com/en-us/library/aa383917(VS.85).aspx">http://msdn.microsoft.com/en-us/library/aa383917(VS.85).aspx</a><br />
<a href="http://msdn.microsoft.com/en-us/library/aa384266(VS.85).aspx">http://msdn.microsoft.com/en-us/library/aa384266(VS.85).aspx</a><br />
<a href="http://msdn.microsoft.com/en-us/library/aa384115(VS.85).aspx">http://msdn.microsoft.com/en-us/library/aa384115(VS.85).aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2008/06/let-me-see-that-certificate-a-little-more-closely-part-1-validating-the-servers-certificate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It all comes back to the basics</title>
		<link>http://www.casaba.com/blog/2008/04/it-all-comes-back-to-the-basics/</link>
		<comments>http://www.casaba.com/blog/2008/04/it-all-comes-back-to-the-basics/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 10:00:25 +0000</pubDate>
		<dc:creator>Samuel Bucholtz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Consulting]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Recently there has been a lot of talk in the security community about the Flash ActionScript exploit written by Mark Dowd (http://documents.iss.net/whitepapers/IBM_X-Force_WP_final.pdf). I will not go into a breakdown of the exploit as others have already done a great job of blogging about it. What I would like to discuss is two big takeaways that [...]]]></description>
			<content:encoded><![CDATA[<p>Recently there has been a lot of talk in the security community about the Flash ActionScript exploit written by Mark Dowd (<a href="http://documents.iss.net/whitepapers/IBM_X-Force_WP_final.pdf" title="http://documents.iss.net/whitepapers/IBM_X-Force_WP_final.pdf">http://documents.iss.net/whitepapers/IBM_X-Force_WP_final.pdf</a>). I will not go into a breakdown of the exploit as others have already done a great job of blogging about it. What I would like to discuss is two big takeaways that even programmers who are not &quot;uber-hackers&quot; can appreciate.</p>
<p>The first takeaway is the importance of understanding and implementing the fundamentals. The exploit above occurs because of a NULL dereference triggered by an out of memory return by malloc(). I remember in my first C programming class when I was working with a partner an a project and he was trying to properly implement malloc(). I had already been using C for a few years and always checked the return of a function. I could not figure out why he was not checking to make sure sufficient memory had been allocated. He gave me the excuse that it would require a lot of code to check the return value and that since the data structure was small the allocation would fail. Nonsense, as I demonstrated by filling up the 640K of standard memory. He then argued that we would be better off implementing XMS or EMS to access the other 3MB of &quot;high&quot; memory, a silly argument if ever there was one.</p>
<p> When non-security professionals describe what hackers do they often say that hackers look for ways to bypass  restrictions and go around roadblocks. This is a somewhat fair description, but what they may not know is that often hackers are merely taking advantage of mistakes or the faulty reasoning of programmers who tried to skip or work around something simple or basic that they felt would be too much work to implement properly. The original &quot;hacks&quot; were simply ways of getting things done quicker, easier, or more elegantly but sometimes there is a fundamental reason for doing things one way and the &quot;hack&quot; just gets you into hot water. Anyone who has ever picked up a C programming book and looked at the function info for malloc() knows that it is NOT guaranteed to return the memory requested. Obviously, it is a BAD idea to simply assume that it succeeded in allocating all the memory requested. Know your functions/methods and how to properly implement them.</p>
<p> The second takeaway for the average programmer is the need to integrate and leverage the latest in security functionality in your code from the ground up. What do I mean by this? Follow-up research on the exploit has shown that if DEP had been turned on and opted-in the exploit would not have worked. DEP marks portions of memory as NX (No Execute). Such areas in memory will trigger a processor fault if an attacker attempts to execute shellcode they have somehow loaded into such memory. Is DEP a panacea- No. But it provides a second layer of defense. Now you might say- DEP is a system setting that users or admins or Microsoft can turn on or off, there is nothing I can do as a programmer. This is not true. First of all, you need to write your application to make sure it works properly with DEP turned on. You need to test your application to verify this. You need to inform users so they know they can safely use DEP with your application. </p>
<p>A number of other features like ASLR (Address space layout randomization), /GS (canary based buffer overflow detection), etc. are provided now by Visual Studio and other compilers or by the latest versions of the Windows operating system.  Developers should be building their code to use these basic security tools that are in most cases so easily integrated. None of these features can prevent all security threats, but there are many applications out there using outdated compilers or failing to implementeven the simplest of automated defenses for lack of awareness or a fear of performance degradation. To the former- browse through just a few of the numerous security respurce out there and then review your compiler/linkers security related flags; to the latter- given the massive code bloat in this object oriented development world compared with the (good) old days of hand tuned assembly in a COM file what is a one or two percent more overhead <img src='http://www.casaba.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2008/04/it-all-comes-back-to-the-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ASP.Net session handling with secure sites (set the secure flag)</title>
		<link>http://www.casaba.com/blog/2008/02/using-asp-net-session-handling-with-secure-sites-set-the-secure-flag/</link>
		<comments>http://www.casaba.com/blog/2008/02/using-asp-net-session-handling-with-secure-sites-set-the-secure-flag/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 07:04:42 +0000</pubDate>
		<dc:creator>Samuel Bucholtz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Security Testing]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[cookies]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[One of the common problems we see with many web applications is reliance on ASP.Net sessionID without understanding the security ramifications. ASP.Net provides web developers with a powerful means of tracking user state and identity with very little coding. Rather than creating your own custom authentication cookie, handling the trickiness of forms auth or mapping [...]]]></description>
			<content:encoded><![CDATA[<p>One of the common problems we see with many web applications is reliance on ASP.Net sessionID without understanding the security ramifications. ASP.Net provides web developers with a powerful means of tracking user state and identity with very little coding. Rather than creating your own custom authentication cookie, handling the trickiness of forms auth or mapping your cookie to a Windows identity, password policy implementation, not to mention creating server objects to store the state for a given user, ASP.net does it all for you. </p>
<p>ASP.Net offers two methods of tracking session state- URL or cookie. URL based methods are used in cases where it is expected that some users will have disabled cookies and still need a server-side session to track state. This has become less common as more and more of the web relies on cookies. In addition the URLs look ugly and are considered unacceptableby many usability gurus. </p>
<p>The second method is a cookie sent as a header to the server. This cookie is sent over HTTP or HTTPS and is used by ASP.net to link an incoming request to the server-side state. So you are running your site on SSL, where is the problem? By default, the SessionID is just a cookie the browser sends it when making any response to the domain. If you go to <a href="https://yourapp/application" title="https://yourapp/application">https://yourapp/application</a>, you will be sent a cookie over SSL that I cannot see. If I e-mail you a link to click for <a href="http://yourapp/application" title="http://yourapp/application">http://yourapp/application</a>, I will see the cookie sent over HTTP as long as your server responds on port 80. </p>
<p>What you want to do is set the &#039;secure&#039; flag on the cookie.  You have many options for doing this: <strong>adsutil set w3svc/1/AspKeepSessionIDSecure 1</strong> will tell ASP.net to mark the session cookie as Secure. When a cookie is marked as secure it will not be sent by the web browser unless the connection to the server is over https. You must be aware that the user will now have no session state if they browse to the site using http your application will need to redirect http requests to https in order to access the session state. </p>
<p>Is the ASP.Net session ID the only cookie I can protect in this way? No. You can use a web.config configuration to customize the security of all your cookies (<a href="http://msdn2.microsoft.com/en-us/library/ms228262.aspx" title="http://msdn2.microsoft.com/en-us/library/ms228262.aspx">http://msdn2.microsoft.com/en-us/library/ms228262.aspx</a>). You will also be able to set cookies to be HttpOnly which adds its own element of security and is supported by newer browsers. </p>
<p>Finally, you can set both the secure flag and the HttpOnly flag for any other cookies you set programmatically through ASP.Net with <a href="http://msdn2.microsoft.com/en-us/library/ms228262.aspx" title="http://msdn2.microsoft.com/en-us/library/ms228262.aspx">http://msdn2.microsoft.com/en-us/library/ms228262.aspx</a>.</p>
<p>A few other things to remember- </p>
<p>ASP.Net sessions expire after 20 minutes UNLESS a new request is seen. Otherwise they can remain until the server is recycled. </p>
<p>SessionIDs can be reused. When stored as a cookie the sessionID will go to any machine hosting the same parent domain. They will NOT have the server-side state though unless some clustering or back-end logic handles sharing state across servers. If you want to ensure that reuse does not happen, rather than using Session.Abandon you must overwrite the ASP.Net session cookie with an empty cookie value. To properly end a session or force a user to start a new one use Session.Abandon. </p>
<p>For more information checkout &#8211; <a href="http://msdn2.microsoft.com/en-us/library/ms972969.aspx" title="http://msdn2.microsoft.com/en-us/library/ms972969.aspx">http://msdn2.microsoft.com/en-us/library/ms972969.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2008/02/using-asp-net-session-handling-with-secure-sites-set-the-secure-flag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Releases the sources to the .Net framework</title>
		<link>http://www.casaba.com/blog/2008/01/microsoft-releases-the-sources-to-the-net-framework/</link>
		<comments>http://www.casaba.com/blog/2008/01/microsoft-releases-the-sources-to-the-net-framework/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 10:59:55 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I suppose this is news to a lot of people. http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-&#8230; The easy access to the source should help people. Even if it helps them use someone elses library. I&#039;ll get back to that thought in a second. Of course the Intermediate Language (IL) can be looked at with it&#039;s rich meta data with ILDASM. [...]]]></description>
			<content:encoded><![CDATA[<p>I suppose this is news to a lot of people.  <a href="http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx" title="http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx">http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-&#8230;</a>  The easy access to the source should help people.  Even if it helps them use someone elses library.  I&#039;ll get back to that thought in a second.</p>
<p>Of course the Intermediate Language (IL) can be looked at with it&#039;s rich meta data with ILDASM.  It&#039;s kind of odd looking at &#8220;machine&#8221; intructions for a virtual machine.  As far as I can tell there&#039;s close to no documentation about their OP codes or a language reference.  The one (and only) great book I&#039;ve found is &#8230;Expert .NET 2.0 IL Assembler<br />
by Serge Lidin, S. Lidin</p>
<p>The much easier way to wander around is <a href="http://www.aisto.com/roeder/dotnet/"> Reflector</a>.  You&#039;ll want the file disassembler add-in (let&#039;s you save all the files in an assembly).</p>
<p>I&#039;ve wandered around in the framework a good deal and for the most part it isn&#039;t &#8230;.mmmmm&#8230;. productive.  Some beanhead professor once upon a time decided that everything possible should be private.  I&#039;m not sure what this accomplishes except that it kills all kinds of code reuse.  For example you want the listbox control to handle hotkeys or whatever just a tad differently for your application.  You should just be able to overload the &#8220;broken&#8221; part of .Net.  No can do, private.  Don&#039;t get me wrong, on occasion you can redo some function.  You borrow the code in Reflector, modify the part that doesn&#039;t work for you, and then you have to figure out how to get it&#039;s 4 uses of private calls fixed.  Copy the whole object you say!  Good idea.  Now you have 4 other internal objects to copy.  Lame lame lame.  It&#039;s a big ole spider web.</p>
<p>The best cheat is to add yourself a CustomAttribute listing your assembly as a a &#8220;friend&#8221;.  Of course this makes the signature invalid, so not exactly distributable.  You could really cheat and sign your own version!  Ahah.                  Who knows what&#039;s next?  Mmmhmm, you have to drag all the other Microsoft Internal Friends with you.  It&#039;s a tar baby I tell ya.</p>
<p>Who want&#039;s to talk about COM and application integration now?  Makes you love those little itty bitty tools that don&#039;t depend on a thing.  I wish thee were more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2008/01/microsoft-releases-the-sources-to-the-net-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008 CRT bug</title>
		<link>http://www.casaba.com/blog/2008/01/visual-studio-2008-crt-bug/</link>
		<comments>http://www.casaba.com/blog/2008/01/visual-studio-2008-crt-bug/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 17:19:16 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I run into this &#8220;issue&#8221; alot compiling this open source project or that open source project (winpcap, cygwin, delegate, snort, nmap. It&#039;s a fun MACRO problem. I love MACROs. &#60;/sarc&#62; Here&#039;s what your compiler will give you. 12&#62;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(358) : error C3163: &#039;_vsnprintf&#039;: attributes inconsistent with previous declaration 12&#62; C:\Program Files [...]]]></description>
			<content:encoded><![CDATA[<p>I run into this &#8220;issue&#8221; alot compiling this open source project or that open source project (winpcap, cygwin, delegate, snort, nmap.  It&#039;s a fun MACRO problem.  I love MACROs.  &lt;/sarc&gt;</p>
<p>Here&#039;s what your compiler will give you.</p>
<p><code><br />
 12&gt;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(358) : error C3163: &#039;_vsnprintf&#039;: attributes inconsistent with previous declaration<br />
 12&gt;        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(350) : see declaration of &#039;_vsnprintf&#039;<br />
 12&gt;Generating Code...<br />
</code></p>
<p>Now this looks like a no brainer, I mean the two declarations are 8 lines apart!  So I stare for a while.  (Looks the same to me).   Hmmmm.  Then I try following a few MACRO&#039;s, often futile if you don&#039;t have browser symbols built yet.  Perhaps I have some crazy path with my includes!?  I only have 12 SDKs or something installed.  So I turn on /showIncludes (how did it take 20yrs to add this option?)  Looks good again&#8230;..</p>
<p>Crap time for the Big Guns &#8212;  If you love MACRO programming you know what&#039;s next.  Turn on the C++ listing output.  The listing output is what the compiler really compiles are the preprocessor has had it&#039;s merry way with the code.  2MB of the finest night time reading you&#039;ll ever find.  Per source file of course.  I was kinda dreading trying to find the function after all it&#039;s beautification had been stripped.</p>
<p>I&#039;ve read a lot of code over the years.  I&#039;m not even sure what this is&#8230;much less what it would preprocess out to.</p>
<p><code><br />
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_ARGLIST_EX(int, __RETURN_POLICY_SAME, _CRTIMP, _snprintf, _vsnprintf, _Pre_notnull_ _Post_maybez_ char, _Out_cap_(_Count) _Post_maybez_, char, _Dest, _In_ size_t, _Count, _In_z_ _Printf_format_string_ const char *, _Format)<br />
</code></p>
<p>I digress&#8230;</p>
<p>It just compiles when you turn on the listing output.</p>
<p>I&#039;ll type it more slowly this time, in case that didn&#039;t sink in.  The compiler switch, that just spits out more information, changed things just enough to have everything compile.  Neato, unless that sort of thing keeps you up at night.</p>
<p>btw, the fix, if you&#039;ve been reading this far, is to not #define vsnprintf in _your_ project.  The CRT must redefine it once or thrice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2008/01/visual-studio-2008-crt-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to apply domain restrictions to a browser plugin (ActiveX or XPCOM)</title>
		<link>http://www.casaba.com/blog/2008/01/how-to-apply-domain-restrictions-to-a-browser-plugin-activex-or-xpcom/</link>
		<comments>http://www.casaba.com/blog/2008/01/how-to-apply-domain-restrictions-to-a-browser-plugin-activex-or-xpcom/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 06:43:13 +0000</pubDate>
		<dc:creator>Chris Weber</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[XPCOM]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[For Internet Explorer, there&#39;s Microsoft&#39;s Sitelock. For Mozilla, I&#39;m not sure what there is&#8230; In that case, we&#39;ve been working on some solutions that could hold up cross-browser on a Windows platform. Sitelock takes a solid approach, check out the code and you&#39;ll see it implements the IObjectSafetySiteLockImpl, replacing the ATL IObjectSafety interface. What am [...]]]></description>
			<content:encoded><![CDATA[<p>
<span style="background-color: #ffffff">For Internet Explorer, there&#39;s Microsoft&#39;s <a href="http://www.microsoft.com/Downloads/details.aspx?FamilyID=43cd7e1e-5719-45c0-88d9-ec9ea7fefbcb&amp;displaylang=en">Sitelock</a>. For Mozilla, I&#39;m not sure what there is&#8230; In that case, we&#39;ve been working on some solutions that could hold up cross-browser on a Windows platform. Sitelock takes a solid approach, check out the code and you&#39;ll see it implements the IObjectSafetySiteLockImpl, replacing the ATL IObjectSafety interface. What am I talking about? Well sometimes, when you develop a browser plugin like an ActiveX control for IE or an XPCOM object for Mozilla, you only want it to load and run from a few trusted domains. The plugin/control runs potentially powerful code after all, executing in the user&#39;s context. For example, you&#39;re a large social networking site, and your new control helps synchronize offline and online data for the user. Well first off, you want to make sure it&#39;s secure as possible:</span>
</p>
<ol>
<li><span style="background-color: #ffffff">code flaws have been identified and addressed (buffer overflows, leaks, etc.)</span></li>
<li><span style="background-color: #ffffff">repurposing threats have been identified and mitigated (the control should not do anything more than it needs, and should be very careful when performing file, registry, or network operations)</span></li>
</ol>
<p>
<span style="background-color: #ffffff">To gain a higher level of assurance that this control won&#39;t be exploited, you take more steps to <strong>restrict the domains which are allowed to call it</strong>.</span>
</p>
<p>
<span style="background-color: #ffffff">So without Sitelock for Mozilla, we&#39;re in search of an alternative solution that will work across both IE and Mozilla. We know a few things available for the cross-browser domain restriction solution:</span>
</p>
<ul>
<li><span style="background-color: #ffffff">we can use C/C++</span></li>
<li><span style="background-color: #ffffff">we have access to the DOM</span></li>
<li><span style="background-color: #ffffff">we have access to COM+</span></li>
<li><span style="background-color: #ffffff">we&#39;d like access to WININET but that&#39;s too far down the stack</span></li>
</ul>
<p>
<span style="background-color: #ffffff">Right now, we&#39;re primarily interested in <strong>getting</strong> the <strong>true domain</strong> which is loading and calling the plugin. How can we gaurantee this? We try getting it from the DOM&#39;s <strong>document.domain</strong> property, but know that t</span><span style="background-color: #ffffff">he document.domain property has historically been a source of security vulnerability in all major browsers. There have even recently been ways to spoof the address bar, or the domain property using JavaScript and other means, and there likely will in the future. For example:</span>
</p>
<p>
<span style="background-color: #ffffff">FireFox<br />
<a href="http://www.thespanner.co.uk/2007/11/14/spoofing-firefox-protected-object">http://www.thespanner.co.uk/2007/11/14/spoofing-firefox-protected-object</a></span>
</p>
<p>
<span style="background-color: #ffffff">IE 6/7. <br />
<a href="http://www.0x000000.com/hacks/crossdomain/crossdomain.html">http://www.0&#215;000000.com/hacks/crossdomain/crossdomain.html</a> </span>
</p>
<p>
<span style="background-color: #ffffff">Safari/Windows <br />
<a href="http://nvd.nist.gov/nvd.cfm?cvename=CVE-2007-3514">http://nvd.nist.gov/nvd.cfm?cvename=CVE-2007-3514</a></span>
</p>
<p>
<span style="background-color: #ffffff">After some research we&#39;re testing some other options. Right now our best bet might be looking like:</span>
</p>
<p><span style="background-color: #ffffff"></p>
<ul>
<li>using <span style="font-size: 11pt; font-family: &#039;Calibri&#039;,&#039;sans-serif&#039;"><span style="color: #000000">IWebBrowser2::get_LocationURL() for Internet Explorer</span></span></li>
<li><span style="font-size: 11pt; font-family: &#039;Calibri&#039;,&#039;sans-serif&#039;"><span style="color: #000000">using <span style="font-size: 11pt; font-family: &#039;Calibri&#039;,&#039;sans-serif&#039;">window.location.href for Mozilla</span></span></span></li>
<li><span style="font-size: 11pt; font-family: &#039;Calibri&#039;,&#039;sans-serif&#039;"><span style="color: #000000"><span style="font-size: 11pt; font-family: &#039;Calibri&#039;,&#039;sans-serif&#039;">InternetCrackUrl() to parse the hostname</span></span></span></li>
<p>After some testing we don&#39;t see the document.domain type issues present in window.location.href, so it seems to be holding up short some unknown browser-flaw.
</ul>
<ul>
	IWebBrowser2::getLocationURL() seems okay but I did find the following issue with get_LocationURL at <a href="http://support.microsoft.com/kb/272095">http://support.microsoft.com/kb/272095</a>.
</ul>
<ul>
	~Chris Weber
</ul>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2008/01/how-to-apply-domain-restrictions-to-a-browser-plugin-activex-or-xpcom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I18N input validation whitelist filter with System.Globalization and GetUnicodeCategory</title>
		<link>http://www.casaba.com/blog/2007/04/i18n-input-validation-whitelist-filter-with-system-globalization-and-getunicodecategory/</link>
		<comments>http://www.casaba.com/blog/2007/04/i18n-input-validation-whitelist-filter-with-system-globalization-and-getunicodecategory/#comments</comments>
		<pubDate>Tue, 24 Apr 2007 05:33:20 +0000</pubDate>
		<dc:creator>Chris Weber</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[whitelist]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Maybe you’re building internationalized code and wondering how to build a whitelist filter that will support all the different character sets your planning to support. If you support more than ten, especially some of the larger east Asian sets, this might seem like an unwieldy or tricky process. Well luckily it’s easier than most people [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe you’re building internationalized code and wondering how to build a whitelist filter that will support all the different character sets your planning to support. If you support more than ten, especially some of the larger east Asian sets, this might seem like an unwieldy or tricky process.<br />
Well luckily it’s easier than most people would think. Building a good input validation filter can be simplified with .Net’s <a linkindex="84" href="http://msdn2.microsoft.com/en-us/library/system.globalization.charunicodeinfo.getunicodecategory.aspx">GetUnicodeCategory</a>. But use the method from the <strong>System.Globalization</strong> namespace as the other one in System.Char looks like it may become the subordinate. </p>
<p>With <strong>GetUnicodeCategory </strong>you can simply build a <strong>whitelist </strong>supporting the character <em><strong>categories </strong></em>you want to allow. So get away from thinking you have to write a regEx filter and list out all the character ranges you want to allow in each character set, it’s much simpler than that! </p>
<p>The Unicode standard assigns ever character to one of about <strong>31 categories</strong>. They make sense too, for example Other Control charactes (Cc) , Lowercase Letter (Ll), Uppercase Letter (Lu), Math Symbol (Sm). So for example you might want to only allow letters, numbers, and punctuation in your whitelist. This could be achieved with the following snippet: </p>
<p><code><br />
char cUntrustedInput; // the untrusted user-input<br />
UnicodeCategory cInputTest = CharUnicodeInfo.GetUnicodeCategory(cUntrustedInput);<br />
if (cTestCategory == UnicodeCategory.LowercaseLetter ||<br />
cTestCategory == UnicodeCategory.UppercaseLetter ||<br />
cTestCategory == UnicodeCategory.DecimalDigitNumber ||<br />
cTestCategory == UnicodeCategory.TitlecaseLetter ||<br />
cTestCategory == UnicodeCategory.OtherLetter ||<br />
cTestCategory == UnicodeCategory.NonSpacingMark ||<br />
cTestCategory == UnicodeCategory.DashPunctuation ||<br />
cTestCategory == UnicodeCategory.ConnectorPunctuation)<br />
{<br />
// character looks safe, continue<br />
}<br />
else<br />
{<br />
// character is not allowed, fail<br />
}<br />
</code></p>
<p>Not too bad eh.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2007/04/i18n-input-validation-whitelist-filter-with-system-globalization-and-getunicodecategory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access to .Net System.dll internal functions</title>
		<link>http://www.casaba.com/blog/2007/02/access-to-net-system-dll-internal-functions/</link>
		<comments>http://www.casaba.com/blog/2007/02/access-to-net-system-dll-internal-functions/#comments</comments>
		<pubDate>Thu, 22 Feb 2007 08:00:00 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Occasionally you will discover a nice class or function you would like to use. I stumbled across [mscorcfg]Microsoft.CLRAdmin.Fusion.AddAssemblytoGac(string strAssembly). Oddly enough there&#039;s no way to add an assembly to the gac from .Net code. This would be just great for MSBuild tasks, or even installing. If you try and use this class or function you [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally you will discover a nice class or function you would like to use.  I stumbled across [mscorcfg]Microsoft.CLRAdmin.Fusion.AddAssemblytoGac(string strAssembly).  Oddly enough there&#039;s no way to add an assembly to the gac from .Net code.  This would be just great for MSBuild tasks, or even installing.</p>
<p>If you try and use this class or function you get this result.</p>
<p><code><br />
c:\dev\test\private test.cs(10,9) : error CS0122: &#039;Microsoft.CLRAdmin.Fusion&#039; is inaccessible due to its protection level<br />
</code></p>
<p>Turns out using this function is pretty easy in theory.  .Net only checks permissions at link time.  You could do get around this the hard way by using ILAsm, or Reflection in C#.</p>
<p>Here&#039;s how you would do this using Reflection.</p>
<p><code></p>
<p>public static Int32 AddAssemblyToGac(string strAssembly)<br />
{<br />
  object[] args = newobject[] { strAssembly };<br />
  BindingFlags bindingFlags = (BindingFlags)314;<br />
  return ((Int32)(FusionType.InvokeMember("AddAssemblytoGac", bindingFlags, null, null, args)));<br />
}</p>
<p></code></p>
<p>Well that just opens up about a million possibilities.  Just try and &#8220;fix&#8221; one class from the ASP.NET framework and you have to drag in 12 million interfaces.  Now you are set, just use the same one&#039;s that it was using.  This is going to save me tons of time.  There&#039;s no way I&#039;m writing a million Reflection proxy interfaces.  Nevermind the fact that you can just call the interface using IL.  There just has to be a good way to do this from C#.  Worse case we could lie/cheat to the compiler.</p>
<p>The C# team has added a nice Attribute for us to do this.</p>
<p>[InternalsVisibleTo("AndrewsAssembly, PublicKeyToken=0b00fde735121dcc")]</p>
<p>You can read up on it viewing <a href="http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx">InternalsVisibleToAttribute</a>.</p>
<p>So ILDasm System.Web.dll, or your favorite assembly, and recompile adding this CustomAttribute.  Compile your assembly and you are off and running.</p>
<p>Here&#039;s a view from Lutz Roeder&#039;s Reflector of my test app using an internal System.Web enum.</p>
<p><a href="http://bp3.blogger.com/_QvA8PCZOesc/Rd3TILXksmI/AAAAAAAAAAM/sXw5k1BlREY/s1600-h/test.GIF"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2007/02/access-to-net-system-dll-internal-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Services denial of service attacks &#8211; XmlTextReader</title>
		<link>http://www.casaba.com/blog/2007/02/web-services-denial-of-service-attacks-xmltextreader/</link>
		<comments>http://www.casaba.com/blog/2007/02/web-services-denial-of-service-attacks-xmltextreader/#comments</comments>
		<pubDate>Mon, 19 Feb 2007 18:10:00 +0000</pubDate>
		<dc:creator>Chris Weber</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Security Testing]]></category>
		<category><![CDATA[DoS]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Most Web Services I look at are built using the .NET Framework and ASP.NET. Today we’re seeing more with ASP.NET’s AJAX extensions but that’s a different story. Many developers choose to implement SOAP and XML as part of their WS solution, and in doing so can inadvertently open the application server up to DoS issues. [...]]]></description>
			<content:encoded><![CDATA[<p>Most Web Services I look at are built using the .NET Framework and ASP.NET. Today we’re seeing more with ASP.NET’s AJAX extensions but that’s a different story. Many developers choose to implement SOAP and XML as part of their WS solution, and in doing so can inadvertently open the application server up to DoS issues.</p>
<p>First there’s XML. When developers choose to implement <strong>XmlTextReader </strong>or <strong>XmlReader </strong>from the .NET Framework, they need to understand the behaviors of these classes. MSDN documents this quite well. I will usually do a quick code review to find implementations of these objects, because the issues can be identified a little faster through code than through testing.</p>
<p><strong>XmlTextReader </strong>defaults to allowing external DTD’s to be specified. This leads to a whole enchilda of issues, and gives attackers a nice bit of control over the host server. Be sure to set the <em><strong>ProhibitDTD </strong></em>property equal to true. Furthermore, there’s no strict schema validation unless the developer implements one.SOAP is fine, but developers need to implement a custom SOAP extension to enforce strict schema validation. Otherwise it gets pretty easy for an attacker to abuse the WS by embedding things like:</p>
<ul>
<li>large payloads</li>
<li>large number of elements</li>
<li>nested elements</li>
<li>malformed data</li>
</ul>
<p>To name a few… Without strict validation, I’ve seen web services easily abused. For example, by sending a few large requests, it becomes trivial to consume memory on the host server which eventually leads to resource starvation. To learn more about implementing a custom SOAP Extension to tackle this problem, read the MSDN article:</p>
<p><a linkindex="49" href="http://msdn.microsoft.com/msdnmag/issues/03/07/XMLSchemaValidation/">http://msdn.microsoft.com/msdnmag/issues/03/07/XMLSchemaValidation/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2007/02/web-services-denial-of-service-attacks-xmltextreader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSIDL &#8211; Shell constants, enumerations, and flags</title>
		<link>http://www.casaba.com/blog/2006/12/csidl-shell-constants-enumerations-and-flags/</link>
		<comments>http://www.casaba.com/blog/2006/12/csidl-shell-constants-enumerations-and-flags/#comments</comments>
		<pubDate>Tue, 26 Dec 2006 08:00:00 +0000</pubDate>
		<dc:creator>Chris Weber</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CSIDL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I worked on an application which had a couple of requirements: Allow users access to their local drive content within a defined scope (e.g. either the entire drive, or the My Documents folder only) Prevent users from accessing files outside of the defined scope. So they shouldn’t be able to access network drives, USB keys, [...]]]></description>
			<content:encoded><![CDATA[<p>I worked on an application which had a couple of requirements:</p>
<ol>
<li>Allow users access to their local drive content within a defined <strong>scope </strong>(e.g. either the entire drive, or the My Documents folder only)</li>
<li>Prevent users from accessing files outside of the defined <strong>scope</strong>. So they shouldn’t be able to access network drives, USB keys, etc.</li>
</ol>
<p>To acheive this, the shell constants were used, as defined in the Windows SDK.<br />
<a set="yes" linkindex="62" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp" title="CSIDL">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp </a></p>
<p>This worked well, and after we looked at the code we actually ran a battery of tests to confirm. So for example we tried the following types of canonicalizations:</p>
<ul>
<li>\\host\share\file</li>
<li>\\?\folder\file</li>
<li>\\10.10.10.10\share\file</li>
<li>\\.\folder\file</li>
</ul>
<p>We kept going, and tried breaking out of the local scope as well:</p>
<ul>
<li>..\..\..\..\boot.ini</li>
<li>../../../../boot.ini</li>
<li>..%2fboot.ini</li>
</ul>
<p>And all that sort of stuff. Using the CSIDL constants proved successful, and we could see this through debugging. Everything we entered was merely relative to the constant value, there was no way to change it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2006/12/csidl-shell-constants-enumerations-and-flags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ViewStateUserKey to prevent XSRF (CSRF or cross-site request forgery) in ASP.NET</title>
		<link>http://www.casaba.com/blog/2006/09/viewstateuserkey-to-prevent-xsrf-csrf-or-cross-site-request-forgery-in-asp-net/</link>
		<comments>http://www.casaba.com/blog/2006/09/viewstateuserkey-to-prevent-xsrf-csrf-or-cross-site-request-forgery-in-asp-net/#comments</comments>
		<pubDate>Sat, 30 Sep 2006 07:00:00 +0000</pubDate>
		<dc:creator>Chris Weber</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Security Testing]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSRF]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[ViewStateUserKey has been around for many years and is an easy solution to prevent the infamous XSRF or cross-site request forgery class of attack. It’s documented: http://msdn2.microsoft.com/en-us/library/system.web.ui.page.viewstateuserkey.aspx ViewStateUserKey mitigates XSRF by including a unique identifier in the user’s request. This protection mechanism has been available for many years when Microsoft identified the one-click attack, now [...]]]></description>
			<content:encoded><![CDATA[<p>ViewStateUserKey has been around for many years and is an easy solution to prevent the infamous XSRF or cross-site request forgery class of attack.</p>
<p>It’s documented:</p>
<p><a set="yes" linkindex="68" href="http://msdn2.microsoft.com/en-us/library/system.web.ui.page.viewstateuserkey.aspx" title="XSRF mitigation">http://msdn2.microsoft.com/en-us/library/system.web.ui.page.viewstateuserkey.aspx</a></p>
<p>ViewStateUserKey mitigates XSRF by including a unique identifier in the user’s request.</p>
<p>This protection mechanism has been available for many years when Microsoft identified the one-click attack, now more commonly referred to as XSRF.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.casaba.com/blog/2006/09/viewstateuserkey-to-prevent-xsrf-csrf-or-cross-site-request-forgery-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

