HighTechTalks DotNet Forums  

is there some location (c.f. [CommonAppData]) where even limited users can modify/write files?

Dotnet Security microsoft.public.dotnet.security


Discuss is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old   
Dominick Baier
 
Posts: n/a

Default Re: is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? - 03-19-2007 , 02:42 AM






You have to run this code with administrative privileges...

How are you running it - as a normal user?


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Quote:
I used "Directory.GetAccessControl", added my new ACL rule (i.e.
AddAccessRule) and then "SetAccessControl", and I'm sure you already
know what happened:

"Attempt to perform an unauthorized operation."

If I didn't have permission to write the file, I probably don't have
permission to change the permissions to write the file.

Is it possible to call some code which will result in the "do you want
to allow this" dialog being pop'd up and if the user says "Accept",
that then gives me administrator privileges to do whatever I want?

Thanks,
Bob
"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote
in message news:51eb3048bc5c8c93741d9bf4c20 (AT) news (DOT) microsoft.com...

Yes,
you can write a custom action in the VS installation project - the
APIs to
change ACLs can be found in System.Security.AccessControl.
e.g. Directory.GetAccessControl(..)

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

My original concern is that in order to make this work, I didn't
want to have to tell the user, "Log in as administrator, go to
such-and-such folder, right-click and choose Properties,
Security..." and I don't personally know how to set ACLs in an
installer.

Is it possible to modify ACLs during installation with VS.Net (2005)
setup projects (merge module or msi)?

Is it possible to modify ACLs during run-time execution of a GAC DLL
assembly? e.g. is it possible to call some code which will result in
the "do you want to allow this" dialog being pop'd up and if the
user says "Accept", that then gives me administrator privileges to
do whatever I want?

For example, could someone give me a 3-5 sentence explanation why
what I said earlier didn't work?

+-------------
I even tried to use:
RegistryPermission rp = new
RegistryPermission(RegistryPermissionAccess.Create , strRegKey);
rp.Assert();
in the GAC assembly to fake the system out that it has permission
and not check the apps higher up the stack, but it just throws a
Security Exception error.

Is this because DLLs (even in the GAC) can't use
SecurityPermissions?

+-------------

I appologize if these are basic questions, but I've looked at
security for several days now and it isn't becoming clearer.

Bob




Reply With Quote
  #12  
Old   
Bob Eaton
 
Posts: n/a

Default Re: is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? - 03-19-2007 , 03:18 AM






In fact, the account I'm using is an administrator account, but I think that
by default, Vista doesn't even give administrator privilege to do many
things. Administrators have permission to change the privileges, but they
don't get many by default.

