Run as SYSTEM using Evil-WinRM
This is a quick blog post on how to elevate to SYSTEM without the need for PSEXEC when you are using PowerShell, or more specifcially in this case, PowerShell Remoting (WinRM).
First off, let me introduce my tool of choice here. It’s Evil-WinRM. I spoke about it in the Practical Exploitation video here: https://www.youtube.com/watch?v=tVgJ-9FJKxE, so I won’t go too far indepth. It’s essentially the only WinRM tool that I’ve found to work well in a non-Windows native situation (also you can proxy it through proxychains which is AWESOME!!).
Anyways.
I want to document how to run commands as SYSTEM without the use of PSEXEC. I found this technique on a 4sysops blog post called Running PowerShell Remotely As System with Invoke-CommandAs. Side-note you should definitely bookmark thier blog it’s great.
Invoke-CommandAs is not a native function of PowerShell, so you need to download it from the original author’s Github repo: https://github.com/mkellerman/Invoke-CommandAs
For our uses all you need to do is get these two particular files:
- https://github.com/mkellerman/Invoke-CommandAs/blob/master/Invoke-CommandAs/Public/Invoke-CommandAs.ps1
- https://github.com/mkellerman/Invoke-CommandAs/blob/master/Invoke-CommandAs/Private/Invoke-ScheduledTask.ps1
Here you can see me putting those two files into a scripts
directory I made inside of the Evil-WinRM folder. (git clone https://github.com/Hackplayers/evil-winrm
+ bundle install
)
|
|
Once that’s ready, I run Evil-WinRM with the -s
flag and specify the scripts
directory I put the two files in.
|
|
Once I have the shell I load each of the scripts by typing out their file names (tab complete should work)
|
|
Once they are loaded you need to run the menu
command to load the functions into memory on the attackers side. I haven’t looked at the code enough to know exactly why this is needed, but it doesn’t seem to work if you don’t.
|
|
As we can see both of the needed functions are loaded and we can finally issue our commands as SYSTEM with the -AsSystem
flag and the command being whoami
:
|
|