0

I'm playing with CAS in Framework 2.0 (I know that it's obsolete).

I have following code, that I'm trying hard to crash. I've compiled project in 2.0 framework:

 using System;
 using System.Security;
 using System.Security.Permissions;

 namespace Authenticode
 {
    class Program
    {
         public static void DoSthmUnmanaged()
         {
             SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
             perm.Demand();
         }

         public static void Main(string[] args)
         {
              Program.DoSthmUnmanaged();

              Console.Write("Press any key to continue . . . ");
              Console.ReadKey(true);
         }
     }
  }

I copy exe file to network drive, then open 'mscorcfg.msc' and evaluate assembly from network drive - Code group is Machine\All_Code\LocalIntranet_Zone which is expected. When I execute it from network all works fine and I don't get it!

It's supposed to throw exception since code from LocalIntranet doesn't has permission to run unmanaged code. Why does it work?

enter image description here

nikita
  • 2,737
  • 2
  • 20
  • 26

1 Answers1

1

If your machine has 3.5 SP 1 installed, remember that that builds on top of 2.0, and it was that Service Pack that switched exes run from network shares to running with Full Trust.

From What's New in the .NET Framework Version 3.5 SP 1:

Managed applications that are opened from network shares have the same behavior as native applications by running with full trust.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • Interesting. Then maybe `mscorcfg.msc` was not changed after 3.5 SP1 changes? – nikita Mar 19 '13 at 10:53
  • @nikita - From a [blog post](http://blogs.msdn.com/b/shawnfa/archive/2008/05/12/fulltrust-on-the-localintranet.aspx) about the change: "The core of this change is a modification in how we assign evidence to network launched applications. When we see an .exe launched directly off a network share, rather than giving that .exe Zone evidence of LocalInranet, we instead give the .exe Zone evidence of MyComputer." - key being "launched directly". If you load the assembly via other means (e.g. `mscorcfg`), it still gets LocalIntranet. – Damien_The_Unbeliever Mar 19 '13 at 11:00
  • Then that's the answer I suppose! Thanks! – nikita Mar 19 '13 at 11:02