-
Notifications
You must be signed in to change notification settings - Fork 197
/
stop.sh
executable file
·76 lines (65 loc) · 2.77 KB
/
stop.sh
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
#!/bin/bash
# stop.sh
# Copyright (C) 2017 Joe Testa <jtesta@positronsecurity.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms version 3 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [[ `id -u` != 0 ]]; then
echo "Error: this script must be run as root."
exit -1
fi
if [[ (! -f /home/ssh-mitm/run.sh) || (! -f /home/ssh-mitm/bin/sshd_mitm) ]]; then
echo "Error: could not find sshd_mitm. You need to first run install.sh."
exit -1
fi
# Check if --force arg is present.
FORCE=0
if [[ ($# == 1) && ($1 == '--force') ]]; then
FORCE=1
fi
# If arpspoof or ettercap are running, stop. Disabling the forwarding
# configuration while still ARP spoofing would cause a denial of service...
ps ax | awk '{print $5}' | egrep 'arpspoof|ettercap' > /dev/null
if [[ ($? == 0) && ($FORCE != 1) ]]; then
echo -e "It looks like arpspoof or ettercap is still running. You need to stop it before running this script, otherwise you'll cause a denial-of-service for the ARP targets.\n\nOtherwise, if you know what you're doing, re-run this script with '--force'."
exit -1
else
echo "Forcing termination..."
fi
# Kill all processes belonging to the ssh-mitm user.
killall -u ssh-mitm 2> /dev/null
echo "Disabling IP forwarding in the kernel..."
echo 0 > /proc/sys/net/ipv4/ip_forward
# Check if the INPUT table has an ACCEPT for destination port 2222. If so,
# delete it.
iptables -nL INPUT | egrep "ACCEPT +tcp +-- +0\.0\.0\.0/0 +0\.0\.0\.0/0 +tcp dpt:2222" > /dev/null
if [[ $? == 0 ]]; then
echo "Executing: iptables -D INPUT -p tcp --dport 2222 -j ACCEPT"
iptables -D INPUT -p tcp --dport 2222 -j ACCEPT
if [[ $? != 0 ]]; then
echo "ERROR: failed to remove iptables rule!"
exit -1
fi
fi
# Check if the PREROUTING table has a REDIRECT for port 22 to 2222. If so,
# delete it.
iptables -t nat -nL PREROUTING | egrep "REDIRECT +tcp +-- +0\.0\.0\.0/0 +0\.0\.0\.0/0 +tcp dpt:22 redir ports 2222" > /dev/null
if [[ $? == 0 ]]; then
echo "Executing: iptables -t nat -D PREROUTING -p tcp --dport 22 -j REDIRECT --to-ports 2222"
iptables -t nat -D PREROUTING -p tcp --dport 22 -j REDIRECT --to-ports 2222
if [[ $? != 0 ]]; then
echo "ERROR: failed to remove iptables rule!"
exit -1
fi
fi
echo -e "\nSuccessfully stopped sshd_mitm daemon and disabled forwarding rules.\n"
exit 0