Skip to content

Commit de43aea

Browse files
author
HackTricks News Bot
committed
Add content from: Research Update Enhanced src/windows-hardening/lateral-movem...
1 parent cb894fc commit de43aea

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

  • src/windows-hardening/lateral-movement

src/windows-hardening/lateral-movement/winrm.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,51 @@ stdout, stderr, rc = client.execute_cmd("whoami /all")
124124
print(stdout, stderr, rc)
125125
```
126126

127+
128+
If you need finer control than the high-level `Client` wrapper, the lower-level `WSMan` + `RunspacePool` APIs are useful for two common operator problems:
129+
130+
- forcing **`WSMAN`** as the Kerberos service/SPN instead of the default `HTTP` expectation used by many PowerShell clients;
131+
- connecting to a **non-default PSRP endpoint** such as a **JEA** / custom session configuration instead of `Microsoft.PowerShell`.
132+
133+
```python
134+
from pypsrp.wsman import WSMan
135+
from pypsrp.powershell import PowerShell, RunspacePool
136+
137+
wsman = WSMan(
138+
"srv01.domain.local",
139+
auth="kerberos",
140+
ssl=False,
141+
negotiate_service="WSMAN",
142+
)
143+
144+
with wsman, RunspacePool(wsman, configuration_name="MyJEAEndpoint") as pool, PowerShell(pool) as ps:
145+
ps.add_script("whoami; Get-Command")
146+
output = ps.invoke()
147+
print(output)
148+
```
149+
150+
### Custom PSRP endpoints and JEA matter during lateral movement
151+
152+
A successful WinRM authentication does **not** always mean you land in the default unrestricted `Microsoft.PowerShell` endpoint. Mature environments may expose **custom session configurations** or **JEA** endpoints with their own ACLs and run-as behavior.
153+
154+
If you already have code execution on a Windows host and want to understand what remoting surfaces exist, enumerate the registered endpoints:
155+
156+
```powershell
157+
Get-PSSessionConfiguration | Select-Object Name, Permission
158+
```
159+
160+
When a useful endpoint exists, target it explicitly instead of the default shell:
161+
162+
```powershell
163+
Enter-PSSession -ComputerName srv01.domain.local -ConfigurationName MyJEAEndpoint
164+
```
165+
166+
Practical offensive implications:
167+
168+
- A **restricted** endpoint can still be enough for lateral movement if it exposes just the right cmdlets/functions for service control, file access, process creation, or arbitrary .NET / external command execution.
169+
- A **misconfigured JEA** role is especially valuable when it exposes dangerous commands such as `Start-Process`, broad wildcards, writable providers, or custom proxy functions that let you escape the intended restrictions.
170+
- Endpoints backed by **RunAs virtual accounts** or **gMSAs** change the effective security context of the commands you run. In particular, a gMSA-backed endpoint can provide **network identity on the second hop** even when a normal WinRM session would hit the classic delegation problem.
171+
127172
## Windows-native WinRM lateral movement
128173

129174
### `winrs.exe`
@@ -135,6 +180,16 @@ winrs -r:srv01.domain.local cmd /c whoami
135180
winrs -r:https://srv01.domain.local:5986 -u:DOMAIN\\user -p:Password123! hostname
136181
```
137182

183+
Two flags are easy to forget and matter in practice:
184+
185+
- `/noprofile` is often required when the remote principal is **not** a local administrator.
186+
- `/allowdelegate` enables the remote shell to use your credentials against a **third host** (for example, when the command needs `\\fileserver\share`).
187+
188+
```cmd
189+
winrs -r:srv01.domain.local /noprofile cmd /c set
190+
winrs -r:srv01.domain.local /allowdelegate cmd /c dir \\fileserver.domain.local\share
191+
```
192+
138193
Operationally, `winrs.exe` commonly results in a remote process chain similar to:
139194

140195
```text
@@ -184,15 +239,18 @@ For multi-hop constraints after landing a first WinRM session, check:
184239

185240
- **Interactive PowerShell remoting** usually creates **`wsmprovhost.exe`** on the target.
186241
- **`winrs.exe`** commonly creates **`winrshost.exe`** and then the requested child process.
242+
- Custom **JEA** endpoints may execute actions as **`WinRM_VA_*`** virtual accounts or as a configured **gMSA**, which changes both telemetry and second-hop behavior compared to a normal user-context shell.
187243
- Expect **network logon** telemetry, WinRM service events, and PowerShell operational/script-block logging if you use PSRP rather than raw `cmd.exe`.
188244
- If you only need a single command, `winrs.exe` or one-shot WinRM execution may be quieter than a long-lived interactive remoting session.
189245
- If Kerberos is available, prefer **FQDN + Kerberos** over IP + NTLM to reduce both trust issues and awkward client-side `TrustedHosts` changes.
190246

191247
## References
192248

193-
- [Evil-WinRM README](https://github.com/Hackplayers/evil-winrm)
249+
- [Microsoft: JEA Security Considerations](https://learn.microsoft.com/en-us/powershell/scripting/security/remoting/jea/security-considerations?view=powershell-7.6)
250+
- [pypsrp README](https://github.com/jborean93/pypsrp)
194251
- [Microsoft: Error `0x80090322` when connecting PowerShell to a remote server via WinRM](https://learn.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/error-0x80090322-when-connecting-powershell-to-remote-server-via-winrm)
195252

253+
196254
{{#include ../../banners/hacktricks-training.md}}
197255

198256

0 commit comments

Comments
 (0)