nmap-parse.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. # .gnmap file as first argument
  3. if [ $# -lt 1 ] ; then
  4. echo '[-] parse <gnmap-file>'
  5. exit 1
  6. fi
  7. if [ ! -f "$1" ]; then
  8. echo '[-] No such file.'
  9. exit 1
  10. fi
  11. if [ ! -d hosts/ ]; then
  12. echo "[*] creating hosts/ folder"
  13. mkdir hosts
  14. fi
  15. function num_hosts {
  16. echo "$(cat "$1" | grep 'Up' | wc -l)"
  17. }
  18. # $1 is the file, $2 must be the port, $3 must be the service-name
  19. function parse_for_service {
  20. num=$(cat "$1" | grep "$2/open" | wc -l)
  21. if [ $num -le 1 ]; then
  22. echo "[-] No hosts with service $3"
  23. return
  24. fi
  25. filename="hosts/hosts.$3"
  26. if [ -f "$filename" ]; then
  27. echo "[-] File exists (for service $3), skiping...."
  28. return
  29. fi
  30. cat "$1" | grep "$2/open" | awk '{print $2}' | sort -u > $filename
  31. echo "[+] Outputing all hosts ($num) with an open $3 service to $filename"
  32. return $num
  33. }
  34. # Parsing
  35. hosts=$(num_hosts "$1")
  36. echo "[*] A total of $hosts Hosts to parse"
  37. parse_for_service "$1" 80 http
  38. parse_for_service "$1" 3389 rdp
  39. parse_for_service "$1" 22 ssh
  40. parse_for_service "$1" 21 ftp
  41. parse_for_service "$1" 53 dns
  42. parse_for_service "$1" 443 https
  43. parse_for_service "$1" 445 smb
  44. echo "[+] Done."