def __init__(self,profile):
     """
     @param profile: file name
     @type profile: string 
     """
     NmapOptions.__init__(self, profile)
     self.modified = False
Exemple #2
0
 def __init__(self, profile):
     """
     @param profile: file name
     @type profile: string 
     """
     NmapOptions.__init__(self, profile)
     self.modified = False
 def update(self):
     try:
         self.nmap_options = NmapOptions(options_file)
         self.options = self.nmap_options.get_options_list()
         self.options.sort()
     
         self.clean_model()
         model = self.get_model()
         for o in self.options:
             model.append([o])
     except:
         pass
    def __init__(self, xml_file, constructor, update_func):
        """ OptionBuilder(xml_file, constructor)

        xml_file is a UI description xml-file
        constructor is a CommandConstructor instance
        """
        xml_desc = open(xml_file)
        self.xml = minidom.parse(xml_desc)
        # Closing file to avoid problems with file descriptors
        xml_desc.close()

        self.constructor = constructor
        self.update_func = update_func

        self.root_tag = "interface"

        self.xml = self.xml.getElementsByTagName(self.root_tag)[0]
        self.options = NmapOptions(options_file)

        self.groups = self.__parse_groups()
        self.section_names = self.__parse_section_names()
        self.tabs = self.__parse_tabs()
    def __init__(self, xml_file):
        '''
        Open XML file 
        It should be inheritance of OptionBuilder But I don't need 
        a function that update command.
        So I implement a new way of read elements like OptionBuilder 
        with support of write in XML 


        @param xml_file: String with a path of file 
        @type xml_file: str 
        '''

        xml_desc = open(xml_file)
        self.xml_parse = minidom.parse(xml_desc)
        xml_desc.close()
        self.root_tag = "interface"
        self.xml = self.xml_parse.getElementsByTagName(self.root_tag)[0]
        self.options = NmapOptions(options)

        self.groups = self.__parse_groups()
        self.section_names = self.__parse_section_names()
        self.tabs = self.__parse_tabs()
class OptionCombo(gtk.ComboBoxEntry):
    def __init__(self):
        gtk.ComboBoxEntry.__init__(self, gtk.ListStore(str), 0)

        self.completion = gtk.EntryCompletion()
        self.child.set_completion(self.completion)
        self.completion.set_model(self.get_model())
        self.completion.set_text_column(0)

        self.update()

    def update(self):
        try:
            self.nmap_options = NmapOptions(options_file)
            self.options = self.nmap_options.get_options_list()
            self.options.sort()
        
            self.clean_model()
            model = self.get_model()
            for o in self.options:
                model.append([o])
        except:
            pass
        
    def clean_model(self):
        model = self.get_model()
        for i in range(len(model)):
            iter = model.get_iter_root()
            del(model[iter])

    def get_selected_option(self):
        return self.child.get_text()

    def set_selected_option(self, option):
        self.child.set_text(option)

    selected_option = property(get_selected_option, set_selected_option)
Exemple #7
0
 def __init__(self):
     self.r_scans = RecentScans()
     self.t_list = TargetList()
     self.nmap_options = NmapOptions(options_file)
Exemple #8
0
class QSData(object):
    """
    Class responsible to import all stored data of scans, profiles and of nmap
    to QS.
    """

    def __init__(self):
        self.r_scans = RecentScans()
        self.t_list = TargetList()
        self.nmap_options = NmapOptions(options_file)

    def get_recent_scans(self):
        """Return the recent scans"""
        return self.r_scans.get_recent_scans_list()

    def get_target_list(self):
        """Return the list of targets previously scanned"""
        return self.t_list.get_target_list()

    def get_nmap_options(self):
        """Get Nmap options to display to user"""
        return self.nmap_options.get_options_list()

    def get_nmap_command_option(self, option="", args=[]):
        """Return the Nmap command option"""
        if option:
            return self.nmap_options.get_command_option(option, args)
        else:
            return ""
        
    def get_from_db(self):
        """Getting results from database"""
        from umit.core.UmitDB import UmitDB # change when this module is ok
        db = UmitDB()
        self.db_data = {}
        
        for scan in db.get_scans():
            
            #creating temporary file to store nmap xml
            temp_file = TemporaryFile()
            temp_file.write(scan.nmap_xml_output)
            #temp_file.seek(0) #---> really need this?
            
            try:
                parsed = NmapParser()
                parsed.set_xml_file(temp_file)
                parsed.parse()
                self.db_data[parsed.get_target()] = \
                    ((u'ip',parsed.get_hosts()[0].get_hostname()),
                     (u'date', parsed.get_formated_date()),
                     (u'nmap_command', parsed.get_nmap_command()),
                     (u'num_open_ports', parsed.get_open_ports()),
                     (u'ports', parsed.get_ports()),
                     (u'profile_name', parsed.get_profile_name()),
                     (u'stats', parsed.get_runstats()),
                     )
                
                # Remove temporary file reference
                parsed.nmap_xml_file = ""
                temp_file.close()
                
            except IndexError:
                #log the error
                #TODO: fix the bug with reg without ip
                pass

        del db
        return self.db_data
        
    def get_profiles(self, option):
        """Get the existing profiles and respective Nmap commands"""
        profiles = open(scan_profile_file, "r").readlines()
        self.profiles = []
        self.commands = {}
        last_profile = ""

        for p in profiles:
            if p.startswith("[Nmap"):
                self.profiles.append(p[1:-2])
                last_profile = p[1:-2]
            if p.startswith("command"):
                self.commands[last_profile] = p.split("=")[1].strip("%s").strip()

        if option == "profile_name":
            return self.profiles
        elif option == "profile_commands":
            return self.commands
        else:
            return False
        

    def get_all(self):
        """Get all data on a single method"""
        self.all_data = {
            'nmap_options': sorted(self.get_nmap_options()),
            'nmap_command_option': sorted(self.get_nmap_command_option()),
            #'recent_scans': sorted(self.get_recent_scans()),
            'target_list': sorted(self.get_target_list()),
            'profiles': sorted(self.get_profiles("profile_name"))
        }

        return self.all_data