Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # A script specifically for the CTF with formatted output which will paste straight
- # into the spreadsheet.
- #
- # Usage = ./portfinder.sh 10.0.0/24
- # Usage = ./portfinder.sh list_of_targets.txt
- #
- # Leon Teale (@leonteale)
- #Variables
- targets="$1"
- #Funcetions
- header () {
- echo " _ __ _ _"
- echo " _ __ ___ _ __| |_ / _(_)_ __ __| | __ _ __"
- echo "| '_ \ / _ \| '__| __| |_| | '_ \ / _\` |/ _ \\ '__|"
- echo "| |_) | (_) | | | |_| _| | | | | (_| | __/ |"
- echo "| .__/ \___/|_| \__|_| |_|_| |_|\__,_|\___|_| (@leonteale)"
- echo "|_|"
- echo " "
- echo "A script specifically for the CTF with formatted output which will paste straight"
- echo "into the spreadsheet."
- }
- usage () {
- echo ""
- echo "Usage = ./portfinder.sh 10.0.0/24 (may take a while to run)"
- echo "Usage = ./portfinder.sh list_of_targets.txt"
- echo ""
- exit 1
- }
- scan () {
- echo " "
- echo "Finding Open Ports For Spreadheet Format"
- echo " "
- echo "Number of hosts found: `cat $targets | wc -l`"
- echo " "
- for hosts in `cat $targets`;do
- nmap $hosts --open > nmap.txt;
- 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,
- done
- }
- scan_range () {
- nmap -n -sn -vv $targets |grep "Host is up" -B 1 |grep "Nmap" |cut -d " " -f 5 > targets.txt
- targets=targets.txt
- scan
- }
- cleanup () {
- if [ -e targets.txt ];
- then
- rm targets.txt
- else
- echo ""
- fi
- rm nmap.txt
- }
- #Start the script
- header
- if [ $# -eq 0 ] || [ -d "$targets" ]
- then
- usage
- elif [ -f "$targets" ]; then
- scan
- cleanup
- else
- scan_range
- cleanup
- fi
Advertisement
Add Comment
Please, Sign In to add comment