From 5638481d1acc6f2b3122dd8ba72f8617238ab9fd Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Tue, 10 Dec 2019 13:49:41 +0000 Subject: [PATCH] Changes to nmap scripts --- bin/.bin/nmap/nmap-clean | 6 ++++++ bin/.bin/nmap/nmap-get | 6 +----- bin/.bin/nmap/nmap-get-json | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100755 bin/.bin/nmap/nmap-clean diff --git a/bin/.bin/nmap/nmap-clean b/bin/.bin/nmap/nmap-clean new file mode 100755 index 00000000..554eeb68 --- /dev/null +++ b/bin/.bin/nmap/nmap-clean @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +cat | grep -v 'host down' |\ + grep -v Increa |\ + grep -v Ignoring |\ + grep -v '^#' diff --git a/bin/.bin/nmap/nmap-get b/bin/.bin/nmap/nmap-get index 8ed1f4a9..78d7754a 100755 --- a/bin/.bin/nmap/nmap-get +++ b/bin/.bin/nmap/nmap-get @@ -1,8 +1,4 @@ #!/usr/bin/env bash -cat | grep -v 'host down' |\ - grep -v Increa |\ - grep -v Ignoring |\ - grep -v '^#' |\ - awk -v RS="\n\n" -v ORS="\n\n" '{if ($0 ~ "'"$1"'" ) print $0}' +cat | awk -v RS="\n\n" -v ORS="\n" '{gsub("\n","§",$0); print $0}' | grep "$@" | sed 's/$/\n/' | sed 's/§/\n/g' diff --git a/bin/.bin/nmap/nmap-get-json b/bin/.bin/nmap/nmap-get-json index 6acb072d..6ccb9355 100755 --- a/bin/.bin/nmap/nmap-get-json +++ b/bin/.bin/nmap/nmap-get-json @@ -38,6 +38,37 @@ function print_basic_info(){ #| [select(."@attributes".protocol)] } +function print_with_match(){ + local match=$1 + echo $json | # Echo the full json file + jq ' if ( .host | type ) == "object" then [ .host ] else .host end ' | # Get the hosts as an array (even if there is only one + #jq '.[9]' + #jq '[ .[9] | { + # address: .address."@attributes".addr, + # domains: .hostnames.hostname."@attributes".name, + # port: { + # tcp : (try ( [ .ports.port[] | select( ."@attributes".protocol == "tcp" ) | select( .service."@attributes".name | test("'"$match"'; "i") ) | { + # port: ."@attributes".portid, + # service: .service."@attributes", + # } ] ) catch null ), + # udp : (try ( [ .ports.port[] | select( ."@attributes".protocol == "udp" ) | { + # port: ."@attributes".portid, + # service: .service."@attributes", + # } ] ) catch null ) + # } + #} ]' + jq '[ .[9] | { + address: .address."@attributes".addr, + domains: .hostnames.hostname."@attributes".name, + port: { + tcp : [ .ports.port | { + port: ., + service: .service."@attributes", + } ], + } + } ]' +} + if [ -n "$1" ] ; then case "$1" in -h|--help) @@ -48,5 +79,9 @@ if [ -n "$1" ] ; then print_basic_info exit 0 ;; + *) + print_with_match "$@" + exit 0 + ;; esac fi