r/PowerShell • • Aug 25 '22

Question Run Powershell as admin without admin rights

Hello everyone, does anyone know or has done this? I need to make Powershell to be able to be ran as admin without actually inputting any credentials from an account, that is not an administrator - a normal domain user to be able to open up elevated Powershell even though he has no rights.

I've tried a few things like giving Full Control to Powershell.exe in System32, but that didn't seem to work

I've tried creating this script this batch file:

@ ECHO OFF
SET ThisScriptsDirectory=C:\
SET PowerShellScriptPath=C:\PSADMIN.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -
ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\PSADMIN.ps1""' -Verb RunAs}";

Which goes to a ps1 file with "Start-Process Powershell"

And run this in task scheduler as a domain admin user with highest privileges, which actually does run OK on my computer in which I'm admin in, but not for a user that is not an admin user (it does say script was ran when it was done by a user but it does not work, but when You run the batch file by hand it does work - strange.)

Is it even possible to do some domain ACLs to let specific users to open up specific programs as an admin?

Thanks a lot

EDIT: From what I can see from replies, this looks like a pretty bad idea, and I couldn't agree more. So I've got an idea to install Hyper-V for people that need to test things with admin rights.

Still not sure what to do with specific programs that need to be ran as admin on a work computer

EDIT 2: Thanks everyone for their insights, I probably should be deleting this thread, as this doesn't seem like a good idea at all, but that's why I'm consulting specialists here, if someone else clueless comes here, he should see this thread. Thanks for solution You were giving. This was quite a broad learning experience which I love. Have a great day.

0 Upvotes

46 comments sorted by

29

u/MNmetalhead Aug 25 '22

So, “how do I bypass device security?”

If the user has a business need for elevated rights, then they should have an account with those rights. If they don’t have a business need, they don’t get those rights. Basic RBAC.

Why does the user need elevated rights for PowerShell? That’s extremely dangerous to the device and the organization.

-2

u/Best_Yasuo_EUW Aug 25 '22 edited Aug 25 '22

I'm not going to lie, I was asking myself the same question and asking my manager this as well, but this is the task that was given. I'm well aware that elevated command prompt is pretty much as having admin rights on the computer.

And to add to that, if I can find a concept to that, I need to find some way for users to run specific shortcuts or programs with administrator rights, because of updates to the main program clients are using that cannot be updated without admin rights and connecting to a few hundred computers for it is not a solution

And for WHY they need them - users are programmers and until now had admin rights on their computer, so I have a request to only allow specific programs to be ran as admin

4

u/MNmetalhead Aug 25 '22

We’ve deployed Make Me Admin in our environment for similar situations where the user occasionally needs to do something with elevated rights.

1

u/Best_Yasuo_EUW Aug 25 '22

Looks promising, I'll check it later on. Thank you!

2

u/nascentt Aug 25 '22 edited Aug 25 '22

I need to find some way for users to run specific shortcuts or programs with administrator rights, because of updates to the main program clients are using that cannot be updated without admin rights and connecting to a few hundred computers for it is not a solution

Huh?!

No. Users shouldn't be updating their own apps. It's one thing for an auto updating app like chrome/Firefox to not be globally managed as they have self updating services. But either IT need to manage software deployments, or users with specific software should get separate admin accounts that they run as admin to elevate. But it should manage software. Use sccm or chocolatey/Winget.

And for WHY they need them - users are programmers and until now had admin rights on their computer

Programmers absolutely should not need admin. They shouldn't have admin because they used to have admin

I have a request to only allow specific programs to be ran as admin

That's not going to work

2

u/Best_Yasuo_EUW Aug 25 '22

For app updates - there is a monthly mandatory update on the specific software used by a few hundred computers and the update file needs to be ran as an admin

As for programmers specifically, even things like Visual Studio need admin rights (can't really confirm yet, got this from their management team)

And for specific apps to be ran as admin, I'm pretty sure that should be possible and I've done quite a few of these, just looking for a universal way to do it, because I haven't found a works-in-all-situations solution yet, probably should be possible with Task Scheduler

4

u/nascentt Aug 25 '22

For app updates - there is a monthly mandatory update on the specific software used by a few hundred computers and the update file needs to be ran as an admin

This is incredibly puzzling. WHich app, and why can't the update be deployed by IT?

Visual Studio need admin rights

I've used visual studio for years as have dozens of staff at work, none use an admin account to use it.

2

u/Best_Yasuo_EUW Aug 25 '22

I'm not sure about update deployment on computers, but the app I was talking about is farm equipment manager that must be updated each month or it doesn't even start, it's a private licensed app.

As for visual studio, I'm not 100% sure as I've said, that's the information I've got

2

u/nascentt Aug 25 '22

how do you receive the farm equipment manager, exe/msi?

if it's possible to install/update it silently, then it's possible to remote deploy everytime there's a new version

2

u/Scooter_127 Aug 25 '22

Visual Studio Code will not install an extension without admin rights. I oughta know, just got a new work laptop and just tried it.

Edit: I'm getting prompted to let windows firewall allow traffic from VS Code and that's where I'm running into trouble.

3

u/StConvolute Aug 25 '22

I manage 3800 endpoints including a bunch of devs with VSCode and visual studio. None of them have admin access to their own devices. We use Intune/GPO to deploy apps and set policies. Just requires planning/testing. Once in place, I click a few buttons, move an object or two and it's all automated. Way easier than fighting management or a dev over local admin rights.

-1

u/Scooter_127 Aug 25 '22

Hoo-fucking-ray for you.

We have 10x the number of endpoints counting workstations/laptops alone. If the people running the show had their shit together it would be a different story. As a company we're getting there, especially with the automaton, but we ain't there yet. But Infosec has sure had their merry way locking things down. Certainly a good way to go but things are a little too locked down for the current levels of support.

I honest to Christ wanted to be the first on my team to say "Look, I don't need admin rights so neither do you" but I'm not spending 3 weeks setting up a new laptop.

1

u/nascentt Aug 25 '22

yeah firewall changes for sure need admin. it's up to how your it department wants to configure windows firewall.

by default all outbound connections are allowed on windows firewall, so either they've set it to block outbound connections, or your visual studio extension runs it's own server

7

u/mmmonszter Aug 25 '22

Push back on this... Jesus christ you are talking about giving developers an admin console. How long do you think will take until one of them will go " Hey guys i just quickly checked what command we can use to add back our users into the admin group"

Holy cow.... Don't go into these half measures. Either give them admin or decline fully or look for a tool that can help you with the in-between like below the other guy mentioned.

3

u/jstar77 Aug 25 '22

Add-LocalGroupMember -Group "Administrators" -Member "$heyLookImAnAdminNow"

1

u/MrSirplx Aug 17 '24

I need admin for that dummy or is it as a .bat fille

1

u/BAdinkers Aug 25 '22

Well Mr.YasuoMain I was recently able to bypass this for some silent installs/updates by telling ps to call on a hidden shared cmdlet script. Since cmd has less trouble preforming operations without administrative UAC.

I say it this way because giving users anymore than basics is downright dangerous/not an option.

1

u/BlackV Aug 25 '22

I'm well aware that elevated command prompt is pretty much as having admin rights on the computer.

its not pretty much , it IS having admin rights

JEA/Constrained endpoints are what you want if you want non privileged users doing specific things

9

u/[deleted] Aug 25 '22

Congrats on your new career as an exploit developer

1

u/[deleted] Aug 25 '22

This guy knows what's up.

1

u/Best_Yasuo_EUW Aug 25 '22

I mean, all of the comments are right and I know this as well (and for gods sake, stop with being aggressive, thanks for the tips, solutions and heads-ups). Everything is still in testing and nothing is live yet and will not go live without a lot of permissions, it's just a request from a company and my manager. Thanks a lot for clearing it all up, people.

4

u/purplemonkeymad Aug 25 '22

What are you expecting people to do with this admin prompt? You would probably be better off updating ACLs of the things that need changes to allow users to change them*.


*There are security considerations you will have to make for each item.

4

u/BruceNotLee Aug 25 '22

Thats a hard NO.

3

u/OptimoP Aug 25 '22

To answer this question.. I don't think you can do this the way you need. I don't know how to give Domain Admin rights to a user or machine without adding the account directly to the Domain Admins group.
Depending on what your needs are, can you set up a terminal that does ONLY what is needed and air-gapped from everything else? Can you set up a scheduled task on the server (I assume) to provide the report/or service at regular intervals?

2

u/C0gn171v3D1550n4nc3 Aug 25 '22

If you wanna be sketchy AF, though I wouldn't recommend it. you could put admin username and password in an array inside a bat or ps1 file that opens powershell.exe. This would allow a non priv user to simply run it and have admin. MASSIVE SECURITY RISK THOUGH. The array won't provide more than basic obfuscation, so your admin cred are pretty much just sitting there.

1

u/lerun Aug 25 '22

Only need to be LOCAL admin on the box the PS script is running to be able to open up elevated.

1

u/ollivierre Aug 25 '22

Look into Autoelevate from Cyber fox

1

u/jstar77 Aug 25 '22

What are the specific programs that still need to be ran as an admin?

1

u/jjgage Aug 25 '22

Jesus. Fuc*ing. Christ

1

u/mjohonson20 Aug 25 '22

Get a PAM solution. Delinea formerly Thycotics allows you elevate the app and not the user. And I think licensing is per agent/device so it should be affordable.

1

u/Narabug Aug 26 '22

The direct answer to your question lies within a toolkit named PowerSploit, and involves token manipulation. You basically have to make an admin token and hand it to the non-admin user or process. For what it’s worth, any security tool will immediately flag PowerSploit libraries and delete or quarantine them.

There are also apps/tools that can similarly accomplish this. For example, you could have a program in SCCM that simply launches an interactive command prompt - by default it will launch as the system account.

Programs I know if are MakeMeAdmin and BeyondTrust Privilege Management for Windows.

As others are saying, you have to be careful with what you allow people to run as admin. Command prompts are a pretty large no no.

1

u/TheOnlyBliebervik Dec 29 '23

If you become an admin, you can make a new administrator account, which you can then use to make your original account an admin account

1

u/jimb2 Aug 26 '22

This would be a serious security failure. This means that any partially compromised user gets the keys to the kingdom. Be careful what you wish for.

1

u/clubstupid Aug 27 '22

So, you need a red line in blue?

1

u/Maximum_Ad_9965 Jan 10 '23

You can setup a GPO to run scriptunder a user or computer context with admin rights. It´s not possible to click "run as administrator" on any .link or binary without admin rights.

1

u/myrland Aug 25 '22

Creating a scheduled task that runs under the SYSTEM context and executes a specific Powershell file should work, but it's not exactly secure in any way whatsoever.

Please don't ever go this route with any sensitive credentials like domain admin.

1

u/johnjones_24210 Aug 25 '22

Stop f*ing guessing with desperation moves like giving Full Control.

Hope you have proven backups

-5

u/Best_Yasuo_EUW Aug 25 '22

For people saying that running powershell with domain admin credentials instead of local admin credentials, is that really a problem? It is opening in elevated state either way, is there any difference?

5

u/yoyoyoitsyaboiii Aug 25 '22

You should never use highly privileged credentials like domain admin on a user workstation unless you want to get your entire domain hacked.

1

u/diamondkiller007 Apr 09 '24

Did you mean ‘entire domain facked?’

1

u/StConvolute Aug 25 '22

Fun fact (maybe?), the pass the hash technique was developed in 1997...

Also, most freshly deployed domains default to allow NTLMv1 for all connections. No password salting, super low cipher strength.

Anyway, in summary. I agree.

1

u/lerun Aug 25 '22

Yes, there is a big difference from being able to change everything in AD and all devices connected to it, to only change things on that one box.

Powershell is a powerfull tool and can do anything on windows it has access to. So always give the least amount of access for the task it is needed for.

1

u/BlackV Aug 25 '22

yes, it is a problem, those creds are now cached on that local machine, any malware/l337 haxor/etc now has a change to steal those creds

1

u/[deleted] Aug 25 '22

Mate I'm sorry to say this but if you can't tell the difference between local admin and domain admin then you really need intense training. Try the MD 100 or MD 101.