def open_file (self, widget):
        file_chooser = ResultsFileChooserDialog(_("Select Scan Result"))
        
        file_chooser.run()
        file_chosen = file_chooser.get_filename()
        file_chooser.destroy()

        if check_access(file_chosen, os.R_OK):
            try:
                parser = NmapParser(file_chosen)
                parser.parse()
            except:
                alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % _('File is not a Umit \
Scan Result'),
                    secondary_text=_("Selected file is not a Umit Scan \
Result file. Umit can not parse this file. Please, select another."))
                alert.run()
                alert.destroy()
                return False

            scan_name = os.path.split(file_chosen)[-1]
            self.add_scan(scan_name, parser)
            
            self.combo_scan.set_active(len(self.list_scan) - 1)
        else:
            alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % \
                                   _('Can not open selected file'),
                    secondary_text=_("Umit can not open selected file. Please, \
select another."))
            alert.run()
            alert.destroy()
    def _check_scans(self):
        """
        Check if some scan finished.
        """
        for item in self.scans.items():
            index = item[0]
            scan = item[1][0]
            network = item[1][1]

            if not scan.scan_state():  # scan finished
                np = NmapParser(scan.get_xml_output_file())
                np.parse()
                for host in np.nmap["hosts"]:  # get hosts with 'up' state
                    if host.state == 'up':
                        self.target_model.append((host.ip['addr'], network))

                # remove scan from list
                del self.scans[index]

                self.scount -= 1
                if self.scount:
                    self._adjust_target_label()

                # clean up temp files
                scan.close()

        if self.scount == 0:  # all scans finished
            self.hostdetect_btn.set_sensitive(True)
            self.target_lbl.set_label(_("Target list"))
            return False

        return True
Exemple #3
0
    def open_file(self, widget):
        file_chooser = ResultsFileChooserDialog(_("Select Scan Result"))

        file_chooser.run()
        file_chosen = file_chooser.get_filename()
        file_chooser.destroy()

        if check_access(file_chosen, os.R_OK):
            try:
                parser = NmapParser(file_chosen)
                parser.parse()
            except:
                alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % _('File is not a Umit \
Scan Result'),
                    secondary_text=_("Selected file is not a Umit Scan \
Result file. Umit can not parse this file. Please, select another."))
                alert.run()
                alert.destroy()
                return False

            scan_name = os.path.split(file_chosen)[-1]
            self.add_scan(scan_name, parser)

            self.combo_scan.set_active(len(self.list_scan) - 1)
        else:
            alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % \
                                   _('Can not open selected file'),
                    secondary_text=_("Umit can not open selected file. Please, \
select another."                ))
            alert.run()
            alert.destroy()
    def _check_scans(self):
        """
        Check if some scan finished.
        """
        for item in self.scans.items():
            index = item[0]
            scan = item[1][0]
            network = item[1][1]

            if not scan.scan_state(): # scan finished
                np = NmapParser(scan.get_xml_output_file())
                np.parse()
                for host in np.nmap["hosts"]: # get hosts with 'up' state
                    if host.state == 'up':
                        self.target_model.append((host.ip['addr'], network))

                # remove scan from list
                del self.scans[index]

                self.scount -= 1
                if self.scount:
                    self._adjust_target_label()

                # clean up temp files
                scan.close()

        if self.scount == 0: # all scans finished
            self.hostdetect_btn.set_sensitive(True)
            self.target_lbl.set_label(_("Target list"))
            return False

        return True
def main():
    from umit.core.NmapParser import NmapParser
    parser = NmapParser("../../umit-within-radialnet/RadialNet2/share/sample/nmap_example.xml")
    #parser = NmapParser("RadialNet2/share/sample/no_trace.xml")
    parser.parse()
    
    graph = GraphBuilder()
    graph.make(parser)
def main():
    from umit.core.NmapParser import NmapParser
    parser = NmapParser(
        "../../umit-within-radialnet/RadialNet2/share/sample/nmap_example.xml")
    #parser = NmapParser("RadialNet2/share/sample/no_trace.xml")
    parser.parse()

    graph = GraphBuilder()
    graph.make(parser)
Exemple #7
0
    def parse(self, valid_xml):
        """
        Parses an existing xml file.
        """
        debug("Parsing file: %r..", valid_xml)

        p = NmapParser(valid_xml)
        p.parse()

        return p
Exemple #8
0
    def get_scan_results(self):
        scan_file = None
        for i in range(self.scan_notebook.get_n_pages()):
            sbook_page = self.scan_notebook.get_nth_page(i)

            if not sbook_page.status.get_empty():
                scan_file = sbook_page.parsed.nmap_xml_file
                if hasattr(scan_file, "name"):
                    # this scan was loaded from a file so nmap_xml_file is
                    # actually a file object, but we are interested only in
                    # the file name.
                    scan_file = scan_file.name

            if scan_file and os.access(scan_file, os.R_OK) and\
               os.path.isfile(scan_file):
                log.debug(">>> Retrieving unsaved scan result: %s" % scan_file)

                try:
                    parsed = NmapParser()
                    parsed.set_xml_file(scan_file)
                    parsed.parse()
                    parsed.scan_name = "Unsaved " + sbook_page.get_tab_label()
                    parsed.unsaved = True
                except:
                    pass
                else:
                    yield parsed
