Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

A ball of Wool and NetCat


A ball of Wool and NetCat

By ghostghost | 19354 Reads |
0     0

A ball of Wool and NetCat

Introduction In this article i will go over some basic netcat commands and will use netcat with other programs to closely replicate other tools/services.

NOTE to Windows users: netcat comes standard with most Unix based systems, it is not provided with Windows. To download netcat for Windows, See Below.

The Basics netcat is a TCP/UDP connection tool, it can be used to connect to other computers and can be used to allow other computers to connect to your host.

Example 1.1 - to connect to HBH’s website, use the following command without quotes: “nc http://www.hellboundhackers.org/ 80” This will connect but will not return any data, to get HBH to return the index/home page type “GET /” with out the quotes and hit enter twice. SYNTAX: nc {REMOTE HOST NAME/IP} {PORT NUMBER} SYNTAX Extra: the -n option is needed to allow numeric addresses or ip addresses

Example 1.2 - to create and open port on you localhost, use the following command without quotes: “nc -l -p 2345” This will open port 2345 on your machine, you can connect to this port with the command from Example 1.1 (nc localhost 2345). You may wonder why I used port 2345, on Unix based systems ports 1-1024 can only be opened by root, where as ports above 1024 can be opened by normal users. Connecting to the port with the example above will not return any results, you can use CTRL+C to exit. SYNTAX: nc -l -p {PORT NUMBER} SYNTAX Extra: -l tells netcat to listen, -p is needed to assign a port number.

Simple Private Chat You may have noticed in the above example, if you type something in the terminal and hit enter, it gets echoed to the terminal listening for connections and the terminal connecting. This is a very simple way to setup a private chat session with your friends whether they are on your local LAN or on the Internet. Your friends don’t need to have netcat to connect to your host, they can use telnet.

Simple File Transfer To send a file across a network with netcat, you can use the command in Example 1.2 with a little extra sugar. Example 2.1: nc -l -p 2345 < newhbhchallengecode Explanation: Using Example 1.2 you create an open port, then using the redirection operator “<” newhbhchallengecode is send to port 2345. Example 2.2: cat newhbhchallengecode | nc -l -p 2345 Explanation: Using Example 1.2 you create an open port, then using the pipe operator “|” newhbhchallengecode is send to port 2345.

NOTE: Windows does not have the cat command, you will have to use the type command.

NOTE: You may think that straight after you hit enter, your command will start sending the data to the port, but netcat will wait until a connection is established before sending the data to the port.

To retrieve the data you can either use telnet or Example 1.1 with the redirection operator “>” and a filename. The filename can be anything you choose. Example 2.3: telnet localhost 2345 > hbhnewchallengecode Example 2.4: nc localhost 2345 > xyz

NOTE: The same above commands can be used to create a webserver, or bulletin board, or news server that serves one page.

NOTE: netcat will close after the first connection is completed, to keep netcat running you will have to create a program that loops the command. That is out side the scope of the article, and i don’t feel like giving an example in C,Perl,Python and PHP.

Adding some security Using OpenSSL you can encrypt your connections that only people with the correct password can access the data on the port. This can be used on all of the above Examples.

NOTE: BOTH host must have OpenSSL or an Equivalent Program.

Example 3.1: openssl enc -aes-128-cbc | nc -l -p 2345 SYNTAX: openssl enc {-CIPHER} Example 3.2: openssl enc -aes-128-cbc -in hbhsecretcode | nc -l -p 2345 SYNTAX: openssl enc {-CIPHER} -in {FILE TO ENCRYPT}

Connecting, and Retrieving Example 3.3: nc localhost 2345 | openssl enc -d -aes-128-cbc Example 3.4: nc localhost 2345 | openssl enc -d -aes-128-cbc -out hbhsecretcode Explanation: Giving OpenSSL -d will tell it to decrypt the data

Example 3.1 is Example 1.2 with encryption, and can also be used for private chat. Example 3.2 is Example 2.1 with encryption and can be used in the same way as you would use Example 2.1. You can add -a to the end of the openssl command (before the piping ‘|’ operator) to add base64 encoding. Remember if you encrypt it a certain way you need to decrypt it the same way.

If you don’t know what cipher commands you can use, the command below will display OpenSSL’s options. Example 3.5: openssl -

NOTE: All Commands can be used to listen or connect to a UDP port, by adding the -u to each netcat command. Keep in mind that telnet cannot connect to UDP ports.

Exercise: NetCat can also be used to setup telnet server, but i will leave that for you to figure out.

NetCat Manual: man netcat (Unix Only)

Download NetCat @ http://tinyurl.com/2rfwr

Comments
korg's avatar
korg 16 years ago

Goddamn internet hung on me, Sorry for double link.

Uber0n's avatar
Uber0n 16 years ago

@korg: Thanks for triple post :D (jk)

ghost's avatar
ghost 16 years ago

Net cat is neeeeeeeeeeett!

korg's avatar
korg 16 years ago

@Uber0n Technically it's only a double post. The last one is me bitching.

ghost's avatar
ghost 16 years ago

Meh.