Wednesday, July 9, 2008

netcat

1)Port Scanning

netcat can also be used for port scanning (with zero-I/O option).

Code:

nc -v -z www.kernel.org 80 21

# or with port ranges

nc -v -z www.kernel.org 21-23


2. Remote Terminal

This example shows how to connect to a remote shell without using telnet or ssh. The terminal server which runs on :

Code:

nc -l -p 4000 -e /bin/sh

and the client :

Code:

nc 4000


3) File Transfer


Lets say you want to transfer a big zip file from machine A to machine B but neither one has FTP, and using email or IM is out of the question due to file size, or other restrictions. What do you do? You can use netcat as a makeshift file transfer software.

On machine B do the following, where 1337 is some unused port on which you want to send the file:

nc -lp 1337 > file.zipAssuming that the IP of machine B is 10.48.2.40 go to machine A and do:

nc -w 1 10.48.2.40 1337 < file.zip Thats it. The file will be magically transfered over the network socket.


4)Chat Server

Have you even needed an improvised one-on-one chat? Netcat can do that too. You simply start listening to connections on some port like this:

nc -lp 1337 Then on another machine simply connect to that port:

nc 10.48.2.40 1337 Now start typing on either machine. When you press enter, the line will immediately show up on the other machine.

OR

nc -l -n -v -p 555

on remote machine nc xxx.xxx.xxx.xxx [PORT]





5)Telnet Server

Nectat can also be used to set up a telnet server in a matter of seconds. You can specify the shell (or for that matter any executable) you want netcat to run at a successful connection with the -e parameter:

nc -lp 1337 -e /bin/bash On windows you can use:

nc -lp 1337 -e cmd.exeThen on a client machine simply connect to port 1337 and you will get full access to the shell, with the permissions of the user who ran nc on the server.


6 Web Server

I think this is my favorite trick. Did you ever need to set up simple makeshift webserver that would serve a single page? I know I did. In the past when my web server at work melted down, I set up laptop with this simple script:

while true; do nc -l -p 80 -q 1 < error.html; done

The error.html page was just a very simple error message notifying our users about the outage, and giving them an estimate of when it would be fixed. It took me 3 minutes to set up, and probably saved us many angry support calls.


source:- http://www.terminally-incoherent.com/blog/2007/08/07/few-useful-netcat-tricks/

No comments:

Post a Comment