BashScripts.org
http://bashscripts.org/forum/

Bash Script Front End Menu for nmap
http://bashscripts.org/forum/viewtopic.php?f=7&t=486
Page 1 of 1

Author:  DeX [ Tue Mar 25, 2008 12:07 pm ]
Post subject:  Bash Script Front End Menu for nmap

Please let me know if you find any problems with this. It's just a simple menu for common scan types in nmap. Obviously it is required that nmap be installed for the script to work properly. Here's the script!

Code:
#!/bin/bash
#A Quick and Dirty Terminal Front End for nmap
#Written by DeX 3/20/08
#This script is completely free and you are welcome to edit and redistribute it as much as you like.

#The Welcoming
        clear;
        echo "Hello "$(whoami)", what would you like me to do? "
       
        sleep 1
       
#The Menu
        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Target Specification"
        echo "2 Host Discovery"
        echo "3 Service / Version Detection"
        echo "4 OS Detection"
        echo "5 Firewall Evasion"
        echo "6 Port Specification"
        echo "7 Custom Scan"
        echo "8 Exit"
       
       
#Execute Menu Choice       
        read choice
       
        while [[ $choice != 0 ]]
        do
           case $choice in
             1)  clear;
                 read -p "Enter Target(s): " target
                 clear;
                 nmap $target;
                 ;;
             2)  clear;
                 read -p "Enter Target(s): " target2
                 clear;
                 nmap -sL $target2;
                 ;;
             3)  clear;
                 read -p "Enter Target(s): " target3
                 nmap -sV $target3;
                 ;;
             4)  clear;
                 read -p "Enter Target(s): " target4
                 nmap -O $target4;
                 ;;
             5)  clear;
                 read -p "Enter Desired Source Address: " target5
                 nmap -S $target5;
                 ;;
             6)  clear;
                 read -p "Enter Port Range: " target6
                 nmap -p $target6;
                 ;;
             7)  clear;
                 read -p "Enter Custom Scan String: " cust
                 read -p "Enter Target(s): " target7
                 nmap $cust $target7;
                 ;;             
             8)  clear;
                 echo "Thanks!"
                 exit;
                 ;;

             *)  clear;
                 echo "You have entered an invalid option!"
                 ;;
           esac

#Menu Loop
         echo "..........................."
         echo "...........MENU............"
         echo
         echo "1 Target Specification"
         echo "2 Host Discovery"
         echo "3 Service / Version Detection"
         echo "4 OS Detection"
         echo "5 Firewall Evasion"
         echo "6 Port Specification"
         echo "7 Custom Scan"
         echo "8 Exit"

         read choice
      done

Author:  jbsnake [ Tue Mar 25, 2008 1:02 pm ]
Post subject: 

very nice... I'd like to suggest one thing... put the menu into a separate function... that way you only have one place to change incase you make additions or changes to the menu.

i definitely like the script! welcome aboard!

Author:  DeX [ Tue Mar 25, 2008 1:29 pm ]
Post subject: 

I've been trying to put it into one function, but i can't seem to get it to loop properly.

Author:  jbsnake [ Wed Mar 26, 2008 4:35 pm ]
Post subject: 

Code:
#!/bin/bash
#A Quick and Dirty Terminal Front End for nmap
#Written by DeX 3/20/08 (slightly morphed by jbsnake 3/26/08)
#This script is completely free and you are welcome to edit and redistribute it as much as you like.


menu ()
{     
#The Menu
        clear
        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Target Specification"
        echo "2 Host Discovery"
        echo "3 Service / Version Detection"
        echo "4 OS Detection"
        echo "5 Firewall Evasion"
        echo "6 Port Specification"
        echo "7 Custom Scan"
        echo "8 Exit"
}       
        choice=""
        menu
        read -p "$(whoami), what would you like me to do? " choice
       
        while [[ "$choice" != "0" ]]
        do
           case $choice in
             1)  clear;
                 read -p "Enter Target(s): " target
                 clear;
                 nmap $target;
                 ;;
             2)  clear;
                 read -p "Enter Target(s): " target2
                 clear;
                 nmap -sL $target2;
                 ;;
             3)  clear;
                 read -p "Enter Target(s): " target3
                 nmap -sV $target3;
                 ;;
             4)  clear;
                 read -p "Enter Target(s): " target4
                 nmap -O $target4;
                 ;;
             5)  clear;
                 read -p "Enter Desired Source Address: " target5
                 nmap -S $target5;
                 ;;
             6)  clear;
                 read -p "Enter Port Range: " target6
                 nmap -p $target6;
                 ;;
             7)  clear;
                 read -p "Enter Custom Scan String: " cust
                 read -p "Enter Target(s): " target7
                 nmap $cust $target7;
                 ;;             
             8)  clear;
                 echo "Thanks!"
                 exit;
                 ;;

             *)  clear;
                 echo "You have entered an invalid option!"
                 read -p "Press enter to continue." deadArg
                 ;;
           esac

            # menu again
            menu
            read -p "$(whoami), what would you like me to do? " choice
      done


i havn't tested this... but this might be something towards what you are looking for...

Author:  DeX [ Thu Mar 27, 2008 12:25 pm ]
Post subject: 

thanks man...i'll play around with it. :)

Author:  DeX [ Thu Mar 27, 2008 5:17 pm ]
Post subject: 

So I've been playing around with it and the menu loop works, but now the nmap scan results don't print. It jumps back to the menu before they appear. I'm trying to figure out a way to fix it with a sleep command...i'll post it when I fix it. Thanks for the cleaner code though jbsnake!

