-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnsesearch.sh
executable file
·78 lines (68 loc) · 2.19 KB
/
nsesearch.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
#!/bin/bash
# nsesearch.sh
# Searches nmap NSE scripts and prints out help, usage, parameter and sample output.
# Created because for some reason there doesn't seem to be an easy way to do this in nmap
# By Sebastien Jeanquier (@securitygen)
# Security Generation - http://www.securitygeneration.com
#
# ChangeLog -
# 0.1: Initial release
#
# Note: Rough hack. Only tested on Mac OS X and Kali Linux!
# -------------------------------------------------------------
# Try using standard grep command by default
grep='grep'
# Check if BSD or GNU grep
flavour=$($grep -V | $grep -o BSD | head -1)
if [[ $flavour == "BSD" ]]; then
if ! type "ggrep" &> /dev/null; then
echo "This won't work with BSD grep. Install GNU grep."
echo "On OS X, install using Homebrew: "
echo "# brew tap homebrew/dupes"
echo "# brew install homebrew/dupes/grep"
echo "# brew install pcre"
exit 0
else
# Use ggrep (installed by Homebrew on OS X when you install GNU grep)
grep='ggrep'
fi
fi
# Check nmap is installed as we'll call it
if ! type "nmap" &> /dev/null; then
echo "Error: nmap not found!"
exit 0
fi
if [ -z "$1" ]; then
echo "./nsesearch <search term> | Searches available nmap NSE scripts."
exit 0
else
search=$1
fi
# Find installed NSE scripts
nmap_basepath=$(nmap -v -d 2>/dev/null | $grep -Po 'Read from \K\/.*(?=:)')
script_list=$($grep -Po '[\w-]+(?=.nse)' "$nmap_basepath"/scripts/script.db | $grep "$search")
# Search NSE script names for search parameter
if [[ -n $script_list ]]; then
num=0
echo "Available nmap NSE scripts:"
for line in $script_list; do
path[$num]="$nmap_basepath/scripts/$line.nse"
name[$num]=$line
echo "${num}) ${name[$num]}"
((num++))
done;
# Read in chosen script number
read -r -p "Select a script number: " selection
until [ "$selection" -ge 0 ] && [ "$selection" -lt $num ];
do
echo "Invalid number!"
read -r -p "Select a script number: " selection
done
# Get script help output from nmap --script-help
output=$(nmap --script-help="${name[$selection]}")
# Get usage, args and output info from script file
output=$output"\n\n$($grep -Poz "(?s)(--\s@.*?\n)\n" "${path[$selection]}")"
echo "$output" | less
else
echo "No NSE scripts found containing '$search'."
fi