<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Didier Stevens &#187; .NET</title>
	<atom:link href="http://blog.didierstevens.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.didierstevens.com</link>
	<description>(blog 'DidierStevens)</description>
	<lastBuildDate>Thu, 26 Aug 2010 12:11:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.didierstevens.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/60bb50c97cd147341ffb43b0e2ef0d15?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Didier Stevens &#187; .NET</title>
		<link>http://blog.didierstevens.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.didierstevens.com/osd.xml" title="Didier Stevens" />
	<atom:link rel='hub' href='http://blog.didierstevens.com/?pushpress=hub'/>
		<item>
		<title>.NET Shellcode</title>
		<link>http://blog.didierstevens.com/2010/04/13/net-shellcode/</link>
		<comments>http://blog.didierstevens.com/2010/04/13/net-shellcode/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 00:00:22 +0000</pubDate>
		<dc:creator>Didier Stevens</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://blog.didierstevens.com/?p=2137</guid>
		<description><![CDATA[As it is easy to instantiate the CLR in a process and load an assembly from C-code, I developed shellcode to load a .NET assembly in the injected process. This allows you to leverage the extended Framework Class Library in your penetration tests.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=2137&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As it is easy to instantiate the <a href="http://en.wikipedia.org/wiki/Common_Language_Runtime">CLR</a> in a process and load an assembly from C-code, I developed <a href="http://blog.didierstevens.com/programs/shellcode#dotNET-Shellcode">shellcode to load a .NET assembly in the injected process</a>.</p>
<p>This allows you to leverage the extended Framework Class Library in your penetration tests.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didierstevens.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didierstevens.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didierstevens.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didierstevens.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didierstevens.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didierstevens.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didierstevens.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didierstevens.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didierstevens.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didierstevens.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didierstevens.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didierstevens.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didierstevens.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didierstevens.wordpress.com/2137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=2137&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.didierstevens.com/2010/04/13/net-shellcode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">didierstevens</media:title>
		</media:content>
	</item>
		<item>
		<title>Detecting EICAR With a .NET Micro-controller</title>
		<link>http://blog.didierstevens.com/2009/12/30/detecting-eicar-with-a-net-micro-controller/</link>
		<comments>http://blog.didierstevens.com/2009/12/30/detecting-eicar-with-a-net-micro-controller/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 22:07:51 +0000</pubDate>
		<dc:creator>Didier Stevens</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Entertainment]]></category>
		<category><![CDATA[Hardware]]></category>

		<guid isPermaLink="false">http://blog.didierstevens.com/?p=1901</guid>
		<description><![CDATA[I&#8217;ve been playing with a .NET Micro Framework micro-controller: the USBizi. A few of its interesting characteristics are that you program it in C# with Visual Studio and that in-circuit debugging (including single-stepping) is supported. The .NET Micro Framework has no assemblies to support USB in host mode (only guest mode), but the USBizi comes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=1901&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with a <a href="http://en.wikipedia.org/wiki/.NET_Micro_Framework" target="_blank">.NET Micro Framework micro-controller</a>: the <a href="http://www.ghielectronics.com/product/113" target="_blank">USBizi</a>. A few of its interesting characteristics are that you program it in C# with Visual Studio and that in-circuit debugging (including single-stepping) is supported.</p>
<p><span style="text-align:center; display: block;"><a href="http://blog.didierstevens.com/2009/12/30/detecting-eicar-with-a-net-micro-controller/"><img src="http://img.youtube.com/vi/q9CIKXBKbmo/2.jpg" alt="" /></a></span></p>
<p>The .NET Micro Framework has no assemblies to support USB in host mode (only guest mode), but the USBizi comes with assemblies for host mode providing support for removable drives like USB sticks. To illustrate this feature, I wrote a program to scan the files on a USB stick for the <a href="http://www.eicar.org/anti_virus_test_file.htm" target="_blank">EICAR test file</a> and replace the content with a message appropriate for the time of the year.</p>
<p>Some ideas I&#8217;ve for this device: program it as a hardware keylogger, a hardware password vault, &#8230;</p>
<pre class="brush: csharp;">
using System.Threading;
using System;
using System.IO;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.System.SystemDevices;
using GHIElectronics.System;
using GHIElectronics.System.IO;
using GHIElectronics.Hardware;

namespace USBiziEICARDetector
{
    public class Program
    {
        static string sEICAR = @&quot;X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*&quot;;

        static void Main()
        {
            Boolean bFoundEicar;
            Debug.Print(&quot;Starting...&quot;);
            while (true)
            {
                // must start system first, no event is associated
                SystemManager.Start(null);
                // wait till we have a device
                while (SystemManager.GetDevices().Length == 0)
                    Thread.Sleep(500);
                // get a list of devices
                Device[] devices = SystemManager.GetDevices();
                // look for a device
                foreach (Device device in devices)
                {
                    // this loop will run once for every device
                    if (device.deviceType == DeviceType.Drive)
                    {
                        try
                        {
                            // USB drive is inserted
                            // Create a new storage device
                            PersistentStorage PS = new PersistentStorage(device.deviceID);
                            // now everything works just like on SD cards....
                            // Mount the file system
                            PS.MountFileSystem();
                            // Assume one storage device is available, access it through NETMF
                            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
                            bFoundEicar = false;
                            string[] files = Directory.GetFiles(rootDirectory);
                            Debug.Print(&quot;Files on root of USB drive...&quot;);
                            foreach (string file in files)
                            {
                                Debug.Print(file);
                                Boolean bFileIsEICAR = false;
                                FileStream fs = File.OpenRead(file);
                                Debug.Print(fs.Length.ToString());
                                if (fs.Length == sEICAR.Length)
                                {
                                    char[] acEICAR = sEICAR.ToCharArray();
                                    for (int iIter = 0; iIter &lt; sEICAR.Length; iIter++)
                                    {
                                        int iByte = fs.ReadByte();
                                        if (acEICAR[iIter] != iByte)
                                            break;
                                        if (iIter == sEICAR.Length - 1)
                                        {
                                            bFoundEicar = true;
                                            bFileIsEICAR = true;
                                        }
                                    }
                                }
                                fs.Close();
                                if (bFileIsEICAR)
                                {
                                    byte[] abHappyNewYear2010 = {
                                        0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x20, 0x58, 0x58, 0x58, 0x20, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x0D, 0x0A, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20,
                                        0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x0D, 0x0A, 0x20,
                                        0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x0D, 0x0A, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x58, 0x20, 0x20,
                                        0x20, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x20, 0x20, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x20, 0x20, 0x58, 0x58, 0x58, 0x20, 0x58, 0x58, 0x58,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x0D, 0x0A, 0x20, 0x20, 0x58, 0x58, 0x58, 0x58, 0x58,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20,
                                        0x58, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20,
                                        0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58,
                                        0x0D, 0x0A, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20,
                                        0x20, 0x58, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x0D, 0x0A, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20,
                                        0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20,
                                        0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20,
                                        0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x0D, 0x0A, 0x20, 0x20, 0x58, 0x20,
                                        0x20, 0x20, 0x58, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x58, 0x20,
                                        0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20,
                                        0x20, 0x20, 0x58, 0x0D, 0x0A, 0x20, 0x58, 0x58, 0x58, 0x20, 0x58, 0x58, 0x58, 0x20, 0x20, 0x58, 0x58, 0x58, 0x58, 0x20, 0x58, 0x20, 0x20, 0x58,
                                        0x58, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58,
                                        0x58, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                                        0x20, 0x58, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58,
                                        0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x58, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x58, 0x58, 0x0D, 0x0A, 0x0D, 0x0A};

                                    File.WriteAllBytes(file, abHappyNewYear2010);
                                    Debug.Print(&quot;EICAR found!&quot;);
                                }
                            }
                            Debug.Print(&quot;... end of list!&quot;);
                            // if we need to unmount
                            Thread.Sleep(500);
                            PS.UnmountFileSystem();
                            Thread.Sleep(500);
                            PS.Remove();
                            OutputPort LED = new OutputPort(USBizi.Pins.E2x, false);
                            if (bFoundEicar)
                            {
                                Debug.Print(&quot;bFoundEicar = true&quot;);
                                BlinkXTimes(LED, 4, 300);
                            }
                            else
                            {
                                Debug.Print(&quot;bFoundEicar = false&quot;);
                                BlinkXTimes(LED, 2, 300);
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.Print(&quot;Exception:&quot;);
                            Debug.Print(e.Message);
                        }
                    }
                }
                Thread.Sleep(500);
                SystemManager.Reboot(SystemManager.RebootMode.Normal);
            }
        }

        public static void BlinkXTimes(OutputPort LED, int times, int milliseconds)
        {
            for (int i = 0; i &lt; times; i++)
            {
                LED.Write(true);
                Thread.Sleep(milliseconds);
                LED.Write(false);
                Thread.Sleep(milliseconds);
            }
        }
    }
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didierstevens.wordpress.com/1901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didierstevens.wordpress.com/1901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didierstevens.wordpress.com/1901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didierstevens.wordpress.com/1901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didierstevens.wordpress.com/1901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didierstevens.wordpress.com/1901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didierstevens.wordpress.com/1901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didierstevens.wordpress.com/1901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didierstevens.wordpress.com/1901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didierstevens.wordpress.com/1901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didierstevens.wordpress.com/1901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didierstevens.wordpress.com/1901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didierstevens.wordpress.com/1901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didierstevens.wordpress.com/1901/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=1901&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.didierstevens.com/2009/12/30/detecting-eicar-with-a-net-micro-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">didierstevens</media:title>
		</media:content>

		<media:content url="http://img.youtube.com/vi/q9CIKXBKbmo/2.jpg" medium="image" />
	</item>
		<item>
		<title>CASToggle and The Polymorphic Podcast</title>
		<link>http://blog.didierstevens.com/2008/02/20/castoggle-and-the-polymorphic-podcast/</link>
		<comments>http://blog.didierstevens.com/2008/02/20/castoggle-and-the-polymorphic-podcast/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 10:15:52 +0000</pubDate>
		<dc:creator>Didier Stevens</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.didierstevens.com/?p=326</guid>
		<description><![CDATA[Craig Shoemaker, a good friend, Microsoft MVP and host of The Polymorphic Podcast, sweetened my little CASToggle quiz by trowing in a license for a Microsoft .NET development tool. Check out hist post. Thanks Craig! BTW, The Polymorphic Podcast is about object oriented development, not about polymorphic malware. Polymorphism is also a programming language concept. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=326&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Craig Shoemaker, a good friend, Microsoft MVP and host of <a href="http://polymorphicpodcast.com/" target="_blank">The Polymorphic Podcast</a>, sweetened my little <a href="http://blog.didierstevens.com/2008/02/12/fine-grained-control-over-code-access-security/">CASToggle quiz</a> by trowing in a license for a Microsoft .NET development tool. Check out hist <a href="http://polymorphicpodcast.com/shows/bock" target="_blank">post</a>. Thanks Craig!</p>
<p>BTW, The Polymorphic Podcast is about object oriented development, not about <a href="http://en.wikipedia.org/wiki/Polymorphic_virus" target="_blank">polymorphic malware</a>. <a href="http://en.wikipedia.org/wiki/Polymorphism_(computer_science)" target="_blank">Polymorphism</a> is also a programming language concept.</p>
<p>When you look at the comments of my <a href="http://blog.didierstevens.com/2008/02/12/fine-grained-control-over-code-access-security/">previous blogpost</a>,  you&#8217;ll read that we have a winner. Let me fill you in on the details.</p>
<p>Caspol requires administrative credentials to disable CAS enforcement:</p>
<p><img src="http://didierstevens.files.wordpress.com/2008/02/caspol-local-admin.png" alt="caspol-local-admin.png" /></p>
<p>The reason is that the setting for disabled CAS enforcement is implemented with a <a href="http://blogs.msdn.com/shawnfa/archive/2005/04/28/412998.aspx" target="_blank">mutex</a> owned by the BUILTIN\Administrators group. As a non-admin user, you can also create this mutex, but it will be owned by your account, not by the administrator group. And the <a href="http://en.wikipedia.org/wiki/Common_Language_Runtime" target="_blank">CLR</a> checks the ownership of the mutex and will only acknowledge it when it is owned by BUILTIN\Administrators.</p>
<p>But my CASToggle tool does not use a mutex. CASToggle allows you to directly manipulate the variable in the CLR where the status of the mutex is stored. This variable can have 3 values:</p>
<ul>
<li>0: uninitialized, this means that the CLR has not yet looked for the presence of the mutex. This is the case when your .NET program starts to run.</li>
<li>1: CAS enforcement disabled, this means that the CLR has found the mutex.</li>
<li>2: CAS enforcement enabled, this means that the CLR has not found the mutex.</li>
</ul>
<p>The CLR will only perform a single check for the presence of the mutex. That&#8217;s why changing the CAS enforcement policy with caspol has no effect on running .NET programs.</p>
<p>Did you know that the CLR runs in your own process memory? And did you know that in Windows, you have full control over your own processes, even as a limited user? To manipulate the process of another user (e.g. reading and writing to the virtual memory owned by the target process), you need the <a href="http://msdn2.microsoft.com/en-us/library/aa379306(VS.85).aspx" target="_blank">debug privilege</a> (local admins have this privilege by default). But you don&#8217;t need this privilege for your own processes.</p>
<p>That&#8217;s what differentiates CASToggle from caspol. If you&#8217;re a local admin (or you have the debug privilege, to be more precise), you can use CASToggle on any process. But as a limited user, you can still use it to disable CAS enforcement for your own processes.</p>
<p>I&#8217;ve been doing some research on security mechanisms implemented in the user&#8217;s own process space. The design of these security mechanisms is fundamentally flawed, because a limited user has full control over his own processes and can thus bypass the security mechanism. He just needs internal knowledge about the mechanisms (or a tool), and then he can bypass it because he has the rights to do so.</p>
<p>Robust security mechanisms are implemented in process space that is off-limit to normal users. This can be inside the kernel (like the <a href="http://en.wikipedia.org/wiki/Reference_monitor" target="_blank">reference monitor</a>) or inside user-land space of a protected account (like services that run under the local system account).</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/didierstevens.wordpress.com/326/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/didierstevens.wordpress.com/326/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didierstevens.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didierstevens.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didierstevens.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didierstevens.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didierstevens.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didierstevens.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didierstevens.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didierstevens.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didierstevens.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didierstevens.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didierstevens.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didierstevens.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didierstevens.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didierstevens.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=326&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.didierstevens.com/2008/02/20/castoggle-and-the-polymorphic-podcast/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">didierstevens</media:title>
		</media:content>

		<media:content url="http://didierstevens.files.wordpress.com/2008/02/caspol-local-admin.png" medium="image">
			<media:title type="html">caspol-local-admin.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Fine-Grained Control over Code Access Security</title>
		<link>http://blog.didierstevens.com/2008/02/12/fine-grained-control-over-code-access-security/</link>
		<comments>http://blog.didierstevens.com/2008/02/12/fine-grained-control-over-code-access-security/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 07:12:28 +0000</pubDate>
		<dc:creator>Didier Stevens</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.didierstevens.com/?p=323</guid>
		<description><![CDATA[With Code Access Security (CAS) in the .NET Framework, Microsoft introduced a whole new security layer on top of Windows security. If you need to temporarily disable CAS, for example during a debugging session, you can use the caspol utility. The command caspol -security off will disable CAS enforcement as long as the caspol tool [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=323&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://en.wikipedia.org/wiki/Code_Access_Security" target="_blank">Code Access Security</a> (CAS) in the .NET Framework, Microsoft introduced a whole new security layer on top of Windows security.</p>
<p>If you need to temporarily disable CAS, for example during a debugging session, you can use the caspol utility. The command <i>caspol -security off</i> will disable CAS enforcement as long as the caspol tool is running (this is true for .NET 2.0 and later). If you are interested in the implementation details: it&#8217;s done via a <a href="http://blogs.msdn.com/shawnfa/archive/2005/04/28/412998.aspx" target="_blank">mutex</a>.</p>
<p>One issue with caspol -security is that its effect is system-wide. If you need to unit test .NET assemblies by repeatedly toggling CAS enforcement, the caspol utility lacks some control.  Not only your assembly will be affected by the toggle, but every other assembly on the machine. And the setting only takes effect for assemblies started after the caspol command was issued. When you re-enable CAS enforcement, it will only affect new processes. Running programs continue to ignore CAS, they have to be restarted for the new setting to take effect.</p>
<p>My new utility, <a href="http://blog.didierstevens.com/programs/castoggle/">CASToggle</a>, gives you more control over CAS enforcement. First of all, it operates on a per-process basis. You have to specify the process ID of the program for which you want to switch CAS enforcement. Second: the effect is immediate, you don&#8217;t have to restart the program.</p>
<p>Example:</p>
<ul>
<li><i>castoggle 123 1</i> &#8211; this will immediately disable CAS enforcement for process 123</li>
<li><i>castoggle 123 2</i> &#8211; this will immediately enable CAS enforcement for process 123</li>
</ul>
<p>CASToggle controls CAS enforcement by directly manipulating the appropriate variable in the process memory of the targeted program. So it&#8217;s best to use CASToggle only for testing purposes. When you look at the source code of CASToggle, you&#8217;ll notice that most of the code is there to ensure that it manipulates the correct memory location. For example, it will check the version of mscorwks.dll before it attempts to access the process memory. But if the DLL is not loaded at its base address (e.g. because of <a href="http://en.wikipedia.org/wiki/Address_space_layout_randomization" target="_blank">ASLR</a> on Vista or Windows 2008), the program could manipulate the wrong memory location and cause the program to crash. Unknown DLL versions cause the tool to break-off without accessing the process memory. I&#8217;ve tested CASToggle on Windows XP SP2, Windows 2003 and Vista with different versions of .NET (2.0 and up).</p>
<p>To see CASToggle at work, take a look <a href="http://youtube.com/watch?v=cK949j7HoSI" target="_blank">here</a> on <a href="http://www.youtube.com" target="_blank">YouTube</a>, hires (XviD) version <a href="https://didierstevens.com/files/movies/CASToggle-XviD.avi" target="_blank">here</a>.</p>
<p>Oh, and there is one more thing that differentiates CASToggle from caspol, but I&#8217;m not going to tell you right now. Can you figure it out? Post a comment! First one to figure it out gets the honors! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/didierstevens.wordpress.com/323/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/didierstevens.wordpress.com/323/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didierstevens.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didierstevens.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didierstevens.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didierstevens.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didierstevens.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didierstevens.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didierstevens.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didierstevens.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didierstevens.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didierstevens.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didierstevens.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didierstevens.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didierstevens.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didierstevens.wordpress.com/323/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.didierstevens.com&amp;blog=264765&amp;post=323&amp;subd=didierstevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.didierstevens.com/2008/02/12/fine-grained-control-over-code-access-security/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">didierstevens</media:title>
		</media:content>
	</item>
	</channel>
</rss>