原贴:http://cb.vu/unixtoolbox.xhtml#ssh
You might need to use the command
Netcat
Netcat http://netcat.sourceforge.net (nc) is better known as the "network Swiss Army Knife", it can manipulate, create or read/write TCP/IP connections. Here some useful examples, there are many more on the net, for example g-loaded.eu[...] http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples and here http://www.terminally-incoherent.com/blog/2007/08/07/few-useful-netcat-tricks.You might need to use the command
netcat
instead of
nc
. Also see the similar command
socat.
File transfer
Copy a large folder over a raw tcp connection. The transfer is very quick (no protocol overhead) and you don't need to mess up with NFS or SMB or FTP or so, simply make the file available on the server, and get it from the client. Here 192.168.1.1 is the server IP address.server# tar -cf - -C VIDEO_TS . | nc -l -p 4444 # Serve tar folder on port 4444 client# nc 192.168.1.1 4444 | tar xpf - -C VIDEO_TS # Pull the file on port 4444 server# cat largefile | nc -l 5678 # Server a single file client# nc 192.168.1.1 5678 > largefile # Pull the single file server# dd if=/dev/da0 | nc -l 4444 # Server partition image client# nc 192.168.1.1 4444 | dd of=/dev/da0 # Pull partition to clone client# nc 192.168.1.1 4444 | dd of=da0.img # Pull partition to file
Other hacks
Specially here, you must know what you are doing.Remote shell
Option -e only on the Windows version? Or use nc 1.10.# nc -lp 4444 -e /bin/bash # Provide a remote shell (server backdoor) # nc -lp 4444 -e cmd.exe # remote shell for Windows
Emergency web server
Serve a single file on port 80 in a loop.# while true; do nc -l -p 80 < unixtoolbox.xhtml; done
Chat
Alice and Bob can chat over a simple TCP socket. The text is transferred with the enter key.alice# nc -lp 4444 bob # nc 192.168.1.1 4444