Register
It is currently Wed Apr 23, 2014 8:26 am

Bash Script Front End Menu for nmap


All times are UTC - 6 hours


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 PostPosted: Tue Mar 25, 2008 12:07 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
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


Top
 Profile  
 PostPosted: Tue Mar 25, 2008 1:02 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
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!


Top
 Profile  
 PostPosted: Tue Mar 25, 2008 1:29 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
I've been trying to put it into one function, but i can't seem to get it to loop properly.


Top
 Profile  
 PostPosted: Wed Mar 26, 2008 4:35 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
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...


Top
 Profile  
 PostPosted: Thu Mar 27, 2008 12:25 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
thanks man...i'll play around with it. :)


Top
 Profile  
 PostPosted: Thu Mar 27, 2008 5:17 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
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!


Top
 Profile  
 PostPosted: Thu Mar 27, 2008 5:25 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
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


Top
 Profile  
 PostPosted: Thu Mar 27, 2008 5:44 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
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


Top
 Profile  
 PostPosted: Thu Mar 27, 2008 6:02 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
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


Top
 Profile  
 PostPosted: Tue Apr 29, 2008 4:48 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
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


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP