class Game(object):
    # Game parameters
    BG_TILE_IMG = 'images/brick_tile.png'
    SCREEN_WIDTH, SCREEN_HEIGHT = 580, 500
    GRID_SIZE = 20
    FIELD_SIZE = 400, 400
    
    CREEP_FILENAMES = [
        ('images/bluecreep_0.png', 'images/bluecreep_45.png'),
        ('images/greencreep_0.png', 'images/greencreep_45.png'),
        ('images/yellowcreep_0.png', 'images/yellowcreep_45.png'),
        ('images/pinkcreep_0.png', 'images/pinkcreep_45.png'),
    ]
    
    MAX_N_CREEPS = 50

    def __init__(self):
        pygame.init()
        
        self.screen = pygame.display.set_mode(
                        (self.SCREEN_WIDTH, self.SCREEN_HEIGHT), 0, 32)
        self.tile_img = pygame.image.load(self.BG_TILE_IMG).convert_alpha()
        self.tile_img_rect = self.tile_img.get_rect()
        
        self.field_border_width = 4
        field_outer_width = self.FIELD_SIZE[0] + 2 * self.field_border_width
        field_outer_height = self.FIELD_SIZE[1] + 2 * self.field_border_width
        self.field_rect_outer = Rect(20, 60, field_outer_width, field_outer_height)
        self.field_bgcolor = Color(109, 41, 1, 100)
        self.field_border_color = Color(0, 0, 0)
        self.field_box = Box(self.screen, 
            rect=self.field_rect_outer, 
            bgcolor=self.field_bgcolor,
            border_width=self.field_border_width,
            border_color=self.field_border_color)
        
        self.tboard_text = ['The amazing Creeps!']
        self.tboard_rect = Rect(20, 20, field_outer_width, 30)
        self.tboard_bgcolor = Color(50, 20, 0)
        self.tboard = MessageBoard(self.screen,
            rect=self.tboard_rect,
            bgcolor=self.tboard_bgcolor,
            border_width=4,
            border_color=Color('black'),
            text=self.tboard_text,
            font=('tahoma', 18),
            font_color=Color('yellow'))
        
        self.mboard_text = []
        self.mboard_rect = Rect(440, 60, 120, 60)
        self.mboard_bgcolor = Color(50, 20, 0)
        self.mboard = MessageBoard(self.screen,
            rect=self.mboard_rect,
            bgcolor=self.mboard_bgcolor,
            border_width=4,
            border_color=Color('black'),
            text=self.mboard_text,
            font=('verdana', 16),
            font_color=Color('white'))
    
        self.clock = pygame.time.Clock()
        self.paused = False

        self.creep_images= [
            (   pygame.image.load(f1).convert_alpha(),
                pygame.image.load(f2).convert_alpha())
            for (f1, f2) in self.CREEP_FILENAMES]

        explosion_img = pygame.image.load('images/explosion1.png').convert_alpha()
        self.explosion_images = [
            explosion_img, pygame.transform.rotate(explosion_img, 90)]
        
        self.field_rect = self.get_field_rect()
        
        self.entrance_rect = Rect(
            self.field_rect.left,
            self.field_rect.top,
            self.GRID_SIZE * 2,
            self.GRID_SIZE * 2)
        
        self.exit_rect = Rect(
            self.field_rect.right - self.GRID_SIZE * 2,
            self.field_rect.bottom - self.GRID_SIZE * 2,
            self.GRID_SIZE * 2,
            self.GRID_SIZE * 2)
        
        # Create the creeps group and the first creep
        self.creeps = pygame.sprite.Group()
        self.spawn_new_creep()
        
        self.creep_spawn_timer = Timer(500, self.spawn_new_creep)
        
        self.create_walls()
        
        # Create the grid-path representation of the field
        #
        self.grid_nrows = self.FIELD_SIZE[1] / self.GRID_SIZE
        self.grid_ncols = self.FIELD_SIZE[0] / self.GRID_SIZE
        self.goal_coord = (self.grid_nrows - 1, self.grid_ncols - 1)
        self.gridpath = GridPath(
            nrows=self.grid_nrows,
            ncols=self.grid_ncols,
            goal=self.goal_coord)
        
        for wall in self.walls:
            self.gridpath.set_blocked(wall)
    
        self.options = dict(
            draw_grid=False)
    
    def create_walls(self):
        walls_list = []
        
        for r in range(0, 15):
            walls_list.append((r, 6))
            
            if r != 7:
                walls_list.append((r, 3))
                walls_list.append((r, 4))
            
            if r > 4:
                walls_list.append((r, 1))
        
        for r in range(9, 20):
            walls_list.append((r, 10))
        
        for c in range(14, 18):
            walls_list.append((15, c))
        
        self.walls = dict().fromkeys(walls_list, True)
    
    def next_on_path(self, coord):
        """ Given a coord, returns the next coord on the path to
            the goal. None is returned if no path exists from
            the coord.
        """
        return self.gridpath.get_next(coord)
    
    def xy2coord(self, pos):
        """ Convert a (x, y) pair to a (nrow, ncol) coordinate
        """
        x, y = (pos[0] - self.field_rect.left, pos[1] - self.field_rect.top)
        return (int(y) / self.GRID_SIZE, int(x) / self.GRID_SIZE)
    
    def coord2xy_mid(self, coord):
        """ Convert a (nrow, ncol) coordinate to a (x, y) pair,
            where x,y is the middle of the square at the coord
        """
        nrow, ncol = coord
        return (
            self.field_rect.left + ncol * self.GRID_SIZE + self.GRID_SIZE / 2, 
            self.field_rect.top + nrow * self.GRID_SIZE + self.GRID_SIZE / 2)
    
    def is_goal_coord(self, coord):
        return coord == self.goal_coord
    
    _spawned_creep_count = 0
    def spawn_new_creep(self):
        if self._spawned_creep_count >= self.MAX_N_CREEPS:
            return
        
        self.creeps.add(
            Creep(  screen=self.screen,
                    game=self,
                    creep_images=choice(self.creep_images),
                    explosion_images=self.explosion_images,
                    field=self.field_rect,
                    init_position=( self.field_rect.left + self.GRID_SIZE / 2,
                                    self.field_rect.top + self.GRID_SIZE / 2),
                    init_direction=(1, 1),
                    speed=0.05))
        self._spawned_creep_count += 1
    
    def get_field_rect(self):
        """ Return the internal field rect - the rect of the game
            field exluding its border.
        """
        return self.field_box.get_internal_rect()
    
    def draw_background(self):
        img_rect = self.tile_img.get_rect()
        nrows = int(self.screen.get_height() / img_rect.height) + 1
        ncols = int(self.screen.get_width() / img_rect.width) + 1
        
        for y in range(nrows):
            for x in range(ncols):
                img_rect.topleft = (x * img_rect.width, 
                                    y * img_rect.height)
                self.screen.blit(self.tile_img, img_rect)
    
    def draw_portals(self):
        entrance_sf = pygame.Surface((self.entrance_rect.w, self.entrance_rect.h))
        entrance_sf.fill(Color(80, 200, 80))
        entrance_sf.set_alpha(150)
        self.screen.blit(entrance_sf, self.entrance_rect)
        
        exit_sf = pygame.Surface((self.exit_rect.w, self.exit_rect.h))
        exit_sf.fill(Color(200, 80, 80))
        exit_sf.set_alpha(150)
        self.screen.blit(exit_sf, self.exit_rect) 
    
    def draw_grid(self):
        for y in range(self.grid_nrows + 1):
            pygame.draw.line(
                self.screen,
                Color(50, 50, 50),
                (self.field_rect.left, self.field_rect.top + y * self.GRID_SIZE - 1),
                (self.field_rect.right - 1, self.field_rect.top + y * self.GRID_SIZE - 1))
        
        for x in range(self.grid_ncols + 1):
            pygame.draw.line(
                self.screen,
                Color(50, 50, 50),
                (self.field_rect.left + x * self.GRID_SIZE - 1, self.field_rect.top),
                (self.field_rect.left + x * self.GRID_SIZE - 1, self.field_rect.bottom - 1))
    
    def draw_walls(self):
        wallcolor = Color(140, 140, 140)
        
        for wall in self.walls:
            nrow, ncol = wall
            
            pos_x = self.field_rect.left + ncol * self.GRID_SIZE + self.GRID_SIZE / 2
            pos_y = self.field_rect.top + nrow * self.GRID_SIZE + self.GRID_SIZE / 2
            radius = 3
            
            pygame.draw.polygon(self.screen, wallcolor,
                [   (pos_x - radius, pos_y), (pos_x, pos_y + radius),
                    (pos_x + radius, pos_y), (pos_x, pos_y - radius)])
            
            if (nrow + 1, ncol) in self.walls:
                pygame.draw.line(self.screen, wallcolor,
                    (pos_x, pos_y), (pos_x, pos_y + self.GRID_SIZE), 3)
            if (nrow, ncol + 1) in self.walls:
                pygame.draw.line(self.screen, wallcolor,
                    (pos_x, pos_y), (pos_x + self.GRID_SIZE, pos_y), 3)
    
    def draw(self):
        self.draw_background()
        self.field_box.draw()
        
        if self.options['draw_grid']:
            self.draw_grid()
        
        self.draw_walls()
        
        self.tboard.draw()
        self.mboard.text = self.mboard_text
        self.mboard.draw()
        
        for creep in self.creeps:
            creep.draw()
        
        self.draw_portals()
        
    def run(self):
        # The main game loop
        #
        while True:
            # Limit frame speed to 30 FPS
            #
            time_passed = self.clock.tick(30)
            #~ time_passed = self.clock.tick()
            #~ print time_passed
            
            # If too long has passed between two frames, don't
            # update (the game must have been suspended for some
            # reason, and we don't want it to "jump forward"
            # suddenly)
            #
            if time_passed > 100:
                continue
            
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        self.paused = not self.paused
                    elif event.key == pygame.K_g:
                        if pygame.key.get_mods() & pygame.KMOD_CTRL:
                            self.options['draw_grid'] = not self.options['draw_grid']
                elif (  event.type == pygame.MOUSEBUTTONDOWN and
                        event.button == 1):
                    for creep in self.creeps:
                        creep.mouse_click_event(event.pos)
            
            if not self.paused:
                msg1 = 'Creeps: %d' % len(self.creeps)
                msg2 = ''

                self.mboard_text = [msg1, msg2]
                
                self.creep_spawn_timer.update(time_passed)
                
                # Update and all creeps
                for creep in self.creeps:
                    creep.update(time_passed)
                    
                self.draw()
                
            pygame.display.flip()

    def quit(self):
        sys.exit()
    def __init__(self):
        pygame.init()
        
        self.screen = pygame.display.set_mode(
                        (self.SCREEN_WIDTH, self.SCREEN_HEIGHT), 0, 32)
        self.tile_img = pygame.image.load(self.BG_TILE_IMG).convert_alpha()
        self.tile_img_rect = self.tile_img.get_rect()
        
        self.field_border_width = 4
        field_outer_width = self.FIELD_SIZE[0] + 2 * self.field_border_width
        field_outer_height = self.FIELD_SIZE[1] + 2 * self.field_border_width
        self.field_rect_outer = Rect(20, 60, field_outer_width, field_outer_height)
        self.field_bgcolor = Color(109, 41, 1, 100)
        self.field_border_color = Color(0, 0, 0)
        self.field_box = Box(self.screen, 
            rect=self.field_rect_outer, 
            bgcolor=self.field_bgcolor,
            border_width=self.field_border_width,
            border_color=self.field_border_color)
        
        self.tboard_text = ['The amazing Creeps!']
        self.tboard_rect = Rect(20, 20, field_outer_width, 30)
        self.tboard_bgcolor = Color(50, 20, 0)
        self.tboard = MessageBoard(self.screen,
            rect=self.tboard_rect,
            bgcolor=self.tboard_bgcolor,
            border_width=4,
            border_color=Color('black'),
            text=self.tboard_text,
            font=('tahoma', 18),
            font_color=Color('yellow'))
        
        self.mboard_text = []
        self.mboard_rect = Rect(440, 60, 120, 60)
        self.mboard_bgcolor = Color(50, 20, 0)
        self.mboard = MessageBoard(self.screen,
            rect=self.mboard_rect,
            bgcolor=self.mboard_bgcolor,
            border_width=4,
            border_color=Color('black'),
            text=self.mboard_text,
            font=('verdana', 16),
            font_color=Color('white'))
    
        self.clock = pygame.time.Clock()
        self.paused = False

        self.creep_images= [
            (   pygame.image.load(f1).convert_alpha(),
                pygame.image.load(f2).convert_alpha())
            for (f1, f2) in self.CREEP_FILENAMES]

        explosion_img = pygame.image.load('images/explosion1.png').convert_alpha()
        self.explosion_images = [
            explosion_img, pygame.transform.rotate(explosion_img, 90)]
        
        self.field_rect = self.get_field_rect()
        
        self.entrance_rect = Rect(
            self.field_rect.left,
            self.field_rect.top,
            self.GRID_SIZE * 2,
            self.GRID_SIZE * 2)
        
        self.exit_rect = Rect(
            self.field_rect.right - self.GRID_SIZE * 2,
            self.field_rect.bottom - self.GRID_SIZE * 2,
            self.GRID_SIZE * 2,
            self.GRID_SIZE * 2)
        
        # Create the creeps group and the first creep
        self.creeps = pygame.sprite.Group()
        self.spawn_new_creep()
        
        self.creep_spawn_timer = Timer(500, self.spawn_new_creep)
        
        self.create_walls()
        
        # Create the grid-path representation of the field
        #
        self.grid_nrows = self.FIELD_SIZE[1] / self.GRID_SIZE
        self.grid_ncols = self.FIELD_SIZE[0] / self.GRID_SIZE
        self.goal_coord = (self.grid_nrows - 1, self.grid_ncols - 1)
        self.gridpath = GridPath(
            nrows=self.grid_nrows,
            ncols=self.grid_ncols,
            goal=self.goal_coord)
        
        for wall in self.walls:
            self.gridpath.set_blocked(wall)
    
        self.options = dict(
            draw_grid=False)
Exemple #3
0
    def build_page1(self):
        box = Box(orientation=VERTICAL, spacing=6)
        box.set_border_width(10)
        _ = m._

        # sqlmap命令语句
        _cmd_area = Frame.new(_('A.Options are collected here:'))
        _cmd_area.add(m._cmd_entry)

        # 主构造区
        _notebook = Notebook(m, self._handlers)

        m._general_area_flush_session_ckbtn.connect(
            'toggled', self._show_warn, 'check --flush-session:\n\n'
            'Flush session files for current target?')
        m._misc_area_purge_ckbtn.connect(
            'toggled', self._show_warn, 'check --purge:\n\n'
            'Safely remove all content from sqlmap data directory?')

        _notebook.add_events(d.EventMask.SCROLL_MASK
                             | d.EventMask.SMOOTH_SCROLL_MASK)
        _notebook.connect('scroll-event', self.scroll_page)

        # 构造与执行
        _exec_area = Box()

        _build_button = btn.new_with_mnemonic(_('A.collect(_A)'))
        _build_button.connect('clicked', self._handlers.build_all)

        _unselect_all_btn = btn.new_with_mnemonic(_('unselect(_S)'))
        _unselect_all_btn.connect('clicked', self.unselect_all_ckbtn)
        _clear_all_entry = btn.new_with_mnemonic(_('clear all inputs(_D)'))
        _clear_all_entry.connect('clicked', self.clear_all_entry)

        _run_button = btn.new_with_mnemonic(_('B.run(_F)'))
        _run_button.connect('clicked', self._handlers.run_cmdline)

        _exec_area.pack_start(_build_button, False, True, 0)
        _exec_area.pack_start(_unselect_all_btn, True, False, 0)
        _exec_area.pack_start(_clear_all_entry, True, False, 0)
        _exec_area.pack_end(_run_button, False, True, 0)

        box.pack_start(_cmd_area, False, True, 0)
        box.pack_start(_notebook, True, True, 0)
        box.pack_end(_exec_area, False, True, 0)
        return box
Exemple #4
0
    def build_page2(self):
        '''
    用subprocess不可实现与sqlmap的交互!
    不管是多线程, 同步还是异步, 都不行, 只能使用pty
    '''
        box = Box(orientation=VERTICAL, spacing=6)
        box.set_border_width(10)

        _row1 = Box(spacing=6)
        m._page2_respwan_btn.connect('clicked',
                                     self._handlers.respawn_terminal)
        m._page2_right_btn.connect("button-press-event", self.on_right_click)
        # can not disable
        # m._page2_right_btn.set_sensitive(False)
        self._build_page2_context()

        _row1.pack_start(m._page2_respwan_btn, False, True, 0)
        _row1.pack_start(m._page2_right_btn, False, True, 0)

        _row2 = Frame()
        # equals: _pty = m._page2_terminal.pty_new_sync(Vte.PtyFlags.DEFAULT)
        _pty = Vte.Pty.new_sync(Vte.PtyFlags.DEFAULT)
        m._page2_terminal.set_pty(_pty)
        m._page2_terminal.connect('key_press_event', self.on_clipboard_by_key)
        m._page2_terminal.connect("button-press-event", self.on_right_click,
                                  m._page2_right_btn)

        # https://stackoverflow.com/questions/55105447/virtual-python-shell-with-vte-pty-spawn-async
        # https://gtk-d.dpldocs.info/vte.Pty.Pty.spawnAsync.html
        # API手册上的该方法签名有问题, 与实际的对不上
        # 最后一个参数为回调函数, 是必填项
        _pty.spawn_async(str(Path.home()), [self._handlers.shell], None,
                         GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None, -1,
                         None, lambda pty, task: None)

        _scrolled = g.ScrolledWindow()
        _scrolled.set_policy(g.PolicyType.NEVER, g.PolicyType.ALWAYS)
        _scrolled.add(m._page2_terminal)
        _row2.add(_scrolled)

        box.pack_start(_row1, False, True, 5)
        box.pack_end(_row2, True, True, 0)
        return box
