Lecture07A Netcat Swiss ArmyKnife
Lecture07A Netcat Swiss ArmyKnife
■ Netcat overview
■ Establishing raw data connections
■ Grabbing Server Banners
■ Transferring files
2
Netcat overview
■ Netcat is nicknamed Swiss army knife among networking
tools.
■ Netcat can accomplish many networking tasks such as:
▬ Establishing raw data connections
▬ Banner grabbing
▬ Transferring files
▬ Scanning ports
▬ Binding shells, and much more …
■ In this lecture, we'll focus on the first three, and we'll talk
more about netcat in future lectures.
3
Establishing raw data connection
■ The following command is used to establish a TCP
connection with given host and port, and then send and
receive raw data:
▬ nc <ip address> <port>
■ Notes:
▬ In Linux, 'nc' and 'netcat' are equivalent command names for netcat.
They are linked to the same executable.
▬ Netcat has several variants.
o A popular variant comes together with nmap installation. It uses the
command name 'ncat'.
o However, 'ncat' is very heavy-weight although it is more powerful. In
hacking, 'nc' is generally preferred due to its small footprint.
4
Raw connection example: FTP
■ If we connect to the FTP server at our Win7 VM:
■ We see that the FTP server will display a banner message upon
accepting the connection.
▬ Many servers have similar behaviour.
▬ A banner typically discloses the service name and sometimes the software
version number.
6
Continued raw connection example: FTP
■ If you know the commands in FTP protocol such as 'user', 'pass', 'pwd',
etc., you can type the raw FTP messages into the connection:
■ The above shows that nc sends/receives raw data to/from the other
party.
▬ To use this feature to play with a protocol, you need to know the message formats
of that protocol.
7
Raw connection example: SMTP
■ If you connect to the Email server at port 25 on Metasploitable2:
8
File transfers
■ ‘nc’ can also be used to transfer files between two computers.
■ Method 1:
▬ Start nc in server mode at R to receive the file.
▬ Start nc in client mode at S to send the file.
■ Method 2:
▬ Start nc in server mode at S to send the file.
▬ Start nc in client mode at R to receive the file.
The '>' operator in the command line is used to redirect the output
to a file. I.e., if you are writing the content into a file, use '>'.
You should always start the server mode 'nc' first; otherwise, when the
client mode 'nc' is started, no server mode 'nc' is waiting for it !!
11
File transfer (Method 1, cont'd)
Step 2. In Kali VM, 'cd' the directory where the file is stored, then run:
13
File transfer (Method 2)
For the same file transfer, you can also do it in another way, that is,
running nc in server mode in the Kali VM.
Step 1. In Kali VM, 'cd' the directory where the file is stored,
then run:
14
File transfer (Method 2)
Step 2. In Win7 VM, cd the directory where the file is to be
uploaded, then run:
nc 192.168.137.128 2222 > open_me.pdf
NB: the port number in client mode should match that one in the server
mode.
15
File transfer (Method 2)
Step 3. Finally, in Win7 VM, you should see:
16