Lab: Shellshock netcat
The goal of this step is to understand how netcat (nc) works.Step: 4
- Netcat is a program that helps developing and testing network programs.
- There are way too many options to discuss here, but we need this tool.
- A bit of background
- For the most part, every computer on the internet has an IP address.
- We can see this by typing
ifconfig - look for an entry like
inet addr: 10.0.2.15
- WRITE THIS DOWN, you will need it multiple times.
- This will be different on different machines.
- This number, 10.0.2.15 in this case identifies your machine.
- This is somewhat of a lie, but live with it for now.
- We can see this by typing
- In addition, each machine supports a number of network ports.
- Think of the ip address as a building.
- And the port as a room number.
- For the most part, httpd is on port 80
- https is on port 443
- Look at /etc/services for a standard list of ports.
- Ports below 1024 are special and usually locked.
- We will use port 9090 for our experiments.
- For the most part, every computer on the internet has an IP address.
- Netcat (nc) can act as either a "client" or a "server"
- Client demo
- Your machine is running a web server.
- We can talk to that web server using nc
- $ represents the prompt.
- 10.0.2.15 is the ip address of the local server.
- After the nc command type
GET index.html -
$ nc 10.0.2.15 80 GET index.html
- The first argument is the computer, the second is the port
- You will see a message that states you are not using http:2.0
- Server demo
- Start a second terminal
- Run the following command
-
nc -l 9090 -v - -l says listen for incoming connections on port 9090
- -v says to be verbose
- This starts netcat listening on port 9090 in verbose mode.
- In a different terminal run a client
-
nc localhost 9090 - or
nc 10.0.2.15 9090
-
- Notice you can type in the client window and it will be echoed on the server window.
- You can also type in the server window and it will be echoed on the client.
- Start a second terminal
- We will use nc in server mode later.