Exemple #5
0
    def __init__(self):
        pygame.init()

        self.screen = pygame.display.set_mode(
            (self.SCREEN_WIDTH, self.SCREEN_HEIGHT), 0, 32)
        self.tile_img = pygame.image.load(self.BG_TILE_IMG).convert_alpha()
        self.tile_img_rect = self.tile_img.get_rect()

        self.field_border_width = 4
        field_outer_width = self.FIELD_SIZE[0] + 2 * self.field_border_width
        field_outer_height = self.FIELD_SIZE[1] + 2 * self.field_border_width
        self.field_rect_outer = Rect(20, 60, field_outer_width,
                                     field_outer_height)
        self.field_bgcolor = Color(109, 41, 1, 100)
        self.field_border_color = Color(0, 0, 0)
        self.field_box = Box(self.screen,
                             rect=self.field_rect_outer,
                             bgcolor=self.field_bgcolor,
                             border_width=self.field_border_width,
                             border_color=self.field_border_color)

        self.tboard_text = ['The amazing Creeps!']
        self.tboard_rect = Rect(20, 20, field_outer_width, 30)
        self.tboard_bgcolor = Color(50, 20, 0)
        self.tboard = MessageBoard(self.screen,
                                   rect=self.tboard_rect,
                                   bgcolor=self.tboard_bgcolor,
                                   border_width=4,
                                   border_color=Color('black'),
                                   text=self.tboard_text,
                                   font=('tahoma', 18),
                                   font_color=Color('yellow'))

        self.mboard_text = []
        self.mboard_rect = Rect(440, 60, 120, 60)
        self.mboard_bgcolor = Color(50, 20, 0)
        self.mboard = MessageBoard(self.screen,
                                   rect=self.mboard_rect,
                                   bgcolor=self.mboard_bgcolor,
                                   border_width=4,
                                   border_color=Color('black'),
                                   text=self.mboard_text,
                                   font=('verdana', 16),
                                   font_color=Color('white'))

        self.clock = pygame.time.Clock()
        self.paused = False

        self.creep_images = list()
        for f1, f2 in self.CREEP_FILENAMES:
            f1_img = pygame.image.load(f1).convert_alpha()
            f2_img = pygame.image.load(f2).convert_alpha()
            self.creep_images.append((f1_img, f2_img))


#       self.creep_images= [
#           (   pygame.image.load(f1).convert_alpha(),
#               pygame.image.load(f2).convert_alpha())
#           for (f1, f2) in self.CREEP_FILENAMES]

        explosion_img = pygame.image.load(
            'images/explosion1.png').convert_alpha()
        self.explosion_images = [
            explosion_img,
            pygame.transform.rotate(explosion_img, 90)
        ]

        self.field_rect = self.get_field_rect()

        self.entrance_rect = Rect(self.field_rect.left, self.field_rect.top,
                                  self.GRID_SIZE * 2, self.GRID_SIZE * 2)

        self.exit_rect = Rect(self.field_rect.right - self.GRID_SIZE * 2,
                              self.field_rect.bottom - self.GRID_SIZE * 2,
                              self.GRID_SIZE * 2, self.GRID_SIZE * 2)

        # Create the creeps group and the first creep
        self.creeps = pygame.sprite.Group()
        self.spawn_new_creep()

        self.creep_spawn_timer = Timer(500, self.spawn_new_creep)

        self.create_walls()

        # Create the grid-path representation of the field
        #
        self.grid_nrows = self.FIELD_SIZE[1] / self.GRID_SIZE
        self.grid_ncols = self.FIELD_SIZE[0] / self.GRID_SIZE
        self.goal_coord = (self.grid_nrows - 1, self.grid_ncols - 1)
        self.gridpath = GridPath(nrows=self.grid_nrows,
                                 ncols=self.grid_ncols,
                                 goal=self.goal_coord)

        for wall in self.walls:
            self.gridpath.set_blocked(wall)

        self.options = dict(draw_grid=False)
Exemple #6
0
    def build_target_notebook(self, target_nb):
        target_nb.add_events(d.EventMask.SCROLL_MASK
                             | d.EventMask.SMOOTH_SCROLL_MASK)
        target_nb.connect('scroll-event', self.scroll_page)
        # --url
        name_store = g.ListStore(int, str)
        name_store.append([1, "http://www.site.com/vuln.php?id=1"])

        _url_area = Box()
        m._url_combobox.set_model(name_store)
        m._url_combobox.set_entry_text_column(1)

        _url_area.pack_start(m._url_combobox, True, True, 0)

        _burp_area = Box()
        m._burp_logfile_chooser.connect('clicked',
                                        self._handlers.set_file_entry_text,
                                        [m._burp_logfile])

        _burp_area.pack_start(m._burp_logfile, True, True, 0)
        _burp_area.pack_start(m._burp_logfile_chooser, False, True, 0)

        _request_area = Box()

        m._request_file_chooser.connect('clicked',
                                        self._handlers.set_file_entry_text,
                                        [m._request_file])

        _request_area.pack_start(m._request_file, True, True, 0)
        _request_area.pack_start(m._request_file_chooser, False, True, 0)

        _bulkfile_area = Box()
        m._bulkfile_chooser.connect('clicked',
                                    self._handlers.set_file_entry_text,
                                    [m._bulkfile])

        _bulkfile_area.pack_start(m._bulkfile, True, True, 0)
        _bulkfile_area.pack_start(m._bulkfile_chooser, False, True, 0)

        _configfile_area = Box()
        m._configfile_chooser.connect('clicked',
                                      self._handlers.set_file_entry_text,
                                      [m._configfile])

        _configfile_area.pack_start(m._configfile, True, True, 0)
        _configfile_area.pack_start(m._configfile_chooser, False, True, 0)

        _google_dork_area = Box()
        _google_dork_area.pack_start(m._google_dork, True, True, 0)

        _direct_connect_area = Box()
        m._direct_connect.set_text(
            'mysql://*****:*****@DBMS_IP:DBMS_PORT/DATABASE_NAME or '
            'access://DATABASE_FILEPATH')
        _direct_connect_area.pack_start(m._direct_connect, True, True, 0)

        _ = m._
        target_nb.append_page(_url_area, label.new(_('-u URL')))
        target_nb.append_page(_burp_area, label.new(_('-l LOGFILE')))
        target_nb.append_page(_request_area, label.new(_('-r REQUESTFILE')))
        target_nb.append_page(_bulkfile_area, label.new(_('-m BULKFILE')))
        target_nb.append_page(_configfile_area, label.new(_('-c CONFIGFILE')))
        target_nb.append_page(_google_dork_area, label.new(_('-g GOOGLEDORK')))
        target_nb.append_page(_direct_connect_area, label.new(_('-d DIRECT')))
