Lateral Movement & Pivoting
Common techniques used to move laterally across a Windows network.
Spawning Processes Remotely
Psexec
Ports: 445/TCP(SMB)
Required Group Memberships: Administrators
PSExec is the go-to for needing to execute a process remotely. PSExec is one of the Sys Internals tools. PSExec works as follows:
Connect and upload the PSEXEC service executable (PSEXESVC.exe)
Create and execute a service named PSEXESVC and associate this with C:\Windows\psexesvc.exe
Create named pipes to handle stdin/stdout/stderr.
To run PSExec, the administrator credentials for the remote host and the command you wish to run are required.
Remote Process Creation Using WinRM
Ports: 5985/TCP(WinRM HTTP) or 5986(WinRM HTTPS)
Required Group Memberships: Remote Management Users
Windows Remote Management is a web-based protocol for sending Powershell commands to hosts remotely, many Windows Server installations run this by default. The following command will connect to a remote Powershell session:
winrs.exe -u:Administrator -p:Password -r:target cmd
The same can be achieved with Powershell, however, to pass different credentials a PSCredential object will need to be created:
Remotely Creating Services Using SC
Ports: 135/TCP, 49152-65535/TCP (DCE/RPC) or 445/TCP (RPC over SMB Named Pipes) or 139/TCP (RPC over SMB Named Pipes)
Required Group Memberships: Administrators
Windows services can be used to run arbitrary commands, if a Windows service is configured to run an application, it will execute the application and fail afterwards. A service can be created on a remote host with sc.exe - a standard tool built into Windows.
When using sc, it will try to connect to the Service Control Manager (SVCCTL) remote service program through RPC in several ways:
A connection attempt is made using DCE/RPC. The client connects to the Endpoint Mapper (EPM) on port 135 which catalogues available RPC endpoints and requests information on the SVCCTL program. The EPM then responds with the IP and port to connect to SVCCTL, normally a dynamic port in the range of 49152-65535.
If the latter connection fails, it will try to reach SVCCTL via named SMB names pipes, on port 445 or 139.
The following commands would create a service called spooky:
Once the service starts, the net user command will execute, to stop and delete the service:
Creating Scheduled Tasks Remotely
Scheduled Tasks can be created and run remotely using schtasks, to create a task named Spooky:
Connecting to WMI from PowerShell
Before connecting to WMI (Windows Management Instrumentation) with PowerShell, a PSCredential object must be created with our username and password. This can be created as follows:
A WMI session can be created using one of the following protocols:
DCOM: RPC over IP using port 135/TCP and ports 49152/65535/TCP
Wsman: WinRM for connecting using ports 5985/TCP (WinRM HTTP) or 5986/TCP (WinRM HTTPS)
To establish a WMI session from PowerShell, we use the following:
Remote Process Creation Using WMI
Ports: 135/TCP, 49152-65535/TCP (DCERPC), 5985/TCP (WinRM HTTP) or 5986 (WinRM HTTPS)
Required Group Memberships: Administrators
A process can be remotely spawned from PowerShell by leveraging WMI, sending a WMI request to the Win32_Process class to spawn the process under the session we created before:
WMI won't let you see the output of any command and will create the required process silently, on legacy systems, this can be done from CMD with WMIC:
Creating Services Remotely with WMI
Ports: 135/TCP, 49152-65535/TCP (DCERPC), 5985/TCP (WinRM HTTP) or 5986/TCP (WinRM HTTPS)
Required Group Memberships: Administrators
To create a service called "contrxl":
Then, we can handle the service and start it using:
Finally, the service can be stopped and deleted with:
Creating Scheduled Tasks Remotely with WMI
Ports: 135/TCP, 49152-65535/TCP (DCERPC), 5985/TCP (WinRM HTTP) or 5986/TCP (WinRM HTTPS)
Required Group Memberships: Administrators
To create and execute a scheduled task:
And then to delete the task once done:
Installing MSI Packages Through WMI
Ports: 135/TCP, 49152-65535/TCP (DCERPC), 5985/TCP (WinRM HTTP) or 5986/TCP (WinRM HTTPS)
Required Group Memberships: Administrators
If an MSI package is copied to the target system, WMI can be used to attempt to install it using:
This can be achieved on legacy systems with:
Use of Alternate Authentication Material
Alternate authentication material refers to a piece of data which can be used to access a Windows account without the password. This is possible because of how some Windows authentication protocols work like NTLM and Kerberos.
NTLM authentication works as follows:
Client sends authentication request to the server they want to access
Server generates a random number and sends it as a challenge to the client
Client combines his NTLM password hash with challenge (and other known data) to generate a response to the challenge and sends it back to the server for verification.
Server forwards both the challenge and response to the Domain Controller for verification
Domain Controller uses the challenge to recalculate the response and compares it to the initial client request. If they match, the client is authenticated, otherwise access is denied.
The server forwards the authentication result to the client.
Pass-the-Hash
When extracting credentials from a host where we have administrative privileges we may end up with non-cracked NTLM hashes. These can be used in a pass-the-hash attack to successfully authenticate without the actual password. Hash extraction can be performed using something like mimikatz to read the local SAM or extract hashes from LSASS.
Last updated