Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » Security Code Snafu


Security Code Snafu

Reply
  #1 (permalink)  
Old 02-02-10, 01:12 PM
Goodes Goodes is offline
New Member
 
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Security Code Snafu

Code:
CodeAccessPermission fiop = new FileIOPermission(PermissionState.Unrestricted); 
CodeAccessPermission ep = new EnvironmentPermission
(EnvironmentPermissionAccess.Read, "USERNAME")); 
CodeAccessPermission fdp = new FileDialogPermission(FileDialogPermissionAccess.Open)); 
CodeAccessPermission isfp = new IsolatedStorageFilePermission(PermissionState.Unrestricted)); 
CodeAccessPermission rp = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)); 
CodeAccessPermission uip = new UIPermission(UIPermissionWindow.SafeTopLevelWindows)); 
CodeAccessPermission pp = new PrintingPermission(PrintingPermissionLevel.SafePrinting)); 
Console.WriteLine(fiop.GetType().ToString() + ": " + SecurityManager.IsGranted(fiop)); 
Console.WriteLine(ep.GetType().ToString() + ": " + SecurityManager.IsGranted(ep)); 
Console.WriteLine(fdp.GetType().ToString() + ": " + SecurityManager.IsGranted(fdp)); 
Console.WriteLine(isfp.GetType().ToString() + ": " + SecurityManager.IsGranted(isfp)); 
Console.WriteLine(rp.GetType().ToString() + ": " + SecurityManager.IsGranted(rp)); 
Console.WriteLine(uip.GetType().ToString() + ": " + SecurityManager.IsGranted(uip)); 
Console.WriteLine(pp.GetType().ToString() + ": " + SecurityManager.IsGranted(pp));


If the above code is ran from a command prompt from C:\ and with administrator privileges, it produces ‘true’ to all permissions (C:\Permissions.exe) since My_Computer_Zone (C:\) has the Full Trust permission set.
If the above code is ran from a command prompt through a loopback with administrator privileges, it should NOT produce ‘true’ for several permissions (\\127.0.0.1\C$\Permissions.exe). Permissions.exe is now running from a shared folder and hence under the Internet Zone. Specifically IsolatedStorageFilePermission. Yet in my case it does!

.NET Configuration Tool shows everything as normal. Zones and their respective trusts are as follows. My Computer: Full Trust; Local Intranet: Medium Trust; Internet: Low Trust; Trusted Sites: Low Trust; Untrusted Sites: No Trust.
Runtime Security Policy –> Machine –> Code Groups –> All_Code –> Internet_Zone –> Internet_Same_Site_Access also reset to normal settings.

I’m baffled! Any help is welcomed.

* Code, although modified, is courtesy of Tony Northrup’s book “Microsoft .NET Framework – Application Development Foundation”.

Last edited by digioz; 02-02-10 at 11:14 PM.
Reply With Quote
  #2 (permalink)  
Old 02-02-10, 11:44 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
I cleaned up the code you had below, and added proper references for each namespace then ran it:

Code:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Security.Permissions;
using System.Drawing.Printing;
 
namespace ZonePermissions
{
    class Program
    {
        static void Main(string[] args)
        {
            CodeAccessPermission fiop = new FileIOPermission(PermissionState.Unrestricted); 
            CodeAccessPermission ep = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME"); 
            CodeAccessPermission fdp = new FileDialogPermission(FileDialogPermissionAccess.Open); 
            CodeAccessPermission isfp = new IsolatedStorageFilePermission(PermissionState.Unrestricted); 
            CodeAccessPermission rp = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess); 
            CodeAccessPermission uip = new UIPermission(UIPermissionWindow.SafeTopLevelWindows); 
            CodeAccessPermission pp = new PrintingPermission(PrintingPermissionLevel.SafePrinting); 
            Console.WriteLine(fiop.GetType().ToString() + ": " + SecurityManager.IsGranted(fiop)); 
            Console.WriteLine(ep.GetType().ToString() + ": " + SecurityManager.IsGranted(ep)); 
            Console.WriteLine(fdp.GetType().ToString() + ": " + SecurityManager.IsGranted(fdp)); 
            Console.WriteLine(isfp.GetType().ToString() + ": " + SecurityManager.IsGranted(isfp)); 
            Console.WriteLine(rp.GetType().ToString() + ": " + SecurityManager.IsGranted(rp)); 
            Console.WriteLine(uip.GetType().ToString() + ": " + SecurityManager.IsGranted(uip)); 
            Console.WriteLine(pp.GetType().ToString() + ": " + SecurityManager.IsGranted(pp));
            Console.ReadLine();
        }
    }
}
It seems that regardless of how you navigate and run the executable locally, the permissions depend on your logged in user's permission, not how you get to it (ie through loopback or directly). It does seem a bit strange though.

Pete
__________________
Reply With Quote
Reply

Bookmarks

Tags
.net, csharp, development, microsoft


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl LWP loses html code?! jialanw Perl 22 04-13-09 02:14 PM
Mentor Sought: Help me code better usallsys Job Offers & Assistance 1 09-24-08 04:39 AM
convert problem jonnekke PHP 12 02-26-08 02:55 AM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 12:10 PM


All times are GMT -5. The time now is 02:19 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.