Exemple #7
0
    def _build_page5(self):
        box = Box(orientation=VERTICAL)
        box.set_border_width(10)

        _row1 = Box()
        self._get_sqlmap_path_btn = btn.new_with_label('获取帮助')
        self._get_sqlmap_path_btn.set_sensitive(False)
        self._get_sqlmap_path_btn.connect('clicked', self._make_help_thread)

        _row1.pack_start(self._get_sqlmap_path_btn, False, True, 5)

        _row2 = Frame()

        self._make_help_thread(None)

        _scrolled = g.ScrolledWindow()
        _scrolled.set_policy(g.PolicyType.NEVER, g.PolicyType.ALWAYS)
        _scrolled.add(m._page5_manual_view)

        _row2.add(_scrolled)

        box.pack_start(_row1, False, True, 5)
        box.pack_start(_row2, True, True, 5)
        return box
Exemple #8
0
class Game(object):
    # Game parameters
    BG_TILE_IMG = 'images/brick_tile.png'
    SCREEN_WIDTH, SCREEN_HEIGHT = 580, 500
    GRID_SIZE = 20
    FIELD_SIZE = 400, 400

    CREEP_FILENAMES = [
        ('images/bluecreep_0.png', 'images/bluecreep_45.png'),
        ('images/greencreep_0.png', 'images/greencreep_45.png'),
        ('images/yellowcreep_0.png', 'images/yellowcreep_45.png'),
        ('images/pinkcreep_0.png', 'images/pinkcreep_45.png'),
    ]

    MAX_N_CREEPS = 50

    def __init__(self):
        pygame.init()

        self.screen = pygame.display.set_mode(
            (self.SCREEN_WIDTH, self.SCREEN_HEIGHT), 0, 32)
        self.tile_img = pygame.image.load(self.BG_TILE_IMG).convert_alpha()
        self.tile_img_rect = self.tile_img.get_rect()

        self.field_border_width = 4
        field_outer_width = self.FIELD_SIZE[0] + 2 * self.field_border_width
        field_outer_height = self.FIELD_SIZE[1] + 2 * self.field_border_width
        self.field_rect_outer = Rect(20, 60, field_outer_width,
                                     field_outer_height)
        self.field_bgcolor = Color(109, 41, 1, 100)
        self.field_border_color = Color(0, 0, 0)
        self.field_box = Box(self.screen,
                             rect=self.field_rect_outer,
                             bgcolor=self.field_bgcolor,
                             border_width=self.field_border_width,
                             border_color=self.field_border_color)

        self.tboard_text = ['The amazing Creeps!']
        self.tboard_rect = Rect(20, 20, field_outer_width, 30)
        self.tboard_bgcolor = Color(50, 20, 0)
        self.tboard = MessageBoard(self.screen,
                                   rect=self.tboard_rect,
                                   bgcolor=self.tboard_bgcolor,
                                   border_width=4,
                                   border_color=Color('black'),
                                   text=self.tboard_text,
                                   font=('tahoma', 18),
                                   font_color=Color('yellow'))

        self.mboard_text = []
        self.mboard_rect = Rect(440, 60, 120, 60)
        self.mboard_bgcolor = Color(50, 20, 0)
        self.mboard = MessageBoard(self.screen,
                                   rect=self.mboard_rect,
                                   bgcolor=self.mboard_bgcolor,
                                   border_width=4,
                                   border_color=Color('black'),
                                   text=self.mboard_text,
                                   font=('verdana', 16),
                                   font_color=Color('white'))

        self.clock = pygame.time.Clock()
        self.paused = False

        self.creep_images = list()
        for f1, f2 in self.CREEP_FILENAMES:
            f1_img = pygame.image.load(f1).convert_alpha()
            f2_img = pygame.image.load(f2).convert_alpha()
            self.creep_images.append((f1_img, f2_img))


