leonteale

portfinder.sh

Dec 13th, 2013
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.71 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # A script specifically for the CTF with formatted output which will paste straight
  4. # into the spreadsheet.
  5. #
  6. # Usage = ./portfinder.sh 10.0.0/24
  7. # Usage = ./portfinder.sh list_of_targets.txt
  8. #
  9. # Leon Teale (@leonteale)
  10.  
  11.  
  12. #Variables
  13. targets="$1"
  14.  
  15. #Funcetions
  16. header () {
  17.     echo "            _    __ _           _"          
  18.     echo " _ __   ___  _ __| |_ / _(_)_ __   __| | __ _ __"
  19.     echo "| '_ \ / _ \| '__| __| |_| | '_ \ / _\` |/ _ \\ '__|"
  20.     echo "| |_) | (_) | |  | |_|  _| | | | | (_| |  __/ |"
  21.     echo "| .__/ \___/|_|   \__|_| |_|_| |_|\__,_|\___|_|  (@leonteale)"
  22.     echo "|_|"
  23.     echo " "  
  24.     echo "A script specifically for the CTF with formatted output which will paste straight"
  25.     echo "into the spreadsheet."
  26.     }
  27.  
  28. usage () {
  29.  
  30.     echo ""
  31.    echo "Usage = ./portfinder.sh 10.0.0/24 (may take a while to run)"
  32.    echo "Usage = ./portfinder.sh list_of_targets.txt"
  33.    echo ""
  34.    exit 1
  35.     }
  36.  
  37. scan () {
  38.     echo " "
  39.     echo "Finding Open Ports For Spreadheet Format"
  40.     echo " "
  41.     echo "Number of hosts found: `cat $targets | wc -l`"
  42.     echo " "
  43.         for hosts in `cat $targets`;do
  44.             nmap $hosts --open > nmap.txt;
  45.             cat nmap.txt | grep "Nmap scan report for" | awk {'printf $NF'};printf "\t";cat nmap.txt | grep "open" | awk {'print $1'} | cut -d / -f 1 | paste -s -d,
  46.         done
  47.     }
  48.  
  49. scan_range () {
  50.     nmap -n -sn -vv $targets |grep "Host is up" -B 1 |grep "Nmap" |cut -d " " -f 5 > targets.txt
  51.     targets=targets.txt
  52.     scan
  53.     }
  54.  
  55. cleanup () {
  56.     if [ -e targets.txt ];
  57.         then
  58.             rm targets.txt
  59.         else
  60.             echo ""
  61.     fi
  62.     rm nmap.txt
  63.     }
  64.  
  65. #Start the script
  66. header
  67. if [ $# -eq 0 ] || [ -d "$targets" ]
  68.  then
  69.     usage
  70. elif [ -f "$targets" ]; then
  71.     scan
  72.     cleanup
  73. else
  74.     scan_range
  75.     cleanup
  76. fi
Advertisement
Add Comment
Please, Sign In to add comment