class HostDetails(HIGVBox): def __init__(self, host): HIGVBox.__init__(self) self.__create_widgets() self.set_os_image(get_os_logo(host)) self.set_vulnerability_image( get_vulnerability_logo(host.get_open_ports())) self.set_host_status({ 'state': host.get_state(), 'open': str(host.get_open_ports()), 'filtered': str(host.get_filtered_ports()), 'closed': str(host.get_closed_ports()), 'scanned': str(host.get_scanned_ports()), 'uptime': host.get_uptime()['seconds'], 'lastboot': host.get_uptime()['lastboot'] }) addresses = {} if host.ip is not None: addresses['ipv4'] = host.ip['addr'] if host.ipv6 is not None: addresses['ipv6'] = host.ipv6['addr'] if host.mac is not None: addresses['mac'] = host.mac['addr'] self.set_addresses(addresses) self.set_hostnames(host.get_hostnames()) os = host.get_best_osmatch() if os: os['portsused'] = host.get_ports_used() self.set_os(os) self.set_tcpseq(host.get_tcpsequence()) self.set_ipseq(host.get_ipidsequence()) self.set_tcptsseq(host.get_tcptssequence()) self.set_comment(host.comment) def __create_widgets(self): self.host_status_expander = gtk.Expander('<b>' + _('Host Status') + '</b>') self.address_expander = gtk.Expander('<b>' + _('Addresses') + '</b>') self.hostnames_expander = gtk.Expander('<b>' + _('Hostnames') + '</b>') self.os_expander = gtk.Expander('<b>' + _('Operating System') + '</b>') self.portsused_expander = gtk.Expander('<b>' + _('Ports used') + '</b>') self.osclass_expander = gtk.Expander('<b>' + _('OS Classes') + '</b>') self.tcp_expander = gtk.Expander('<b>' + _('TCP Sequence') + '</b>') self.ip_expander = gtk.Expander('<b>' + _('IP ID Sequence') + '</b>') self.tcpts_expander = gtk.Expander('<b>' + _('TCP TS Sequence') + '</b>') self.comment_expander = gtk.Expander('<b>' + _('Comments') + '</b>') self.os_image = gtk.Image() self.vulnerability_image = gtk.Image() # Host Status expander self.host_state_label = HIGEntryLabel(_('State:')) self.info_host_state_label = HIGEntryLabel(na) self.open_label = HIGEntryLabel(_('Open ports:')) self.info_open_ports = HIGEntryLabel(na) self.filtered_label = HIGEntryLabel(_('Filtered ports:')) self.info_filtered_label = HIGEntryLabel(na) self.closed_label = HIGEntryLabel(_('Closed ports:')) self.info_closed_ports = HIGEntryLabel(na) self.scanned_label = HIGEntryLabel(_('Scanned ports:')) self.info_scanned_label = HIGEntryLabel(na) self.uptime_label = HIGEntryLabel(_('Up time:')) self.info_uptime_label = HIGEntryLabel(na) self.lastboot_label = HIGEntryLabel(_('Last boot:')) self.info_lastboot_label = HIGEntryLabel(na) # Addresses expander self.ipv4_label = HIGEntryLabel(_('IPv4:')) self.info_ipv4_label = HIGEntryLabel(na) self.ipv6_label = HIGEntryLabel(_('IPv6:')) self.info_ipv6_label = HIGEntryLabel(na) self.mac_label = HIGEntryLabel(_('MAC:')) self.info_mac_label = HIGEntryLabel(na) self.vendor_label = HIGEntryLabel(_('Vendor:')) self.info_vendor_label = HIGEntryLabel(na) def create_table_hbox(self): table = HIGTable() hbox = HIGHBox() hbox._pack_noexpand_nofill(hig_box_space_holder()) hbox._pack_noexpand_nofill(table) return table, hbox def set_host_status(self, status): self.host_status_expander.set_use_markup(True) self.host_status_expander.set_expanded(True) table, hbox = self.create_table_hbox() if ('state' in status and status['state'] != ''): self.info_host_state_label.set_text(status['state']) if ('open' in status and status['open'] != ''): self.info_open_ports.set_text(status['open']) if ('filtered' in status and status['filtered'] != ''): self.info_filtered_label.set_text(status['filtered']) if ('closed' in status and status['closed'] != ''): self.info_closed_ports.set_text(status['closed']) if ('scanned' in status and status['scanned'] != ''): self.info_scanned_label.set_text(status['scanned']) if ('uptime' in status and status['uptime'] != ''): self.info_uptime_label.set_text(status['uptime']) if ('lastboot' in status and status['lastboot'] != ''): self.info_lastboot_label.set_text(status['lastboot']) table.attach(self.host_state_label, 0, 1, 0, 1) table.attach(self.info_host_state_label, 1, 2, 0, 1) table.attach(self.open_label, 0, 1, 1, 2) table.attach(self.info_open_ports, 1, 2, 1, 2) table.attach(self.filtered_label, 0, 1, 2, 3) table.attach(self.info_filtered_label, 1, 2, 2, 3) table.attach(self.closed_label, 0, 1, 3, 4) table.attach(self.info_closed_ports, 1, 2, 3, 4) table.attach(self.scanned_label, 0, 1, 4, 5) table.attach(self.info_scanned_label, 1, 2, 4, 5) table.attach(self.uptime_label, 0, 1, 5, 6) table.attach(self.info_uptime_label, 1, 2, 5, 6) table.attach(self.lastboot_label, 0, 1, 6, 7) table.attach(self.info_lastboot_label, 1, 2, 6, 7) table.attach(self.os_image, 2, 4, 0, 3, xoptions=1, yoptions=0) table.attach(self.vulnerability_image, 2, 4, 4, 7, xoptions=1, yoptions=0) table.set_col_spacing(1, 50) self.host_status_expander.add(hbox) self._pack_noexpand_nofill(self.host_status_expander) def set_os_image(self, image): self.os_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) def set_vulnerability_image(self, image): self.vulnerability_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) def set_addresses(self, address): self.address_expander.set_use_markup(True) table, hbox = self.create_table_hbox() self.address_expander.set_expanded(True) #print '>>> Address:', address if ('ipv4' in address and address['ipv4'] != 1): self.info_ipv4_label.set_text(address['ipv4']) if ('ipv6' in address and address['ipv6'] != 1): self.info_ipv6_label.set_text(address['ipv6']) if ('mac' in address and address['mac'] != 1): self.info_mac_label.set_text(address['mac']) table.attach(self.ipv4_label, 0, 1, 0, 1) table.attach(self.info_ipv4_label, 1, 2, 0, 1) table.attach(self.ipv6_label, 0, 1, 1, 2) table.attach(self.info_ipv6_label, 1, 2, 1, 2) table.attach(self.mac_label, 0, 1, 2, 3) table.attach(self.info_mac_label, 1, 2, 2, 3) self.address_expander.add(hbox) self._pack_noexpand_nofill(self.address_expander) def set_hostnames(self, hostname): if hostname: self.hostnames_expander.set_use_markup(True) self.hostnames_expander.set_expanded(True) table, hbox = self.create_table_hbox() y1 = 1 y2 = 2 for h in hostname: name = h.get('hostname', na) type = h.get('hostname_type', na) table.attach(HIGEntryLabel(_('Name - Type:')), 0, 1, y1, y2) table.attach(HIGEntryLabel(name + ' - ' + type), 1, 2, y1, y2) y1 += 1 y2 += 1 self.hostnames_expander.add(hbox) self._pack_noexpand_nofill(self.hostnames_expander) def set_os(self, os): if os: self.os_expander.set_use_markup(True) self.os_expander.set_expanded(True) table, hbox = self.create_table_hbox() progress = gtk.ProgressBar() if 'accuracy' in os: progress.set_fraction(float(os['accuracy']) / 100.0) progress.set_text(os['accuracy'] + '%') else: progress.set_text(_('Not Available')) table.attach(HIGEntryLabel(_('Name:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(os['name']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Accuracy:')), 0, 1, 1, 2) table.attach(progress, 1, 2, 1, 2) y1 = 2 y2 = 3 if 'portsused' in os: self.set_ports_used(os['portsused']) table.attach(self.portsused_expander, 0, 2, y1, y2) y1 += 1 y2 += 1 if 'osclasses' in os: self.set_osclass(os['osclasses']) self.osclass_expander.set_use_markup(True) table.attach(self.osclass_expander, 0, 2, y1, y2) self.os_expander.add(hbox) self._pack_noexpand_nofill(self.os_expander) def set_ports_used(self, ports): self.portsused_expander.set_use_markup(True) table, hbox = self.create_table_hbox() y1 = 0 y2 = 1 for p in ports: table.attach(HIGEntryLabel(_('Port-Protocol-State:')), 0, 1, y1, y2) table.attach( HIGEntryLabel(p['portid'] + ' - ' + p['proto'] + ' - ' + p['state']), 1, 2, y1, y2) y1 += 1 y2 += 1 self.portsused_expander.add(hbox) def set_osclass(self, osclass): if osclass: self.osclass_expander.set_use_markup(True) table, hbox = self.create_table_hbox() table.attach(HIGEntryLabel(_('Type')), 0, 1, 0, 1) table.attach(HIGEntryLabel(_('Vendor')), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('OS Family')), 2, 3, 0, 1) table.attach(HIGEntryLabel(_('OS Generation')), 3, 4, 0, 1) table.attach(HIGEntryLabel(_('Accuracy')), 4, 5, 0, 1) y1 = 1 y2 = 2 for o in osclass: table.attach(HIGEntryLabel(o['type']), 0, 1, y1, y2) table.attach(HIGEntryLabel(o['vendor']), 1, 2, y1, y2) table.attach(HIGEntryLabel(o['osfamily']), 2, 3, y1, y2) table.attach(HIGEntryLabel(o['osgen']), 3, 4, y1, y2) progress = gtk.ProgressBar() progress.set_text(o['accuracy'] + '%') progress.set_fraction(float(o['accuracy']) / 100.0) table.attach(progress, 4, 5, y1, y2) y1 += 1 y2 += 1 self.osclass_expander.add(hbox) def set_tcpseq(self, tcpseq): if tcpseq: self.tcp_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for v in tcpseq['values'].split(','): combo.append_text(v) table.attach(HIGEntryLabel(_('Difficulty:')), 0, 1, 1, 2) table.attach(HIGEntryLabel(tcpseq['difficulty']), 1, 2, 1, 2) table.attach(HIGEntryLabel(_('Index:')), 0, 1, 2, 3) table.attach(HIGEntryLabel(tcpseq['index']), 1, 2, 2, 3) table.attach(HIGEntryLabel(_('Values:')), 0, 1, 3, 4) table.attach(combo, 1, 2, 3, 4) self.tcp_expander.add(hbox) self._pack_noexpand_nofill(self.tcp_expander) def set_ipseq(self, ipseq): if ipseq: self.ip_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for i in ipseq['values'].split(','): combo.append_text(i) table.attach(HIGEntryLabel(_('Class:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(ipseq['class']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Values:')), 0, 1, 1, 2) table.attach(combo, 1, 2, 1, 2) self.ip_expander.add(hbox) self._pack_noexpand_nofill(self.ip_expander) def set_tcptsseq(self, tcptsseq): if tcptsseq: self.tcpts_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for i in tcptsseq['values'].split(','): combo.append_text(i) table.attach(HIGEntryLabel(_('Class:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(tcptsseq['class']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Values:')), 0, 1, 1, 2) table.attach(combo, 1, 2, 1, 2) self.tcpts_expander.add(hbox) self._pack_noexpand_nofill(self.tcpts_expander) def set_comment(self, comment=''): self.comment_expander.set_use_markup(True) if comment: self.comment_expander.set_expanded(True) hbox = HIGHBox() self.comment_scrolled = gtk.ScrolledWindow() self.comment_scrolled.set_border_width(5) self.comment_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.comment_txt_vw = gtk.TextView() self.comment_txt_vw.set_wrap_mode(gtk.WRAP_WORD) self.comment_txt_vw.get_buffer().set_text(comment) self.comment_scrolled.add(self.comment_txt_vw) hbox._pack_expand_fill(self.comment_scrolled) self.comment_expander.add(hbox) self._pack_noexpand_nofill(self.comment_expander) def get_comment(self): buffer = self.comment_txt_vw.get_buffer() return buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
class ScanRunDetailsPage(HIGVBox): def __init__(self, scan): HIGVBox.__init__(self) na = _('Not available') # Command info self.command_label = HIGEntryLabel(_('Command:')) self.info_command_label = HIGEntryLabel(na) self.nmap_version_label = HIGEntryLabel(_('Nmap Version:')) self.info_nmap_version_label = HIGEntryLabel(na) self.verbose_label = HIGEntryLabel(_('Verbosity level:')) self.info_verbose_label = HIGEntryLabel(na) self.debug_label = HIGEntryLabel(_('Debug level:')) self.info_debug_label = HIGEntryLabel(na) self.command_expander = gtk.Expander("<b>" + _("Command Info") + "</b>") self.command_expander.set_use_markup(True) self.command_table = HIGTable() self.command_table.set_border_width(5) self.command_table.set_row_spacings(6) self.command_table.set_col_spacings(6) self.command_hbox = HIGHBox() self.command_hbox._pack_noexpand_nofill(hig_box_space_holder()) self.command_hbox._pack_noexpand_nofill(self.command_table) self.command_table.attach(self.command_label, 0, 1, 0, 1) self.command_table.attach(self.info_command_label, 1, 2, 0, 1) self.command_table.attach(self.nmap_version_label, 0, 1, 1, 2) self.command_table.attach(self.info_nmap_version_label, 1, 2, 1, 2) self.command_table.attach(self.verbose_label, 0, 1, 2, 3) self.command_table.attach(self.info_verbose_label, 1, 2, 2, 3) self.command_table.attach(self.debug_label, 0, 1, 3, 4) self.command_table.attach(self.info_debug_label, 1, 2, 3, 4) self.command_expander.add(self.command_hbox) self._pack_noexpand_nofill(self.command_expander) self.command_expander.set_expanded(True) # General info: self.start_label = HIGEntryLabel(_('Started on:')) self.info_start_label = HIGEntryLabel(na) self.finished_label = HIGEntryLabel(_('Finished on:')) self.info_finished_label = HIGEntryLabel(na) self.host_up_label = HIGEntryLabel(_('Hosts up:')) self.info_hosts_up_label = HIGEntryLabel(na) self.host_down_label = HIGEntryLabel(_('Hosts down:')) self.info_hosts_down_label = HIGEntryLabel(na) self.host_scanned_label = HIGEntryLabel(_('Hosts scanned:')) self.info_hosts_scanned_label = HIGEntryLabel(na) self.open_label = HIGEntryLabel(_('Open ports:')) self.info_open_label = HIGEntryLabel(na) self.filtered_label = HIGEntryLabel(_('Filtered ports:')) self.info_filtered_label = HIGEntryLabel(na) self.closed_label = HIGEntryLabel(_('Closed ports:')) self.info_closed_label = HIGEntryLabel(na) self.general_expander = gtk.Expander("<b>" + _("General Info") + "</b>") self.general_expander.set_use_markup(True) self.general_table = HIGTable() self.general_table.set_border_width(5) self.general_table.set_row_spacings(6) self.general_table.set_col_spacings(6) self.general_hbox = HIGHBox() self.general_hbox._pack_noexpand_nofill(hig_box_space_holder()) self.general_hbox._pack_noexpand_nofill(self.general_table) self.general_table.attach(self.start_label, 0, 1, 0, 1) self.general_table.attach(self.info_start_label, 1, 2, 0, 1) self.general_table.attach(self.finished_label, 0, 1, 1, 2) self.general_table.attach(self.info_finished_label, 1, 2, 1, 2) self.general_table.attach(self.host_up_label, 0, 1, 2, 3) self.general_table.attach(self.info_hosts_up_label, 1, 2, 2, 3) self.general_table.attach(self.host_down_label, 0, 1, 3, 4) self.general_table.attach(self.info_hosts_down_label, 1, 2, 3, 4) self.general_table.attach(self.host_scanned_label, 0, 1, 4, 5) self.general_table.attach(self.info_hosts_scanned_label, 1, 2, 4, 5) self.general_table.attach(self.open_label, 0, 1, 5, 6) self.general_table.attach(self.info_open_label, 1, 2, 5, 6) self.general_table.attach(self.filtered_label, 0, 1, 6, 7) self.general_table.attach(self.info_filtered_label, 1, 2, 6, 7) self.general_table.attach(self.closed_label, 0, 1, 7, 8) self.general_table.attach(self.info_closed_label, 1, 2, 7, 8) self.general_expander.add(self.general_hbox) self._pack_noexpand_nofill(self.general_expander) self.general_expander.set_expanded(True) self._set_from_scan(scan) def _set_from_scan(self, scan): """Initialize the display from a parsed scan.""" # Command info. self.info_command_label.set_text(scan.get_nmap_command()) self.info_nmap_version_label.set_text(scan.get_scanner_version()) self.info_verbose_label.set_text(scan.get_verbose_level()) self.info_debug_label.set_text(scan.get_debugging_level()) # General info. self.info_start_label.set_text(scan.get_formatted_date()) self.info_finished_label.set_text(scan.get_formatted_finish_date()) self.info_hosts_up_label.set_text(str(scan.get_hosts_up())) self.info_hosts_down_label.set_text(str(scan.get_hosts_down())) self.info_hosts_scanned_label.set_text(str(scan.get_hosts_scanned())) self.info_open_label.set_text(str(scan.get_open_ports())) self.info_filtered_label.set_text(str(scan.get_filtered_ports())) self.info_closed_label.set_text(str(scan.get_closed_ports())) for scaninfo in scan.get_scaninfo(): exp = gtk.Expander('<b>%s - %s</b>' % (_('Scan Info'), scaninfo['type'].capitalize())) exp.set_use_markup(True) display = self.make_scaninfo_display(scaninfo) exp.add(display) self._pack_noexpand_nofill(exp) def make_scaninfo_display(self, scaninfo): """Return a widget displaying a scan's "scaninfo" information: type, protocol, number of scanned ports, and list of services.""" hbox = HIGHBox() table = HIGTable() table.set_border_width(5) table.set_row_spacings(6) table.set_col_spacings(6) table.attach(HIGEntryLabel(_('Scan type:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(scaninfo['type']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Protocol:')), 0, 1, 1, 2) table.attach(HIGEntryLabel(scaninfo['protocol']), 1, 2, 1, 2) table.attach(HIGEntryLabel(_('# scanned ports:')), 0, 1, 2, 3) table.attach(HIGEntryLabel(scaninfo['numservices']), 1, 2, 2, 3) table.attach(HIGEntryLabel(_('Services:')), 0, 1, 3, 4) table.attach(self.make_services_display(scaninfo['services']), 1, 2, 3, 4) hbox._pack_noexpand_nofill(hig_box_space_holder()) hbox._pack_noexpand_nofill(table) return hbox def make_services_display(self, services): """Return a widget displaying a list of services like 1-1027,1029-1033,1040,1043,1050,1058-1059,1067-1068,1076,1080""" combo = gtk.combo_box_new_text() for i in services.split(","): combo.append_text(i) return combo
class HighlightProperty(object): def __init__(self, property_name, property): self.__create_widgets() self.property_name = property_name self.property_label = property[0].capitalize() self.example = property[1] self.bold = property[2] self.italic = property[3] self.underline = property[4] self.text_color = property[5] self.highlight_color = property[6] self.__connect_buttons() def __create_widgets(self): self.property_name_label = HIGEntryLabel("") self.example_label = HIGEntryLabel("") self.bold_tg_button = HIGToggleButton("", gtk.STOCK_BOLD) self.italic_tg_button = HIGToggleButton("", gtk.STOCK_ITALIC) self.underline_tg_button = HIGToggleButton("", gtk.STOCK_UNDERLINE) self.text_color_button = HIGButton( _("Text"), stock=gtk.STOCK_SELECT_COLOR) self.highlight_color_button = HIGButton( _("Highlight"), stock=gtk.STOCK_SELECT_COLOR) def __connect_buttons(self): self.bold_tg_button.connect("toggled", self.update_example) self.italic_tg_button.connect("toggled", self.update_example) self.underline_tg_button.connect("toggled", self.update_example) self.text_color_button.connect("clicked", self.text_color_dialog) self.highlight_color_button.connect( "clicked", self.highlight_color_dialog) #################################### # Text color dialog def text_color_dialog(self, widget): color_dialog = gtk.ColorSelectionDialog( "%s %s" % (self.label, _("text color"))) color_dialog.colorsel.set_current_color(self.text_color) color_dialog.ok_button.connect( "clicked", self.text_color_dialog_ok, color_dialog) color_dialog.cancel_button.connect( "clicked", self.text_color_dialog_cancel, color_dialog) color_dialog.connect( "delete-event", self.text_color_dialog_close, color_dialog) color_dialog.run() def text_color_dialog_ok(self, widget, color_dialog): self.text_color = color_dialog.colorsel.get_current_color() color_dialog.destroy() self.update_example() def text_color_dialog_cancel(self, widget, color_dialog): color_dialog.destroy() def text_color_dialog_close(self, widget, extra, color_dialog): color_dialog.destroy() ######################################### # Highlight color dialog def highlight_color_dialog(self, widget): color_dialog = gtk.ColorSelectionDialog( "%s %s" % (self.property_name, _("highlight color"))) color_dialog.colorsel.set_current_color(self.highlight_color) color_dialog.ok_button.connect( "clicked", self.highlight_color_dialog_ok, color_dialog) color_dialog.cancel_button.connect( "clicked", self.highlight_color_dialog_cancel, color_dialog) color_dialog.connect( "delete-event", self.highlight_color_dialog_close, color_dialog) color_dialog.run() def highlight_color_dialog_ok(self, widget, color_dialog): self.highlight_color = color_dialog.colorsel.get_current_color() color_dialog.destroy() self.update_example() def highlight_color_dialog_cancel(self, widget, color_dialog): color_dialog.destroy() def highlight_color_dialog_close(self, widget, extra, color_dialog): color_dialog.destroy() def update_example(self, widget=None): start = 0 end = len(self.example) attributes = pango.AttrList() attributes.insert( pango.AttrForeground(self.text_color.red, self.text_color.green, self.text_color.blue, start, end)) attributes.insert(pango.AttrBackground(self.highlight_color.red, self.highlight_color.green, self.highlight_color.blue, start, end)) # Bold verification if self.bold_tg_button.get_active(): attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, start, end)) else: attributes.insert( pango.AttrWeight(pango.WEIGHT_NORMAL, start, end)) # Italic verification if self.italic_tg_button.get_active(): attributes.insert(pango.AttrStyle(pango.STYLE_ITALIC, start, end)) else: attributes.insert(pango.AttrStyle(pango.STYLE_NORMAL, start, end)) # Underline verification if self.underline_tg_button.get_active(): attributes.insert( pango.AttrUnderline(pango.UNDERLINE_SINGLE, start, end)) else: attributes.insert( pango.AttrUnderline(pango.UNDERLINE_NONE, start, end)) self.example_label.set_attributes(attributes) def show_bold(self, widget): self.example_label.set_markup("<>") def get_example(self): return self.example_label.get_text() def set_example(self, example): self.example_label.set_text(example) def get_bold(self): if self.bold_tg_button.get_active(): return 1 return 0 def set_bold(self, bold): self.bold_tg_button.set_active(bold) def get_italic(self): if self.italic_tg_button.get_active(): return 1 return 0 def set_italic(self, italic): self.italic_tg_button.set_active(italic) def get_underline(self): if self.underline_tg_button.get_active(): return 1 return 0 def set_underline(self, underline): self.underline_tg_button.set_active(underline) def get_label(self): return self.property_name_label.get_text() def set_label(self, label): self.property_name_label.set_text(label) label = property(get_label, set_label) example = property(get_example, set_example) bold = property(get_bold, set_bold) italic = property(get_italic, set_italic) underline = property(get_underline, set_underline)
class HostDetails(HIGVBox): def __init__(self, host): HIGVBox.__init__(self) self.__create_widgets() self.set_os_image(get_os_logo(host)) self.set_vulnerability_image(get_vulnerability_logo(host.get_open_ports())) self.set_host_status( { "state": host.get_state(), "open": str(host.get_open_ports()), "filtered": str(host.get_filtered_ports()), "closed": str(host.get_closed_ports()), "scanned": str(host.get_scanned_ports()), "uptime": host.get_uptime()["seconds"], "lastboot": host.get_uptime()["lastboot"], } ) addresses = {} if host.ip is not None: addresses["ipv4"] = host.ip["addr"] if host.ipv6 is not None: addresses["ipv6"] = host.ipv6["addr"] if host.mac is not None: addresses["mac"] = host.mac["addr"] self.set_addresses(addresses) self.set_hostnames(host.get_hostnames()) os = host.get_best_osmatch() if os: os["portsused"] = host.get_ports_used() self.set_os(os) self.set_tcpseq(host.get_tcpsequence()) self.set_ipseq(host.get_ipidsequence()) self.set_tcptsseq(host.get_tcptssequence()) self.set_comment(host.comment) def __create_widgets(self): self.host_status_expander = gtk.Expander("<b>" + _("Host Status") + "</b>") self.address_expander = gtk.Expander("<b>" + _("Addresses") + "</b>") self.hostnames_expander = gtk.Expander("<b>" + _("Hostnames") + "</b>") self.os_expander = gtk.Expander("<b>" + _("Operating System") + "</b>") self.portsused_expander = gtk.Expander("<b>" + _("Ports used") + "</b>") self.osclass_expander = gtk.Expander("<b>" + _("OS Classes") + "</b>") self.tcp_expander = gtk.Expander("<b>" + _("TCP Sequence") + "</b>") self.ip_expander = gtk.Expander("<b>" + _("IP ID Sequence") + "</b>") self.tcpts_expander = gtk.Expander("<b>" + _("TCP TS Sequence") + "</b>") self.comment_expander = gtk.Expander("<b>" + _("Comments") + "</b>") self.os_image = gtk.Image() self.vulnerability_image = gtk.Image() # Host Status expander self.host_state_label = HIGEntryLabel(_("State:")) self.info_host_state_label = HIGEntryLabel(na) self.open_label = HIGEntryLabel(_("Open ports:")) self.info_open_ports = HIGEntryLabel(na) self.filtered_label = HIGEntryLabel(_("Filtered ports:")) self.info_filtered_label = HIGEntryLabel(na) self.closed_label = HIGEntryLabel(_("Closed ports:")) self.info_closed_ports = HIGEntryLabel(na) self.scanned_label = HIGEntryLabel(_("Scanned ports:")) self.info_scanned_label = HIGEntryLabel(na) self.uptime_label = HIGEntryLabel(_("Up time:")) self.info_uptime_label = HIGEntryLabel(na) self.lastboot_label = HIGEntryLabel(_("Last boot:")) self.info_lastboot_label = HIGEntryLabel(na) # Addresses expander self.ipv4_label = HIGEntryLabel(_("IPv4:")) self.info_ipv4_label = HIGEntryLabel(na) self.ipv6_label = HIGEntryLabel(_("IPv6:")) self.info_ipv6_label = HIGEntryLabel(na) self.mac_label = HIGEntryLabel(_("MAC:")) self.info_mac_label = HIGEntryLabel(na) self.vendor_label = HIGEntryLabel(_("Vendor:")) self.info_vendor_label = HIGEntryLabel(na) def create_table_hbox(self): table = HIGTable() hbox = HIGHBox() hbox._pack_noexpand_nofill(hig_box_space_holder()) hbox._pack_noexpand_nofill(table) return table, hbox def set_host_status(self, status): self.host_status_expander.set_use_markup(True) self.host_status_expander.set_expanded(True) table, hbox = self.create_table_hbox() try: if status["state"] == "": raise Exception self.info_host_state_label.set_text(status["state"]) except: pass try: if status["open"] == "": raise Exception self.info_open_ports.set_text(status["open"]) except: pass try: if status["filtered"] == "": raise Exception self.info_filtered_label.set_text(status["filtered"]) except: pass try: if status["closed"] == "": raise Exception self.info_closed_ports.set_text(status["closed"]) except: pass try: if status["scanned"] == "": raise Exception self.info_scanned_label.set_text(status["scanned"]) except: pass try: if status["uptime"] == "": raise Exception self.info_uptime_label.set_text(status["uptime"]) except: pass try: if status["lastboot"] == "": raise Exception self.info_lastboot_label.set_text(status["lastboot"]) except: pass table.attach(self.host_state_label, 0, 1, 0, 1) table.attach(self.info_host_state_label, 1, 2, 0, 1) table.attach(self.open_label, 0, 1, 1, 2) table.attach(self.info_open_ports, 1, 2, 1, 2) table.attach(self.filtered_label, 0, 1, 2, 3) table.attach(self.info_filtered_label, 1, 2, 2, 3) table.attach(self.closed_label, 0, 1, 3, 4) table.attach(self.info_closed_ports, 1, 2, 3, 4) table.attach(self.scanned_label, 0, 1, 4, 5) table.attach(self.info_scanned_label, 1, 2, 4, 5) table.attach(self.uptime_label, 0, 1, 5, 6) table.attach(self.info_uptime_label, 1, 2, 5, 6) table.attach(self.lastboot_label, 0, 1, 6, 7) table.attach(self.info_lastboot_label, 1, 2, 6, 7) table.attach(self.os_image, 2, 4, 0, 3, xoptions=1, yoptions=0) table.attach(self.vulnerability_image, 2, 4, 4, 7, xoptions=1, yoptions=0) table.set_col_spacing(1, 50) self.host_status_expander.add(hbox) self._pack_noexpand_nofill(self.host_status_expander) def set_os_image(self, image): self.os_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) def set_vulnerability_image(self, image): self.vulnerability_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) def set_addresses(self, address): self.address_expander.set_use_markup(True) table, hbox = self.create_table_hbox() self.address_expander.set_expanded(True) # print '>>> Address:', address try: if address["ipv4"] == 1: raise Exception self.info_ipv4_label.set_text(address["ipv4"]) except: pass try: if address["ipv6"] == 1: raise Exception self.info_ipv6_label.set_text(address["ipv6"]) except: pass try: if address["mac"] == 1: raise Exception self.info_mac_label.set_text(address["mac"]) except: pass table.attach(self.ipv4_label, 0, 1, 0, 1) table.attach(self.info_ipv4_label, 1, 2, 0, 1) table.attach(self.ipv6_label, 0, 1, 1, 2) table.attach(self.info_ipv6_label, 1, 2, 1, 2) table.attach(self.mac_label, 0, 1, 2, 3) table.attach(self.info_mac_label, 1, 2, 2, 3) self.address_expander.add(hbox) self._pack_noexpand_nofill(self.address_expander) def set_hostnames(self, hostname): if hostname: self.hostnames_expander.set_use_markup(True) self.hostnames_expander.set_expanded(True) table, hbox = self.create_table_hbox() y1 = 1 y2 = 2 for h in hostname: name = na try: name = h["hostname"] except: pass type = na try: type = h["hostname_type"] except: pass table.attach(HIGEntryLabel(_("Name - Type:")), 0, 1, y1, y2) table.attach(HIGEntryLabel(name + " - " + type), 1, 2, y1, y2) y1 += 1 y2 += 1 self.hostnames_expander.add(hbox) self._pack_noexpand_nofill(self.hostnames_expander) def set_os(self, os): if os: self.os_expander.set_use_markup(True) self.os_expander.set_expanded(True) table, hbox = self.create_table_hbox() progress = gtk.ProgressBar() try: progress.set_fraction(float(os["accuracy"]) / 100.0) progress.set_text(os["accuracy"] + "%") except: progress.set_text(_("Not Available")) table.attach(HIGEntryLabel(_("Name:")), 0, 1, 0, 1) table.attach(HIGEntryLabel(os["name"]), 1, 2, 0, 1) table.attach(HIGEntryLabel(_("Accuracy:")), 0, 1, 1, 2) table.attach(progress, 1, 2, 1, 2) y1 = 2 y2 = 3 try: self.set_ports_used(os["portsused"]) table.attach(self.portsused_expander, 0, 2, y1, y2) y1 += 1 y2 += 1 except: pass try: self.set_osclass(os["osclasses"]) self.osclass_expander.set_use_markup(True) table.attach(self.osclass_expander, 0, 2, y1, y2) except: pass self.os_expander.add(hbox) self._pack_noexpand_nofill(self.os_expander) def set_ports_used(self, ports): self.portsused_expander.set_use_markup(True) table, hbox = self.create_table_hbox() y1 = 0 y2 = 1 for p in ports: table.attach(HIGEntryLabel(_("Port-Protocol-State:")), 0, 1, y1, y2) table.attach(HIGEntryLabel(p["portid"] + " - " + p["proto"] + " - " + p["state"]), 1, 2, y1, y2) y1 += 1 y2 += 1 self.portsused_expander.add(hbox) def set_osclass(self, osclass): if osclass: self.osclass_expander.set_use_markup(True) table, hbox = self.create_table_hbox() table.attach(HIGEntryLabel(_("Type")), 0, 1, 0, 1) table.attach(HIGEntryLabel(_("Vendor")), 1, 2, 0, 1) table.attach(HIGEntryLabel(_("OS Family")), 2, 3, 0, 1) table.attach(HIGEntryLabel(_("OS Generation")), 3, 4, 0, 1) table.attach(HIGEntryLabel(_("Accuracy")), 4, 5, 0, 1) y1 = 1 y2 = 2 for o in osclass: table.attach(HIGEntryLabel(o["type"]), 0, 1, y1, y2) table.attach(HIGEntryLabel(o["vendor"]), 1, 2, y1, y2) table.attach(HIGEntryLabel(o["osfamily"]), 2, 3, y1, y2) table.attach(HIGEntryLabel(o["osgen"]), 3, 4, y1, y2) progress = gtk.ProgressBar() progress.set_text(o["accuracy"] + "%") progress.set_fraction(float(o["accuracy"]) / 100.0) table.attach(progress, 4, 5, y1, y2) y1 += 1 y2 += 1 self.osclass_expander.add(hbox) def set_tcpseq(self, tcpseq): if tcpseq: self.tcp_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for v in tcpseq["values"].split(","): combo.append_text(v) table.attach(HIGEntryLabel(_("Difficulty:")), 0, 1, 1, 2) table.attach(HIGEntryLabel(tcpseq["difficulty"]), 1, 2, 1, 2) table.attach(HIGEntryLabel(_("Index:")), 0, 1, 2, 3) table.attach(HIGEntryLabel(tcpseq["index"]), 1, 2, 2, 3) table.attach(HIGEntryLabel(_("Values:")), 0, 1, 3, 4) table.attach(combo, 1, 2, 3, 4) self.tcp_expander.add(hbox) self._pack_noexpand_nofill(self.tcp_expander) def set_ipseq(self, ipseq): if ipseq: self.ip_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for i in ipseq["values"].split(","): combo.append_text(i) table.attach(HIGEntryLabel(_("Class:")), 0, 1, 0, 1) table.attach(HIGEntryLabel(ipseq["class"]), 1, 2, 0, 1) table.attach(HIGEntryLabel(_("Values:")), 0, 1, 1, 2) table.attach(combo, 1, 2, 1, 2) self.ip_expander.add(hbox) self._pack_noexpand_nofill(self.ip_expander) def set_tcptsseq(self, tcptsseq): if tcptsseq: self.tcpts_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for i in tcptsseq["values"].split(","): combo.append_text(i) table.attach(HIGEntryLabel(_("Class:")), 0, 1, 0, 1) table.attach(HIGEntryLabel(tcptsseq["class"]), 1, 2, 0, 1) table.attach(HIGEntryLabel(_("Values:")), 0, 1, 1, 2) table.attach(combo, 1, 2, 1, 2) self.tcpts_expander.add(hbox) self._pack_noexpand_nofill(self.tcpts_expander) def set_comment(self, comment=""): self.comment_expander.set_use_markup(True) if comment: self.comment_expander.set_expanded(True) hbox = HIGHBox() self.comment_scrolled = gtk.ScrolledWindow() self.comment_scrolled.set_border_width(5) self.comment_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.comment_txt_vw = gtk.TextView() self.comment_txt_vw.set_wrap_mode(gtk.WRAP_WORD) self.comment_txt_vw.get_buffer().set_text(comment) self.comment_scrolled.add(self.comment_txt_vw) hbox._pack_expand_fill(self.comment_scrolled) self.comment_expander.add(hbox) self._pack_noexpand_nofill(self.comment_expander) def get_comment(self): buffer = self.comment_txt_vw.get_buffer() return buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
class HostDetails(HIGVBox): def __init__(self, host): HIGVBox.__init__(self) self.__create_widgets() self.set_os_image(get_os_logo(host)) self.set_vulnerability_image( get_vulnerability_logo(host.get_open_ports())) self.set_host_status({'state': host.get_state(), 'open': str(host.get_open_ports()), 'filtered': str(host.get_filtered_ports()), 'closed': str(host.get_closed_ports()), 'scanned': str(host.get_scanned_ports()), 'uptime': host.get_uptime()['seconds'], 'lastboot': host.get_uptime()['lastboot']}) addresses = {} if host.ip is not None: addresses['ipv4'] = host.ip['addr'] if host.ipv6 is not None: addresses['ipv6'] = host.ipv6['addr'] if host.mac is not None: addresses['mac'] = host.mac['addr'] self.set_addresses(addresses) self.set_hostnames(host.get_hostnames()) os = host.get_best_osmatch() if os: os['portsused'] = host.get_ports_used() self.set_os(os) self.set_tcpseq(host.get_tcpsequence()) self.set_ipseq(host.get_ipidsequence()) self.set_tcptsseq(host.get_tcptssequence()) self.set_comment(host.comment) def __create_widgets(self): self.host_status_expander = gtk.Expander( '<b>' + _('Host Status') + '</b>') self.address_expander = gtk.Expander('<b>' + _('Addresses') + '</b>') self.hostnames_expander = gtk.Expander('<b>' + _('Hostnames') + '</b>') self.os_expander = gtk.Expander('<b>' + _('Operating System') + '</b>') self.portsused_expander = gtk.Expander( '<b>' + _('Ports used') + '</b>') self.osclass_expander = gtk.Expander('<b>' + _('OS Classes') + '</b>') self.tcp_expander = gtk.Expander('<b>' + _('TCP Sequence') + '</b>') self.ip_expander = gtk.Expander('<b>' + _('IP ID Sequence') + '</b>') self.tcpts_expander = gtk.Expander( '<b>' + _('TCP TS Sequence') + '</b>') self.comment_expander = gtk.Expander('<b>' + _('Comments') + '</b>') self.os_image = gtk.Image() self.vulnerability_image = gtk.Image() # Host Status expander self.host_state_label = HIGEntryLabel(_('State:')) self.info_host_state_label = HIGEntryLabel(na) self.open_label = HIGEntryLabel(_('Open ports:')) self.info_open_ports = HIGEntryLabel(na) self.filtered_label = HIGEntryLabel(_('Filtered ports:')) self.info_filtered_label = HIGEntryLabel(na) self.closed_label = HIGEntryLabel(_('Closed ports:')) self.info_closed_ports = HIGEntryLabel(na) self.scanned_label = HIGEntryLabel(_('Scanned ports:')) self.info_scanned_label = HIGEntryLabel(na) self.uptime_label = HIGEntryLabel(_('Up time:')) self.info_uptime_label = HIGEntryLabel(na) self.lastboot_label = HIGEntryLabel(_('Last boot:')) self.info_lastboot_label = HIGEntryLabel(na) # Addresses expander self.ipv4_label = HIGEntryLabel(_('IPv4:')) self.info_ipv4_label = HIGEntryLabel(na) self.ipv6_label = HIGEntryLabel(_('IPv6:')) self.info_ipv6_label = HIGEntryLabel(na) self.mac_label = HIGEntryLabel(_('MAC:')) self.info_mac_label = HIGEntryLabel(na) self.vendor_label = HIGEntryLabel(_('Vendor:')) self.info_vendor_label = HIGEntryLabel(na) def create_table_hbox(self): table = HIGTable() hbox = HIGHBox() hbox._pack_noexpand_nofill(hig_box_space_holder()) hbox._pack_noexpand_nofill(table) return table, hbox def set_host_status(self, status): self.host_status_expander.set_use_markup(True) self.host_status_expander.set_expanded(True) table, hbox = self.create_table_hbox() if ('state' in status and status['state'] != ''): self.info_host_state_label.set_text(status['state']) if ('open' in status and status['open'] != ''): self.info_open_ports.set_text(status['open']) if ('filtered' in status and status['filtered'] != ''): self.info_filtered_label.set_text(status['filtered']) if ('closed' in status and status['closed'] != ''): self.info_closed_ports.set_text(status['closed']) if ('scanned' in status and status['scanned'] != ''): self.info_scanned_label.set_text(status['scanned']) if ('uptime' in status and status['uptime'] != ''): self.info_uptime_label.set_text(status['uptime']) if ('lastboot' in status and status['lastboot'] != ''): self.info_lastboot_label.set_text(status['lastboot']) table.attach(self.host_state_label, 0, 1, 0, 1) table.attach(self.info_host_state_label, 1, 2, 0, 1) table.attach(self.open_label, 0, 1, 1, 2) table.attach(self.info_open_ports, 1, 2, 1, 2) table.attach(self.filtered_label, 0, 1, 2, 3) table.attach(self.info_filtered_label, 1, 2, 2, 3) table.attach(self.closed_label, 0, 1, 3, 4) table.attach(self.info_closed_ports, 1, 2, 3, 4) table.attach(self.scanned_label, 0, 1, 4, 5) table.attach(self.info_scanned_label, 1, 2, 4, 5) table.attach(self.uptime_label, 0, 1, 5, 6) table.attach(self.info_uptime_label, 1, 2, 5, 6) table.attach(self.lastboot_label, 0, 1, 6, 7) table.attach(self.info_lastboot_label, 1, 2, 6, 7) table.attach(self.os_image, 2, 4, 0, 3, xoptions=1, yoptions=0) table.attach( self.vulnerability_image, 2, 4, 4, 7, xoptions=1, yoptions=0) table.set_col_spacing(1, 50) self.host_status_expander.add(hbox) self._pack_noexpand_nofill(self.host_status_expander) def set_os_image(self, image): self.os_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) def set_vulnerability_image(self, image): self.vulnerability_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) def set_addresses(self, address): self.address_expander.set_use_markup(True) table, hbox = self.create_table_hbox() self.address_expander.set_expanded(True) #print '>>> Address:', address if ('ipv4' in address and address['ipv4'] != 1): self.info_ipv4_label.set_text(address['ipv4']) if ('ipv6' in address and address['ipv6'] != 1): self.info_ipv6_label.set_text(address['ipv6']) if ('mac' in address and address['mac'] != 1): self.info_mac_label.set_text(address['mac']) table.attach(self.ipv4_label, 0, 1, 0, 1) table.attach(self.info_ipv4_label, 1, 2, 0, 1) table.attach(self.ipv6_label, 0, 1, 1, 2) table.attach(self.info_ipv6_label, 1, 2, 1, 2) table.attach(self.mac_label, 0, 1, 2, 3) table.attach(self.info_mac_label, 1, 2, 2, 3) self.address_expander.add(hbox) self._pack_noexpand_nofill(self.address_expander) def set_hostnames(self, hostname): if hostname: self.hostnames_expander.set_use_markup(True) self.hostnames_expander.set_expanded(True) table, hbox = self.create_table_hbox() y1 = 1 y2 = 2 for h in hostname: name = h.get('hostname', na) type = h.get('hostname_type', na) table.attach(HIGEntryLabel(_('Name - Type:')), 0, 1, y1, y2) table.attach(HIGEntryLabel(name + ' - ' + type), 1, 2, y1, y2) y1 += 1 y2 += 1 self.hostnames_expander.add(hbox) self._pack_noexpand_nofill(self.hostnames_expander) def set_os(self, os): if os: self.os_expander.set_use_markup(True) self.os_expander.set_expanded(True) table, hbox = self.create_table_hbox() progress = gtk.ProgressBar() if 'accuracy' in os: progress.set_fraction(float(os['accuracy']) / 100.0) progress.set_text(os['accuracy'] + '%') else: progress.set_text(_('Not Available')) table.attach(HIGEntryLabel(_('Name:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(os['name']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Accuracy:')), 0, 1, 1, 2) table.attach(progress, 1, 2, 1, 2) y1 = 2 y2 = 3 if 'portsused' in os: self.set_ports_used(os['portsused']) table.attach(self.portsused_expander, 0, 2, y1, y2) y1 += 1 y2 += 1 if 'osclasses' in os: self.set_osclass(os['osclasses']) self.osclass_expander.set_use_markup(True) table.attach(self.osclass_expander, 0, 2, y1, y2) self.os_expander.add(hbox) self._pack_noexpand_nofill(self.os_expander) def set_ports_used(self, ports): self.portsused_expander.set_use_markup(True) table, hbox = self.create_table_hbox() y1 = 0 y2 = 1 for p in ports: table.attach(HIGEntryLabel( _('Port-Protocol-State:')), 0, 1, y1, y2) table.attach(HIGEntryLabel( p['portid'] + ' - ' + p['proto'] + ' - ' + p['state'] ), 1, 2, y1, y2) y1 += 1 y2 += 1 self.portsused_expander.add(hbox) def set_osclass(self, osclass): if osclass: self.osclass_expander.set_use_markup(True) table, hbox = self.create_table_hbox() table.attach(HIGEntryLabel(_('Type')), 0, 1, 0, 1) table.attach(HIGEntryLabel(_('Vendor')), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('OS Family')), 2, 3, 0, 1) table.attach(HIGEntryLabel(_('OS Generation')), 3, 4, 0, 1) table.attach(HIGEntryLabel(_('Accuracy')), 4, 5, 0, 1) y1 = 1 y2 = 2 for o in osclass: table.attach(HIGEntryLabel(o['type']), 0, 1, y1, y2) table.attach(HIGEntryLabel(o['vendor']), 1, 2, y1, y2) table.attach(HIGEntryLabel(o['osfamily']), 2, 3, y1, y2) table.attach(HIGEntryLabel(o['osgen']), 3, 4, y1, y2) progress = gtk.ProgressBar() progress.set_text(o['accuracy'] + '%') progress.set_fraction(float(o['accuracy']) / 100.0) table.attach(progress, 4, 5, y1, y2) y1 += 1 y2 += 1 self.osclass_expander.add(hbox) def set_tcpseq(self, tcpseq): if tcpseq: self.tcp_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for v in tcpseq['values'].split(','): combo.append_text(v) table.attach(HIGEntryLabel(_('Difficulty:')), 0, 1, 1, 2) table.attach(HIGEntryLabel(tcpseq['difficulty']), 1, 2, 1, 2) table.attach(HIGEntryLabel(_('Index:')), 0, 1, 2, 3) table.attach(HIGEntryLabel(tcpseq['index']), 1, 2, 2, 3) table.attach(HIGEntryLabel(_('Values:')), 0, 1, 3, 4) table.attach(combo, 1, 2, 3, 4) self.tcp_expander.add(hbox) self._pack_noexpand_nofill(self.tcp_expander) def set_ipseq(self, ipseq): if ipseq: self.ip_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for i in ipseq['values'].split(','): combo.append_text(i) table.attach(HIGEntryLabel(_('Class:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(ipseq['class']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Values:')), 0, 1, 1, 2) table.attach(combo, 1, 2, 1, 2) self.ip_expander.add(hbox) self._pack_noexpand_nofill(self.ip_expander) def set_tcptsseq(self, tcptsseq): if tcptsseq: self.tcpts_expander.set_use_markup(True) table, hbox = self.create_table_hbox() combo = gtk.combo_box_new_text() for i in tcptsseq['values'].split(','): combo.append_text(i) table.attach(HIGEntryLabel(_('Class:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(tcptsseq['class']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Values:')), 0, 1, 1, 2) table.attach(combo, 1, 2, 1, 2) self.tcpts_expander.add(hbox) self._pack_noexpand_nofill(self.tcpts_expander) def set_comment(self, comment=''): self.comment_expander.set_use_markup(True) if comment: self.comment_expander.set_expanded(True) hbox = HIGHBox() self.comment_scrolled = gtk.ScrolledWindow() self.comment_scrolled.set_border_width(5) self.comment_scrolled.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.comment_txt_vw = gtk.TextView() self.comment_txt_vw.set_wrap_mode(gtk.WRAP_WORD) self.comment_txt_vw.get_buffer().set_text(comment) self.comment_scrolled.add(self.comment_txt_vw) hbox._pack_expand_fill(self.comment_scrolled) self.comment_expander.add(hbox) self._pack_noexpand_nofill(self.comment_expander) def get_comment(self): buffer = self.comment_txt_vw.get_buffer() return buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
class ScanRunDetailsPage(HIGVBox): def __init__(self, scan): HIGVBox.__init__(self) na = _('Not available') # Command info self.command_label = HIGEntryLabel(_('Command:')) self.info_command_label = HIGEntryLabel(na) self.nmap_version_label = HIGEntryLabel(_('Nmap Version:')) self.info_nmap_version_label = HIGEntryLabel(na) self.verbose_label = HIGEntryLabel(_('Verbosity level:')) self.info_verbose_label = HIGEntryLabel(na) self.debug_label = HIGEntryLabel(_('Debug level:')) self.info_debug_label = HIGEntryLabel(na) self.command_expander = gtk.Expander( "<b>" + _("Command Info") + "</b>") self.command_expander.set_use_markup(True) self.command_table = HIGTable() self.command_table.set_border_width(5) self.command_table.set_row_spacings(6) self.command_table.set_col_spacings(6) self.command_hbox = HIGHBox() self.command_hbox._pack_noexpand_nofill(hig_box_space_holder()) self.command_hbox._pack_noexpand_nofill(self.command_table) self.command_table.attach(self.command_label, 0, 1, 0, 1) self.command_table.attach(self.info_command_label, 1, 2, 0, 1) self.command_table.attach(self.nmap_version_label, 0, 1, 1, 2) self.command_table.attach(self.info_nmap_version_label, 1, 2, 1, 2) self.command_table.attach(self.verbose_label, 0, 1, 2, 3) self.command_table.attach(self.info_verbose_label, 1, 2, 2, 3) self.command_table.attach(self.debug_label, 0, 1, 3, 4) self.command_table.attach(self.info_debug_label, 1, 2, 3, 4) self.command_expander.add(self.command_hbox) self._pack_noexpand_nofill(self.command_expander) self.command_expander.set_expanded(True) # General info: self.start_label = HIGEntryLabel(_('Started on:')) self.info_start_label = HIGEntryLabel(na) self.finished_label = HIGEntryLabel(_('Finished on:')) self.info_finished_label = HIGEntryLabel(na) self.host_up_label = HIGEntryLabel(_('Hosts up:')) self.info_hosts_up_label = HIGEntryLabel(na) self.host_down_label = HIGEntryLabel(_('Hosts down:')) self.info_hosts_down_label = HIGEntryLabel(na) self.host_scanned_label = HIGEntryLabel(_('Hosts scanned:')) self.info_hosts_scanned_label = HIGEntryLabel(na) self.open_label = HIGEntryLabel(_('Open ports:')) self.info_open_label = HIGEntryLabel(na) self.filtered_label = HIGEntryLabel(_('Filtered ports:')) self.info_filtered_label = HIGEntryLabel(na) self.closed_label = HIGEntryLabel(_('Closed ports:')) self.info_closed_label = HIGEntryLabel(na) self.general_expander = gtk.Expander( "<b>" + _("General Info") + "</b>") self.general_expander.set_use_markup(True) self.general_table = HIGTable() self.general_table.set_border_width(5) self.general_table.set_row_spacings(6) self.general_table.set_col_spacings(6) self.general_hbox = HIGHBox() self.general_hbox._pack_noexpand_nofill(hig_box_space_holder()) self.general_hbox._pack_noexpand_nofill(self.general_table) self.general_table.attach(self.start_label, 0, 1, 0, 1) self.general_table.attach(self.info_start_label, 1, 2, 0, 1) self.general_table.attach(self.finished_label, 0, 1, 1, 2) self.general_table.attach(self.info_finished_label, 1, 2, 1, 2) self.general_table.attach(self.host_up_label, 0, 1, 2, 3) self.general_table.attach(self.info_hosts_up_label, 1, 2, 2, 3) self.general_table.attach(self.host_down_label, 0, 1, 3, 4) self.general_table.attach(self.info_hosts_down_label, 1, 2, 3, 4) self.general_table.attach(self.host_scanned_label, 0, 1, 4, 5) self.general_table.attach(self.info_hosts_scanned_label, 1, 2, 4, 5) self.general_table.attach(self.open_label, 0, 1, 5, 6) self.general_table.attach(self.info_open_label, 1, 2, 5, 6) self.general_table.attach(self.filtered_label, 0, 1, 6, 7) self.general_table.attach(self.info_filtered_label, 1, 2, 6, 7) self.general_table.attach(self.closed_label, 0, 1, 7, 8) self.general_table.attach(self.info_closed_label, 1, 2, 7, 8) self.general_expander.add(self.general_hbox) self._pack_noexpand_nofill(self.general_expander) self.general_expander.set_expanded(True) self._set_from_scan(scan) def _set_from_scan(self, scan): """Initialize the display from a parsed scan.""" # Command info. self.info_command_label.set_text(scan.get_nmap_command()) self.info_nmap_version_label.set_text(scan.get_scanner_version()) self.info_verbose_label.set_text(scan.get_verbose_level()) self.info_debug_label.set_text(scan.get_debugging_level()) # General info. self.info_start_label.set_text(scan.get_formatted_date()) self.info_finished_label.set_text(scan.get_formatted_finish_date()) self.info_hosts_up_label.set_text(str(scan.get_hosts_up())) self.info_hosts_down_label.set_text(str(scan.get_hosts_down())) self.info_hosts_scanned_label.set_text(str(scan.get_hosts_scanned())) self.info_open_label.set_text(str(scan.get_open_ports())) self.info_filtered_label.set_text(str(scan.get_filtered_ports())) self.info_closed_label.set_text(str(scan.get_closed_ports())) for scaninfo in scan.get_scaninfo(): exp = gtk.Expander('<b>%s - %s</b>' % ( _('Scan Info'), scaninfo['type'].capitalize())) exp.set_use_markup(True) display = self.make_scaninfo_display(scaninfo) exp.add(display) self._pack_noexpand_nofill(exp) def make_scaninfo_display(self, scaninfo): """Return a widget displaying a scan's "scaninfo" information: type, protocol, number of scanned ports, and list of services.""" hbox = HIGHBox() table = HIGTable() table.set_border_width(5) table.set_row_spacings(6) table.set_col_spacings(6) table.attach(HIGEntryLabel(_('Scan type:')), 0, 1, 0, 1) table.attach(HIGEntryLabel(scaninfo['type']), 1, 2, 0, 1) table.attach(HIGEntryLabel(_('Protocol:')), 0, 1, 1, 2) table.attach(HIGEntryLabel(scaninfo['protocol']), 1, 2, 1, 2) table.attach(HIGEntryLabel(_('# scanned ports:')), 0, 1, 2, 3) table.attach(HIGEntryLabel(scaninfo['numservices']), 1, 2, 2, 3) table.attach(HIGEntryLabel(_('Services:')), 0, 1, 3, 4) table.attach( self.make_services_display(scaninfo['services']), 1, 2, 3, 4) hbox._pack_noexpand_nofill(hig_box_space_holder()) hbox._pack_noexpand_nofill(table) return hbox def make_services_display(self, services): """Return a widget displaying a list of services like 1-1027,1029-1033,1040,1043,1050,1058-1059,1067-1068,1076,1080""" combo = gtk.combo_box_new_text() for i in services.split(","): combo.append_text(i) return combo
class HighlightProperty(object): def __init__(self, property_name, property): self.__create_widgets() self.property_name = property_name self.property_label = property[0].capitalize() self.example = property[1] self.bold = property[2] self.italic = property[3] self.underline = property[4] self.text_color = property[5] self.highlight_color = property[6] self.__connect_buttons() def __create_widgets(self): self.property_name_label = HIGEntryLabel("") self.example_label = HIGEntryLabel("") self.bold_tg_button = HIGToggleButton("", gtk.STOCK_BOLD) self.italic_tg_button = HIGToggleButton("", gtk.STOCK_ITALIC) self.underline_tg_button = HIGToggleButton("", gtk.STOCK_UNDERLINE) self.text_color_button = HIGButton(_("Text"), stock=gtk.STOCK_SELECT_COLOR) self.highlight_color_button = HIGButton(_("Highlight"), stock=gtk.STOCK_SELECT_COLOR) def __connect_buttons(self): self.bold_tg_button.connect("toggled", self.update_example) self.italic_tg_button.connect("toggled", self.update_example) self.underline_tg_button.connect("toggled", self.update_example) self.text_color_button.connect("clicked", self.text_color_dialog) self.highlight_color_button.connect("clicked", self.highlight_color_dialog) #################################### # Text color dialog def text_color_dialog(self, widget): color_dialog = gtk.ColorSelectionDialog("%s %s" % (self.label, _("text color"))) color_dialog.colorsel.set_current_color(self.text_color) color_dialog.ok_button.connect("clicked", self.text_color_dialog_ok, color_dialog) color_dialog.cancel_button.connect("clicked", self.text_color_dialog_cancel, color_dialog) color_dialog.connect("delete-event", self.text_color_dialog_close, color_dialog) color_dialog.run() def text_color_dialog_ok(self, widget, color_dialog): self.text_color = color_dialog.colorsel.get_current_color() color_dialog.destroy() self.update_example() def text_color_dialog_cancel(self, widget, color_dialog): color_dialog.destroy() def text_color_dialog_close(self, widget, extra, color_dialog): color_dialog.destroy() ######################################### # Highlight color dialog def highlight_color_dialog(self, widget): color_dialog = gtk.ColorSelectionDialog( "%s %s" % (self.property_name, _("highlight color"))) color_dialog.colorsel.set_current_color(self.highlight_color) color_dialog.ok_button.connect("clicked", self.highlight_color_dialog_ok, color_dialog) color_dialog.cancel_button.connect("clicked", self.highlight_color_dialog_cancel, color_dialog) color_dialog.connect("delete-event", self.highlight_color_dialog_close, color_dialog) color_dialog.run() def highlight_color_dialog_ok(self, widget, color_dialog): self.highlight_color = color_dialog.colorsel.get_current_color() color_dialog.destroy() self.update_example() def highlight_color_dialog_cancel(self, widget, color_dialog): color_dialog.destroy() def highlight_color_dialog_close(self, widget, extra, color_dialog): color_dialog.destroy() def update_example(self, widget=None): start = 0 end = len(self.example) attributes = pango.AttrList() attributes.insert( pango.AttrForeground(self.text_color.red, self.text_color.green, self.text_color.blue, start, end)) attributes.insert( pango.AttrBackground(self.highlight_color.red, self.highlight_color.green, self.highlight_color.blue, start, end)) # Bold verification if self.bold_tg_button.get_active(): attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, start, end)) else: attributes.insert(pango.AttrWeight(pango.WEIGHT_NORMAL, start, end)) # Italic verification if self.italic_tg_button.get_active(): attributes.insert(pango.AttrStyle(pango.STYLE_ITALIC, start, end)) else: attributes.insert(pango.AttrStyle(pango.STYLE_NORMAL, start, end)) # Underline verification if self.underline_tg_button.get_active(): attributes.insert( pango.AttrUnderline(pango.UNDERLINE_SINGLE, start, end)) else: attributes.insert( pango.AttrUnderline(pango.UNDERLINE_NONE, start, end)) self.example_label.set_attributes(attributes) def show_bold(self, widget): self.example_label.set_markup("<>") def get_example(self): return self.example_label.get_text() def set_example(self, example): self.example_label.set_text(example) def get_bold(self): if self.bold_tg_button.get_active(): return 1 return 0 def set_bold(self, bold): self.bold_tg_button.set_active(bold) def get_italic(self): if self.italic_tg_button.get_active(): return 1 return 0 def set_italic(self, italic): self.italic_tg_button.set_active(italic) def get_underline(self): if self.underline_tg_button.get_active(): return 1 return 0 def set_underline(self, underline): self.underline_tg_button.set_active(underline) def get_label(self): return self.property_name_label.get_text() def set_label(self, label): self.property_name_label.set_text(label) label = property(get_label, set_label) example = property(get_example, set_example) bold = property(get_bold, set_bold) italic = property(get_italic, set_italic) underline = property(get_underline, set_underline)