#       self.creep_images= [
#           (   pygame.image.load(f1).convert_alpha(),
#               pygame.image.load(f2).convert_alpha())
#           for (f1, f2) in self.CREEP_FILENAMES]

        explosion_img = pygame.image.load(
            'images/explosion1.png').convert_alpha()
        self.explosion_images = [
            explosion_img,
            pygame.transform.rotate(explosion_img, 90)
        ]

        self.field_rect = self.get_field_rect()

        self.entrance_rect = Rect(self.field_rect.left, self.field_rect.top,
                                  self.GRID_SIZE * 2, self.GRID_SIZE * 2)

        self.exit_rect = Rect(self.field_rect.right - self.GRID_SIZE * 2,
                              self.field_rect.bottom - self.GRID_SIZE * 2,
                              self.GRID_SIZE * 2, self.GRID_SIZE * 2)

        # Create the creeps group and the first creep
        self.creeps = pygame.sprite.Group()
        self.spawn_new_creep()

        self.creep_spawn_timer = Timer(500, self.spawn_new_creep)

        self.create_walls()

        # Create the grid-path representation of the field
        #
        self.grid_nrows = self.FIELD_SIZE[1] / self.GRID_SIZE
        self.grid_ncols = self.FIELD_SIZE[0] / self.GRID_SIZE
        self.goal_coord = (self.grid_nrows - 1, self.grid_ncols - 1)
        self.gridpath = GridPath(nrows=self.grid_nrows,
                                 ncols=self.grid_ncols,
                                 goal=self.goal_coord)

        for wall in self.walls:
            self.gridpath.set_blocked(wall)

        self.options = dict(draw_grid=False)

    def create_walls(self):
        walls_list = []

        for r in range(0, 15):
            walls_list.append((r, 6))

            if r != 7:
                walls_list.append((r, 3))
                walls_list.append((r, 4))

            if r > 4:
                walls_list.append((r, 1))

        for r in range(9, 20):
            walls_list.append((r, 10))

        for c in range(14, 18):
            walls_list.append((15, c))

        self.walls = dict().fromkeys(walls_list, True)

    def next_on_path(self, coord):
        """ Given a coord, returns the next coord on the path to
            the goal. None is returned if no path exists from
            the coord.
        """
        return self.gridpath.get_next(coord)

    def xy2coord(self, pos):
        """ Convert a (x, y) pair to a (nrow, ncol) coordinate
        """
        x, y = (pos[0] - self.field_rect.left, pos[1] - self.field_rect.top)
        return (int(y) / self.GRID_SIZE, int(x) / self.GRID_SIZE)

    def coord2xy_mid(self, coord):
        """ Convert a (nrow, ncol) coordinate to a (x, y) pair,
            where x,y is the middle of the square at the coord
        """
        nrow, ncol = coord
        return (self.field_rect.left + ncol * self.GRID_SIZE +
                self.GRID_SIZE / 2, self.field_rect.top +
                nrow * self.GRID_SIZE + self.GRID_SIZE / 2)

    def is_goal_coord(self, coord):
        return coord == self.goal_coord

    _spawned_creep_count = 0

    def spawn_new_creep(self):
        if self._spawned_creep_count >= self.MAX_N_CREEPS:
            return

        self.creeps.add(
            Creep(screen=self.screen,
                  game=self,
                  creep_images=choice(self.creep_images),
                  explosion_images=self.explosion_images,
                  field=self.field_rect,
                  init_position=(self.field_rect.left + self.GRID_SIZE / 2,
                                 self.field_rect.top + self.GRID_SIZE / 2),
                  init_direction=(1, 1),
                  speed=0.05))
        self._spawned_creep_count += 1

    def get_field_rect(self):
        """ Return the internal field rect - the rect of the game
            field exluding its border.
        """
        return self.field_box.get_internal_rect()

    def draw_background(self):
        img_rect = self.tile_img.get_rect()
        nrows = int(self.screen.get_height() / img_rect.height) + 1
        ncols = int(self.screen.get_width() / img_rect.width) + 1

        for y in range(nrows):
            for x in range(ncols):
                img_rect.topleft = (x * img_rect.width, y * img_rect.height)
                self.screen.blit(self.tile_img, img_rect)

    def draw_portals(self):
        entrance_sf = pygame.Surface(
            (self.entrance_rect.w, self.entrance_rect.h))
        entrance_sf.fill(Color(80, 200, 80))
        entrance_sf.set_alpha(150)
        self.screen.blit(entrance_sf, self.entrance_rect)

        exit_sf = pygame.Surface((self.exit_rect.w, self.exit_rect.h))
        exit_sf.fill(Color(200, 80, 80))
        exit_sf.set_alpha(150)
        self.screen.blit(exit_sf, self.exit_rect)

    def draw_grid(self):
        for y in range(self.grid_nrows + 1):
            pygame.draw.line(self.screen, Color(50, 50, 50),
                             (self.field_rect.left,
                              self.field_rect.top + y * self.GRID_SIZE - 1),
                             (self.field_rect.right - 1,
                              self.field_rect.top + y * self.GRID_SIZE - 1))

        for x in range(self.grid_ncols + 1):
            pygame.draw.line(self.screen, Color(50, 50, 50),
                             (self.field_rect.left + x * self.GRID_SIZE - 1,
                              self.field_rect.top),
                             (self.field_rect.left + x * self.GRID_SIZE - 1,
                              self.field_rect.bottom - 1))

    def draw_walls(self):
        wallcolor = Color(140, 140, 140)

        for wall in self.walls:
            nrow, ncol = wall

            pos_x = self.field_rect.left + ncol * self.GRID_SIZE + self.GRID_SIZE / 2
            pos_y = self.field_rect.top + nrow * self.GRID_SIZE + self.GRID_SIZE / 2
            radius = 3

            pygame.draw.polygon(self.screen, wallcolor,
                                [(pos_x - radius, pos_y),
                                 (pos_x, pos_y + radius),
                                 (pos_x + radius, pos_y),
                                 (pos_x, pos_y - radius)])

            if (nrow + 1, ncol) in self.walls:
                pygame.draw.line(self.screen, wallcolor, (pos_x, pos_y),
                                 (pos_x, pos_y + self.GRID_SIZE), 3)
            if (nrow, ncol + 1) in self.walls:
                pygame.draw.line(self.screen, wallcolor, (pos_x, pos_y),
                                 (pos_x + self.GRID_SIZE, pos_y), 3)

    def draw(self):
        self.draw_background()
        self.field_box.draw()

        if self.options['draw_grid']:
            self.draw_grid()

        self.draw_walls()

        self.tboard.draw()
        self.mboard.text = self.mboard_text
        self.mboard.draw()

        for creep in self.creeps:
            creep.draw()

        self.draw_portals()

    def run(self):
        # The main game loop
        #
        while True:
            # Limit frame speed to 30 FPS
            #
            time_passed = self.clock.tick(30)
            #~ time_passed = self.clock.tick()
            #~ print time_passed

            # If too long has passed between two frames, don't
            # update (the game must have been suspended for some
            # reason, and we don't want it to "jump forward"
            # suddenly)
            #
            if time_passed > 100:
                continue

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        self.paused = not self.paused
                    elif event.key == pygame.K_g:
                        if pygame.key.get_mods() & pygame.KMOD_CTRL:
                            self.options[
                                'draw_grid'] = not self.options['draw_grid']
                elif (event.type == pygame.MOUSEBUTTONDOWN
                      and event.button == 1):
                    for creep in self.creeps:
                        creep.mouse_click_event(event.pos)

            if not self.paused:
                msg1 = 'Creeps: %d' % len(self.creeps)
                msg2 = ''

                self.mboard_text = [msg1, msg2]

                self.creep_spawn_timer.update(time_passed)

                # Update and all creeps
                for creep in self.creeps:
                    creep.update(time_passed)

                self.draw()

            pygame.display.flip()

    def quit(self):
        sys.exit()
