Skip to content

Instantly share code, notes, and snippets.

@ErbaZZ
Last active July 10, 2020 12:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErbaZZ/52508649ab7156842d942f11459d6b54 to your computer and use it in GitHub Desktop.
Save ErbaZZ/52508649ab7156842d942f11459d6b54 to your computer and use it in GitHub Desktop.
gnmap2banner.sh - Find "http" or any specified service type in .gnmap file and convert into "IP:PORT:PROTOCOL:SERVICE:BANNER" format
#!/bin/bash
# Name: gnmap2banner.sh
# Purpose: Search for a specific service type from gnmap file and
# prints out the result in "IP:Port:Service:Banner" format
# Usage: ./gnmap2banner.sh nmap_result.gnmap [service]
# Author: Weerawat Pawanawiwat <ErbaZZ>
file=$1
service="http"
if [ -z "$1" ]
then
echo "Usage: $0 gnmap_file [service]"
exit 1
fi
if [ -n "$2" ]
then
service="$2"
fi
while read line; do
ip=`echo $line | cut -d " " -f 2`
echo $line | grep -ioP "\d+/open/(tcp|udp)//[^/]*$service[^/]*//[^,]*/" | while read -r match ; do
echo $ip:`echo $match | cut -s -d "/" -f 1,3,5,7 --output-delimiter=":"`
done
done < <(cat $1 | grep "Ports:")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment