-
Notifications
You must be signed in to change notification settings - Fork 7
/
nmap
237 lines (228 loc) · 9.54 KB
/
nmap
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
# nmap bash completion file
# by Daniel Miller
_escape_compreply() {
local IFS=$'\n'
local i=0
local entry
for entry in ${COMPREPLY[*]}
do
if [[ "${cur:0:1}" == "'" ]]
then
COMPREPLY[$i]="${entry//\'/\'\\\'\'}"
elif [[ "${cur:0:1}" == '"' ]]
then
entry="${entry//\\/\\\\}"
COMPREPLY[$i]="${entry//\"/\\\"}" #"comment
else
entry="${entry//\\/\\\\}"
entry="${entry//\'/\'}"
entry="${entry//\"/\\\"}"
COMPREPLY[$i]="${entry// /\\ }"
fi
(( i++ ))
done
}
_nmap() {
COMPREPLY=()
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ -z "$NMAPDIR" ]; then
[ -d /usr/share/nmap ] && NMAPDIR=/usr/share/nmap
[ -d /usr/local/share/nmap ] && NMAPDIR=/usr/local/share/nmap
fi
common_options="-b -D -f -g -M -r -R -S -V (other 1-letter options)
-6 (IPv6 scan)
-A (-O -sV -sC --traceroute)
-d (debug mode)
-e <iface> (Use specified interface)
-F (Scan top 100 ports)
--help (Print help and exit)
-i[INPUT_TARGETS] (Alternative target specification)
-n (No DNS resolution)
-O (OS detection)
-o[OUTPUT_TYPE] (Output to file)
--open (Show open ports only)
-P[PING_TYPE] (Host discovery type)
-p[PORTS] (Ports to scan)
--reason (Show why port is open/closed)
--script <NSE scripts> (run these scripts)
-s[SCAN_TECHNIQUES] (Scan type to use)
--top-ports <number> (Scan <number> most common ports)
--traceroute (Do traceroute on targets)
-T[TIMING] (Timing templates)
-v (Be verbose)
--version (Show version and exit)"
ping_types="-Pn (skip host discovery)
-PS[portlist] (TCP SYN)
-PA[portlist] (TCP ACK)
-PU[portlist] (UDP)
-PY[portlist] (SCTP)
-PE (ICMP echo)
-PP (ICMP timestamp)
-PM (ICMP netmask)
-PO[protocol list] (IP Protocol)"
scan_types="-sL (List only)
-sS (TCP SYN)
-sT (TCP Connect)
-sA (TCP ACK)
-sW (TCP Window)
-sM (TCP Maimon)
-sU (UDP)
-sN (TCP Null)
-sF (TCP FIN)
-sX (TCP Xmas)
-sI <zombie host[:probeport]> (Idle scan)
-sY (SCTP INIT)
-sZ (SCTP COOKIE-ECHO)
-sO (IP Protocol)
-sV (Version scan)
-sC (--script=default)
-sn (skip port scan)"
input_types="-iL <inputfilename> (Input from list of hosts/networks)
-iR <num hosts> (Choose random targets)"
output_types="-oA <basename> (Normal, XML, and Grepable, auto-add extension)
-oN <file> (Normal output)
-oX <file> (XML output)
-oS <file> (s|<rIpt kIddi3)
-oG <file> (Grepable output)"
all_options="-6 -A --adler32 --allports --append-output -b --badsum -d -D --datadir --data-length --debug --defeat-rst-ratelimit --deprecated-xml-osclass --disable-arp-ping --dns-servers -e --exclude -f --ff -F -g --help --iflist --ip-options -iR --log-errors -M --max-hostgroup --max-os-tries --max-parallelism --max-rate --max-retries --min-hostgroup --min-parallelism --min-rate --mtu -n --nogcc --no-stylesheet --nsock-engine -O -oA -oG -oN --open -oS --osscan-guess --osscan-limit -oX -p -PA --packet-trace -PE -PM -Pn -PO --port-ratio -PP -p --privileged -PS -PU -PY -r -R --randomize-hosts --reason --release-memory --route-dst -S -sA -sC --scanflags --script --script-args --script-help --script-trace --script-updatedb --send-eth --send-ip -sF -sI -sL -sM -sn -sN -sO --source-port --spoof-mac -sR -sS -sT -sU -sV -sW -sX -sY --system-dns -sZ -T --timing --top-ports --traceroute --ttl --unprivileged -V -v --verbose --version --version-all --version-intensity --version-light --version-trace --webxml"
file_opts="-iL --excludefile --resume --stylesheet --servicedb --versiondb --script-args-file"
time_opts="--min-rtt-timeout --max-rtt-timeout --initial-rtt-timeout --host-timeout --scan-delay --max-scan-delay --stats-every"
pref_opts="-oA -oG -oN -oX -oS --datadir --servicedb --versiondb --max-os-tries --max-parallelism -M --min-parallelism --max-rtt-timeout --min-rtt-timeout --initial-rtt-timeout --excludefile --exclude --max-hostgroup --min-hostgroup --scanflags --host-timeout --scan-delay --max-scan-delay --max-retries -iL -iR -sI --source-port -g --data-length --stylesheet --mtu --spoof-mac --ttl --dns-servers --port-ratio --top-ports --script --script-args --script-args-file --ip-options --min-rate --max-rate --stats-every --proxies"
if [[ "$cur" == - ]]; then
# Don't overwhelm the casual user.
# Only show common options
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$common_options" -- $cur ) )
elif [[ "$cur" == -P ]]; then
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$ping_types" -- "$cur" ) )
elif [[ "$cur" == -P@(S|Y|A|U|O) ]]; then
# Cannot have space between these pings and port list
COMPREPLY=( $( compgen -P "$cur" -- $cur ) )
elif [[ "$cur" == -s ]]; then
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$scan_types" -- "$cur" ) )
elif [[ "$cur" == -i ]]; then
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$input_types" -- "$cur" ) )
elif [[ "$cur" == -o ]]; then
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$output_types" -- "$cur" ) )
elif [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$all_options $file_opts $time_opts" -- $cur ) )
else
case "$prev" in
-T)
COMPREPLY=( $( compgen -W "paranoid sneaky polite normal aggressive insane" -- $cur ) )
;;
--nsock-engine)
COMPREPLY=( $( compgen -W "epoll select" -- $cur ) )
;;
--version-intensity)
COMPREPLY=( $( compgen -W "0 1 2 3 4 5 6 7 8 9" -- $cur ) )
;;
-e)
_available_interfaces
;;
--spoof-mac)
[ -z "$NMAPDIR" ] && exit 1
local IFS=$'\n'
local realcur=${cur#[\'\"]} # comment for syntax highlighting'
COMPREPLY=( $( compgen -W "$( grep -i "^[^#]..... $realcur" $NMAPDIR/nmap-mac-prefixes | cut -d\ -f2- )" -X "!$realcur*" -P "'" -S "'" -- $realcur ) )
;;
--script|--script-help)
[ -z "$NMAPDIR" ] && exit 1 #[comment
categories="auth broadcast default discovery dos exploit external fuzzer intrusive malware safe version vuln"
if [[ "$cur" == *,* ]]; then #[comment
local realcur=${cur##*,}
local prefix=${cur%,*}
COMPREPLY=( $( cd "$NMAPDIR/scripts/" 2>/dev/null &&
compgen -W "$categories all" -G "*.nse" -X "!$realcur*" -P "$prefix," -- $realcur )
$( cd ~/.nmap/scripts/ 2>/dev/null &&
compgen -G "*.nse" -X "!$cur*" -- $realcur ) )
else
COMPREPLY=( $( cd "$NMAPDIR/scripts/" 2>/dev/null &&
compgen -W "$categories all" -G "*.nse" -X "!$cur*" -- $cur )
$( cd ~/.nmap/scripts/ 2>/dev/null &&
compgen -G "*.nse" -X "!$cur*" -- $cur ) )
fi
;;&
+(${file_opts// /|}))
_filedir
;;&
+(${time_opts// /|}))
local digits=${cur%%+([msh])}
COMPREPLY=( $( compgen -W "${digits}ms ${digits}s ${digits}m ${digits}h $digits" -- $cur ) )
;;&
--datadir)
_filedir -d
;;&
+(${pref_opts// /|}))
# Credit to Eugene on Stack Overflow for the general idea here
# http://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion
if [ -f ~/.nmap/prefs ]; then #[comment
local -a prefs=()
eval "prefs=( $( awk "/^$prev /{\$1=\"\"; print}" ~/.nmap/prefs ) ) "
local IFS=$'\n'
COMPREPLY+=( $( compgen -W "${prefs[*]}" -- "$cur" ) )
_escape_compreply
fi
;;&
*)
return 0
;;
esac
fi
return 0
}
_zenmap() {
COMPREPLY=()
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
local short_opts long_opts
short_opts="-f -h -n -p -t -v"
long_opts="--file --help --nmap --profile --target --verbose"
local offset i
offset=0
for (( i=1; i <= COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" == --nmap ]]; then #[comment
offset=$i
break
fi
done
if [[ $offset -gt 0 ]]; then #[comment
if [[ ${#COMP_WORDS[@]} -ge $(( 2 + offset )) ]]; then #[comment
_nmap nmap "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
else
_nmap nmap "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
fi
return 0
else
if [[ "$cur" == - ]]; then #[comment
COMPREPLY=( $( compgen -W "$short_opts" -- "$cur" ) )
elif [[ "$cur" == -* ]]; then #[comment
COMPREPLY=( $( compgen -W "$short_opts $long_opts" -- "$cur" ) )
else
case "$prev" in
-f|--file)
_filedir
return 0
;;
-p|--profile)
local IFS=$'\n'
COMPREPLY=( $( compgen -W \
"$( awk -F'[][]' '/^\[/{print $2}' ~/.zenmap/scan_profile.usp )" \
-- "$cur" ) )
_escape_compreply
return 0
;;
esac
fi
fi
}
complete -F _nmap -o default nmap
complete -F _zenmap -o default zenmap
# vi:ft=sh