-
Notifications
You must be signed in to change notification settings - Fork 119
/
autonse.sh
367 lines (363 loc) · 11.4 KB
/
autonse.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/usr/bin/env bash
# **********************************************
# AutoNSE - Massive NSE AutoSploit/AutoScanner *
# Momo Outaadi (M4ll0k) *
# https://github.com/m4ll0k/AutoNSE *
# **********************************************
# colors
r='\e[1;31m'
g='\e[1;32m'
y='\e[1;33m'
b='\e[1;34m'
c='\e[1;36m'
w='\e[0;38m'
e='\e[0m'
# vars
name='AutoNSE'
author='Momo Outaadi (m4ll0k)'
version='v0.1.0'
repo='https://github.com/m4ll0k'
description='AutoNSE - Massive NSE AutoSploit/AutoScanner'
# best port
exec_command='nmap -Pn --open -p 21,22,23,25,53,80,443,455,110,123,1521,389,143,3306,27017,5984'
function banner() {
clear
echo -e $w"-------------------------------------"$e
echo -e $r" _____ _ _____ _____ _____ "$e
echo -e $r"| _ |_ _| |_ ___| | | __| __|"$e
echo -e $r"| | | | _| . | | | |__ | __|"$e
echo -e $r"|__|__|___|_| |___|_|___|_____|_____|"$e
echo
echo -e $w"$description "$e
echo -e $w"$name - $version "$e
echo -e $w"$author "$e
echo -e $w"$repo "$e
echo -e $w"-------------------------------------"$e
echo
}
function user() {
if [ $(id -u) != "0" ]; then
echo -e "\n$r[!]$e Please run this script with root user!"
exit 1
fi
}
function connect() {
ping -c 1 -w 3 google.com > /dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e "\n$r[!]$e This script needs an active internet connection!"
exit 1
fi
}
function inmap() {
echo -e "$g[i]$e Installing nmap... please wait..."
apt-get install nmap > /dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e "\n$r[!]$e Nmap not installed... please try again or check your connection.."
exit 1
else
echo -e "\n$g[+]$e Nmap is installed..."
fi
}
function wnmap() {
which nmap > /dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e "\n$r[!]$e This script needs nmap!!"
inmap
fi
}
function check() {
banner
echo -ne $g"[+]$e Checking user..."
user;sleep 1;echo -e $g"\t\t[✔]"$e
echo -ne $g"[+]$e Checking connection..."
connect;sleep 1;echo -e $g"\t[✔]"$e
echo -ne $g"[+]$e Checking nmap..."
wnmap;sleep 1;echo -e $g"\t\t[✔]"$e
sleep 2
}
function exit_p() {
echo -e "$r[!]$e Exiting..."
sleep 1
exit 1
}
function nmap_path() {
path=$(whereis nmap | awk '{print $3}')
}
function search_nse() {
nmap_path
query=$1
echo -e "$b[+]$e Searching $1 nse..."
nse=$(ls "$path/scripts" |egrep -o "(^$query\S*)"|cut -d' ' -f4-|sort -b|tr '\n' ', ')
}
function scan_ftp() {
ip=$1;output=$2
echo -e $b"[*]$e Loading ftp nse scripts..."
search_nse 'ftp'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 21 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_ssh() {
ip=$1;output=$2
echo -e $b"[*]$e Loading ssh nse scripts..."
search_nse 'ssh'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 22 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_telnet() {
ip=$1;output=$2
echo -e $b"[*]$e Loading telnet nse scripts..."
search_nse 'telnet'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 23 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_smtp() {
ip=$1;output=$2
echo -e $b"[*]$e Loading smtp nse scripts..."
search_nse 'smtp'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 25 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_dns() {
ip=$1;output=$2
echo -e $b"[*]$e Loading dns nse scripts..."
search_nse 'dns'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 53 $output --script=$nse --script-args dns-brute.threads=5,dns-brute.hostlist=wordlist.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_http() {
ip=$1;output=$2
echo -e $b"[*]$e Loading http nse scripts..."
search_nse 'http'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 80 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_ssl() {
ip=$1;output=$2
echo -e $b"[*]$e Loading https/ssl nse scripts..."
search_nse 'ssl'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 443 $output --script=$nse $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_smb() {
ip=$1;output=$2
echo -e $b"[*]$e Loading smb nse scripts..."
search_nse 'smb'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 445 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_pop() {
ip=$1;output=$2
echo -e $b"[*]$e Loading pop3 nse scripts..."
search_nse 'pop3'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 110 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_ntp() {
ip=$1;output=$2
echo -e $b"[*]$e Loading ntp nse scripts..."
search_nse 'ntp'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 123 $output --script=$nse $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_imap() {
ip=$1;output=$2
echo -e $b"[*]$e Loading imap nse scripts..."
search_nse 'imap'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 143 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_mysql() {
ip=$1;output=$2
echo -e $b"[*]$e Loading mysql nse scripts..."
search_nse 'mysql'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 3306 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_mongodb() {
ip=$1;output=$2
echo -e $b"[*]$e Loading mongodb nse scripts..."
search_nse 'mongodb'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 27017 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_couchdb() {
ip=$1;output=$2
echo -e $b"[*]$e Loading couchdb nse scripts..."
search_nse 'couchdb'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 5984 $output --script=$nse $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scan_ldap() {
ip=$1;output=$2
echo -e $b"[*]$e Loading ldap nse scripts..."
search_nse 'ldap'
echo -e $b"[+]$e Found $(echo $nse|tr ',' '\n'|wc -l) scripts..."
exec_command="nmap -p 389 $output --script=$nse --script-args userdb=user.txt,passdb=pass.txt $ip "
echo -e $y"[i]$e Scanning... Please wait..."
echo -e $w"----------------------------------------------"$e
$exec_command
echo -e $w"----------------------------------------------"$e
}
function scanner() {
ip=$1;port=$2;output=$3
if [ $port == "21" ]; then
scan_ftp "$ip" "$output"
fi
if [ $port == "22" ]; then
scan_ssh "$ip" "$output"
fi
if [ $port == "23" ]; then
scan_telnet "$ip" "$output"
fi
if [ $port == "25" ]; then
scan_smtp "$ip" "$output"
fi
if [ $port == "53" ]; then
scan_dns "$ip" "$output"
fi
if [ $port == "80" ]; then
scan_http "$ip" "$output"
fi
if [ $port == "443" ]; then
scan_ssl "$ip" "$output"
fi
if [ $port == "445" ]; then
scan_smb "$ip" "$output"
fi
if [ $port == "110" ]; then
scan_pop "$ip" "$output"
fi
if [ $port == "123" ]; then
scan_ntp "$ip" "$output"
fi
if [ $port == "143" ]; then
scan_imap "$ip" "$output"
fi
if [ $port == "3306" ]; then
scan_mysql "$ip" "$output"
fi
if [ $port == "27017" ]; then
scan_mongodb "$ip" "$output"
fi
if [ $port == "5984" ]; then
scan_couchdb "$ip" "$output"
fi
if [ $port == "389" ]; then
scan_ldap "$ip" "$output"
fi
}
function ask() {
echo
echo -ne " $g[+]$e Output path >> "
read path
echo -ne " $g[+]$e Name of report >> "
read filename
echo -ne " $g[+]$e Target IP or Host >> "
read ip
echo
}
function start() {
clear
banner
echo -e " Select nmap output:\n"
echo -e " 1) Output scan in xml format"
echo -e " 2) Output scan in normal format"
echo -e " 3) Output scan in grepable format\n"
echo -e " 99) Exit"
echo
echo -n -e " AutoNSE@Sploit: ";tput sgr0
read input
if test $input == '1'; then
ask
scan="$exec_command $ip"
result=$($scan|grep -o '[0-9]\+/'|awk -F'[^0-9]' '{print $1}')
output="-oX $path/$filename.xml"
for i in ${result};do
echo -e "$g[+]$e Port $i is open.."
scanner "$ip" "$i" "$output"
done
fi
if test $input == '2'; then
ask
scan="$exec_command $ip"
result=$($scan|grep -o '[0-9]\+/'|awk -F'[^0-9]' '{print $1}')
output="-oN $path/$filename.txt"
for i in ${result};do
echo -e "$g[+]$e Port $i is open.."
scanner "$ip" "$i" "$output"
done
fi
if test $input == '3'; then
ask
scan="$exec_command $ip"
result=$($scan|grep -o '[0-9]\+/'|awk -F'[^0-9]' '{print $1}')
output="-oG $path/$filename.grep"
for i in ${result};do
echo -e "$g[+]$e Port $i is open.."
scanner "$ip" "$i" "$output"
done
fi
if test $input == '99'; then
exit_p
fi
}
# start
check
clear
start