Ejemplo n.º 1
0
class Gui(JFrame):
    '''
    classdocs
    '''


    def __init__(self, pP):
        '''
        Constructor
        '''
        self.pP = pP
        self.annotationType = self.pP.getAnnotationType()
        
        self.setTitle("Random Picture Picker")

        #annotation Panel
        annoPanel = JPanel()
        annoPanel.setBorder(BorderFactory.createTitledBorder("Annotations"))
        annoPLayout = GroupLayout(annoPanel)
        annoPanel.setLayout(annoPLayout)
        annoPLayout.setAutoCreateContainerGaps(True)
        annoPLayout.setAutoCreateGaps(True)        

        # dynamic creation of annotation panel
        # yesNoIgnore, int, number, list
        if len(self.pP.getAnnotationType()) == 1:
            self.annoField = JTextField("", 16)
            annoPLayout.setHorizontalGroup(annoPLayout.createParallelGroup().addComponent(self.annoField))
            annoPLayout.setVerticalGroup(annoPLayout.createSequentialGroup().addComponent(self.annoField))
        elif len(self.pP.getAnnotationType()) > 1:
            choices = pP.getAnnotationType()
            print "choices", choices
            choiceBtns = []
            self.annoField = ButtonGroup()
            for c in choices:
                Btn = JRadioButton(c, actionCommand=c)
                self.annoField.add(Btn)
                choiceBtns.append(Btn)
          
            h = annoPLayout.createParallelGroup()
            for b in choiceBtns:
                h.addComponent(b)
            annoPLayout.setHorizontalGroup(h)
            
            v = annoPLayout.createSequentialGroup()
            for b in choiceBtns:
                v.addComponent(b)
            annoPLayout.setVerticalGroup(v)


        # Control Panel
        ctrlPanel = JPanel()
        ctrlPLayout = GroupLayout(ctrlPanel, autoCreateContainerGaps=True, autoCreateGaps=True)
        ctrlPanel.setLayout(ctrlPLayout)
        
        nextImgButton = JButton("Next >", actionPerformed=self.nextPicture)
        prevImgButton = JButton("< Prev", actionPerformed=self.pP.prevPicture)
        quitButton = JButton("Quit", actionPerformed=self.exit)

        ctrlPLayout.setHorizontalGroup(ctrlPLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
                                       .addGroup(ctrlPLayout.createSequentialGroup()
                                                 .addComponent(prevImgButton)
                                                 .addComponent(nextImgButton))
                                       .addComponent(quitButton))
        ctrlPLayout.setVerticalGroup(ctrlPLayout.createSequentialGroup()
                                     .addGroup(ctrlPLayout.createParallelGroup()
                                               .addComponent(prevImgButton)
                                               .addComponent(nextImgButton))
                                     .addComponent(quitButton))
        ctrlPLayout.linkSize(SwingConstants.HORIZONTAL, quitButton)

        
        statusPanel = JPanel()   # contains status information: progress bar
        self.progressBar = JProgressBar()
        self.progressBar.setStringPainted(True)
        self.progressBar.setValue(0)
        statusPanel.add(self.progressBar)
        
        #MainLayout
        mainLayout = GroupLayout(self.getContentPane())
        self.getContentPane().setLayout(mainLayout)
        
        mainLayout.setHorizontalGroup(mainLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
                                    .addComponent(annoPanel)
                                    .addComponent(ctrlPanel)
                                    .addComponent(statusPanel)
                                    )
        mainLayout.setVerticalGroup(mainLayout.createSequentialGroup()
                                    .addComponent(annoPanel)
                                    .addComponent(ctrlPanel)
                                    .addComponent(statusPanel)
                                    )
        mainLayout.linkSize(SwingConstants.HORIZONTAL, annoPanel, ctrlPanel, statusPanel)
         
      
        self.pack()
        self.setVisible(True)
        
        self.pP.nextPicture()
        
    def nextPicture(self, event):
        percent = (float(len(self.pP.usedList))/len(self.pP.pictureList))*100
        self.progressBar.setValue(int(percent))

        self.setAnnotation()
        self.pP.nextPicture()

        #try:
        #    self.setAnnotation()
        #    self.pP.nextPicture()
        #except AttributeError:
        #    print "Please choose something!"
     
    def setAnnotationField(self, a):
        if len(self.pP.getAnnotationType()) > 1:
            [Rbutton.setSelected(True) for Rbutton in self.annoField.getElements() if Rbutton.getActionCommand()==a]
        if len(self.pP.getAnnotationType()) == 1:
            self.annoField.setText(a)
        
    #rename this method to something clearer!    
    def setAnnotation(self):
        if len(self.pP.getAnnotationType()) > 1:
            annotation = self.annoField.getSelection().getActionCommand()
        if len(self.pP.getAnnotationType()) == 1:
            annotation = self.annoField.getText()
            self.annoField.setText(None)
        self.pP.getCurrentPicture().annotate(annotation)
        
    def getAnnotation(self):
        return self.annotation
    
    def exit(self, event):
        self.pP.exit()
        self.dispose()
