## 下面这几行检查参数输入情况 test "$3" && echo "too many args" && exit 1 test ! "$1" && echo "no args?" && exit 1 me=`echo $0 | sed 's+.*/++'` test "$me" = "nzp" && echo '[compressed mode]'
# if second arg, it's a host to send an [extant] file to. if test "$2" ; then test ! -f "$1" && echo "can't find $1" && exit 1 if test "$me" = "nzp" ; then compress -c < "$1" | nc -v -w 2 $2 $MYPORT && exit 0 else nc -v -w 2 $2 $MYPORT < "$1" && exit 0 fi echo "transfer FAILED!" exit 1 fi
# 是否在接收文件机器当前目录有同名文件 if test -f "$1" ; then echo -n "Overwrite $1? " read aa test ! "$aa" = "y" && echo "[punted!]" && exit 1 fi # 30 seconds oughta be pleeeeenty of time, but change if you want. if test "$me" = "nzp" ; then # 注意这里nc的用法,结合了重定向符号和管道 nc -v -w 30 -p $MYPORT -l < /dev/null | uncompress -c > "$1" && exit 0 else nc -v -w 30 -p $MYPORT -l < /dev/null > "$1" && exit 0 fi echo "transfer FAILED!" # clean up, since even if the transfer failed, $1 is already trashed rm -f "$1" exit 1
这样的话,我只要在A机器上先 QuackA# ncp ../abcd listening on [any] 23456 ... 然后在另一台机器B上 QuackB#ncp abcd 192.168.0.2 quackb [192.168.0.1] 23456 (?) A机上出现 open connect to [192.168.0.2] from quackb [192.168.0.1] 1027 # 查看一下,文件传输完毕。
#! /bin/sh ## launch a whole buncha shit at yon victim in no particular order; capture ## stderr+stdout in one place. Run as root for rservice and low -p to work. ## Fairly thorough example of using netcat to collect a lot of host info. ## Will set off every intrusion alarm in existence on a paranoid machine!