#!/usr/bin/python """ Nmap Script search, this script displays all nmap scripts, or searches for a string within the title of the nmap script""" import sys,subprocess,os # to see if nmap is installed and the script directory is in default directories usage = """ nmap nse search script coded by bostonlink @ pentest-labs.org example1: ./nse_search.py -l example2: ./nse_search.py -s smb""" help = """ Nmap nse search script options -l = lists all nmap nse scripts within the /nmap/scripts directory -s [search string] = searches all nse scripts and prints ones that matches the search string\n""" if len(sys.argv) <= 1: print usage print help sys.exit(0) cwd = os.getcwd() script_path = '/usr/local/share/nmap/scripts/' def chg_dir(): if cwd != script_path: os.chdir('/usr/local/share/nmap/scripts/') print '\nChanged CWD to default nmap script directory\n' def list_all(): cmd1 = subprocess.Popen(["ls","-l"], stdout=subprocess.PIPE) lista = cmd1.stdout.read() cmd1.wait() print lista def list_search(): if len(sys.argv) <= 2: print usage print help sys.exit(0) else: search_string = sys.argv[2] cmd1 = subprocess.Popen(["ls"], stdout=subprocess.PIPE) lista = cmd1.stdout.read() cmd1.wait() lista1 = lista.strip().split() for i in lista1: if search_string in i: print i if sys.argv[1] == '-l': chg_dir() list_all() if sys.argv[1] == '-s': chg_dir() list_search()