def add_extraports_diff(self, host_parent, state, extraports1, extraports2): if extraports1 or extraports2: section = _("Extraports") parent = self.append_parent(host_parent, section, state) self.set_parent_status(parent, state) self.diff_it(parent, "", _("Count"), extraports1.get("count"), extraports2.get("count")) self.diff_it(parent, "", _("State"), extraports1.get("state"), extraports2.get("state"))
def get_services(self): services = [] for port in self.ports: for p in port.get("port", []): services.append({"service_name":p.get("service_name", _("unknown")), "portid":p.get("portid", ""), "service_version":p.get("service_version", _("Unknown version")), "service_product":p.get("service_product", ""), "port_state":p.get("port_state", _("Unknown")), "protocol":p.get("protocol", "")}) return services
def generate (self): self.html_file = self.make_file (self.result1, self.result2) self.html_file = ' '.join(self.html_file.split(' ')) txt_diff = Diff (self.result1, self.result2, self.junk) self.text_file = '''<br /><br /> <!-- %s --> <center><div class="umit" align="center">%s</div></center> <pre align="center">%s</pre> '''% (_("Changes to this file can make Umit unable to read it."),\ _('Regular Text Diff: '),\ ''.join(txt_diff.generate ())) return self.insert_banner ()
def get_time_list(self): # Time as key, seconds a value return {_("Hours"): 60 * 60, _("Days"): 60 * 60 * 24, _("Weeks"): 60 * 60 * 24 * 7, _("Months"): 60 * 60 * 24 * 7 * 30, _("Years"): 60 * 60 * 24 * 7 * 30 * 12, _("Minutes"): 60, _("Seconds"): 1}
def get_hostname(self): hostname = '' try: hostname = self._hostnames[0]['hostname'] + ' ' except: pass # FIXME: Check if i can return the 'addr' key directly from get_ip, # get_ipv6 and get_mac if self.ip: hostname += self._ip['addr'] elif self.ipv6: hostname += self._ipv6['addr'] elif self.mac: hostname += self._mac['addr'] else: hostname = _('Unknown Host') return hostname
def add_port_diff(self, port_parent, state, port1, port2): if (port1 or port2) and (type(port1) == type({})) and (type(port2) == type({})): section = port1.get("portid", False) if not section: # If port1 is empty, then, try port2 section = port2.get("portid", "") parent = self.append_parent(port_parent, section, state) self.diff_it(parent, "", _("State"), port1.get("port_state", ""), port2.get("port_state", "")) self.diff_it(parent, "", _("Service Name"), port1.get("service_name", ""), port2.get("service_name", "")) self.diff_it(parent, "", _("Product"), port1.get("service_product", ""), port2.get("service_product", "")) self.diff_it(parent, "", _("Service Version"), port1.get("service_version", ""), port2.get("service_version", "")) self.diff_it(parent, "", _("Protocol"), port1.get("protocol", ""), port2.get("protocol", "")) self.diff_it(parent, "", _("Extra Info"), port1.get("service_extrainfo", ""), port2.get("service_extrainfo", "")) self.diff_it(parent, "", _("Service Conf"), port1.get("service_conf", ""), port2.get("service_conf", "")) # Last parent status modification if state.upper() == "A": self.set_parent_status(parent, "A")
def __init__(self, result1=[''], result2=[''], junk = "\n"): self.result1 = result1 self.result2 = result2 self.junk = junk self.umit_top_banner = ['|'+'-'*70+'|\n', '|'+_('Umit - Take the red pill').center (70)+'|\n', '|'+_('http://www.umitproject.org').center(70)+'|\n', '|'+' '*70+'|\n', '|'+_('This diff was generated by Umit').center(70)+'|\n', '|'+_("(Changes to this file can make Umit unable to read \ it.)").center(70)+'|\n', '|'+'-'*70+'|\n', '\n', '-'*10+_(' Start of diff ')+'-'*10+'\n'] self.end_diff = ['\n'+'-'*10+_(' End of diff ')+'-'*10+'\n'] Differ.__init__ (self, self.line_junk)
def __init__(self, result1=[''], result2=[''], junk="\n"): self.result1 = result1 self.result2 = result2 self.junk = junk self.umit_top_banner = [ '|' + '-' * 70 + '|\n', '|' + _('Umit - Take the red pill').center(70) + '|\n', '|' + _('http://www.umitproject.org').center(70) + '|\n', '|' + ' ' * 70 + '|\n', '|' + _('This diff was generated by Umit').center(70) + '|\n', '|' + _("(Changes to this file can make Umit unable to read \ it.)").center(70) + '|\n', '|' + '-' * 70 + '|\n', '\n', '-' * 10 + _(' Start of diff ') + '-' * 10 + '\n' ] self.end_diff = [ '\n' + '-' * 10 + _(' End of diff ') + '-' * 10 + '\n' ] Differ.__init__(self, self.line_junk)
def set_ipv6_address(self, addr): log.warning(_("umitCore.NmapParser.set_ipv6_address deprecated! Use \ umitCore.NmapParser.set_ipv6 instead.")) self.set_ipv6(addr)
def get_mac_address(self): log.warning(_("umitCore.NmapParser.get_mac_address deprecated! Use \ umitCore.NmapParser.get_mac instead.")) return self.get_mac()
def __init__(self, message=_("Internal Server Error")): HttpError.__init__(self, 500, message)
def __init__(self, message=_("Forbidden")): HttpError.__init__(self, 403, message)
def __init__(self): HttpError.__init__(self, 404, _("Page Not Found"))
def get_ipv6_addresses (self): log.warning(_("umitCore.NmapParser.get_ipv6_address deprecated! Use \ umitCore.NmapParser.get_ipv6 instead.")) return self.get_ipv6()
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import sys sys.path.append(".") import os import re import threading import unittest from tempfile import mktemp from types import StringTypes try: from subprocess import Popen, PIPE except ImportError, e: raise ImportError(str(e) + ".\n" + _("Python 2.4 or later is required.")) from umitCore.NmapOptions import NmapOptions from umitCore.OptionsConf import options_file from umitCore.UmitLogging import log from umitCore.I18N import _, enc from umitCore.Paths import Path # shell_state = True avoids python to open a terminal to execute nmap.exe # shell_state = False is needed to run correctly at Linux shell_state = (sys.platform == "win32") #nmap_command_path = "nmap" # Don't need the line below anymore #if sys.platform == "win32": # nmap_command_path = os.path.join(os.path.split(os.path.abspath(\
def __init__(self, args=False): OptionParser.__init__(self) ## Network Inventory (GUI) ### This option should raise the Network Inventory window ### with the last used inventory self.add_option("-i", "--inventory", default=False, action="store_true", help=_("*NOT IMPLEMENTED* - Start Umit and go \ straight to Network Inventory window.")) ## Run nmap with args (GUI) ### Open Umit and runs nmap with specified args. The positional ### args should be used to feed the nmap command self.add_option("-n", "--nmap", default=[], action="callback", callback=self.__nmap_callback, help=_("Open Umit and runs a Nmap scan with \ specified args.")) ## Execute a profile against a target (GUI) ### Positional args should be taken as targets to feed this scan self.add_option("-p", "--profile", default="", action="store", help=_("Open Umit with the specified profile \ selected. If combined with the -t (--target) option, open Umit and \ automatically run the profile against the specified target.")) ## Compare results in compare mode (GUI) ### Run the diff compare window in compare mode as default self.add_option("-c", "--compare", action="store", nargs=2, help=_("*NOT IMPLEMENTED* - Open the diff compare \ window, in compare mode comparing the two given scan result files \ (Nmap XML output or usr (Umit Scan Result) file).")) ## Compare results in text mode (GUI) ### Run the diff compare window in text mode as default self.add_option("-e", "--compare-text", action="store", nargs=2, help=_("*NOT IMPLEMENTED* - Open the diff compare \ window, in text mode comparing the two given scan result files (Nmap XML \ output or usr, Umit Scan Result).")) ## Compare results showing text diff in terminal (TEXT) ### Doesn't actually run Umit interface. Just take the result files, ### generate the text diff and send it back to terminal self.add_option("-d", "--diff", action="store", nargs=2, help=_("*NOT IMPLEMENTED* - Take two scan result files \ (Nmap XML output or usr, Umit Scan Result), make a text diff and print it in \ the terminal without openning Umit Interface.")) ## NSE Facilitator (GUI) ### Opens Umit and go straigh to NSE Facilitator interface. ### If a positional argument is given, it can be an nse script which ### should be openned by the NSE Facilitator interface self.add_option("-s", "--nse-facilitator", default=False, action="store_true", help=_("*NOT IMPLEMENTED* - Run Umit and go straight \ to NSE Facilitator Interface. You may specify nse scripts as arguments \ if you want use them.")) ## Targets (GUI) ### Specify a target to be used along with other command line option ### or simply opens Umit with the first tab target field filled with ### the target specified with this option self.add_option("-t", "--target", default=False, action="store", help=_("Specify a target to be used along with other \ options. If specified alone, opens Umit with the target field filled with the \ specified target")) ## Open Scan Results (GUI) ### Run Umit openning the specified scan result file, which should be ### a nmap XML output or an usr (Umit Scan Result) xml file. ### This option should be verified if there is no options, and user ### specified some positional arguments, which should be considered as ### scan result files. self.add_option("-f", "--file", default=[], action="append", type="string", dest="result_files", help=_("Specify a scan result file in Nmap XML Output \ or Umit Scan Result file. Can be used more than once to specify several \ scan result files.")) ## Open a give file, showing it at mapper (GUI) ### Specify a scan file result to open at mapper self.add_option("-m", "--mapper", default=False, action="store", help=_("*NOT IMPLEMENTED* - Open Umit showing the \ given file at Umit Mapper")) ## Verbosity self.add_option("-v", "--verbose", default=0, action="count", help=_("Increase verbosity of the output. May be \ used more than once to get even more verbosity")) # Parsing options and arguments if args: self.options, self.args = self.parse_args(args) else: self.options, self.args = self.parse_args()
def add_host_diff(self, host_state, host, host2=None): section = _("Host") if host.ip: section = _("Host %s") % (host.ip["addr"]) elif host.ipv6: section = _("Host %s") % (host.ipv6["addr"]) elif host.mac: section = _("Host %s") % (host.mac["addr"]) parent = self.append_parent(None, section, host_state) self.root_sections.append(parent) self.diff_it(parent, "", _("Comment"), host.comment, host2.comment) self.diff_it(parent, "", _("LastBoot"), host.uptime.get("lastboot", ""), host2.uptime.get("lastboot", "")) self.diff_it(parent, "", _("OS Match"), host.osmatch.get("name", ""), host2.osmatch.get("name", "")) host_ports = host.ports[:] host2_ports = host2.ports[:] for port in xrange(len(host_ports)): # Making sure that extraports1 will get a sanity value to be processed try: extraports1 = host_ports[port].get("extraports", []) except: extraports1 = {} else: if len(extraports1) == 0: extraports1 = {} elif len(extraports1) == 1: extraports1 = extraports1[0] # Making sure that extraports2 will get a sanity value to be processed try: extraports2 = host2_ports[port].get("extraports", []) except: extraports2 = {} else: if len(extraports2) == 0: extraports2 = {} elif len(extraports2) == 1: extraports2 = extraports2[0] if extraports1 and extraports2: self.add_extraports_diff(parent, "", extraports1, extraports2) elif extraports1 and not extraports2: self.add_extraports_diff(parent, "N", extraports1, extraports2) elif not extraports1 and extraports2: self.add_extraports_diff(parent, "A", extraports1, extraports2) section = _("Ports") parent = self.append_parent(parent, section, "") # Making sure that ports1 will get a sanity value to be processed try: ports1 = host_ports[port].get("port", []) except: ports1 = {} else: if len(ports1) == 0: ports1 = {} elif len(ports1) == 1: ports1 = ports1[0] # Making sure that ports2 will get a sanity value to be processed try: ports2 = host2_ports[port].get("port", []) except: ports2 = {} else: if len(ports2) == 0: ports2 = [{}] elif len(ports2) == 1: ports2 = ports2[0] if type(ports2) != type([]): ports2 = [ports2] if type(ports1) != type([]): ports1 = [ports1] for p1 in ports1: if not p1: continue p2 = [port2 for port2 in ports2 \ if port2.get("portid", "a") == p1.get("portid", "b")] if p2: # Removing found port ports2.remove(p2[0]) if p1 and p2: self.add_port_diff(parent, "", p1, p2[0]) elif p1 and not p2: self.add_port_diff(parent, "N", p1, {}) for p2 in ports2: # If there is something left... self.add_port_diff(parent, "A", {}, p2)
def add_host_diff(self, host_state, host, host2=None): section = _("Host") if host.ip: section = _("Host %s") % (host.ip["addr"]) elif host.ipv6: section = _("Host %s") % (host.ipv6["addr"]) elif host.mac: section = _("Host %s") % (host.mac["addr"]) parent = self.append_parent(None, section, host_state) self.root_sections.append(parent) self.diff_it(parent, "", _("Comment"), host.comment, host2.comment) self.diff_it(parent, "", _("LastBoot"), host.uptime.get("lastboot", ""), host2.uptime.get("lastboot", "")) self.diff_it(parent, "", _("OS Match"), host.osmatch.get("name", ""), host2.osmatch.get("name", "")) host_ports = host.ports[:] host2_ports = host2.ports[:] for port in xrange(len(host_ports)): # Making sure that extraports1 will get a sanity value to be processed try: extraports1 = host_ports[port].get("extraports", []) except: extraports1 = {} else: if len(extraports1) == 0: extraports1 = {} elif len(extraports1) == 1: extraports1 = extraports1[0] # Making sure that extraports2 will get a sanity value to be processed try: extraports2 = host2_ports[port].get("extraports", []) except: extraports2 = {} else: if len(extraports2) == 0: extraports2 = {} elif len(extraports2) == 1: extraports2 = extraports2[0] if extraports1 and extraports2: self.add_extraports_diff(parent, "", extraports1, extraports2) elif extraports1 and not extraports2: self.add_extraports_diff(parent, "N", extraports1, extraports2) elif not extraports1 and extraports2: self.add_extraports_diff(parent, "A", extraports1, extraports2) section = _("Ports") parent = self.append_parent(parent, section, "") # Making sure that ports1 will get a sanity value to be processed try: ports1 = host_ports[port].get("port", []) except: ports1 = {} else: if len(ports1) == 0: ports1 = {} elif len(ports1) == 1: ports1 = ports1[0] # Making sure that ports2 will get a sanity value to be processed try: ports2 = host2_ports[port].get("port", []) except: ports2 = {} else: if len(ports2) == 0: ports2 = [{}] elif len(ports2) == 1: ports2 = ports2[0] if type(ports2)!= type([]): ports2 = [ports2] if type(ports1) != type([]): ports1 = [ports1] for p1 in ports1: if not p1: continue p2 = [port2 for port2 in ports2 \ if port2.get("portid", "a") == p1.get("portid", "b")] if p2: # Removing found port ports2.remove(p2[0]) if p1 and p2: self.add_port_diff(parent, "", p1, p2[0]) elif p1 and not p2: self.add_port_diff(parent, "N", p1, {}) for p2 in ports2: # If there is something left... self.add_port_diff(parent, "A", {}, p2)
def make_diff(self): self.clear_diff_tree() self.root_sections = [] section = _("Umit Info") parent = self.append_parent(None, section, "") self.root_sections.append(parent) self.diff_it(parent, "", _("Profile"), self.parsed1.profile, self.parsed2.profile) self.diff_it(parent, "", _("Profile Name"), self.parsed1.profile_name, self.parsed2.profile_name) self.diff_it(parent, "", _("Profile Options"), self.parsed1.profile_options, self.parsed2.profile_options) self.diff_it(parent, "", _("Target"), self.parsed1.target, self.parsed2.target) section = _("Nmap Info") parent = self.append_parent(None, section, "") self.root_sections.append(parent) self.diff_it(parent, "", _("Debugging"), self.parsed1.debugging_level, self.parsed2.debugging_level) self.diff_it(parent, "", _("Verbosity"), self.parsed1.verbose_level, self.parsed2.verbose_level) self.diff_it(parent, "", _("Command"), self.parsed1.nmap_command, self.parsed2.nmap_command) self.diff_it(parent, "", _("Scanner version"), self.parsed1.scanner_version, self.parsed2.scanner_version) section = _("Scan Info") parent = self.append_parent(None, section, "") self.root_sections.append(parent) self.diff_it(parent, "", _("Open Ports"), self.parsed1.open_ports, self.parsed2.open_ports) self.diff_it(parent, "", _("Filtered Ports"), self.parsed1.filtered_ports, self.parsed2.filtered_ports) self.diff_it(parent, "", _("Closed Ports"), self.parsed1.closed_ports, self.parsed2.closed_ports) self.diff_it(parent, "", _("Hosts Up"), self.parsed1.hosts_up, self.parsed2.hosts_up) self.diff_it(parent, "", _("Hosts Down"), self.parsed1.hosts_down, self.parsed2.hosts_down) self.diff_it(parent, "", _("Hosts Scanned"), self.parsed1.hosts_scanned, self.parsed2.hosts_scanned) self.diff_it(parent, "", _("Finish date"), self.parsed1.formated_finish_date, self.parsed2.formated_finish_date) hosts1 = self.parsed1.hosts[:] hosts2 = self.parsed2.hosts[:] while hosts1: host = hosts1.pop() second_host = HostInfo(0) host_state = "N" for host2 in hosts2: if (host.mac and host.mac == host2.mac) or \ (host.ip and host.ip == host2.ip) or \ (host.ipv6 and host.ipv6 == host2.ipv6): second_host = host2 host_state = "" del(hosts2[hosts2.index(host2)]) # Remove it from the hosts2 break self.add_host_diff(host_state, host, second_host) for host in hosts2: self.add_host_diff("A", host, host) return self.root_sections
def make_diff(self): self.clear_diff_tree() self.root_sections = [] section = _("Umit Info") parent = self.append_parent(None, section, "") self.root_sections.append(parent) self.diff_it(parent, "", _("Profile"), self.parsed1.profile, self.parsed2.profile) self.diff_it(parent, "", _("Profile Name"), self.parsed1.profile_name, self.parsed2.profile_name) self.diff_it(parent, "", _("Profile Options"), self.parsed1.profile_options, self.parsed2.profile_options) self.diff_it(parent, "", _("Target"), self.parsed1.target, self.parsed2.target) section = _("Nmap Info") parent = self.append_parent(None, section, "") self.root_sections.append(parent) self.diff_it(parent, "", _("Debugging"), self.parsed1.debugging_level, self.parsed2.debugging_level) self.diff_it(parent, "", _("Verbosity"), self.parsed1.verbose_level, self.parsed2.verbose_level) self.diff_it(parent, "", _("Command"), self.parsed1.nmap_command, self.parsed2.nmap_command) self.diff_it(parent, "", _("Scanner version"), self.parsed1.scanner_version, self.parsed2.scanner_version) section = _("Scan Info") parent = self.append_parent(None, section, "") self.root_sections.append(parent) self.diff_it(parent, "", _("Open Ports"), self.parsed1.open_ports, self.parsed2.open_ports) self.diff_it(parent, "", _("Filtered Ports"), self.parsed1.filtered_ports, self.parsed2.filtered_ports) self.diff_it(parent, "", _("Closed Ports"), self.parsed1.closed_ports, self.parsed2.closed_ports) self.diff_it(parent, "", _("Hosts Up"), self.parsed1.hosts_up, self.parsed2.hosts_up) self.diff_it(parent, "", _("Hosts Down"), self.parsed1.hosts_down, self.parsed2.hosts_down) self.diff_it(parent, "", _("Hosts Scanned"), self.parsed1.hosts_scanned, self.parsed2.hosts_scanned) self.diff_it(parent, "", _("Finish date"), self.parsed1.formated_finish_date, self.parsed2.formated_finish_date) hosts1 = self.parsed1.hosts[:] hosts2 = self.parsed2.hosts[:] while hosts1: host = hosts1.pop() second_host = HostInfo(0) host_state = "N" for host2 in hosts2: if (host.mac and host.mac == host2.mac) or \ (host.ip and host.ip == host2.ip) or \ (host.ipv6 and host.ipv6 == host2.ipv6): second_host = host2 host_state = "" del (hosts2[hosts2.index(host2)] ) # Remove it from the hosts2 break self.add_host_diff(host_state, host, second_host) for host in hosts2: self.add_host_diff("A", host, host) return self.root_sections
def get_vendor(self): try:return self._mac['vendor'] except:return _('Unknown')
def __init__(self, args=False): OptionParser.__init__(self) ## Network Inventory (GUI) ### This option should raise the Network Inventory window ### with the last used inventory self.add_option("-i", "--inventory", default=False, action="store_true", help=_("*NOT IMPLEMENTED* - Start Umit and go \ straight to Network Inventory window.")) ## Run nmap with args (GUI) ### Open Umit and runs nmap with specified args. The positional ### args should be used to feed the nmap command self.add_option("-n", "--nmap", default=[], action="callback", callback=self.__nmap_callback, help=_("Open Umit and runs a Nmap scan with \ specified args.")) ## Execute a profile against a target (GUI) ### Positional args should be taken as targets to feed this scan self.add_option("-p", "--profile", default="", action="store", help=_("Open Umit with the specified profile \ selected. If combined with the -t (--target) option, open Umit and \ automatically run the profile against the specified target.")) ## Compare results in compare mode (GUI) ### Run the diff compare window in compare mode as default self.add_option("-c", "--compare", action="store", nargs=2, help=_("*NOT IMPLEMENTED* - Open the diff compare \ window, in compare mode comparing the two given scan result files \ (Nmap XML output or usr (Umit Scan Result) file).")) ## Compare results in text mode (GUI) ### Run the diff compare window in text mode as default self.add_option("-e", "--compare-text", action="store", nargs=2, help=_("*NOT IMPLEMENTED* - Open the diff compare \ window, in text mode comparing the two given scan result files (Nmap XML \ output or usr, Umit Scan Result).")) ## Compare results showing text diff in terminal (TEXT) ### Doesn't actually run Umit interface. Just take the result files, ### generate the text diff and send it back to terminal self.add_option( "-d", "--diff", action="store", nargs=2, help=_("*NOT IMPLEMENTED* - Take two scan result files \ (Nmap XML output or usr, Umit Scan Result), make a text diff and print it in \ the terminal without openning Umit Interface.")) ## NSE Facilitator (GUI) ### Opens Umit and go straigh to NSE Facilitator interface. ### If a positional argument is given, it can be an nse script which ### should be openned by the NSE Facilitator interface self.add_option("-s", "--nse-facilitator", default=False, action="store_true", help=_("*NOT IMPLEMENTED* - Run Umit and go straight \ to NSE Facilitator Interface. You may specify nse scripts as arguments \ if you want use them.")) ## Targets (GUI) ### Specify a target to be used along with other command line option ### or simply opens Umit with the first tab target field filled with ### the target specified with this option self.add_option("-t", "--target", default=False, action="store", help=_("Specify a target to be used along with other \ options. If specified alone, opens Umit with the target field filled with the \ specified target")) ## Open Scan Results (GUI) ### Run Umit openning the specified scan result file, which should be ### a nmap XML output or an usr (Umit Scan Result) xml file. ### This option should be verified if there is no options, and user ### specified some positional arguments, which should be considered as ### scan result files. self.add_option("-f", "--file", default=[], action="append", type="string", dest="result_files", help=_("Specify a scan result file in Nmap XML Output \ or Umit Scan Result file. Can be used more than once to specify several \ scan result files.")) ## Open a give file, showing it at mapper (GUI) ### Specify a scan file result to open at mapper self.add_option("-m", "--mapper", default=False, action="store", help=_("*NOT IMPLEMENTED* - Open Umit showing the \ given file at Umit Mapper")) ## Verbosity self.add_option("-v", "--verbose", default=0, action="count", help=_("Increase verbosity of the output. May be \ used more than once to get even more verbosity")) # Parsing options and arguments if args: self.options, self.args = self.parse_args(args) else: self.options, self.args = self.parse_args()
def parse(self): """Parse the object passed by the instance to a string containing the JSON object. """ raise NameError, _("Method not implemented")
def _to_json(self, obj): raise NameError, _("Method not implemented")
import re import os import os.path import time from types import StringTypes from xml.sax import make_parser from xml.sax.handler import ContentHandler from xml.sax.saxutils import XMLGenerator from xml.sax.xmlreader import AttributesImpl as Attributes from umitCore.I18N import _ from umitCore.UmitLogging import log months = ('',_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December'),) class HostInfo(object): def __init__(self, id): self.id = id