This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
netass2.bash
477 lines (458 loc) · 16.4 KB
/
netass2.bash
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#!/bin/bash
function AsciiPrint() {
echo ""
echo " __ _ _ ____ "
echo " /\ \ \___| |_ / \ ___ ___|___ \ "
echo " / \/ / _ \ __|/ O \/ __/ __| __) | "
echo " / /\ / __/ |_/ _ \__ \__ \/ __/ "
echo " \_\ \/ \___|\__\_/ \_/___/___/_____\ "
echo " Network Assessment Assistance "
echo ""
}
function BannerPrint() {
echo ' ------------------------------------------ '
echo ' | NAME : Network Assessment Assistance | '
echo ' | ALIAS : NetAss2 | '
echo ' | TYPE : VA Framework | '
echo ' | VERS : 0.1-RC | '
echo ' | LICEN : GPL v3 | '
echo ' | LINK : github.com/zerobyte-id/NetAss2 | '
echo ' ------------------------------------------ '
}
if [[ $(whoami) != "root" ]]; then
echo " ERROR: Please run as root"
exit
elif [[ -z $(command -v nmap) ]]; then
echo " ERROR: \"nmap\" tool not found"
echo " HINT: Please install nmap first"
exit
elif [[ -z $(command -v zmap) ]]; then
echo " ERROR: \"zmap\" tool not found"
echo " HINT: Please install zmap first"
exit
elif [[ ! -z $(cat /etc/zmap/zmap.conf | grep ^"blacklist-file") ]]; then
echo " ERROR: Please turn off zmap \"blacklist\""
echo " HINT: Remove \"blacklist-file\" in /etc/zmap/zmap.conf"
exit
fi
if [[ -d /opt ]]; then
if [[ ! -d /opt/NetAss2 ]]; then
mkdir /opt/NetAss2
fi
fi
if [[ -d /opt ]]; then
if [[ ! -d /opt/NetAss2/project ]]; then
mkdir /opt/NetAss2/project
fi
fi
while true
do
echo ""
BannerPrint
echo ""
echo -ne " Enter a project name: "
read PROJECT
echo ""
if [[ -d /opt/NetAss2/project/${PROJECT} ]]; then
echo " ERROR: Project already exist"
else
mkdir /opt/NetAss2/project/${PROJECT}
break
fi
done
echo " --------------------------------------------------"
while true
do
AsciiPrint
echo " [1]. HOST DISCOVERY"
echo " [2]. PORT SCAN ON SINGLE HOST"
echo " [3]. MASSIVE PORT SCAN VIA DISCOVERED HOSTS"
echo " [4]. MASSIVE PORT SCAN VIA LIST ON FILE"
echo " [5]. SINGLE PORT QUICK SCAN VIA NETWORK BLOCK"
echo " [6]. MULTIPLE PORT QUICK SCAN VIA NETWORK BLOCK"
echo " [!]. SHOW REPORTS"
echo " [0]. EXIT"
echo ""
echo -ne " INPUT: "
read MENU
echo ""
if [[ ${MENU} == 1 ]]; then
echo " ----------------[ HOST DISCOVERY ]----------------"
echo ""
if [[ ! -z $(ip a | grep 'inet ' | grep -v ' lo'$ | awk '{print $2}') ]]; then
echo " NOTE: Your network block reminder"
for NETBLOCK in $(ip a | grep 'inet ' | grep -v ' lo'$ | awk '{print $2}')
do
echo " + ${NETBLOCK}"
done
echo ""
fi
echo " NOTE: Enter the network block that you want to scan"
echo " NOTE: Example: 192.168.1.0/24"
echo -ne " INPUT: "
read NETWORK
if [[ -z ${NETWORK} ]]; then
echo " ERROR: Please input network block"
elif [[ -z $(echo ${NETWORK} | grep -E "^([0-9]{1,3}[\.]){3}[0-9]{1,3}[/][0-9]{1,2}$") ]]; then
echo " ERROR: Please input valid network block"
else
if [[ -f host-discover.na2out ]]; then
rm host-discover.na2out
fi
echo " INFO: Nmap run..."
echo " INFO: Discovering host..."
nmap -sn -T5 ${NETWORK} -o nmap-host.na2out &> /dev/null
if [[ $(cat nmap-host.na2out | grep -i 'Nmap scan report for' | awk '{print $5}' | wc -l) -ge 1 ]]; then
cat nmap-host.na2out | grep -i 'Nmap scan report for' | awk '{print $5}' >> /opt/NetAss2/project/${PROJECT}/host-alive.csv
if [[ -f nmap-host.na2out ]]; then
rm nmap-host.na2out
fi
cat /opt/NetAss2/project/${PROJECT}/host-alive.csv | sort -V | uniq >> hostdicovery.na2tmp
rm /opt/NetAss2/project/${PROJECT}/host-alive.csv
mv hostdicovery.na2tmp /opt/NetAss2/project/${PROJECT}/host-alive.csv
echo " Host" > hostdsc.na2tmp
echo " ------------" >> hostdsc.na2tmp
cat /opt/NetAss2/project/${PROJECT}/host-alive.csv | sed "s/^/ /g" >> hostdsc.na2tmp
echo ""
cat hostdsc.na2tmp
rm hostdsc.na2tmp
fi
fi
elif [[ ${MENU} == 2 ]]; then
echo " -----------[ PORT SCAN ON SINGLE HOST ]-----------"
echo ""
if [[ -f /opt/NetAss2/project/${PROJECT}/host-alive.csv ]]; then
if [[ $(cat /opt/NetAss2/project/${PROJECT}/host-alive.csv | wc -l) -ge 1 ]]; then
echo " INFO: Discovered host"
for IP in $(cat /opt/NetAss2/project/${PROJECT}/host-alive.csv)
do
echo " + ${IP}"
done
echo ""
fi
fi
echo " NOTE: Enter the specific host that you want to scan"
echo " NOTE: Example: 192.168.1.100"
echo -ne " INPUT: "
read IPADDR
if [[ -z $(echo ${IPADDR} | grep -E "^([0-9]{1,3}[\.]){3}[0-9]{1,3}$") ]]; then
echo " ERROR: Please input valid network block"
else
if [[ -f port-scan.na2out ]]; then
rm port-scan.na2out
fi
echo " INFO: Nmap run..."
echo " INFO: Discovering port on ${IPADDR}..."
nmap -p- -sT -sV --version-intensity 5 -T5 ${IPADDR} -oN port-scan.na2out -v &> /dev/null
cat port-scan.na2out | grep ^[0-9] | grep '[0-9][/]' | sed 's/;/,/g' | awk '{for(i=4;i<=NF;i++) printf $i" ";print ";"$1";"$3}' | sed 's/ ;/;/g' | awk -F ';' '{print $2";"$3";"$1}' | sed "s/^/${IPADDR};/g" >> /opt/NetAss2/project/${PROJECT}/port-open.csv
if [[ -f na2-output.tmp ]]; then
rm na2-output.tmp
fi
cat /opt/NetAss2/project/${PROJECT}/port-open.csv | sort -V | uniq >> na2-output.tmp
rm /opt/NetAss2/project/${PROJECT}/port-open.csv
mv na2-output.tmp /opt/NetAss2/project/${PROJECT}/port-open.csv
if [[ $(cat /opt/NetAss2/project/${PROJECT}/port-open.csv | grep "${IPADDR}" | wc -l) -lt 1 ]]; then
echo " INFO: Port not found"
else
echo "IP Addr;Port;Service;Vendor" > na2out.csv
echo "-------;----;-------;------" >> na2out.csv
cat /opt/NetAss2/project/${PROJECT}/port-open.csv | grep "${IPADDR}" >> na2out.csv
sed -i "s/^/ /g" na2out.csv
echo ""
cat na2out.csv | column -t -s';'
rm na2out.csv
fi
if [[ -f port-scan.na2out ]]; then
rm port-scan.na2out
fi
fi
elif [[ ${MENU} == 3 ]]; then
echo " ----[ MASSIVE PORT SCAN VIA DISCOVERED HOSTS ]----"
echo ""
if [[ ! -f /opt/NetAss2/project/${PROJECT}/host-alive.csv ]]; then
echo " ERROR: Please run host discovery first"
elif [[ $(cat /opt/NetAss2/project/${PROJECT}/host-alive.csv | wc -l) -eq 0 ]]; then
echo " ERROR: No discovered host"
else
for IPADDR in $(cat /opt/NetAss2/project/${PROJECT}/host-alive.csv)
do
if [[ -f port-scan.na2out ]]; then
rm port-scan.na2out
fi
echo " INFO: Nmap run..."
echo " INFO: Discovering port on ${IPADDR}..."
nmap -p- -sT -sV --version-intensity 5 -T5 ${IPADDR} -oN port-scan.na2out -v &> /dev/null
cat port-scan.na2out | grep ^[0-9] | grep '[0-9][/]' | sed 's/;/,/g' | awk '{for(i=4;i<=NF;i++) printf $i" ";print ";"$1";"$3}' | sed 's/ ;/;/g' | awk -F ';' '{print $2";"$3";"$1}' | sed "s/^/${IPADDR};/g" >> /opt/NetAss2/project/${PROJECT}/port-open.csv
if [[ -f na2-output.tmp ]]; then
rm na2-output.tmp
fi
if [[ -f port-scan.na2out ]]; then
rm port-scan.na2out
fi
cat /opt/NetAss2/project/${PROJECT}/port-open.csv | sort -V | uniq >> na2-output.tmp
rm /opt/NetAss2/project/${PROJECT}/port-open.csv
mv na2-output.tmp /opt/NetAss2/project/${PROJECT}/port-open.csv
done
if [[ $(cat /opt/NetAss2/project/${PROJECT}/port-open.csv | wc -l) -lt 1 ]]; then
echo " INFO: Port not found"
else
echo "IP Addr;Port;Service;Vendor" > na2out.csv
echo "-------;----;-------;------" >> na2out.csv
cat /opt/NetAss2/project/${PROJECT}/port-open.csv >> na2out.csv
sed -i "s/^/ /g" na2out.csv
echo ""
cat na2out.csv | column -t -s';'
rm na2out.csv
fi
fi
elif [[ ${MENU} == 4 ]]; then
echo " ------[ MASSIVE PORT SCAN VIA LIST ON FILE ]------"
echo ""
echo " INFO: Your current path is $(pwd)"
echo ""
echo " NOTE: Input filename"
echo " NOTE: Example: /path-to/ip-list.txt"
echo -ne " INPUT: "
read FILENAME
if [[ -z ${FILENAME} ]]; then
echo " ERROR: Please input filename correctly"
elif [[ -f ${FILENAME} ]]; then
if [[ -z $(cat ${FILENAME} | grep -Eo "([0-9]{1,3}[\.]){3}[0-9]{1,3}") ]]; then
echo " ERROR: No valid IP address on ${FILENAME}"
else
for IPADDR in $(cat ${FILENAME} | grep -Eo "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
do
if [[ -f port-scan.na2out ]]; then
rm port-scan.na2out
fi
echo " INFO: Nmap run..."
echo " INFO: Discovering port on ${IPADDR}..."
nmap -p- -sT -sV --version-intensity 5 -T5 ${IPADDR} -oN port-scan.na2out -v &> /dev/null
cat port-scan.na2out | grep ^[0-9] | grep '[0-9][/]' | sed 's/;/,/g' | awk '{for(i=4;i<=NF;i++) printf $i" ";print ";"$1";"$3}' | sed 's/ ;/;/g' | awk -F ';' '{print $2";"$3";"$1}' | sed "s/^/${IPADDR};/g" >> /opt/NetAss2/project/${PROJECT}/port-open.csv
if [[ -f na2-output.tmp ]]; then
rm na2-output.tmp
fi
if [[ -f port-scan.na2out ]]; then
rm port-scan.na2out
fi
cat /opt/NetAss2/project/${PROJECT}/port-open.csv | sort -V | uniq >> na2-output.tmp
rm /opt/NetAss2/project/${PROJECT}/port-open.csv
mv na2-output.tmp /opt/NetAss2/project/${PROJECT}/port-open.csv
done
if [[ $(cat /opt/NetAss2/project/${PROJECT}/port-open.csv | wc -l) -lt 1 ]]; then
echo " INFO: Port not found"
else
echo "IP Addr;Port;Service;Vendor" > na2out.csv
echo "-------;----;-------;------" >> na2out.csv
cat /opt/NetAss2/project/${PROJECT}/port-open.csv >> na2out.csv
sed -i "s/^/ /g" na2out.csv
echo ""
cat na2out.csv | column -t -s';'
rm na2out.csv
fi
fi
else
echo " ERROR: ${FILENAME} not found"
fi
elif [[ ${MENU} == 5 ]]; then
echo "----[ SINGLE PORT QUICKSCAN VIA NETWORK BLOCK ]----"
echo ""
echo " NOTE: Enter the single port that you want to scan"
echo " NOTE: Example: 80"
echo -ne " INPUT: "
read PORT
if [[ -z ${PORT} ]]; then
echo " ERROR: Please input single port"
elif ! [[ ${PORT} =~ ^[0-9]+$ ]] ; then
echo " ERROR: Please enter a valid port"
elif [[ ${PORT} -lt 1 ]] && [[ ${PORT} -gt 65535 ]]; then
echo " ERROR: Please enter a valid port"
else
if [[ ! -z $(ip a | grep 'inet ' | grep -v ' lo'$ | awk '{print $2}') ]]; then
echo " NOTE: Your network block reminder"
for NETBLOCK in $(ip a | grep 'inet ' | grep -v ' lo'$ | awk '{print $2}')
do
echo " + ${NETBLOCK}"
done
echo ""
fi
echo " NOTE: Enter the network block that you want to scan"
echo " NOTE: Example: 192.168.1.0/24"
echo -ne " INPUT: "
read NETWORK
if [[ -z ${NETWORK} ]]; then
echo " ERROR: Please input network block"
elif [[ -z $(echo ${NETWORK} | grep -E "^([0-9]{1,3}[\.]){3}[0-9]{1,3}[/][0-9]{1,2}$") ]]; then
echo " ERROR: Please input valid network block"
else
if [[ -f zmap-result.na2out ]]; then
rm zmap-result.na2out
fi
if [[ $(ip a | grep 'inet ' | grep -v ' lo' | awk '{print $2}' | wc -l) -gt 1 ]]; then
echo " WARNING: Your PC using multiple interface"
ip a | grep 'inet ' | grep -v ' lo' | awk '{print " + "$NF" ("$2")"}'
echo " INFO: Please enter your interface (example: eth0)"
echo -ne " INPUT: "
read IFACE
if [[ -z $(ip a | grep 'inet ' | grep -v ' lo' | awk '{print $NF}' | grep ^"${IFACE}"$) ]]; then
echo " ERROR: Please input your iface correctly"
else
echo " INFO: Single port quickscan running..."
zmap -p ${PORT} ${NETWORK} -i ${IFACE} -o zmap-result.na2out &> /dev/null
fi
else
zmap -p ${PORT} ${NETWORK} -o zmap-result.na2out &> /dev/null
fi
cat zmap-result.na2out | sed "s/$/;${PORT}/g" >> /opt/NetAss2/project/${PROJECT}/quickscan-${PORT}.csv
rm zmap-result.na2out
cat /opt/NetAss2/project/${PROJECT}/quickscan-${PORT}.csv | sort -V | uniq >> na2-qsport.tmp
rm /opt/NetAss2/project/${PROJECT}/quickscan-${PORT}.csv
mv na2-qsport.tmp /opt/NetAss2/project/${PROJECT}/quickscan-${PORT}.csv
echo "IP Addr;Port" > qsscanshow.tmp
echo "-------;----" >> qsscanshow.tmp
cat /opt/NetAss2/project/${PROJECT}/quickscan-${PORT}.csv >> qsscanshow.tmp
sed -i "s/^/ /g" qsscanshow.tmp
echo ""
cat qsscanshow.tmp | column -t -s';'
rm qsscanshow.tmp
fi
fi
elif [[ ${MENU} == '6' ]]; then
echo "----[ MULTI PORT QUICK SCAN VIA NETWORK BLOCK ]----"
echo ""
if [[ $(ip a | grep 'inet ' | grep -v ' lo' | awk '{print $2}' | wc -l) -gt 1 ]]; then
echo " WARNING: Your PC using multiple interface"
ip a | grep 'inet ' | grep -v ' lo' | awk '{print " + "$NF" ("$2")"}'
echo " INFO: Please enter your interface (example: eth0)"
echo -ne " INPUT: "
read IFACE
if [[ -z $(ip a | grep 'inet ' | grep -v ' lo' | awk '{print $NF}' | grep ^"${IFACE}"$) ]]; then
echo " ERROR: Please input your iface correctly"
IFACE="false"
else
IFACE=${IFACE}
fi
fi
if [[ ${IFACE} == "false" ]]; then
echo -ne ""
else
if [[ ! -z $(ip a | grep 'inet ' | grep -v ' lo'$ | awk '{print $2}') ]]; then
echo " NOTE: Your network block reminder"
for NETBLOCK in $(ip a | grep 'inet ' | grep -v ' lo'$ | awk '{print $2}')
do
echo " + ${NETBLOCK}"
done
echo ""
fi
echo " NOTE: Enter the network block that you want to scan"
echo " NOTE: Example: 192.168.1.0/24"
echo -ne " INPUT: "
read NETWORK
if [[ -z ${NETWORK} ]]; then
echo " ERROR: Please input network block"
elif [[ -z $(echo ${NETWORK} | grep -E "^([0-9]{1,3}[\.]){3}[0-9]{1,3}[/][0-9]{1,2}$") ]]; then
echo " ERROR: Please input valid network block"
else
echo " INFO: Input multiple port"
echo " NOTE: Example: 22,80,443"
echo -ne " INPUT: "
read PORTS
for PORT in $(echo "${PORTS}" | sed 's/,/\n/g')
do
if [[ -z ${PORT} ]]; then
echo " ERROR: ${PORT} is invalid port"
elif ! [[ ${PORT} =~ ^[0-9]+$ ]] ; then
echo " ERROR: ${PORT} is invalid port"
elif [[ ${PORT} -lt 1 ]] && [[ ${PORT} -gt 65535 ]]; then
echo " ERROR: ${PORT} is invalid port"
else
if [[ -f zmap-result.na2out ]]; then
rm zmap-result.na2out
fi
if [[ ! -z ${IFACE} ]]; then
echo " INFO: Scanning port ${PORT} on ${NETWORK}..."
zmap -p ${PORT} ${NETWORK} -i ${IFACE} -o zmap-result.na2out &> /dev/null
else
echo " INFO: Scanning port ${PORT} on ${NETWORK}..."
zmap -p ${PORT} ${NETWORK} -o zmap-result.na2out &> /dev/null
fi
cat zmap-result.na2out | sed "s/$/;${PORT}/g" >> /opt/NetAss2/project/${PROJECT}/multiple-quickscan.csv
rm zmap-result.na2out
cat /opt/NetAss2/project/${PROJECT}/multiple-quickscan.csv | sort -V | uniq >> na2-qsport.tmp
rm /opt/NetAss2/project/${PROJECT}/multiple-quickscan.csv
mv na2-qsport.tmp /opt/NetAss2/project/${PROJECT}/multiple-quickscan.csv
fi
done
echo "IP Addr;Port" > qsscanshow.tmp
echo "-------;----" >> qsscanshow.tmp
cat /opt/NetAss2/project/${PROJECT}/multiple-quickscan.csv >> qsscanshow.tmp
sed -i "s/^/ /g" qsscanshow.tmp
echo ""
cat qsscanshow.tmp | column -t -s';'
rm qsscanshow.tmp
fi
fi
elif [[ ${MENU} == '!' ]]; then
echo "--------------[ NetAss2 - REPORTING ]--------------"
echo ""
if [[ $(ls /opt/NetAss2/project/${PROJECT}/ | wc -l) == 0 ]]; then
echo " ERROR: No reporting data"
else
echo " INFO: Existing reports"
for DATA in $(ls /opt/NetAss2/project/${PROJECT}/)
do
echo " + ${DATA}"
done
echo ""
echo -ne " INPUT: "
read FILE
echo ""
if [[ -z ${FILE} ]]; then
echo " ERROR: File cannot empty"
elif [[ ! -f /opt/NetAss2/project/${PROJECT}/${FILE} ]]; then
echo " ERROR: File not found"
elif [[ $(cat /opt/NetAss2/project/${PROJECT}/${FILE} | wc -l) == 0 ]]; then
echo " ERROR: No data for this report"
else
if [[ ${FILE} =~ ^"host-alive" ]]; then
echo " HOST-ALIVE" > hostdsc.na2tmp
echo " ------------" >> hostdsc.na2tmp
cat /opt/NetAss2/project/${PROJECT}/${FILE} | sed "s/^/ /g" >> hostdsc.na2tmp
cat hostdsc.na2tmp
rm hostdsc.na2tmp
elif [[ ${FILE} =~ ^"port-open" ]]; then
echo "IP Addr;Port;Service;Vendor" > na2out.csv
echo "-------;----;-------;------" >> na2out.csv
cat /opt/NetAss2/project/${PROJECT}/${FILE} >> na2out.csv
sed -i "s/^/ /g" na2out.csv
cat na2out.csv | column -t -s';'
rm na2out.csv
elif [[ ${FILE} =~ ^"quickscan-" ]]; then
echo "IP Addr;Port" > qsscanshow.tmp
echo "-------;----" >> qsscanshow.tmp
cat /opt/NetAss2/project/${PROJECT}/${FILE} >> qsscanshow.tmp
sed -i "s/^/ /g" qsscanshow.tmp
cat qsscanshow.tmp | column -t -s';'
rm qsscanshow.tmp
elif [[ ${FILE} =~ ^"multiple-" ]]; then
echo "IP Addr;Port" > qsscanshow.tmp
echo "-------;----" >> qsscanshow.tmp
cat /opt/NetAss2/project/${PROJECT}/${FILE} >> qsscanshow.tmp
sed -i "s/^/ /g" qsscanshow.tmp
cat qsscanshow.tmp | column -t -s';'
rm qsscanshow.tmp
else
echo " ERROR: Something wrong (RPT error)"
fi
fi
fi
elif [[ ${MENU} == '0' ]]; then
echo " INFO: Good bye~"
echo ""
exit
else
echo " ERROR: Please select one menu correctly"
fi
echo ""
echo " --------------------------------------------------"
done