-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewrite.sh
More file actions
executable file
·94 lines (73 loc) · 2.29 KB
/
Copy pathrewrite.sh
File metadata and controls
executable file
·94 lines (73 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
DEBUG=false
INT_OUT_FILE_NAME="yturewrite_output_intermediate.pcap"
INT_CACHE_FILE_NAME="yturewrite_output_intermediate_cache.cache"
INT_FINAL_OUT_FILE_NAME="yturewrite_output_intermediate_2.pcap"
for i in "$@"
do
case $i in
-h*|--help*)
printf "Usage: Please edit rewrite_config.conf for options."
;;
-v*|--verbose*)
DEBUG=true
shift #past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source rewrite_config.conf
if [ -z "$DEST_ALIAS" ]; then
echo "Missing destination IP."
exit 0
fi
if [ -z "$ETH_ALIAS" ]; then
echo "Missing ethernet alias."
exit 0
fi
if [ -z "$FILE_NAME" ]; then
echo "Missing pcap file name."
exit 0
fi
sourceMacAddress=$(cat /sys/class/net/$ETH_ALIAS/address)
sourceIPAddress=$(ifconfig | awk '/inet addr/{print substr($2,6)}' | head -1)
ping $DEST_ALIAS -c 1
destinationMacAddress=$(arp -a | sed -n -e /^$DEST_ALIAS/p | grep -o -E -m -1 '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | head -1)
destinationIPAddress=$(arp -a | sed -n -e /^$DEST_ALIAS/p | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)
echo "Detected source MAC:$sourceMacAddress"
echo "Detected source IP:$sourceIPAddress"
echo "Detected destination Mac Address:$destinationMacAddress"
echo "Detected destination IP Address:$destinationIPAddress"
if $DEBUG ;
then
echo "Running tcprewrite to convert MAC addresses.."
fi
tcprewrite --enet-dmac=$destinationMacAddress --enet-smac=$sourceMacAddress --infile=$FILE_NAME --outfile=$INT_OUT_FILE_NAME
if $DEBUG ;
then
echo 'Running tcpprep..'
fi
tcpprep --auto=bridge --pcap=$FILE_NAME --cachefile=$INT_CACHE_FILE_NAME
if $DEBUG ;
then
echo 'Running tcprewrite to convert IP addresses..'
fi
tcprewrite --endpoints=$sourceIPAddress:$destinationIPAddress --cachefile=$INT_CACHE_FILE_NAME --infile=$INT_OUT_FILE_NAME --outfile=$INT_FINAL_OUT_FILE_NAME --skipbroadcast
if $DEBUG ;
then
echo 'Removing unncessesary files'
fi
rm $INT_OUT_FILE_NAME
rm $INT_CACHE_FILE_NAME
if $DEBUG ;
then
echo 'Running tcpreplay to broadcast..'
fi
tcpreplay --loop=$TCPREPLAY_LOOP --intf1=$ETH_ALIAS --mbps=$TCPREPLAY_SPEED yturewrite_output_intermediate_2.pcap