Exemple #9
0
    def _build_page4(self):
        box = Box(orientation=VERTICAL)
        box.set_border_width(10)

        _row1 = Box(spacing=6)
        _row1.pack_start(m._page4_api_server_label, False, True, 0)
        _row1.pack_start(m._page4_api_server_entry, True, True, 0)
        _row1.pack_start(m._page4_admin_token_label, False, True, 0)
        _row1.pack_start(m._page4_admin_token_entry, True, True, 0)

        _row2 = Box(spacing=6)
        _arrow_down = g.Image.new_from_icon_name('pan-down-symbolic', 1)
        m._page4_admin_list_btn.set_image(_arrow_down)
        m._page4_admin_list_btn.set_image_position(g.PositionType.RIGHT)
        m._page4_admin_list_btn.set_always_show_image(True)

        m._page4_task_new_btn.connect('clicked', self._handlers.api.task_new)
        m._page4_admin_list_btn.connect('clicked',
                                        self._handlers.api.admin_list)
        m._page4_admin_flush_btn.connect('clicked',
                                         self._handlers.api.admin_flush)
        m._page4_clear_task_view_btn.connect(
            'clicked', self._handlers.clear_task_view_buffer)

        _row2.pack_start(m._page4_task_new_btn, False, True, 0)
        _row2.pack_start(m._page4_admin_list_btn, False, True, 0)
        _row2.pack_start(m._page4_admin_flush_btn, False, True, 0)
        _row2.pack_start(m._page4_clear_task_view_btn, False, True, 0)
        _row2.pack_end(m._page4_password_entry, False, True, 0)
        _row2.pack_end(m._page4_password_label, False, True, 0)
        _row2.pack_end(m._page4_username_entry, False, True, 0)
        _row2.pack_end(m._page4_username_label, False, True, 0)

        _row3 = Frame()
        _paned = g.Paned()

        self._api_admin_list_rows = g.ListBox.new()
        self._api_admin_list_rows.set_selection_mode(g.SelectionMode.NONE)

        _lscrolled = g.ScrolledWindow()
        _lscrolled.set_size_request(400, -1)
        _lscrolled.set_policy(g.PolicyType.NEVER, g.PolicyType.ALWAYS)
        _lscrolled.add(self._api_admin_list_rows)

        _rbox = Box(orientation=VERTICAL)
        _page4_option_set_view_tip = label(
            label='所有选项见sqlmap目录中的optiondict.py', halign=g.Align.START)
        _option_set_view_textbuffer = m._page4_option_set_view.get_buffer()
        _options_example = ("{\n"
                            "  'url': 'http://www.site.com/vuln.php?id=1',\n"
                            "  'level': 1, 'risk': 1,\n\n"
                            "}\n")
        _option_set_view_textbuffer.set_text(
            _options_example, len(_options_example.encode('utf8')))
        # 貌似scrollwindow要直接包含textview,
        # 不然一直回车后, 页面不会向上滚
        _option_set_scrolled = g.ScrolledWindow()
        _option_set_scrolled.set_size_request(400, -1)
        _option_set_scrolled.set_policy(g.PolicyType.NEVER,
                                        g.PolicyType.ALWAYS)
        _option_set_scrolled.add(m._page4_option_set_view)

        _rbox.pack_start(m._page4_option_get_entry, False, True, 2)
        _rbox.pack_start(_page4_option_set_view_tip, False, True, 2)
        _rbox.pack_start(_option_set_scrolled, True, True, 2)

        # Warning: don't edit pack1(), pack2() again, or it would be strange.
        _paned.pack1(_lscrolled, False, False)
        _paned.pack2(_rbox, False, True)
        _row3.add(_paned)

        _row4 = Frame()

        _task_view_textbuffer = m._page4_task_view.get_buffer()
        _end = _task_view_textbuffer.get_end_iter()
        _task_view_textbuffer.create_mark('end', _end, False)
        self._handlers.api.task_view_append('此处显示反馈的结果:')

        _scrolled = g.ScrolledWindow()
        _scrolled.set_policy(g.PolicyType.NEVER, g.PolicyType.ALWAYS)
        _scrolled.add(m._page4_task_view)

        _row4.add(_scrolled)

        box.pack_start(_row1, False, True, 5)
        box.pack_start(_row2, False, True, 5)
        box.pack_start(_row3, True, True, 5)
        box.pack_start(_row4, True, True, 5)
        return box
Exemple #10
0
    def _build_page3(self):
        box = Box(orientation=VERTICAL, spacing=6)
        box.set_border_width(10)

        _row1 = Frame()

        _log_view_textbuffer = m._page3_log_view.get_buffer()
        self._handlers.clear_log_view_buffer(None)

        _end = _log_view_textbuffer.get_end_iter()
        _log_view_textbuffer.create_mark('end', _end, False)

        _scrolled = g.ScrolledWindow()
        _scrolled.set_policy(g.PolicyType.NEVER, g.PolicyType.ALWAYS)
        _scrolled.add(m._page3_log_view)
        _row1.add(_scrolled)

        _row2 = Box()
        m._page3_read_target_btn.connect('clicked',
                                         self._handlers.read_target_file)
        m._page3_clear_btn.connect('clicked',
                                   self._handlers.clear_log_view_buffer)
        m._page3_read_log_btn.connect('clicked', self._handlers.read_log_file)

        _row2.pack_start(m._page3_read_target_btn, True, False, 0)
        _row2.pack_start(m._page3_clear_btn, True, False, 0)
        _row2.pack_start(m._page3_read_log_btn, True, False, 0)

        box.pack_start(_row1, True, True, 5)
        box.pack_end(_row2, False, True, 0)
        return box
