So... if I install this on a machine for a user, remove the admin rights of that user, they would be able to execute commands as if they were still an admin?
It uses Start-Process -Verb RunAs to run the admin process, no funny business with actual privilege escalation.
"like sudo" is about the UX, not about replicating the behavior of the sudoers file. I believe there are projects that attempt to do this sort of thing on the gallery, but my needs had more to do with ergonomics than reinventing privilege escalation and access control.
Edit: In other words, if you installed this on a machine for a user and then removed their admin rights that it would fail if they tried to use it because they don't have the ability to start processes as admin.
Ah, then I suspect my problem won't go away since that's how I'm currently opening my script. I was hoping to use this in conjunction with a .cmd file to set -ExecutionPolicy Bypass and run just the part of the script where I need elevated access using this, but I also launch that with -NoProfile, so I don't have access to the Invoke-AsAdministrator available and I can't Import-Module because I can't execute scripts.
There's probably a way to do this I'm just not seeing.
I don't know how much control over the environment you have or how viable this is, but one suggestion is to create a windows service that exposes a server over some kind of socket - a named pipe like I'm using, or good ol' fashioned tcp, or user-space COM objects if that's a thing - and then connect to that with your user account in your script. This way, your server runs as administrator and your clients can connect to it using whatever out-of-band authentication system you like.
Or, I change the account to an Administrator account, change the Policy, run the script I made, and set everything back... That was the approach I took. I had to restore a bunch of user files and I needed to reset the ownership after I deleted the original accounts they were associated with.
Please do not do this as this will make your organisation vulnerable and probably end up with ransomeware or stolen data. Normal users are normal users for a reason!
An ideal solution would likely work just like that but with some filtering on the server side - possibly using a pssc file, but you could simply whitelist allowed commands in the service.
This is the nature of applications, really. If I got up PayPal and authorise a payment, I don't have privileges on the web server. I've authenticated to it, and there are a set of pre-defined commands that are then enabled.
3
u/[deleted] Apr 28 '20
So... if I install this on a machine for a user, remove the admin rights of that user, they would be able to execute commands as if they were still an admin?
Even with UAC enabled?