-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathplunderbug.sh
executable file
·211 lines (186 loc) · 5.49 KB
/
plunderbug.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
# Plunder Bug
# (C) Hak5 2019
#
# Bash mute script that manages iptables for the bug interface
# used to prevent the capture host from sending data over the wire the bug is tapping
OS=0
function banner(){
echo " ###########################################"
echo " # | \ / Plunder Bug by Hak5 #"
echo " # \ O.o #"
echo " # ( _ )\ Bug Interface Mute Script #"
echo " # '' ''¿ #"
echo " ###########################################"
}
function usage() {
echo "Usage: sudo ./plunderbug.sh"
echo " --mute Mute plunder bug interface and exit"
echo " --unmute Unmute plunder bug interface and exit"
}
function iptables_check() {
if [[ -z $(which iptables) ]]; then
echo "iptables required to mute interface"
fi
}
function os_check() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "\nOSX Detected\n"
OS=1
elif [[ "$OSTYPE" == "cygwin" ]]; then
err "Cygwin not supported"
else
OS=0
iptables_check
fi
}
function micdrop(){
echo "Exited"
exit $1
}
function err() {
echo "[FATAL] $1"
QUIT=1
micdrop 1
}
function root_check() {
if [[ "$EUID" -ne 0 ]]; then
echo "Please re-run as root"
usage
micdrop 1
fi
}
function wait_for_bug_connection() {
printf "%s" 'Waiting for a plunder bug to be connected...'
while [[ -z $IFACE ]]; do
printf "%s" .
if [[ "$OS" -eq 1 ]]; then
IFACE=$(ifconfig | grep 00:13:37 -B2 | head -1 | awk {'print $1'} | sed 's/ *:.*//')
else
IFACE=$(find /sys/class/net -mindepth 1 -maxdepth 1 ! -name lo -printf "%P " -execdir cat {}/address \; | grep "00:13:37" | cut -d " " -f1)
fi
sleep 1
done
echo -e "\n\n[$IFACE] Plunder Bug connected\n"
}
function check_ip6tables_rule_exists(){
if [[ -z $(ip6tables -vL|grep $IFACE) ]];then
echo 1
else
echo 0
fi
}
function add_rule_to_ip6tables() {
pre_existing_rule=$(check_ip6tables_rule_exists)
if [[ "$pre_existing_rule" -eq 1 ]];then
printf "\t%s" "[+] Adding ip6tables rule..."
ip6tables -A OUTPUT -o $IFACE -j DROP && echo "Success" || err "failed to add rule to ip6tables"
else
echo "IPv6 Mute rule already exists on system..."
fi
}
function check_iptables_rule_exists(){
if [[ -z $(iptables -vL|grep $IFACE) ]];then
echo 1
else
echo 0
fi
}
function add_rule_to_iptables() {
pre_existing_rule=$(check_iptables_rule_exists)
if [[ "$pre_existing_rule" -eq 1 ]];then
printf "\t%s" "[+] Adding iptables rule..."
iptables -A OUTPUT -o $IFACE -j DROP && echo "Success" || err "failed to add rule to iptables"
else
echo "IPv4 Mute rule already exists on system..."
fi
}
function remove_rule_from_ip6tables() {
pre_existing_rule=$(check_ip6tables_rule_exists)
if [[ "$pre_existing_rule" -eq 0 ]];then
printf "\t%s" "[-] Removing ip6tables rule..."
ip6tables -D OUTPUT -o $IFACE -j DROP && echo "Success" || err "failed to remove ip6tables rule"
else
echo "IPv6 Mute rule already removed from system..."
fi
}
function remove_rule_from_iptables() {
pre_existing_rule=$(check_iptables_rule_exists)
if [[ "$pre_existing_rule" -eq 0 ]];then
printf "\t%s" "[-] Removing iptables rule..."
iptables -D OUTPUT -o $IFACE -j DROP && echo "Success" || err "failed to remove iptables rule"
else
echo "IPv4 Mute rule already removed from system..."
fi
}
function disable_interface_in_networksetup() {
BUGIFACE=$(ifconfig | grep 00:13:37 -B2 | head -1 | awk {'print $1'} | sed 's/ *:.*//')
if [[ -n "$BUGIFACE" ]]; then
BUGIFACENAME=$(networksetup -listnetworkserviceorder | grep $BUGIFACE -B1 | head -1 | sed 's/(.*)//' | cut -c2-)
networksetup -setv4off "$BUGIFACENAME" || err "error disabling ipv4 on bug interface"
networksetup -setv6off "$BUGIFACENAME" || err "error disabling ipv6 on bug interface"
fi
}
function enable_interface_in_networksetup(){
BUGIFACE=$(ifconfig | grep 00:13:37 -B2 | head -1 | awk {'print $1'} | sed 's/ *:.*//')
if [[ -n "$BUGIFACE" ]]; then
BUGIFACENAME=$(networksetup -listnetworkserviceorder | grep $BUGIFACE -B1 | head -1 | sed 's/(.*)//' | cut -c2-)
networksetup -setdhcp "$BUGIFACENAME" || err "error enabling ipv4 on bug interface"
networksetup -setv6automatic "$BUGIFACENAME" || err "error enabling ipv6 on bug interface"
fi
}
function mute(){
echo "[*] Muting plunder bug interface..."
if [[ "$OS" -eq 0 ]]; then
add_rule_to_iptables
add_rule_to_ip6tables
elif [[ "$OS" -eq 1 ]];then
disable_interface_in_networksetup
fi
echo -e "[*] Mute complete\n"
}
function unmute() {
echo "[*] Unmuting plunder bug interface... $IFACE"
if [[ "$OS" -eq 0 ]]; then
remove_rule_from_iptables
remove_rule_from_ip6tables
elif [[ "$OS" -eq 1 ]];then
enable_interface_in_networksetup
fi
echo -e "[*] Unmute complete\n"
QUIT=1
}
function cleanup() {
echo -e "\n[!] Cleaning up..."
unmute
}
##########################
# MAIN ENTRY
##########################
QUIT=0
# Validate args
banner
# Validate priv / iptables
root_check
os_check
if [[ -z "$2" ]]; then
# Wait for device to be connected - no arg supplied for --mute/--unmute
wait_for_bug_connection
else
# Arg given for --mute/--unmute
IFACE=$2
fi
# Handle modes
if [[ "$1" = "--unmute" ]]; then
cleanup
micdrop 0
elif [[ "$1" = "--mute" ]]; then
mute
micdrop 0
else
usage
micdrop 1
fi
# Wait for bug to be unplugged/ctrl-c - cleanup and exit
trap cleanup INT
micdrop 0