def __send_callback(self, packet, udata): if packet and isinstance(packet, Exception): self.internal = False self.summary = str(packet) else: if packet: self.count += 1 else: self.state = self.NOT_RUNNING if self.count == self.tot_count: self.summary = _("%d packet(s) sent.") % self.tot_count else: self.summary = _("Sending packet %d of %d") % (self.count, self.tot_count) self.percentage = float(self.count) / float(self.tot_count) * 100.0 if self.callback: self.callback(packet, udata) if not self.internal: self.state = self.NOT_RUNNING return self.state == self.NOT_RUNNING or \ self.state == self.PAUSED
def set_enabled(self, val): self._enabled = val # We need more testing on color/saturate on enabled if self._enabled: self.action_btn.set_label(_("Disable")) self.action_btn.set_image(self.img_stop) # color = self.style.text[gtk.STATE_NORMAL] self.saturate = False else: self.action_btn.set_label(_("Enable")) self.action_btn.set_image(self.img_play) # color = self.style.text[gtk.STATE_INSENSITIVE] self.saturate = True self.label.set_text( \ "<span color=\"%s\">" "<span size=\"x-large\" weight=\"bold\">%s</span>" \ " %s" \ "\n<tt>%s</tt>" \ "</span>" % \ ( \ color.to_string(), \ self._reader.name, \ self._reader.version, \ self._message \ ) \ ) self.label.set_use_markup(True)
def __send_callback(self, packet, udata): if packet and isinstance(packet, Exception): self.internal = False self.summary = str(packet) else: if packet: self.count += 1 else: self.state = self.NOT_RUNNING if self.count == self.tot_count: self.summary = _("%d packet(s) sent.") % self.tot_count else: self.summary = _("Sending packet %d of %d") % ( self.count, self.tot_count) self.percentage = float(self.count) / float( self.tot_count) * 100.0 if self.callback: self.callback(packet, udata) if not self.internal: self.state = self.NOT_RUNNING return self.state == self.NOT_RUNNING or \ self.state == self.PAUSED
def __on_button_press(self, widget, evt, typo): if evt.button != 3: return menu = gtk.Menu() # OK show a popup to copy and paste # cut/copy/paste/delete txts = (_('Cu_t'), _('_Copy'), _('_Paste'), _('Copy from _both')) icons = (gtk.STOCK_CUT, gtk.STOCK_COPY, gtk.STOCK_PASTE, gtk.STOCK_COPY) cbcs = (self.__on_cut, self.__on_copy, self.__on_paste, self.__on_bcopy) clipboard_sel = gtk.clipboard_get().wait_for_text() and True or False idx = 0 for txt, icon, cbc in zip(txts, icons, cbcs): action = gtk.Action(None, txt, None, icon) action.connect('activate', cbc, typo) item = action.create_menu_item() if not clipboard_sel and idx == 2: item.set_sensitive(False) menu.append(item) idx += 1 menu.popup(None, None, None, evt.button, evt.time, None) menu.show_all()
def __send_callback(self, packet, udata): if packet and isinstance(packet, Exception): self.internal = False self.summary = str(packet) elif self.tot_count: if packet: self.count += 1 else: self.state = self.NOT_RUNNING if self.count == self.tot_count: self.summary = _("%d packet(s) sent.") % self.tot_count else: self.summary = _("Sending packet %d of %d") % (self.count, self.tot_count) self.percentage = float(self.count) / float(self.tot_count) * 100.0 else: # If we are here we need to pulse the value self.summary = _("Sending packet %s") % packet.summary() self.percentage = (self.percentage + 536870911) % 2147483647 if self.callback: self.callback(packet, udata) if not self.internal: self.state = self.NOT_RUNNING return self.state == self.NOT_RUNNING or self.state == self.PAUSED
def __recv_callback(self, packet, is_reply, udata): if not packet: self.internal = False self.summary = _('%d of %d replie(s) received') % \ (self.answers, self.received) else: self.received += 1 self.summary = _('Received/Answered/Remaining %d/%d/%d') % \ (self.received, self.answers, self.remaining) if is_reply: self.answers += 1 self.remaining -= 1 if is_reply or self.report_recv: self.data.append(packet) self.percentage = (self.percentage + 536870911) % 2147483647 if self.rcallback: self.rcallback(packet, is_reply, udata) if not self.internal: self.state = self.NOT_RUNNING return self.state == self.NOT_RUNNING or \ self.state == self.PAUSED
def __init__(self, obj, type): """ @param obj if type is TYPE_LOAD the path of the file to load or a Session to save. @param type TYPE_LOAD or TYPE_SAVE """ Operation.__init__(self) self.file = file self.type = type if type == FileOperation.TYPE_LOAD: self.file = obj else: self.session = obj self.ctx = self.session.context self.percentage = 0 self.thread = None self.state = self.NOT_RUNNING self.loading_view = False if type == FileOperation.TYPE_LOAD: self.summary = _('Loading of %s pending.') % self.file else: self.summary = _('Saving to %s pending.') % self.ctx.cap_file
def __on_sort_layer(self, item): lst = self.populate(False) dct = defaultdict(list) for proto in lst: dct[backend.get_proto_layer(proto)].append(proto) for i in xrange(1, 8, 1): if not i in dct: continue it = self.store.append(None, [self.layer_icon, _('Layer %d') % i, None]) for proto in dct[i]: self.store.append(it, [self.proto_icon, backend.get_proto_class_name(proto), proto]) if None in dct: it = self.store.append(None, [self.layer_icon, _('Unknown layer'), None]) for proto in dct[None]: self.store.append(it, [self.proto_icon, backend.get_proto_class_name(proto), proto]) self.tree.set_rules_hint(False) self.tree.set_model(self.store)
def __on_skip_updates(self, widget): "Called when the user click on the skip button" # We need to repopulate the tree self.richlist.clear() self.populate() self.p_window.toolbar.unset_status() if self.restart_btn.flags() & gtk.VISIBLE: # That callback is called from a self.___on_install_updates self.restart_btn.hide() self.p_window.animated_bar.label = \ _('Rembember to restart PacketManipulator to use new version ' 'of plugins.') else: self.p_window.animated_bar.label = \ _('Update skipped') self.p_window.animated_bar.start_animation(True) self.skip_install_btn.hide() self.install_updates_btn.hide() self.find_updates_btn.show() self.menu_enabled = True
def __on_button_press(self, widget, evt, typo): if evt.button != 3: return menu = gtk.Menu() # OK show a popup to copy and paste # cut/copy/paste/delete txts = (_("Cu_t"), _("_Copy"), _("_Paste"), _("Copy from _both")) icons = (gtk.STOCK_CUT, gtk.STOCK_COPY, gtk.STOCK_PASTE, gtk.STOCK_COPY) cbcs = (self.__on_cut, self.__on_copy, self.__on_paste, self.__on_bcopy) clipboard_sel = gtk.clipboard_get().wait_for_text() and True or False idx = 0 for txt, icon, cbc in zip(txts, icons, cbcs): action = gtk.Action(None, txt, None, icon) action.connect("activate", cbc, typo) item = action.create_menu_item() if not clipboard_sel and idx == 2: item.set_sensitive(False) menu.append(item) idx += 1 menu.popup(None, None, None, evt.button, evt.time, None) menu.show_all()
def send_redirect(self, sip, dip): key = sip + ':' + dip delay = self.connections.get(key, None) if delay and (time.time() - delay) <= self.delay: return self.connections[key] = time.time() pkt = MetaPacket.new('ip') / MetaPacket.new('icmp') pkt.set_field('ip.src', self.gateway) pkt.set_field('ip.dst', dip) pkt.set_field('icmp.type', 5) # Redirect pkt.set_field('icmp.code', 0) # Redirect for network pkt.set_field('icmp.gw', self.source) self.packets += 1 self.session.context.si_l3(pkt) self.session.output_page.user_msg( _('%s to %s matches - redirect to %s') % (sip, dip, self.source), STATUS_INFO, AUDIT_NAME) self.summary = AUDIT_MSG % (_('%d redirects sent') % self.packets) self.percentage = (self.percentage + 536870911) % \ gobject.G_MAXINT
def create_ui(self): self.output = AuditOutput() self.user_msg(_('<tt>New audit session started.</tt>'), STATUS_INFO, 'AuditManager') iface1 = self.session.context.get_iface1() mac1 = self.session.context.get_mac1() ip1 = self.session.context.get_ip1() if iface1 and mac1 and ip1: self.user_msg('%s -> %s (%s)' % (iface1, ip1, mac1), STATUS_INFO, 'AuditManager') elif iface1: self.user_msg(_('Error listening on %s') % iface1, STATUS_ERR, 'AuditManager') iface2 = self.session.context.get_iface2() mac2 = self.session.context.get_mac2() ip2 = self.session.context.get_ip2() if iface2 and mac2 and ip2: self.user_msg('%s -> %s (%s)' % (iface2, ip2, mac2), STATUS_INFO, 'AuditManager') elif iface2: self.user_msg(_('Error listening on %s') % iface2, STATUS_ERR, 'AuditManager') self.pack_start(self.output) self.show_all()
def __create_columns(self): col = gtk.TreeViewColumn(_('Audits')) col.set_expand(True) col.set_resizable(True) col.set_resizable(True) col.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY) rend = gtk.CellRendererPixbuf() col.pack_start(rend, False) col.set_cell_data_func(rend, self.__pix_data_func) rend = gtk.CellRendererText() col.pack_start(rend) col.set_cell_data_func(rend, self.__text_data_func) self.tree.append_column(col) rend = gtk.CellRendererProgress() col = gtk.TreeViewColumn(_('Status'), rend) col.set_expand(False) col.set_resizable(True) col.set_fixed_width(150) col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) col.set_cell_data_func(rend, self.__progress_data_func) self.tree.append_column(col) self.tree.set_rules_hint(True) self.icon_operation = get_pixbuf('operation_small')
def __init__(self): gtk.VBox.__init__(self, False, 2) self.entry = FilterEntry() self.tree = AuditOutputTree() self.toolbar = gtk.Toolbar() self.toolbar.set_style(gtk.TOOLBAR_ICONS) action = gtk.Action('save', _('Save log'), _('Save log to file'), gtk.STOCK_SAVE) action.connect('activate', self.tree.on_save_log) item = action.create_tool_item() self.toolbar.insert(item, -1) item = gtk.ToolItem() item.add(self.entry) item.set_expand(True) self.toolbar.insert(item, -1) self.pack_start(self.toolbar, False, False) self.pack_end(self.tree) self.entry.get_entry().connect('changed', self.__on_filter)
def _create_widgets(self): self.email_label = HIGHintSectionLabel( _("Email"), _("Please inform a valid e-mail address from " "where you can be reached to be notified when the bug gets " "fixed. Not used for other purposes.")) self.email_entry = gtk.Entry() self.description_label = HIGHintSectionLabel( _("Description"), _("This is where you should write about the bug, " "describing it as clear as possible and giving as many " "informations as you can along with your system informations, " "like: Which operating system are you using?")) self.description_scrolled = gtk.ScrolledWindow() self.description_text = gtk.TextView() self.bug_icon = gtk.Image() self.bug_text = gtk.Label( _("This Bug Report dialog allows you " "to easily tell us about a problem that you may have found on " "PM. Doing so, you help us to help you, by fixing and " "improving PM faster than usual.")) self.hbox = HIGHBox(False) self.table = HIGTable()
def __send_callback(self, packet, udata): if packet and isinstance(packet, Exception): self.internal = False self.summary = str(packet) elif self.tot_count: if packet: self.count += 1 else: self.state = self.NOT_RUNNING if self.count == self.tot_count: self.summary = _("%d packet(s) sent.") % self.tot_count else: self.summary = _("Sending packet %d of %d") % ( self.count, self.tot_count) self.percentage = float(self.count) / float( self.tot_count) * 100.0 else: # If we are here we need to pulse the value self.summary = _("Sending packet %s") % packet.summary() self.percentage = (self.percentage + 536870911) % 2147483647 if self.callback: self.callback(packet, udata) if not self.internal: self.state = self.NOT_RUNNING return self.state == self.NOT_RUNNING or \ self.state == self.PAUSED
def on_resolved(self, send, mpkt, reply, udata): if self.report: diff = None now = time.time() while self.times: tm = self.times.pop(0) diff = now - tm diff *= 100.0 if diff > 0 and diff < self.delay: break else: diff = None # Too fast :) if diff is not None: self.session.output_page.user_msg( _('Reply from %s [%s] %.2fms') % \ (reply.get_field('arp.pdst'), reply.get_field('arp.hwsrc'), diff), STATUS_INFO, AUDIT_NAME ) self.packets += 1 if self.probes > 0: self.percentage = (self.packets / float(self.probes)) * 100.0 self.summary = AUDIT_MSG % _('%d of %d sent') % (self.packets, self.probes) else: self.summary = AUDIT_MSG % _('%d sent' % self.packets) self.percentage = (self.percentage + 536870911) % \ gobject.G_MAXINT
def __create_columns(self): col = gtk.TreeViewColumn(_("Audits")) col.set_expand(True) col.set_resizable(True) col.set_resizable(True) col.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY) rend = gtk.CellRendererPixbuf() col.pack_start(rend, False) col.set_cell_data_func(rend, self.__pix_data_func) rend = gtk.CellRendererText() col.pack_start(rend) col.set_cell_data_func(rend, self.__text_data_func) self.tree.append_column(col) rend = gtk.CellRendererProgress() col = gtk.TreeViewColumn(_("Status"), rend) col.set_expand(False) col.set_resizable(True) col.set_fixed_width(150) col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) col.set_cell_data_func(rend, self.__progress_data_func) self.tree.append_column(col) self.tree.set_rules_hint(True) self.icon_operation = get_pixbuf("operation_small")
def __on_open_session(self, action): types = {} sessions = (backend.StaticContext, backend.SequenceContext, backend.SniffContext) for ctx in sessions: for name, pattern in ctx.file_types: types[pattern] = (name, ctx) dialog = gtk.FileChooserDialog( _("Select a session"), self, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)) dialog.set_transient_for(self) filterall = gtk.FileFilter() filterall.set_name(_('All supported files')) [filterall.add_pattern(k) for k in types] dialog.add_filter(filterall) for pattern, (name, ctx) in types.items(): filter = gtk.FileFilter() filter.set_name(name) filter.add_pattern(pattern) dialog.add_filter(filter) if dialog.run() == gtk.RESPONSE_ACCEPT: ctx = None fname = dialog.get_filename() try: find = fname.split('.')[-1] for pattern in types: if pattern.split('.')[-1] == find: ctx = types[pattern][1] except: pass if ctx is not backend.SequenceContext and \ ctx is not backend.SniffContext and \ ctx is not backend.StaticContext: d = HIGAlertDialog( type=gtk.MESSAGE_ERROR, message_format=_("Unable to open selected session"), secondary_text=_( "PacketManipulator is unable to guess the " "file type. Try to modify the extension " "and to reopen the file.")) d.set_transient_for(self) d.run() d.destroy() else: self.open_generic_file_async(fname) dialog.hide() dialog.destroy()
def create_widgets(self): self.widgets = [ (_('Checks'), (('system.check_root', None, gtk.CheckButton(_('Check for root privileges at startup'))), ('system.check_pyver', None, gtk.CheckButton(_('Check for compatible Python version'))))), ]
def __property_cell_func(self, col, cell, model, iter): cell.editor, cell.field = None, None cell.set_property('editable', False) cell.set_property('text', '') obj = model.get_value(iter, 0) if isinstance(obj, TField) and backend.is_flags(obj.ref): # Flag container cell.set_property('cell-background-gdk', self.style.mid[gtk.STATE_NORMAL]) value = backend.get_field_value_repr(obj.proto, obj.ref) try: if value: cell.set_property('markup', '<tt>%s</tt>' % \ gobject.markup_escape_text(unicode(value))) except UnicodeDecodeError: cell.set_property('markup', _('<tt>N/A</tt>')) # If we are a field or a string (a sub field of flags) elif isinstance(obj, (TField, TFlag)): cell.field = None cell.set_property('editable', True) cell.set_property('cell-background-gdk', None) # We have a standard field if isinstance(obj, TField): value = backend.get_field_value(obj.proto, obj.ref) if value is not None: try: value = gobject.markup_escape_text(unicode(value)) except UnicodeDecodeError: value = None if not value: value = _("N/A") cell.set_property('markup', '<tt>%s</tt>' % value) cell.editor = get_editor(obj.ref) if cell.editor: cell.field = (obj.proto, obj.ref) elif isinstance(obj, TFlag): # We have a subkey of Flags cell.editor = BitEditor cell.field = (obj.proto, obj.field.ref, obj.ref) else: cell.set_property('cell-background-gdk', self.style.mid[gtk.STATE_NORMAL])
def load(self, operation=None): log.debug("Loading sequence from %s" % self.cap_file) if self.cap_file: self.seq = None try: plen = 0 fsize = None loader = load_sequence(self.cap_file) for tree, tlen, perc, size in loader.parse_async(): if operation and tlen % 10 == 0: if not fsize: if size >= 1024**3: fsize = "%.1f GB" % (size / (1024.0**3)) elif size >= 1024**2: fsize = "%.1f MB" % (size / (1024.0**2)) else: fsize = "%.1f KB" % (size / 1024.0) operation.summary = \ _('Loading sequence %s - %d packets (%s)') % \ (self.cap_file, tlen, fsize) operation.percentage = perc self.seq = tree plen = tlen self.tot_loop_count = loader.attr_loopcnt self.inter = loader.attr_inter self.strict = loader.attr_strict self.report_sent = loader.attr_sent self.report_recv = loader.attr_recv self.title = self.cap_file self.summary = \ _('Sequence %s loaded - %d packets (%s)') % \ (self.cap_file, plen, fsize) if operation: operation.summary = self.summary operation.percentage = 100.0 except Exception, err: self.seq = None self.summary = str(err) if operation: operation.summary = str(err) operation.percentage = 100.0 if self.seq is not None: self.status = self.SAVED return True
def load(self, operation=None): log.debug("Loading sequence from %s" % self.cap_file) if self.cap_file: self.seq = None try: plen = 0 fsize = None loader = load_sequence(self.cap_file) for tree, tlen, perc, size in loader.parse_async(): if operation and tlen % 10 == 0 : if not fsize: if size >= 1024 ** 3: fsize = "%.1f GB" % (size / (1024.0 ** 3)) elif size >= 1024 ** 2: fsize = "%.1f MB" % (size / (1024.0 ** 2)) else: fsize = "%.1f KB" % (size / 1024.0) operation.summary = \ _('Loading sequence %s - %d packets (%s)') % \ (self.cap_file, tlen, fsize) operation.percentage = perc self.seq = tree plen = tlen self.tot_loop_count = loader.attr_loopcnt self.inter = loader.attr_inter self.strict = loader.attr_strict self.report_sent = loader.attr_sent self.report_recv = loader.attr_recv self.title = self.cap_file self.summary = \ _('Sequence %s loaded - %d packets (%s)') % \ (self.cap_file, plen, fsize) if operation: operation.summary = self.summary operation.percentage = 100.0 except Exception, err: self.seq = None self.summary = str(err) if operation: operation.summary = str(err) operation.percentage = 100.0 if self.seq is not None: self.status = self.SAVED return True
def create_ui(self): self.hbox = gtk.HBox(False, 2) # Create the toolbar for sending selected packet self.toolbar = gtk.Toolbar() self.toolbar.set_style(gtk.TOOLBAR_ICONS) self.toolbar.set_orientation(gtk.ORIENTATION_VERTICAL) stocks = ( gtk.STOCK_EDIT, gtk.STOCK_DELETE, gtk.STOCK_CLEAR, gtk.STOCK_SELECT_COLOR ) tooltips = ( _('Complete layers'), _('Remove selected layer'), _('Reset layer to default'), _('Graph packet') ) callbacks = ( self.__on_complete, self.__on_remove, self.__on_reset, self.__on_graph ) for tooltip, stock, callback in zip(tooltips, stocks, callbacks): action = gtk.Action(None, None, tooltip, stock) action.connect('activate', callback) self.toolbar.insert(action.create_tool_item(), -1) self.proto_hierarchy = ProtocolHierarchy(self.session) self.hexview = HexView() try: # Only the read write hexview provide this self.hexview.set_insert_mode(True) self.hexview.set_read_only_mode(False) self.hexview.changed_callback = self.__on_hexview_changed self.hexview.connect('focus-out-event', self.__on_hexview_focus_out) self._packet_changed = False except: pass self.hbox.pack_start(self.proto_hierarchy, False, False, 0) self.hbox.pack_start(self.toolbar, False, False) self.hbox.pack_start(self.hexview)#, False, False) Prefs()['gui.maintab.hexview.font'].connect(self.hexview.modify_font) Prefs()['gui.maintab.hexview.bpl'].connect(self.hexview.set_bpl) self.pack_start(self.hbox)
def __on_open_session(self, action): types = {} sessions = (backend.StaticContext, backend.SequenceContext, backend.SniffContext) for ctx in sessions: for name, pattern in ctx.file_types: types[pattern] = (name, ctx) dialog = gtk.FileChooserDialog(_("Select a session"), self, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)) dialog.set_transient_for(self) filterall = gtk.FileFilter() filterall.set_name(_('All supported files')) [filterall.add_pattern(k) for k in types] dialog.add_filter(filterall) for pattern, (name, ctx) in types.items(): filter = gtk.FileFilter() filter.set_name(name) filter.add_pattern(pattern) dialog.add_filter(filter) if dialog.run() == gtk.RESPONSE_ACCEPT: ctx = None fname = dialog.get_filename() try: find = fname.split('.')[-1] for pattern in types: if pattern.split('.')[-1] == find: ctx = types[pattern][1] except: pass if ctx is not backend.SequenceContext and \ ctx is not backend.SniffContext and \ ctx is not backend.StaticContext: d = HIGAlertDialog(type=gtk.MESSAGE_ERROR, message_format=_("Unable to open selected session"), secondary_text=_("PacketManipulator is unable to guess the " "file type. Try to modify the extension " "and to reopen the file.")) d.set_transient_for(self) d.run() d.destroy() else: self.open_generic_file_async(fname) dialog.hide() dialog.destroy()
def __thread_main(self): try: log.debug('Entered in __thread_main') packets = 0 probes = self.probes while probes != 0 and self.internal: pkt = MetaPacket.new('ip') / MetaPacket.new('tcp') if self.sip is True: sip = random_ip() elif self.sip != '0.0.0.0': sip = self.sip if self.sport is True: sport = randint(1, 65535) else: sport = self.sport pkt.set_fields('ip', { 'dst' : self.dip, 'src' : sip}) pkt.set_fields('tcp', { 'sport' : sport, 'dport' : self.dport, 'flags' : TH_SYN, 'seq' : randint(0, 2L**32-1)}) self.context.si_l3(pkt) sleep(self.delay) probes -= 1 packets += 1 if self.probes > 0: self.summary = AUDIT_MSG % _('%d of %d sent' \ % (packets, self.probes)) self.percentage = (packets / float(self.probes)) * 100.0 else: self.summary = AUDIT_MSG % _('%d sent' % packets) self.percentage = (self.percentage + 536870911) % \ gobject.G_MAXINT if self.internal: self.summary = AUDIT_MSG % _('Finished with %d sent' % packets) self.internal = False else: self.summary = AUDIT_MSG % _('stopped') self.percentage = 100.0 self.state = self.NOT_RUNNING except Exception, err: log.error(generate_traceback())
def __thread_main(self): try: log.debug('Entered in __thread_main') packets = 0 probes = self.probes while probes != 0 and self.internal: pkt = MetaPacket.new('ip') / MetaPacket.new('tcp') if self.sip is True: sip = random_ip() elif self.sip != '0.0.0.0': sip = self.sip if self.sport is True: sport = randint(1, 65535) else: sport = self.sport pkt.set_fields('ip', {'dst': self.dip, 'src': sip}) pkt.set_fields( 'tcp', { 'sport': sport, 'dport': self.dport, 'flags': TH_SYN, 'seq': randint(0, 2L**32 - 1) }) self.context.si_l3(pkt) sleep(self.delay) probes -= 1 packets += 1 if self.probes > 0: self.summary = AUDIT_MSG % _('%d of %d sent' \ % (packets, self.probes)) self.percentage = (packets / float(self.probes)) * 100.0 else: self.summary = AUDIT_MSG % _('%d sent' % packets) self.percentage = (self.percentage + 536870911) % \ gobject.G_MAXINT if self.internal: self.summary = AUDIT_MSG % _('Finished with %d sent' % packets) self.internal = False else: self.summary = AUDIT_MSG % _('stopped') self.percentage = 100.0 self.state = self.NOT_RUNNING except Exception, err: log.error(generate_traceback())
def __on_bool_toggled(self, widget, udata): conf_name, opt_id = udata if widget.get_active(): widget.get_child().set_text(_('Enabled')) else: widget.get_child().set_text(_('Disabled')) AuditManager().get_configuration(conf_name)[opt_id] = \ widget.get_active()
def __init__(self, args): """ PacketManipulator Application class @param args pass sys.argv """ gobject.threads_init() self._args = args root = False try: # FIXME: add maemo if sys.platform == 'win32': import ctypes root = bool(ctypes.windll.shell32.IsUserAnAdmin()) elif os.getuid() == 0: root = True except: pass if Prefs()['system.check_pyver'].value == True and \ sys.version_info[1] < 6: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO, _('Packet Manipulator requires at least ' '2.6 version of Python but you\'ve %s ' 'installed. We not guarantee that all ' 'functionalities works properly.\n\n' 'Do you want to continue?') % ".".join(map(str, sys.version_info[:3]))) ret = dialog.run() dialog.hide() dialog.destroy() if ret == gtk.RESPONSE_NO: sys.exit(-1) if Prefs()['system.check_root'].value == True and not root: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO, _('You are running Packet Manipulator as' ' non-root user!\nSome functionalities' ' need root privileges to work\n\nDo ' 'you want to continue?')) ret = dialog.run() dialog.hide() dialog.destroy() if ret == gtk.RESPONSE_NO: sys.exit(-1) self.phase = 0 self.splash = SplashScreen()
def __init__(self, args): """ PacketManipulator Application class @param args pass sys.argv """ gobject.threads_init() self._args = args root = False try: # FIXME: add maemo if sys.platform == 'win32': import ctypes root = bool(ctypes.windll.shell32.IsUserAnAdmin()) elif os.getuid() == 0: root = True except: pass if Prefs()['system.check_pyver'].value == True and \ sys.version_info[1] < 6: dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO, _('Packet Manipulator requires at least ' '2.6 version of Python but you\'ve %s ' 'installed. We not guarantee that all ' 'functionalities works properly.\n\n' 'Do you want to continue?') % ".".join( map(str, sys.version_info[:3]))) ret = dialog.run() dialog.hide() dialog.destroy() if ret == gtk.RESPONSE_NO: sys.exit(-1) if Prefs()['system.check_root'].value == True and not root: dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO, _('You are running Packet Manipulator as' ' non-root user!\nSome functionalities' ' need root privileges to work\n\nDo ' 'you want to continue?')) ret = dialog.run() dialog.hide() dialog.destroy() if ret == gtk.RESPONSE_NO: sys.exit(-1) self.phase = 0 self.splash = SplashScreen()
def create_ui(self): self.status = StatusView() self.status.info(_("PacketManipulator %s started on %s") % (PM_VERSION, os.name)) self.status.info(_("Using %s as backend") % \ Prefs()['backend.system'].value) self.status.info(_("What do you wanna pwn today?")) self._main_widget.add(self.status) self._main_widget.show_all()
def _idle(self): if self.phase == 0: self.splash.text = _("Registering icons ...") from icons import register_icons register_icons() elif self.phase == 1: self.splash.text = _("Loading preferences ...") from umit.pm.manager.preferencemanager import Prefs self.prefs = Prefs() elif self.phase == 2: services_boot() self.splash.text = _("Creating main window ...") from mainwindow import MainWindow self.bus = ServiceBus() self.main_window = MainWindow() self.main_window.connect_tabs_signals() self.plugin_engine = PluginEngine() self.plugin_engine.load_selected_plugins() # Destroy the splash screen self.splash.hide() self.splash.destroy() self.splash.finished = True del self.splash # Now let's parse the args passed in the constructor parser = self._create_parser() options, args = parser.parse_args(self._args) if options.fread: self.main_window.open_generic_file_async(options.fread) if options.audit: dev1, dev2, bpf_filter = options.audit, '', '' try: dev1, dev2 = options.audit.split(',', 1) dev2, bpf_filter = other.split(':', 1) except: pass self.main_window.start_new_audit(dev1, dev2, bpf_filter, False, False) return False self.phase += 1 return True
def on_complete(self, send, udata): if self.probes > 0: self.summary = AUDIT_MSG % (_('Finished with %d of %d sent') % \ (self.packets, self.probes)) else: self.summary = AUDIT_MSG % (_('Finished with %d sent') % \ self.packets) self.percentage = 100.0 self.sender = None self.state = self.NOT_RUNNING
def create_ui(self): self.status = StatusView() self.status.info( _("PacketManipulator %s started on %s") % (PM_VERSION, os.name)) self.status.info(_("Using %s as backend") % \ Prefs()['backend.system'].value) self.status.info(_("What do you wanna pwn today?")) self._main_widget.add(self.status) self._main_widget.show_all()
def start(self): if self.state == self.RUNNING: return self.state = self.RUNNING if self.type == FileOperation.TYPE_LOAD: self.summary = _('Loading %s') % self.file self._read_file() else: self.summary = _('Saving to %s') % self.ctx.cap_file self._save_file()
def create_widgets(self): self.widgets = [ (_('Checks'), ( ('system.check_root', None, gtk.CheckButton(_('Check for root privileges at startup'))), ('system.check_pyver', None, gtk.CheckButton(_('Check for compatible Python version'))) ) ), ]
def _save_file(self): """ @see umit.pm.gui.sessions.base.Session.save_session """ log.debug('Saving context %s to %s' % (self.ctx, self.ctx.cap_file)) if isinstance(self.ctx, backend.StaticContext): self.summary = _('Saving packets to %s') % self.ctx.cap_file elif isinstance(self.ctx, backend.SequenceContext): self.summary = _('Saving sequence to %s') % self.ctx.cap_file self.start_async_thread(())
def banner(self): """ Display python banner """ iter = self.buffer.get_iter_at_mark(self.buffer.get_insert()) self.buffer.insert_with_tags_by_name( iter, _("Welcome to PacketManipulator Python Shell (running on %s)\n") % os.name, "center", "extern" ) iter = self.buffer.get_iter_at_mark(self.buffer.get_insert()) self.buffer.insert_with_tags_by_name( iter, _("Please be carefull becouse you are in the PM main loop\n"), "center", "script" ) self.text.scroll_to_mark(self.buffer.get_insert(), 0) self.prompt1()
def __send_callback(self, packet, want_reply, udata): if not packet: self.loop_count += 1 if self.tot_loop_count: self.summary = _('Running sequence %d of %d times') % \ (self.loop_count, self.tot_loop_count) else: self.summary = _('Sequence runned for %d times') % \ self.loop_count else: self.packet_count += 1 if want_reply: self.summary = _('Sending packet %s and waiting a reply') \ % packet.summary() else: self.summary = _('Sending packet %s') % packet.summary() if self.report_sent: self.data.append(packet) pkts = self.packet_count % self.tot_packet_count if self.packet_count >= self.tot_packet_count and pkts == 0 and \ not self.tot_loop_count: pkts = 1 else: pkts /= float(self.tot_packet_count) # Calculate percentage using also the loop counter if we # are not in infinite loop. if self.tot_loop_count: self.percentage = \ ((pkts * (1.0 / self.tot_loop_count)) * \ (float(self.loop_count) / float(self.tot_loop_count))) * 100.0 else: self.percentage = pkts * 100.0 if self.scallback: # FIXME: THIS F*****G UDATA also in other files self.scallback(packet, want_reply, self.loop_count, self.packet_count, udata) if not self.internal: self.state = self.NOT_RUNNING return self.state == self.NOT_RUNNING or \ self.state == self.PAUSED
def __on_button_release(self, widget, event): # We should get the selection and show the popup if event.button != 3: return if not self.tree.get_selection().get_selected(): return model, iter = self.tree.get_selection().get_selected() field = model.get_value(iter, 0) if not isinstance(field, TField): return # We could reset the selected field, all the field in the current # protocol, the field in the current protocol and the protocols # above, and for all the packet. menu = gtk.Menu() stocks = ( gtk.STOCK_GO_FORWARD, gtk.STOCK_GO_DOWN, gtk.STOCK_GOTO_BOTTOM, gtk.STOCK_GOTO_TOP ) labels = ( _('Reset selected field'), _('Reset fields in this protocol'), _('Reset fields in above protocols'), _('Reset all the packet fields') ) callbacks = ( self.__on_reset_field, self.__on_reset_proto_fields, self.__on_reset_above_protos_fields, self.__on_reset_packet_fields ) for stock, label, cback, in zip(stocks, labels, callbacks): action = gtk.Action(None, label, None, stock) action.connect('activate', cback) item = action.create_menu_item() menu.append(item) menu.show_all() menu.popup(None, None, None, event.button, event.time)
def create_widgets(self): self.widgets = [ (_('Show views at startup'), (('gui.views.protocol_selector_tab', None, gtk.CheckButton(_('Protocol selector'))), ('gui.views.property_tab', None, gtk.CheckButton(_('Protocol properties'))), ('gui.views.status_tab', None, gtk.CheckButton(_('Status view'))), ('gui.views.operations_tab', None, gtk.CheckButton(_('Operations'))), ('gui.views.vte_tab', None, gtk.CheckButton(_('Terminal'))), ('gui.views.hack_tab', None, gtk.CheckButton(_('Payload Hack tab'))), ('gui.views.console_tab', None, gtk.CheckButton(_('Python shell'))) )) ]
def populate(self): self.store.clear() passive_it = self.store.append(None, [None, _('Passive audits'), None]) active_it = self.store.append(None, [None, _('Active audits'), None]) for plugin in self.p_window.engine.available_plugins: if plugin.audit_type == 0: self.store.append( passive_it, [plugin.get_logo(24, 24), plugin.name, plugin]) elif plugin.audit_type == 1: self.store.append( active_it, [plugin.get_logo(24, 24), plugin.name, plugin])
def execute_audit(self, sess, inp_dict): source = inp_dict['source'] target = inp_dict['target'] sport = inp_dict['sport'] dport = inp_dict['dport'] randip = inp_dict['randomize source'] randport = inp_dict['randomize sport'] probes = inp_dict['probes'] if probes < -1 or probes == 0: sess.output_page.user_msg(_('Probes could be -1 or > 1'), STATUS_ERR, AUDIT_NAME) return False if dport < 1 or dport > 65535: sess.output_page.user_msg(_('Dport is not a valid TCP port'), STATUS_ERR, AUDIT_NAME) return False if not randport and (sport < 1 or sport > 65535): sess.output_page.user_msg(_('Sport is not a valid TCP port'), STATUS_ERR, AUDIT_NAME) return False resolve = lambda x: is_ip(x) and x or gethostbyname(x) dip = resolve(target) if not randip: sip = resolve(source) if dip == '0.0.0.0': sess.output_page.user_msg(_('Target not valid'), STATUS_ERR, AUDIT_NAME) return False return SynFloodOperation( randip and randip or sip, dip, randport and randport or sport, dport, probes, max(inp_dict['delay'], 0), sess.context )