This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
nmap_automated_discovery.sh
137 lines (113 loc) · 4.75 KB
/
nmap_automated_discovery.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
#!/bin/bash
#Check Root Priv
if [[ "$EUID" = 0 ]]; then
echo "(1) PASSED: Root Privleges Check "
else
echo "Root privileges required for thorough scan."
sudo -su # make sure to ask for password on next sudo
if sudo true; then
echo "(2) correct password"
else
echo "(3) wrong password"
exit 1
fi
fi
#Define Subnet
while true
do
read -r -p "Enter IP [EXAMPLE: 10.1.1.0]: " IP
read -r -p "Enter Subnet in CIDR format without the / [EXAMPLE: 24]: " SUBNET
scanrange="${IP}/${SUBNET}"
scanname="${IP}_${SUBNET}"
discoveredhosts="${scanname}_discoveredhosts"
echo "Your scan range is $scanrange "
read -r -p "Is this correct? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Splendid. Your scanfiles will start with $scanname"
break
;;
[nN][oO]|[nN])
echo "No? Let's try this again..."
;;
*)
echo "Invalid input..."
;;
esac
done
#Discovery Scan Options
mainmenu() {
echo -ne "
MAIN MENU - Select your scan type
1) Sneaky - Sneak past IDS/IPS
2) Fast - Speedy but not so thorough or quite
3) Thorough - Good balance between speed and comprehensive. Noisy.
4) Comprehensive - Slow, Noisy but most comprehensive.
0) Exit
Choose an option: "
read -r ans
case $ans in
1)
echo "Running Sneaky Discovery Scan... Sneaking by IPS/IDS"
nmap -sS -P0 -T sneaky -f -v -oA $discoveredhosts $scanrange
echo "Discovery Scan complete. Scan output files begin with $discoveredhosts "
exit 1
;;
2)
echo "Running Fast (Noisy) Discovery Scan..."
nmap -T5 -PS21-25,53,88,80,110,135,139,389,443,445,1099,3306,3389,4786,5432,8000,8080,8443,9443 -v -oA $discoveredhosts $scanrange
echo "Discovery Scan complete. Scan output files begin with $discoveredhosts "
exit 2
;;
3)
echo "Running Thorough (Noisy) Discovery Scan..."
nmap -sS -sU -T5 -A -v -oA $discoveredhosts $scanrange
echo "Discovery Scan complete. Scan output files begin with $discoveredhosts "
exit 3
;;
4)
echo "Running Slow, (Noisy) Comprehensive Discovery Scan..."
nmap -sS -sU -T4 -A -v -PE -PP -PS80,443 -PA3389 -PU40125 -PY -g 53 --script "default or (discovery and safe)" -oA $discoveredhosts $scanrange
echo "Discovery Scan complete. Scan output files begin with $discoveredhosts "
exit 4
;;
0)
echo "Bye bye."
exit 0
;;
*)
echo "Wrong option."
exit 1
;;
esac
}
mainmenu
#Create HTML Report of the NMAP XML Output
xsltproc ${discoveredhosts}.xml -o ${discoveredhosts}.html
#Create list of live IPs
awk '/is up/ {print up}; {gsub (/\(|\)/,""); up = $NF}' ${discoveredhosts}.xml > ${scanname}_liveIPaddresses.txt
#Create lists of IP based on Service
### More can be added be appending additional services and repeating the code block below
###1099 (Java RMI), 4786 (Cisco Smart Install), 5432 (PostgreSQL)
service="netbios-ssn"
xmlstarlet sel -t -m "//port[@protocol='tcp' and service/@name=$service and state/@state='open']/ancestor::host/address[@addrtype='ipv4']" -v '@addr' -n ${discoveredhosts}.xml > ${scanname}_${service}_open_ip.txt
echo "${service}_open_ip.txt Generated "
service="microsoft-ds"
xmlstarlet sel -t -m "//port[@protocol='tcp' and service/@name=$service and state/@state='open']/ancestor::host/address[@addrtype='ipv4']" -v '@addr' -n ${discoveredhosts}.xml > ${scanname}_${service}_open_ip.txt
echo "${service}_open_ip.txt Generated "
service="telnet"
xmlstarlet sel -t -m "//port[@protocol='tcp' and service/@name=$service and state/@state='open']/ancestor::host/address[@addrtype='ipv4']" -v '@addr' -n ${discoveredhosts}.xml > ${scanname}_${service}_open_ip.txt
echo "${service}_open_ip.txt Generated "
service="ssh"
xmlstarlet sel -t -m "//port[@protocol='tcp' and service/@name=$service and state/@state='open']/ancestor::host/address[@addrtype='ipv4']" -v '@addr' -n ${discoveredhosts}.xml > ${scanname}_${service}_open_ip.txt
echo "${service}_open_ip.txt Generated "
service="ftp"
xmlstarlet sel -t -m "//port[@protocol='tcp' and service/@name=$service and state/@state='open']/ancestor::host/address[@addrtype='ipv4']" -v '@addr' -n ${discoveredhosts}.xml > ${scanname}_${service}_open_ip.txt
echo "${service}_open_ip.txt Generated "
service="http"
xmlstarlet sel -t -m "//port[@protocol='tcp' and service/@name=$service and state/@state='open']/ancestor::host/address[@addrtype='ipv4']" -v '@addr' -n ${discoveredhosts}.xml > ${scanname}_${service}_open_ip.txt
echo "${service}_open_ip.txt Generated "
service="https"
xmlstarlet sel -t -m "//port[@protocol='tcp' and service/@name=$service and state/@state='open']/ancestor::host/address[@addrtype='ipv4']" -v '@addr' -n ${discoveredhosts}.xml > ${scanname}_${service}_open_ip.txt
echo "${service}_open_ip.txt Generated "
echo "FIN"