And in any case, I think in this situation, it depends on the executable
calling my code, right? My code is in a DLL being executed out of the global
assembly cache and is ultimately being called by Microsoft Word 2007. That
is, Word is the 'exe', which eventually calls my GAC assembly (by means of a
COM Add-in). Word is not being "Run as Administrator", but just as normal
(which I think means that it doesn't inherit administrator privileges from
the user's account).

So if Word isn't being run "as Administrator"--even though I'm on an
Administrator account--my GAC DLL will just inherit the permissions that
Word has (which is effectively limited), correct?

In fact, I had intended this to be a limited account, because I have to make
this work on a limited account also, but I recently checked and discovered
that the account I'm logged into is actually part of the Administrators
group.

Now, when I say that "I have to make this work on even a limited account",
I'm fully aware that this should require something like I asked in my last
message: I would like to call something in my GAC DLL which results in the
user getting the 'you need administrative permissions to do this" dialog and
if they say "Accept", then I can do it. If they say "Don't accept", then I
feel free to fail to do it (c.f. trying to start Regedit on Vista--even with
an adminstrator account--you still get the "User Account Control" dialog box
saying "Windows needs your permission to continue: Continue or Cancel).

But my problem is that I can't even figure out what to call to get the UAC
dialog box to show up. Or maybe it is the case that you can only get that
dialog box when the application is started and then only when it's started
by the operating system (rather than programmatically or during the course
of execution)? And, in particular, maybe there's no way at all of doing this
in a GAC DLL...

The bummer is that 98% of the operation of my GAC assembly is very
straightforward and needs no additional privileges, so I'd hate to have it
always "Run as Administrator" (even if that's possible) since that is only
necessary in a very small use case. But when one of those 2% additional
cases occur when I have to write to a file on the disk, it be nice if I
could request additional permissions at that time.

Bob


"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote in
message news:51eb3048bd208c93808e8476440 (AT) news (DOT) microsoft.com...
Quote:
You have to run this code with administrative privileges...

How are you running it - as a normal user?


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

I used "Directory.GetAccessControl", added my new ACL rule (i.e.
AddAccessRule) and then "SetAccessControl", and I'm sure you already
know what happened:

"Attempt to perform an unauthorized operation."

If I didn't have permission to write the file, I probably don't have
permission to change the permissions to write the file.

Is it possible to call some code which will result in the "do you want
to allow this" dialog being pop'd up and if the user says "Accept",
that then gives me administrator privileges to do whatever I want?

Thanks,
Bob
"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote
in message news:51eb3048bc5c8c93741d9bf4c20 (AT) news (DOT) microsoft.com...

Yes,
you can write a custom action in the VS installation project - the
APIs to
change ACLs can be found in System.Security.AccessControl.
e.g. Directory.GetAccessControl(..)

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

My original concern is that in order to make this work, I didn't
want to have to tell the user, "Log in as administrator, go to
such-and-such folder, right-click and choose Properties,
Security..." and I don't personally know how to set ACLs in an
installer.

Is it possible to modify ACLs during installation with VS.Net (2005)
setup projects (merge module or msi)?

Is it possible to modify ACLs during run-time execution of a GAC DLL
assembly? e.g. is it possible to call some code which will result in
the "do you want to allow this" dialog being pop'd up and if the
user says "Accept", that then gives me administrator privileges to
do whatever I want?

For example, could someone give me a 3-5 sentence explanation why
what I said earlier didn't work?

+-------------
I even tried to use:
RegistryPermission rp = new
RegistryPermission(RegistryPermissionAccess.Create , strRegKey);
rp.Assert();
in the GAC assembly to fake the system out that it has permission
and not check the apps higher up the stack, but it just throws a
Security Exception error.

Is this because DLLs (even in the GAC) can't use
SecurityPermissions?

+-------------

I appologize if these are basic questions, but I've looked at
security for several days now and it isn't becoming clearer.

Bob







Reply With Quote
  #13  
Old   
Kerry Brown
 
Posts: n/a

Default Re: is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? - 03-19-2007 , 09:54 AM



Your program needs a manifest to tell Vista it needs administrative
permissions. This will cause Vista to throw a UAC prompt when the program
starts then the program will get administrative permissions. A better way to
do it is figure what ACLs need to be set and do it during the install.
Create a manifest for the installer. The program itself shouldn't need to
run as an administrator.

http://msdn2.microsoft.com/en-us/library/aa480150.aspx

http://technet2.microsoft.com/Window....mspx?mfr=true

--
Kerry Brown
Microsoft MVP - Shell/User
http://www.vistahelp.ca


"Bob Eaton" <pete_dembrowski (AT) hotmail (DOT) com> wrote

Quote:
In fact, the account I'm using is an administrator account, but I think
that
by default, Vista doesn't even give administrator privilege to do many
things. Administrators have permission to change the privileges, but they
don't get many by default.

And in any case, I think in this situation, it depends on the executable
calling my code, right? My code is in a DLL being executed out of the
global
assembly cache and is ultimately being called by Microsoft Word 2007. That
is, Word is the 'exe', which eventually calls my GAC assembly (by means of
a
COM Add-in). Word is not being "Run as Administrator", but just as normal
(which I think means that it doesn't inherit administrator privileges from
the user's account).

So if Word isn't being run "as Administrator"--even though I'm on an
Administrator account--my GAC DLL will just inherit the permissions that
Word has (which is effectively limited), correct?

In fact, I had intended this to be a limited account, because I have to
make
this work on a limited account also, but I recently checked and discovered
that the account I'm logged into is actually part of the Administrators
group.

Now, when I say that "I have to make this work on even a limited account",
I'm fully aware that this should require something like I asked in my last
message: I would like to call something in my GAC DLL which results in the
user getting the 'you need administrative permissions to do this" dialog
and
if they say "Accept", then I can do it. If they say "Don't accept", then I
feel free to fail to do it (c.f. trying to start Regedit on Vista--even
with
an adminstrator account--you still get the "User Account Control" dialog
box
saying "Windows needs your permission to continue: Continue or Cancel).

But my problem is that I can't even figure out what to call to get the UAC
dialog box to show up. Or maybe it is the case that you can only get that
dialog box when the application is started and then only when it's started
by the operating system (rather than programmatically or during the course
of execution)? And, in particular, maybe there's no way at all of doing
this
in a GAC DLL...

The bummer is that 98% of the operation of my GAC assembly is very
straightforward and needs no additional privileges, so I'd hate to have it
always "Run as Administrator" (even if that's possible) since that is only
necessary in a very small use case. But when one of those 2% additional
cases occur when I have to write to a file on the disk, it be nice if I
could request additional permissions at that time.

Bob


"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote in
message news:51eb3048bd208c93808e8476440 (AT) news (DOT) microsoft.com...
You have to run this code with administrative privileges...

How are you running it - as a normal user?


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

I used "Directory.GetAccessControl", added my new ACL rule (i.e.
AddAccessRule) and then "SetAccessControl", and I'm sure you already
know what happened:

"Attempt to perform an unauthorized operation."

If I didn't have permission to write the file, I probably don't have
permission to change the permissions to write the file.

Is it possible to call some code which will result in the "do you want
to allow this" dialog being pop'd up and if the user says "Accept",
that then gives me administrator privileges to do whatever I want?

Thanks,
Bob
"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote
in message news:51eb3048bc5c8c93741d9bf4c20 (AT) news (DOT) microsoft.com...

Yes,
you can write a custom action in the VS installation project - the
APIs to
change ACLs can be found in System.Security.AccessControl.
e.g. Directory.GetAccessControl(..)

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

My original concern is that in order to make this work, I didn't
want to have to tell the user, "Log in as administrator, go to
such-and-such folder, right-click and choose Properties,
Security..." and I don't personally know how to set ACLs in an
installer.

Is it possible to modify ACLs during installation with VS.Net (2005)
setup projects (merge module or msi)?

Is it possible to modify ACLs during run-time execution of a GAC DLL
assembly? e.g. is it possible to call some code which will result in
the "do you want to allow this" dialog being pop'd up and if the
user says "Accept", that then gives me administrator privileges to
do whatever I want?

For example, could someone give me a 3-5 sentence explanation why
what I said earlier didn't work?

+-------------
I even tried to use:
RegistryPermission rp = new
RegistryPermission(RegistryPermissionAccess.Create , strRegKey);
rp.Assert();
in the GAC assembly to fake the system out that it has permission
and not check the apps higher up the stack, but it just throws a
Security Exception error.

Is this because DLLs (even in the GAC) can't use
SecurityPermissions?

+-------------

I appologize if these are basic questions, but I've looked at
security for several days now and it isn't becoming clearer.

Bob








Reply With Quote
  #14  
Old   
Dominick Baier
 
Posts: n/a

Default Re: is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? - 03-19-2007 , 01:40 PM



OK - i see.

Yes you are right - the component runs with the privileges (token) of the
user that started Word.

In Vista there are two types of accounts - administrator and limited users
- the privileges they get by default are very similar - but an administrator
can choose to elevate using UAC. That means you should design your software
for a limited user (without having to elevate since in corporate environments
users will be limited users).

That in turn means you should set the necessary ACLs at deployment time (when
you add the COM addin or the GACed component - in this moment you need full
admin privs anyways and can modify the necessary ACLs on the shared directory).

makes sense?

That all said - you can manually elevate a process. You can use Process.Start()
with a ProcessStartInfo that has the verb set to "runas" and UseShellExecute
to "true". But this will only work for users in the administrator group.


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Quote:
In fact, the account I'm using is an administrator account, but I
think that by default, Vista doesn't even give administrator privilege
to do many things. Administrators have permission to change the
privileges, but they don't get many by default.

And in any case, I think in this situation, it depends on the
executable calling my code, right? My code is in a DLL being executed
out of the global assembly cache and is ultimately being called by
Microsoft Word 2007. That is, Word is the 'exe', which eventually
calls my GAC assembly (by means of a COM Add-in). Word is not being
"Run as Administrator", but just as normal (which I think means that
it doesn't inherit administrator privileges from the user's account).

So if Word isn't being run "as Administrator"--even though I'm on an
Administrator account--my GAC DLL will just inherit the permissions
that Word has (which is effectively limited), correct?

In fact, I had intended this to be a limited account, because I have
to make this work on a limited account also, but I recently checked
and discovered that the account I'm logged into is actually part of
the Administrators group.

Now, when I say that "I have to make this work on even a limited
account", I'm fully aware that this should require something like I
asked in my last message: I would like to call something in my GAC DLL
which results in the user getting the 'you need administrative
permissions to do this" dialog and if they say "Accept", then I can do
it. If they say "Don't accept", then I feel free to fail to do it
(c.f. trying to start Regedit on Vista--even with an adminstrator
account--you still get the "User Account Control" dialog box saying
"Windows needs your permission to continue: Continue or Cancel).

But my problem is that I can't even figure out what to call to get the
UAC dialog box to show up. Or maybe it is the case that you can only
get that dialog box when the application is started and then only when
it's started by the operating system (rather than programmatically or
during the course of execution)? And, in particular, maybe there's no
way at all of doing this in a GAC DLL...

The bummer is that 98% of the operation of my GAC assembly is very
straightforward and needs no additional privileges, so I'd hate to
have it always "Run as Administrator" (even if that's possible) since
that is only necessary in a very small use case. But when one of those
2% additional cases occur when I have to write to a file on the disk,
it be nice if I could request additional permissions at that time.

Bob

"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote
in message news:51eb3048bd208c93808e8476440 (AT) news (DOT) microsoft.com...

You have to run this code with administrative privileges...

How are you running it - as a normal user?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

I used "Directory.GetAccessControl", added my new ACL rule (i.e.
AddAccessRule) and then "SetAccessControl", and I'm sure you already
know what happened:

"Attempt to perform an unauthorized operation."

If I didn't have permission to write the file, I probably don't have
permission to change the permissions to write the file.

Is it possible to call some code which will result in the "do you
want to allow this" dialog being pop'd up and if the user says
"Accept", that then gives me administrator privileges to do whatever
I want?

Thanks,
Bob
"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com
wrote
in message news:51eb3048bc5c8c93741d9bf4c20 (AT) news (DOT) microsoft.com...
Yes,
you can write a custom action in the VS installation project - the
APIs to
change ACLs can be found in System.Security.AccessControl.
e.g. Directory.GetAccessControl(..)
-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)
My original concern is that in order to make this work, I didn't
want to have to tell the user, "Log in as administrator, go to
such-and-such folder, right-click and choose Properties,
Security..." and I don't personally know how to set ACLs in an
installer.

Is it possible to modify ACLs during installation with VS.Net
(2005) setup projects (merge module or msi)?

Is it possible to modify ACLs during run-time execution of a GAC
DLL assembly? e.g. is it possible to call some code which will
result in the "do you want to allow this" dialog being pop'd up
and if the user says "Accept", that then gives me administrator
privileges to do whatever I want?

For example, could someone give me a 3-5 sentence explanation why
what I said earlier didn't work?

+-------------
I even tried to use:
RegistryPermission rp = new
RegistryPermission(RegistryPermissionAccess.Create , strRegKey);
rp.Assert();
in the GAC assembly to fake the system out that it has permission
and not check the apps higher up the stack, but it just throws a
Security Exception error.
Is this because DLLs (even in the GAC) can't use
SecurityPermissions?
+-------------

I appologize if these are basic questions, but I've looked at
security for several days now and it isn't becoming clearer.

Bob




Reply With Quote
  #15  
Old   
Bob Eaton
 
Posts: n/a

Default Re: is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? - 03-19-2007 , 10:41 PM



This makes sense. But, can you call Process.Start with a DLL? Or did you
mean that I should start Word that way?

And also, it sounds like there's no way of doing this *during* execution
(e.g. when I discover I'm in the unusual case of needing to write to the
registry, let's say). It has to be done when the app starts (in this case
Word, right?), or not at all.

Thanks to both of you for all your patient help on this :-)

Bob


"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote in
message news:51eb3048bd418c93864d3d02540 (AT) news (DOT) microsoft.com...
Quote:
OK - i see.

Yes you are right - the component runs with the privileges (token) of the
user that started Word.

In Vista there are two types of accounts - administrator and limited
users - the privileges they get by default are very similar - but an
administrator can choose to elevate using UAC. That means you should
design your software for a limited user (without having to elevate since
in corporate environments users will be limited users).

That in turn means you should set the necessary ACLs at deployment time
(when you add the COM addin or the GACed component - in this moment you
need full admin privs anyways and can modify the necessary ACLs on the
shared directory).

makes sense?

That all said - you can manually elevate a process. You can use
Process.Start() with a ProcessStartInfo that has the verb set to "runas"
and UseShellExecute to "true". But this will only work for users in the
administrator group.


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

In fact, the account I'm using is an administrator account, but I
think that by default, Vista doesn't even give administrator privilege
to do many things. Administrators have permission to change the
privileges, but they don't get many by default.

And in any case, I think in this situation, it depends on the
executable calling my code, right? My code is in a DLL being executed
out of the global assembly cache and is ultimately being called by
Microsoft Word 2007. That is, Word is the 'exe', which eventually
calls my GAC assembly (by means of a COM Add-in). Word is not being
"Run as Administrator", but just as normal (which I think means that
it doesn't inherit administrator privileges from the user's account).

So if Word isn't being run "as Administrator"--even though I'm on an
Administrator account--my GAC DLL will just inherit the permissions
that Word has (which is effectively limited), correct?

In fact, I had intended this to be a limited account, because I have
to make this work on a limited account also, but I recently checked
and discovered that the account I'm logged into is actually part of
the Administrators group.

Now, when I say that "I have to make this work on even a limited
account", I'm fully aware that this should require something like I
asked in my last message: I would like to call something in my GAC DLL
which results in the user getting the 'you need administrative
permissions to do this" dialog and if they say "Accept", then I can do
it. If they say "Don't accept", then I feel free to fail to do it
(c.f. trying to start Regedit on Vista--even with an adminstrator
account--you still get the "User Account Control" dialog box saying
"Windows needs your permission to continue: Continue or Cancel).

But my problem is that I can't even figure out what to call to get the
UAC dialog box to show up. Or maybe it is the case that you can only
get that dialog box when the application is started and then only when
it's started by the operating system (rather than programmatically or
during the course of execution)? And, in particular, maybe there's no
way at all of doing this in a GAC DLL...

The bummer is that 98% of the operation of my GAC assembly is very
straightforward and needs no additional privileges, so I'd hate to
have it always "Run as Administrator" (even if that's possible) since
that is only necessary in a very small use case. But when one of those
2% additional cases occur when I have to write to a file on the disk,
it be nice if I could request additional permissions at that time.

Bob

"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote
in message news:51eb3048bd208c93808e8476440 (AT) news (DOT) microsoft.com...

You have to run this code with administrative privileges...

How are you running it - as a normal user?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

I used "Directory.GetAccessControl", added my new ACL rule (i.e.
AddAccessRule) and then "SetAccessControl", and I'm sure you already
know what happened:

"Attempt to perform an unauthorized operation."

If I didn't have permission to write the file, I probably don't have
permission to change the permissions to write the file.

Is it possible to call some code which will result in the "do you
want to allow this" dialog being pop'd up and if the user says
"Accept", that then gives me administrator privileges to do whatever
I want?

Thanks,
Bob
"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com
wrote
in message news:51eb3048bc5c8c93741d9bf4c20 (AT) news (DOT) microsoft.com...
Yes,
you can write a custom action in the VS installation project - the
APIs to
change ACLs can be found in System.Security.AccessControl.
e.g. Directory.GetAccessControl(..)
-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)
My original concern is that in order to make this work, I didn't
want to have to tell the user, "Log in as administrator, go to
such-and-such folder, right-click and choose Properties,
Security..." and I don't personally know how to set ACLs in an
installer.

Is it possible to modify ACLs during installation with VS.Net
(2005) setup projects (merge module or msi)?

Is it possible to modify ACLs during run-time execution of a GAC
DLL assembly? e.g. is it possible to call some code which will
result in the "do you want to allow this" dialog being pop'd up
and if the user says "Accept", that then gives me administrator
privileges to do whatever I want?

For example, could someone give me a 3-5 sentence explanation why
what I said earlier didn't work?

+-------------
I even tried to use:
RegistryPermission rp = new
RegistryPermission(RegistryPermissionAccess.Create , strRegKey);
rp.Assert();
in the GAC assembly to fake the system out that it has permission
and not check the apps higher up the stack, but it just throws a
Security Exception error.
Is this because DLLs (even in the GAC) can't use
SecurityPermissions?
+-------------

I appologize if these are basic questions, but I've looked at
security for several days now and it isn't becoming clearer.

Bob







Reply With Quote
  #16  
Old   
Dominick Baier
 
Posts: n/a

Default Re: is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? - 03-20-2007 , 04:25 AM



Hi,

as i said - you should assume that Word cannot be elevated (normal user scenario).
You should do all the necessary steps (ACLing etc) during an installation
process.

And you have to factor out the functionality into an .exe, yes - there is
another way for COM DLLs - but that, of course, required COM.

You can do that in between (e.g. restarting your own process) - you can do
a graceful check if you have full privileges by checking if your current
user has the administrator group enabled in the token, e.g.

if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsI nRole(WindowsBuiltInRole.Administrator))
{...}


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Quote:
This makes sense. But, can you call Process.Start with a DLL? Or did
you mean that I should start Word that way?

And also, it sounds like there's no way of doing this *during*
execution (e.g. when I discover I'm in the unusual case of needing to
write to the registry, let's say). It has to be done when the app
starts (in this case Word, right?), or not at all.

Thanks to both of you for all your patient help on this :-)

Bob

"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com> wrote
in message news:51eb3048bd418c93864d3d02540 (AT) news (DOT) microsoft.com...

OK - i see.

Yes you are right - the component runs with the privileges (token) of
the user that started Word.

In Vista there are two types of accounts - administrator and limited
users - the privileges they get by default are very similar - but an
administrator can choose to elevate using UAC. That means you should
design your software for a limited user (without having to elevate
since in corporate environments users will be limited users).

That in turn means you should set the necessary ACLs at deployment
time (when you add the COM addin or the GACed component - in this
moment you need full admin privs anyways and can modify the necessary
ACLs on the shared directory).

makes sense?

That all said - you can manually elevate a process. You can use
Process.Start() with a ProcessStartInfo that has the verb set to
"runas" and UseShellExecute to "true". But this will only work for
users in the administrator group.

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

In fact, the account I'm using is an administrator account, but I
think that by default, Vista doesn't even give administrator
privilege to do many things. Administrators have permission to
change the privileges, but they don't get many by default.

And in any case, I think in this situation, it depends on the
executable calling my code, right? My code is in a DLL being
executed out of the global assembly cache and is ultimately being
called by Microsoft Word 2007. That is, Word is the 'exe', which
eventually calls my GAC assembly (by means of a COM Add-in). Word is
not being "Run as Administrator", but just as normal (which I think
means that it doesn't inherit administrator privileges from the
user's account).

So if Word isn't being run "as Administrator"--even though I'm on an
Administrator account--my GAC DLL will just inherit the permissions
that Word has (which is effectively limited), correct?

In fact, I had intended this to be a limited account, because I have
to make this work on a limited account also, but I recently checked
and discovered that the account I'm logged into is actually part of
the Administrators group.

Now, when I say that "I have to make this work on even a limited
account", I'm fully aware that this should require something like I
asked in my last message: I would like to call something in my GAC
DLL which results in the user getting the 'you need administrative
permissions to do this" dialog and if they say "Accept", then I can
do it. If they say "Don't accept", then I feel free to fail to do it
(c.f. trying to start Regedit on Vista--even with an adminstrator
account--you still get the "User Account Control" dialog box saying
"Windows needs your permission to continue: Continue or Cancel).

But my problem is that I can't even figure out what to call to get
the UAC dialog box to show up. Or maybe it is the case that you can
only get that dialog box when the application is started and then
only when it's started by the operating system (rather than
programmatically or during the course of execution)? And, in
particular, maybe there's no way at all of doing this in a GAC
DLL...

The bummer is that 98% of the operation of my GAC assembly is very
straightforward and needs no additional privileges, so I'd hate to
have it always "Run as Administrator" (even if that's possible)
since that is only necessary in a very small use case. But when one
of those 2% additional cases occur when I have to write to a file on
the disk, it be nice if I could request additional permissions at
that time.

Bob

"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com
wrote in message
news:51eb3048bd208c93808e8476440 (AT) news (DOT) microsoft.com...

You have to run this code with administrative privileges...

How are you running it - as a normal user?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)
I used "Directory.GetAccessControl", added my new ACL rule (i.e.
AddAccessRule) and then "SetAccessControl", and I'm sure you
already know what happened:

"Attempt to perform an unauthorized operation."

If I didn't have permission to write the file, I probably don't
have permission to change the permissions to write the file.

Is it possible to call some code which will result in the "do you
want to allow this" dialog being pop'd up and if the user says
"Accept", that then gives me administrator privileges to do
whatever I want?

Thanks,
Bob
"Dominick Baier" <dbaier (AT) pleasepleasenospam_leastprivilege (DOT) com
wrote
in message news:51eb3048bc5c8c93741d9bf4c20 (AT) news (DOT) microsoft.com...
Yes,
you can write a custom action in the VS installation project -
the
APIs to
change ACLs can be found in System.Security.AccessControl.
e.g. Directory.GetAccessControl(..)
-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)
My original concern is that in order to make this work, I didn't
want to have to tell the user, "Log in as administrator, go to
such-and-such folder, right-click and choose Properties,
Security..." and I don't personally know how to set ACLs in an
installer.

Is it possible to modify ACLs during installation with VS.Net
(2005) setup projects (merge module or msi)?

Is it possible to modify ACLs during run-time execution of a GAC
DLL assembly? e.g. is it possible to call some code which will
result in the "do you want to allow this" dialog being pop'd up
and if the user says "Accept", that then gives me administrator
privileges to do whatever I want?

For example, could someone give me a 3-5 sentence explanation
why what I said earlier didn't work?

+-------------
I even tried to use:
RegistryPermission rp = new
RegistryPermission(RegistryPermissionAccess.Create , strRegKey);
rp.Assert();
in the GAC assembly to fake the system out that it has
permission
and not check the apps higher up the stack, but it just throws a
Security Exception error.
Is this because DLLs (even in the GAC) can't use
SecurityPermissions?
+-------------
I appologize if these are basic questions, but I've looked at
security for several days now and it isn't becoming clearer.

Bob




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.