Ejemplo n.º 2
0
class BurpExtender(IBurpExtender, IHttpListener, IContextMenuFactory, ITab):
    def registerExtenderCallbacks(self, callbacks):
        self.lastTimestamp = None

        self.callbacks = callbacks
        self.helpers = callbacks.getHelpers()
        sys.stdout = callbacks.getStdout()

        l = self.callbacks.loadExtensionSetting
        self.es_host = l("elasticburp.host") or 'localhost'
        self.es_index = l("elasticburp.index") or 'burp'
        self.whitelist = l("elasticburp.whitelist") or ''
        tools = l("elasticburp.tools")
        self.tools = int(tools) if tools is not None else 511
        self.log_level = l("elasticburp.logLevel") or 'INFO'
        logger.setLevel(getattr(logging, self.log_level))

        self.callbacks.setExtensionName("ElasticBurp")
        self.callbacks.registerHttpListener(self)
        self.callbacks.registerContextMenuFactory(self)
        self.callbacks.addSuiteTab(self)

    def processHttpMessage(self, tool, isRequest, msg):
        if (tool & self.tools):
            logger.warning('Indexing single document')
            doc = self.create_document(msg)
            if doc is not None:
                doc.save()

    def create_document(self, msg):
        http_service = msg.getHttpService()

        host = http_service.getHost()
        if self.whitelist and self.whitelist not in host:
            logger.warning('Skipping {} because it\'s not in '
                           'the whitelist'.format(host))
            return

        doc = ElasticBurpDocument(
            self.es_index, self.es_host, http_service.getProtocol(),
            host, http_service.getPort())

        request = msg.getRequest()
        response = msg.getResponse()

        if request:
            req = self.helpers.analyzeRequest(msg)
            doc.request['method'] = req.getMethod()
            doc.request['url'] = req.getUrl().toString()

            logger.info('Indexing {} request from {}'.format(
                doc.request['method'], doc.request['url']))

            doc.add_request_headers(req.getHeaders())

            parameters = req.getParameters()
            for parameter in parameters:
                doc.add_request_parameter(
                    PARAMETER_TYPES[parameter.getType()],
                    parameter.getName(), parameter.getValue())

            ct = CONTENT_TYPES[req.getContentType()]
            doc.request['content_type'] = ct

            bodyOffset = req.getBodyOffset()
            doc.request['body'] = request[bodyOffset:].tostring().decode(
                "ascii", "replace")

        if response:
            iResponse = self.helpers.analyzeResponse(response)

            doc.response['status'] = iResponse.getStatusCode()
            doc.response['content_type'] = iResponse.getStatedMimeType()
            doc.response['inferred_content_type'] = \
                iResponse.getInferredMimeType()

            logger.info('Indexing {} response'.format(doc.response['status']))

            doc.add_response_headers(iResponse.getHeaders())

            cookies = iResponse.getCookies()
            for cookie in cookies:
                expCookie = cookie.getExpiration()
                expiration = datetime.fromtimestamp(expCookie.time / 1000) if \
                    expCookie else None
                doc.add_response_cookie(
                    cookie.getName(), cookie.getValue(), cookie.getDomain(),
                    cookie.getPath(), expiration)

            bodyOffset = iResponse.getBodyOffset()
            doc.response['body'] = response[bodyOffset:].tostring().decode(
                "ascii", "replace")

        return doc

    def getTabCaption(self):
        return "ElasticBurp"

    def getUiComponent(self):
        ui_panel = JPanel()
        ui_panel.setLayout(BoxLayout(ui_panel, BoxLayout.PAGE_AXIS))

        ui_host_line = JPanel()
        ui_host_line.setLayout(BoxLayout(ui_host_line, BoxLayout.LINE_AXIS))
        ui_host_line.setAlignmentX(JPanel.LEFT_ALIGNMENT)
        ui_host_line.add(JLabel("ElasticSearch Host: "))
        self.ui_es_host = JTextField(40)
        self.ui_es_host.setMaximumSize(self.ui_es_host.getPreferredSize())
        self.ui_es_host.setText(self.es_host)
        ui_host_line.add(self.ui_es_host)
        ui_panel.add(ui_host_line)

        ui_index_line = JPanel()
        ui_index_line.setLayout(BoxLayout(ui_index_line, BoxLayout.LINE_AXIS))
        ui_index_line.setAlignmentX(JPanel.LEFT_ALIGNMENT)
        ui_index_line.add(JLabel("ElasticSearch Index: "))
        self.ui_es_index = JTextField(40)
        self.ui_es_index.setText(self.es_index)
        self.ui_es_index.setMaximumSize(self.ui_es_index.getPreferredSize())
        ui_index_line.add(self.ui_es_index)
        ui_panel.add(ui_index_line)

        ui_whitelist_line = JPanel()
        ui_whitelist_line.setLayout(
            BoxLayout(ui_whitelist_line, BoxLayout.LINE_AXIS))
        ui_whitelist_line.setAlignmentX(JPanel.LEFT_ALIGNMENT)
        ui_whitelist_line.add(JLabel("Host whitelist: "))
        self.ui_whitelist = JTextField(40)
        self.ui_whitelist.setText(self.whitelist)
        self.ui_whitelist.setMaximumSize(self.ui_whitelist.getPreferredSize())
        ui_whitelist_line.add(self.ui_whitelist)
        ui_panel.add(ui_whitelist_line)

        ui_tools_panel = JPanel()
        ui_tools_panel.setLayout(
            BoxLayout(ui_tools_panel, BoxLayout.LINE_AXIS))
        ui_tools_panel.setAlignmentX(JPanel.LEFT_ALIGNMENT)
        self.ui_tool_suite = JCheckBox(
            "Suite", self.tools & ECallbacks.TOOL_SUITE != 0)
        ui_tools_panel.add(self.ui_tool_suite)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_target = JCheckBox(
            "Target", self.tools & ECallbacks.TOOL_TARGET != 0)
        ui_tools_panel.add(self.ui_tool_target)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_proxy = JCheckBox(
            "Proxy", self.tools & ECallbacks.TOOL_PROXY != 0)
        ui_tools_panel.add(self.ui_tool_proxy)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_spider = JCheckBox(
            "Spider", self.tools & ECallbacks.TOOL_SPIDER != 0)
        ui_tools_panel.add(self.ui_tool_spider)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_scanner = JCheckBox(
            "Scanner", self.tools & ECallbacks.TOOL_SCANNER != 0)
        ui_tools_panel.add(self.ui_tool_scanner)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_intruder = JCheckBox(
            "Intruder", self.tools & ECallbacks.TOOL_INTRUDER != 0)
        ui_tools_panel.add(self.ui_tool_intruder)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_repeater = JCheckBox(
            "Repeater", self.tools & ECallbacks.TOOL_REPEATER != 0)
        ui_tools_panel.add(self.ui_tool_repeater)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_sequencer = JCheckBox(
            "Sequencer", self.tools & ECallbacks.TOOL_SEQUENCER != 0)
        ui_tools_panel.add(self.ui_tool_sequencer)
        ui_tools_panel.add(Box.createRigidArea(Dimension(10, 0)))
        self.ui_tool_extender = JCheckBox(
            "Extender", self.tools & ECallbacks.TOOL_EXTENDER != 0)
        ui_tools_panel.add(self.ui_tool_extender)
        ui_panel.add(ui_tools_panel)
        ui_panel.add(Box.createRigidArea(Dimension(0, 10)))

        ui_log_line = JPanel()
        ui_log_line.setLayout(BoxLayout(ui_log_line, BoxLayout.LINE_AXIS))
        ui_log_line.setAlignmentX(JPanel.LEFT_ALIGNMENT)
        ui_debug = JRadioButton("DEBUG", self.log_level == 'DEBUG')
        ui_log_line.add(ui_debug)
        ui_log_line.add(Box.createRigidArea(Dimension(10, 0)))
        ui_info = JRadioButton("INFO", self.log_level == 'INFO')
        ui_log_line.add(ui_info)
        ui_log_line.add(Box.createRigidArea(Dimension(10, 0)))
        ui_warning = JRadioButton("WARNING", self.log_level == 'WARNING')
        ui_log_line.add(ui_warning)
        ui_log_line.add(Box.createRigidArea(Dimension(10, 0)))
        ui_error = JRadioButton("ERROR", self.log_level == 'ERROR')
        ui_log_line.add(ui_error)
        ui_log_line.add(Box.createRigidArea(Dimension(10, 0)))
        ui_critical = JRadioButton(
            "CRITICAL", self.log_level == 'CRITICAL')
        ui_log_line.add(ui_critical)
        ui_log_line.add(Box.createRigidArea(Dimension(10, 0)))
        ui_panel.add(ui_log_line)
        ui_panel.add(Box.createRigidArea(Dimension(0, 10)))
        self.ui_log_level = ButtonGroup()
        self.ui_log_level.add(ui_debug)
        self.ui_log_level.add(ui_info)
        self.ui_log_level.add(ui_warning)
        self.ui_log_level.add(ui_error)
        self.ui_log_level.add(ui_critical)

        ui_buttons_line = JPanel()
        ui_buttons_line.setLayout(
            BoxLayout(ui_buttons_line, BoxLayout.LINE_AXIS))
        ui_buttons_line.setAlignmentX(JPanel.LEFT_ALIGNMENT)
        ui_buttons_line.add(
            JButton("Save config", actionPerformed=self.save_config))
        ui_panel.add(ui_buttons_line)

        return ui_panel

    def save_config(self, event):
        logger.warning('Saving changes in config')
        self.es_host = self.ui_es_host.getText()
        self.es_index = self.ui_es_index.getText()
        self.whitelist = self.ui_whitelist.getText()

        self.tools = int(
            (self.ui_tool_suite.isSelected() and ECallbacks.TOOL_SUITE) |
            (self.ui_tool_target.isSelected() and ECallbacks.TOOL_TARGET) |
            (self.ui_tool_proxy.isSelected() and ECallbacks.TOOL_PROXY) |
            (self.ui_tool_spider.isSelected() and ECallbacks.TOOL_SPIDER) |
            (self.ui_tool_scanner.isSelected() and ECallbacks.TOOL_SCANNER) |
            (self.ui_tool_intruder.isSelected() and ECallbacks.TOOL_INTRUDER) |
            (self.ui_tool_repeater.isSelected() and ECallbacks.TOOL_REPEATER) |
            (self.ui_tool_sequencer.isSelected() and
                ECallbacks.TOOL_SEQUENCER) |
            (self.ui_tool_extender.isSelected() and ECallbacks.TOOL_EXTENDER))
        logger.debug('Changing tools in config to %d' % self.tools)

        for button in self.ui_log_level.getElements():
            if button.isSelected():
                logger.debug('Changing logLevel to %s' % button.getText())
                self.log_level = button.getText()

        s = self.callbacks.saveExtensionSetting
        s("elasticburp.host", self.es_host)
        s("elasticburp.index", self.es_index)
        s("elasticburp.tools", str(self.tools))
        s("elasticburp.logLevel", self.log_level)
        s("elasticburp.whitelist", self.whitelist)
        logger.setLevel(getattr(logging, self.log_level))