Author:  jbsnake [ Thu Mar 27, 2008 5:25 pm ]
Post subject: 

notice what i did here:
Code:
*)  clear;
                 echo "You have entered an invalid option!"
                 read -p "Press enter to continue." deadArg

i'm sure you could put something similar at the end of each nmap... or just before the menu() call again

Author:  DeX [ Thu Mar 27, 2008 5:44 pm ]
Post subject: 

yeah...i found the problem. the menu module starts with the clear command. So naturally when its called up again after the scan the first thing it does is clear. Just for fun I will try to figure out a way to tell the script not to use the clear command if the menu has already been displayed. The obviously more efficient solution would be a deadArg. Thanks for all your help with this one. I'm really trying to learn and this site has been unbelievably helpful and you and crouse in particular have been both patient and helpful.

Thanks,

DeX

Author:  DeX [ Thu Mar 27, 2008 6:02 pm ]
Post subject: 

okay...so the working script is as follows. Thanks jbsnake for all your help.

Code:
#!/bin/bash
#A Quick and Dirty Terminal Front End for nmap
#Written by DeX 3/20/08 (slightly morphed by jbsnake 3/26/08) (and slightly re-morphed by DeX and jbsnake 3/27/08)
#This script is completely free and you are welcome to edit and redistribute it as much as you like.

menu ()
{     
#The Menu
       

   clear;

        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Target Specification"
        echo "2 Host Discovery"
        echo "3 Service / Version Detection"
        echo "4 OS Detection"
        echo "5 Firewall Evasion"
        echo "6 Port Specification"
        echo "7 Custom Scan"
        echo "8 Exit"
}       
        menu

   read -p "Hello $(whoami), what would you like me to do? " choice
       
        while [[ "$choice" != "0" ]]
        do
           case $choice in
             1)  clear;
                 read -p "Enter Target(s): " target
                 clear;
                 nmap $target;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             2)  clear;
                 read -p "Enter Target(s): " target2
                 clear;
                 nmap -sL $target2;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             3)  clear;
                 read -p "Enter Target(s): " target3
                 nmap -sV $target3;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             4)  clear;
                 read -p "Enter Target(s): " target4
                 nmap -O $target4;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             5)  clear;
                 read -p "Enter Desired Source Address: " target5
                 nmap -S $target5;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             6)  clear;
                 read -p "Enter Port Range: " target6
                 nmap -p $target6;
                 echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
       ;;
             7)  clear;
                 read -p "Enter Custom Scan String: " cust
                 read -p "Enter Target(s): " target7
                 nmap $cust $target7;
                 echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
       ;;             
             8)  clear;
                 echo "Thanks $(whoami)!"
                 exit;
                 ;;

             *)  clear;
                 echo "You have entered an invalid option!"
                 read -p "Press enter to continue." deadArg
                 ;;
      esac
         
      # menu again
   
      menu
            read -p "Hello $(whoami), what would you like me to do? " choice
      done

Author:  DeX [ Tue Apr 29, 2008 4:48 pm ]
Post subject: 

made some improvements...really I just added error handling for those who don't have nmap installed.

Code:
#!/bin/bash
#A Quick and Dirty Terminal Front End for nmap
#Written by DeX 3/20/08 (slightly morphed by jbsnake 3/26/08) (and slightly re-morphed by DeX and jbsnake 3/27/08)
#This script is completely free and you are welcome to edit and redistribute it as much as you like.

#error handling
error_msg(){
    echo "$PROG: ERROR: $*" | fold >&2
    }

#check for nmap
which nmap >/dev/null 2>&1  ||
{ error_msg "Cannot find 'nmap', which is needed for this script."
          exit 1;}

menu ()
{     
#The Menu
       

   clear;

        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Target Specification"
        echo "2 Host Discovery"
        echo "3 Service / Version Detection"
        echo "4 OS Detection"
        echo "5 Firewall Evasion"
        echo "6 Port Specification"
        echo "7 Custom Scan"
        echo "8 Exit"
}       
        menu

   read -p "Hello $(whoami), what would you like me to do? " choice
       
        while [[ "$choice" != "0" ]]
        do
           case $choice in
             1)  clear;
                 read -p "Enter Target(s): " target
                 clear;
                 nmap $target;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             2)  clear;
                 read -p "Enter Target(s): " target2
                 clear;
                 nmap -sL $target2;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             3)  clear;
                 read -p "Enter Target(s): " target3
                 nmap -sV $target3;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             4)  clear;
                 read -p "Enter Target(s): " target4
                 nmap -O $target4;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             5)  clear;
                 read -p "Enter Desired Source Address: " target5
                 nmap -S $target5;
       echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
                 ;;
             6)  clear;
                 read -p "Enter Port Range: " target6
                 nmap -p $target6;
                 echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
       ;;
             7)  clear;
                 read -p "Enter Custom Scan String: " cust
                 read -p "Enter Target(s): " target7
                 nmap $cust $target7;
                 echo
       read -p "Scan Complete!  Press Enter to Return to the Menu." deadArg;
       ;;             
             8)  clear;
                 echo "Thanks $(whoami)!"
                 exit;
                 ;;

             *)  clear;
                 echo "You have entered an invalid option!"
                 read -p "Press enter to continue." deadArg
                 ;;
      esac
         
      # menu again
   
      menu
            read -p "Hello $(whoami), what would you like me to do? " choice
      done

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com