Exemple #11
0
    def _build_page2(self):
        '''
    用subprocess不可实现与sqlap的交互!
    不管是多线程, 同步还是异步, 都不行, 只能使用pty
    '''
        box = Box(orientation=VERTICAL, spacing=6)
        box.set_border_width(10)

        _row1 = Box(spacing=6)
        # m._page2_cmdline_str_label.set_alignment(0, 0.5)    # 怎么没有垂直居中?
        m._page2_respwan_btn.connect('clicked',
                                     self._handlers.respawn_terminal)

        # _row1.pack_start(m._page2_cmdline_str_label, True, True, 0)
        _row1.pack_start(m._page2_respwan_btn, False, True, 0)

        _row2 = Frame()
        # 等价于_pty = m._page2_terminal.pty_new_sync(Vte.PtyFlags.DEFAULT)
        _pty = Vte.Pty.new_sync(Vte.PtyFlags.DEFAULT)
        m._page2_terminal.set_pty(_pty)

        # https://stackoverflow.com/questions/55105447/virtual-python-shell-with-vte-pty-spawn-async
        # https://gtk-d.dpldocs.info/vte.Pty.Pty.spawnAsync.html
        # API手册上的该方法签名有问题, 与实际的对不上
        # 最后一个参数为回调函数, 是必填项
        _pty.spawn_async(str(Path.home()), [self._handlers.shell], None,
                         GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None, -1,
                         None, lambda pty, task: None)

        _scrolled = g.ScrolledWindow()
        _scrolled.set_policy(g.PolicyType.NEVER, g.PolicyType.ALWAYS)
        _scrolled.add(m._page2_terminal)
        _row2.add(_scrolled)

        box.pack_start(_row1, False, True, 5)
        box.pack_end(_row2, True, True, 0)
        return box
Exemple #12
0
    def _build_page1(self):
        box = Box(orientation=VERTICAL, spacing=6)
        box.set_border_width(10)

        # sqlmap命令语句
        _cmd_area = Frame.new('A.收集选项 的结果显示在这:')

        _cmd_area.add(m._cmd_entry)

        box.pack_start(_cmd_area, False, True, 0)

        # 主构造区
        _notebook = Notebook(m, self._handlers)

        m._page1_misc_purge_ckbtn.connect('toggled', self._show_warn,
                                          '这将抹除所有本地记录!\n确定勾选?')
        m._page1_general_flush_session_ckbtn.connect('toggled',
                                                     self._show_warn,
                                                     '这将清除本地缓存!\n确定勾选?')

        _notebook.add_events(d.EventMask.SCROLL_MASK
                             | d.EventMask.SMOOTH_SCROLL_MASK)
        _notebook.connect('scroll-event', self.scroll_page)

        box.pack_start(_notebook, True, True, 0)

        # 构造与执行
        _exec_area = Box()

        _build_button = btn.new_with_mnemonic('A.收集选项(_A)')
        _build_button.connect('clicked', self._handlers.build_all)
        # 用于改善ui的使用体验
        _unselect_all_btn = btn.new_with_mnemonic('反选所有复选框(_S)')
        _unselect_all_btn.connect('clicked', self.unselect_all_ckbtn)
        _clear_all_entry = btn.new_with_mnemonic('清空所有输入框(_D)')
        _clear_all_entry.connect('clicked', self.clear_all_entry)

        _run_button = btn.new_with_mnemonic('B.开始(_F)')
        _run_button.connect('clicked', self._handlers.run_cmdline)

        _exec_area.pack_start(_build_button, False, True, 0)
        _exec_area.pack_start(_unselect_all_btn, True, False, 0)
        _exec_area.pack_start(_clear_all_entry, True, False, 0)
        _exec_area.pack_end(_run_button, False, True, 0)

        box.pack_end(_exec_area, False, True, 0)
        return box
Exemple #13
0
    def _build_target_notebook(self, target_nb):
        target_nb.add_events(d.EventMask.SCROLL_MASK
                             | d.EventMask.SMOOTH_SCROLL_MASK)
        target_nb.connect('scroll-event', self.scroll_page)
        # 目标url
        name_store = g.ListStore(int, str)
        name_store.append([1, "http://www.site.com/vuln.php?id=1"])

        _url_area = Box()
        m._url_combobox.set_model(name_store)
        m._url_combobox.set_entry_text_column(1)

        _url_area.pack_start(m._url_combobox, True, True, 0)

        _burp_area = Box()
        m._burp_logfile_chooser.connect('clicked',
                                        self._handlers.set_file_entry_text,
                                        [m._burp_logfile])

        _burp_area.pack_start(m._burp_logfile, True, True, 0)
        _burp_area.pack_start(m._burp_logfile_chooser, False, True, 0)

        _request_area = Box()

        m._request_file_chooser.connect('clicked',
                                        self._handlers.set_file_entry_text,
                                        [m._request_file])

        _request_area.pack_start(m._request_file, True, True, 0)
        _request_area.pack_start(m._request_file_chooser, False, True, 0)

        _bulkfile_area = Box()
        m._bulkfile_chooser.connect('clicked',
                                    self._handlers.set_file_entry_text,
                                    [m._bulkfile])

        _bulkfile_area.pack_start(m._bulkfile, True, True, 0)
        _bulkfile_area.pack_start(m._bulkfile_chooser, False, True, 0)

        _configfile_area = Box()
        m._configfile_chooser.connect('clicked',
                                      self._handlers.set_file_entry_text,
                                      [m._configfile])

        _configfile_area.pack_start(m._configfile, True, True, 0)
        _configfile_area.pack_start(m._configfile_chooser, False, True, 0)

        _sitemap_url_area = Box()
        _sitemap_url_area.pack_start(m._sitemap_url, True, True, 0)

        _google_dork_area = Box()
        _google_dork_area.pack_start(m._google_dork, True, True, 0)

        target_nb.append_page(_url_area, label.new('目标url'))
        target_nb.append_page(_burp_area, label.new('burp日志'))
        target_nb.append_page(_request_area, label.new('HTTP请求'))
        target_nb.append_page(_bulkfile_area, label.new('BULKFILE'))
        target_nb.append_page(_configfile_area, label.new('ini文件'))
        target_nb.append_page(_sitemap_url_area, label.new('xml_url'))
        target_nb.append_page(_google_dork_area, label.new('GOOGLEDORK'))