Exemple #9
0
    def get_scan_results(self):
        log.debug(">>> Getting scan results stored in data base")
        u = UmitDB()

        for scan in u.get_scans():
            log.debug(">>> Retrieving result of scans_id %s" % scan.scans_id)
            log.debug(">>> Nmap xml output: %s" % scan.nmap_xml_output)

            temp_file = mktemp(".usr", "umit_")

            tmp = open(temp_file, "w")
            tmp.write(scan.nmap_xml_output)
            tmp.close()

            try:
                parsed = NmapParser()
                parsed.set_xml_file(temp_file)
                parsed.parse()

                # Remove temporary file reference
                parsed.nmap_xml_file = ""
            except:
                pass
            else:
                yield parsed
    def get_scan_results(self):
        scan_file = None
        for i in range(self.scan_notebook.get_n_pages()):
            sbook_page = self.scan_notebook.get_nth_page(i)

            if not sbook_page.status.get_empty():
                scan_file = sbook_page.parsed.nmap_xml_file
                if hasattr(scan_file, "name"):
                    # this scan was loaded from a file so nmap_xml_file is
                    # actually a file object, but we are interested only in
                    # the file name.
                    scan_file = scan_file.name

            if scan_file and os.access(scan_file, os.R_OK) and\
               os.path.isfile(scan_file):
                log.debug(">>> Retrieving unsaved scan result: %s" % scan_file)

                try:
                    parsed = NmapParser()
                    parsed.set_xml_file(scan_file)
                    parsed.parse()
                    parsed.scan_name = "Unsaved " + sbook_page.get_tab_label()
                    parsed.unsaved = True
                except:
                    pass
                else:
                    yield parsed
    def get_scan_results(self):
        log.debug(">>> Getting directory's scan results")
        files = []
        for ext in self.file_extensions:
            files += glob(os.path.join(self.search_directory, "*.%s" % ext))

        log.debug(">>> Scan results at selected directory: %s" % files)
        for scan_file in files:
            log.debug(">>> Retrieving scan result %s" % scan_file)
            if os.access(scan_file, os.R_OK) and os.path.isfile(scan_file):

                try:
                    parsed = NmapParser()
                    parsed.set_xml_file(scan_file)
                    parsed.parse()
                except:
                    pass
                else:
                    yield parsed
    def get_scan_results(self):
        log.debug(">>> Getting scan results stored in data base")
        u = UmitDB()

        for scan in u.get_scans():
            log.debug(">>> Retrieving result of scans_id %s" % scan.scans_id)
            log.debug(">>> Nmap xml output: %s" % scan.nmap_xml_output)
            
            temp_file = mktemp(".usr", "umit_")
            
            tmp = open(temp_file, "w")
            tmp.write(scan.nmap_xml_output)
            tmp.close()

            try:
                parsed = NmapParser()
                parsed.set_xml_file(temp_file)
                parsed.parse()
                
                # Remove temporary file reference
                parsed.nmap_xml_file = ""
            except:
                pass
            else:
                yield parsed
Exemple #13
0
    def get_scan_results(self):
        log.debug(">>> Getting directory's scan results")
        files = []
        for ext in self.file_extensions:
            files += glob(os.path.join(self.search_directory, "*.%s" % ext))

        log.debug(">>> Scan results at selected directory: %s" % files)
        for scan_file in files:
            log.debug(">>> Retrieving scan result %s" % scan_file)
            if os.access(scan_file, os.R_OK) and os.path.isfile(scan_file):

                try:
                    parsed = NmapParser()
                    parsed.set_xml_file(scan_file)
                    parsed.parse()
                except:
                    pass
                else:
                    yield parsed
Exemple #14
0
    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
Exemple #15
0
def diff_state(prop1, prop2):
    if prop1 == prop2:
        return "U" # Property remained "Unchanged" at the second scan
    elif prop1 == "" and prop2 != "":
        return "A" # Property "Added" at the second scan
    elif prop1 != "" and prop2 != "":
        return "M" # Property "Modified" at the second scan
    else:
        return "N" # Property "Not present" at the second scan


if __name__ == "__main__":
    from umit.core.NmapParser import NmapParser

    parsed1 = NmapParser("test/xml_test1.xml")
    parsed2 = NmapParser("test/xml_test2.xml")
    parsed3 = NmapParser("test/xml_test3.xml")
    parsed4 = NmapParser("test/xml_test4.xml")

    parsed1.parse()
    parsed2.parse()
    parsed3.parse()
    parsed4.parse()
    
    dw = DiffWindow({"Parsed 1": parsed1,
                     "Parsed 2": parsed2,
                     "Parsed 3": parsed3,
                     "Parsed 4": parsed4})

    dw.show_all()
Exemple #16
0
def diff_state(prop1, prop2):
    if prop1 == prop2:
        return "U"  # Property remained "Unchanged" at the second scan
    elif prop1 == "" and prop2 != "":
        return "A"  # Property "Added" at the second scan
    elif prop1 != "" and prop2 != "":
        return "M"  # Property "Modified" at the second scan
    else:
        return "N"  # Property "Not present" at the second scan


if __name__ == "__main__":
    from umit.core.NmapParser import NmapParser

    parsed1 = NmapParser("test/xml_test1.xml")
    parsed2 = NmapParser("test/xml_test2.xml")
    parsed3 = NmapParser("test/xml_test3.xml")
    parsed4 = NmapParser("test/xml_test4.xml")

    parsed1.parse()
    parsed2.parse()
    parsed3.parse()
    parsed4.parse()

    dw = DiffWindow({
        "Parsed 1": parsed1,
        "Parsed 2": parsed2,
        "Parsed 3": parsed3,
        "Parsed 4": parsed4
    })