Setting IPGrant on a folder from a WebMethod

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Setting IPGrant on a folder from a WebMethod

    I want to be able to limit access to a folder in IIS by IP address. I
    am trying to add IP addresses from a WebMethod to the IPGrant property.
    Here's my code:

    DirectoryEntry defaultRoot = new
    DirectoryEntry("IIS://SERVERNAME/w3svc/1/root/examplefolder",username,password,
    AuthenticationTypes.Secure);
    defaultRoot.RefreshCache();
    object oIPSecurity = defaultRoot.Invoke("Get", new
    string[]{"IPSecurity"});
    Type t = oIPSecurity.GetType();
    //Get the list of granted IPs
    Array IPs = (Array)t.InvokeMember("IPGrant", BindingFlags.GetProperty,
    null, oIPSecurity, null);
    //create a new Array of IPs
    object[] newIPs = new object[IPs.Length+1];
    //copy the existing IPs to the new Array
    IPs.CopyTo(newIPs,0);
    //add a new value
    newIPs.SetValue("192.168.0.21",IPs.Length);
    //Set the new IPlist
    t.InvokeMember("IPGrant", BindingFlags.SetProperty, null, oIPSecurity,
    new object[]{newIPs});
    defaultRoot.Invoke("Put", new object[]{"IPSecurity", oIPSecurity});
    defaultRoot.CommitChanges();

    When executed, I get this error:

    System.UnauthorizedAccessException: Access is denied. at
    System.DirectoryServices.Interop.IAds.SetInfo() at
    System.DirectoryServices.DirectoryEntry.CommitChan ges()
    >From the research I've done, I'm concerned that the solution to this
    problem is going to be a security threat. Any thoughts or alternative
    ideas to accomplish this?

    Thanks,

    David

    DAve Guest

  2. Similar Questions and Discussions

    1. Unable to locate the folder Adobe PDF setting file or other resources
      Get this message when trying to create a pdf file from an office document either from office or from Adobe 6.0 Professional. Using XP Professional OS...
    2. Setting writing permissions to a folder.
      At ASP.Net application I have a folder which contains the files, being updated by the users. The application deployed by Web Setup project. The...
    3. Folder setting?
      Hi, i want to set some limitation for each user's document on disk usage. for example, for user1's my documents, i want it not exceeds 100MB. is...
    4. Help with setting folder permissions
      I'm running XP Home Edition on a Dell Dimension 8100, Pentium 4, 80 gig HD, 256 RAM (although none of that info will probably be needed to answer...
    5. Setting Folder Permissions
      Hi, I am sooo lost with a problem I have. I bought a new digital camera and when I tried to install the software it got an error message "unable to...
  3. #2

    Default Re: Setting IPGrant on a folder from a WebMethod

    The IIS provider for ADSI doesn't use alternate credentials. It only works
    based on the security context of the current thread. The credentials you
    pass in are simply ignored.

    In order to get this to work, you need to make the current security context
    have the correct rights to perform the action.

    Joe K.

    "DAve" <dsalonius@pobox.com> wrote in message
    news:1109004163.416526.183190@l41g2000cwc.googlegr oups.com...
    >I want to be able to limit access to a folder in IIS by IP address. I
    > am trying to add IP addresses from a WebMethod to the IPGrant property.
    > Here's my code:
    >
    > DirectoryEntry defaultRoot = new
    > DirectoryEntry("IIS://SERVERNAME/w3svc/1/root/examplefolder",username,password,
    > AuthenticationTypes.Secure);
    > defaultRoot.RefreshCache();
    > object oIPSecurity = defaultRoot.Invoke("Get", new
    > string[]{"IPSecurity"});
    > Type t = oIPSecurity.GetType();
    > //Get the list of granted IPs
    > Array IPs = (Array)t.InvokeMember("IPGrant", BindingFlags.GetProperty,
    > null, oIPSecurity, null);
    > //create a new Array of IPs
    > object[] newIPs = new object[IPs.Length+1];
    > //copy the existing IPs to the new Array
    > IPs.CopyTo(newIPs,0);
    > //add a new value
    > newIPs.SetValue("192.168.0.21",IPs.Length);
    > //Set the new IPlist
    > t.InvokeMember("IPGrant", BindingFlags.SetProperty, null, oIPSecurity,
    > new object[]{newIPs});
    > defaultRoot.Invoke("Put", new object[]{"IPSecurity", oIPSecurity});
    > defaultRoot.CommitChanges();
    >
    > When executed, I get this error:
    >
    > System.UnauthorizedAccessException: Access is denied. at
    > System.DirectoryServices.Interop.IAds.SetInfo() at
    > System.DirectoryServices.DirectoryEntry.CommitChan ges()
    >
    >>From the research I've done, I'm concerned that the solution to this
    > problem is going to be a security threat. Any thoughts or alternative
    > ideas to accomplish this?
    >
    > Thanks,
    >
    > David
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: Setting IPGrant on a folder from a WebMethod



    To change the current security context - would I accomplish this in my
    web.config or machine.config files? Or would I need to use the
    impersonate method?

    Thanks for your help,

    David

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    David Salonius Guest

  5. #4

    Default Re: Setting IPGrant on a folder from a WebMethod


    My web service is running under NT AUTHORITY\NETWORK SERVICE. I've then
    given full control under folder security to that user. Under Advanced
    Security Settings, I've verified that NETWORK SERVICE has full control
    to all permissions. The error still persists. Is this what you're
    referring to?

    Thanks,

    David

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    David Salonius Guest

  6. #5

    Default Re: Setting IPGrant on a folder from a WebMethod

    My guess is that you need to be an administrator in order to change the IIS
    metabase. That is normally required.

    Did you consider changing the Application Pool identity to an administrator
    account? That should accomplish your goal, at least for testing purposes.

    However, you may not wish to solve the problem that way. Running your app
    pool as administrator opens you up to some significant security risks. You
    may wish to put the IIS ADSI code in a COM+ component and run that under a
    separate identity with admin privileges. This would allow your main web
    application process to continue running with least privileges (as NETWORK
    SERVICE).

    Joe K.

    "David Salonius" <dsalonius@charter.net> wrote in message
    news:OnizSDEGFHA.560@TK2MSFTNGP15.phx.gbl...
    >
    > My web service is running under NT AUTHORITY\NETWORK SERVICE. I've then
    > given full control under folder security to that user. Under Advanced
    > Security Settings, I've verified that NETWORK SERVICE has full control
    > to all permissions. The error still persists. Is this what you're
    > referring to?
    >
    > Thanks,
    >
    > David
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Joe Kaplan \(MVP - ADSI\) Guest

  7. #6

    Default Re: Setting IPGrant on a folder from a WebMethod

    On 21 Feb 2005, David Salonius <dsalonius@charter.net> postulated in
    news:OnizSDEGFHA.560@TK2MSFTNGP15.phx.gbl:
    >
    > My web service is running under NT AUTHORITY\NETWORK SERVICE. I've
    then
    > given full control under folder security to that user. Under
    Advanced
    > Security Settings, I've verified that NETWORK SERVICE has full
    control
    > to all permissions. The error still persists. Is this what you're
    > referring to?
    >
    > Thanks,
    >
    > David
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!
    Use IIS to manage this for you, buy assigning a new application pool
    for this site that impersonates administrator (using LocalSystem as
    Identity). (I use one called AdmininstrationPool that I keep reserved
    for roles where I need this level access).

    Remember, This IS a security hole, so be careful who has access.

    -- ipgrunt

    IPGrunt Guest

  8. #7

    Default Re: Setting IPGrant on a folder from a WebMethod



    Setting the user in the Application Pool identity to an administrator
    account solved the problem. From what I can tell, as long as my web
    methods folder is locked down to where no one can upload code, this
    should be safe. Is that a fair assessment?

    Thanks,

    David

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    David Salonius Guest

  9. #8

    Default Re: Setting IPGrant on a folder from a WebMethod

    I'd make sure you don't use that app pool for any other websites or
    applications on the same server. Always use a different app pool with lower
    privileges for other sites. That will help restrict it as well.

    Other than that, it is up to you to consider whether you need to go to COM+
    or not for additional security. As long as you don't have any other entry
    points into this site and you are comfortable with the security you are
    providing, then I think it can be secure. Just be careful and spend some
    time doing some threat modeling to make sure you don't miss anything.

    Joe K.

    "David Salonius" <dsalonius@charter.net> wrote in message
    news:%23MKOlGFGFHA.228@TK2MSFTNGP15.phx.gbl...
    >
    >
    > Setting the user in the Application Pool identity to an administrator
    > account solved the problem. From what I can tell, as long as my web
    > methods folder is locked down to where no one can upload code, this
    > should be safe. Is that a fair assessment?
    >
    > Thanks,
    >
    > David
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Joe Kaplan \(MVP - ADSI\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139