1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #!/bin/bash
- # trigger.sh
-
- myip() {
- ip addr \
- | grep 192 \
- | sed 's/^ *//' \
- | cut -d\ -f 2 \
- | cut -d/ -f 1
- }
-
- user=joe
- use_tcpdump=true
- use_nc_proxy=false
- delay=2
- verbose=false
- out=out/$(date +%Y%m%d-%H%M%S)
- srv_port=1234
- srv_host=$(myip)
-
-
- while true ; do
- case "$1" in
- -o) out="$2"; shift 2
- ;;
- -u) user="$2"; shift 2
- ;;
- -h) srv_host="$2"; shift 2
- ;;
- -p) srv_port="$2"; shift 2
- ;;
- -P) pxy_port="$2"; shift 2
- ;;
- -d) delay="$2"; shift 2
- ;;
- -t) use_tcpdump=true; shift 1
- ;;
- -T) use_tcpdump=false; shift 1
- ;;
- -n) use_nc_proxy=true; shift 1
- ;;
- -N) use_nc_proxy=false; shift 1
- ;;
- -v) verbose=true; shift 1
- ;;
- --) shift 1
- break;
- ;;
- *) break;
- ;;
- esac
- done
-
-
- tmp=$(mktemp -d)
- mkdir -p $out
-
- start_tcpdump() {
- local pcap=$out/traffic.pcap
- echo starting tcpdump
- yum -q -y install tcpdump &>/dev/null
- tcpdump -i any -w $pcap "port $srv_port" \
- &
- }
-
- start_nc_proxy() {
- local pxy_port=$(($srv_port - 1))
- local back=$tmp/back
- local sent=$out/sent
- local rcvd=$out/rcvd
- echo starting proxy
- mkfifo $back
- cat < $back \
- | nc -k -l -p $pxy_port \
- | tee $sent \
- | nc $srv_host $srv_port \
- | tee $rcvd \
- > $back \
- &
- }
-
- trigger() {
- echo adding + removing $user
- useradd $user
- userdel -r $user
- }
-
- $use_tcpdump && start_tcpdump
- $use_nc_proxy && start_nc_proxy
-
- sleep $delay
-
- trigger
-
- echo cleaning up
- $use_nc_proxy && killall ncat
- $use_tcpdump && killall tcpdump
- rm -rf $tmp
|