Ejemplo n.º 1
0
Archivo: gui.py Proyecto: wflk/pbtk
    def prompt_extractor(self, item):
        extractor = extractors[item.data(Qt.UserRole)]
        inputs = []
        if not assert_installed(self.view, **extractor.get('depends', {})):
            return

        if not extractor.get('pick_url', False):
            files, mime = QFileDialog.getOpenFileNames()
            for path in files:
                inputs.append((path, Path(path).stem))
        else:
            text, good = QInputDialog.getText(self.view, ' ', 'Input an URL:')
            if text:
                url = urlparse(text)
                inputs.append((url.geturl(), url.netloc))

        if inputs:
            wait = QProgressDialog('Extracting .proto structures...', None, 0,
                                   0)
            wait.setWindowTitle(' ')
            self.set_view(wait)

            self.worker = Worker(inputs, extractor)
            self.worker.progress.connect(self.extraction_progress)
            self.worker.finished.connect(self.extraction_done)
            self.worker.signal_proxy.connect(self.signal_proxy)
            self.worker.start()
Ejemplo n.º 2
0
Archivo: gui.py Proyecto: wflk/pbtk
    def new_endpoint(self, path):
        if not self.proto_fs.isDir(path):
            path = self.proto_fs.filePath(path)

            if assert_installed(self.choose_proto, binaries=['protoc']):
                if not getattr(self, 'only_resp_combo', False):
                    self.create_endpoint.pbRequestCombo.clear()
                self.create_endpoint.pbRespCombo.clear()

                has_msgs = False
                for name, cls in load_proto_msgs(path):
                    has_msgs = True
                    if not getattr(self, 'only_resp_combo', False):
                        self.create_endpoint.pbRequestCombo.addItem(
                            name, (path, name))
                    self.create_endpoint.pbRespCombo.addItem(
                        name, (path, name))
                if not has_msgs:
                    QMessageBox.warning(
                        self.view, ' ',
                        'There is no message defined in this .proto.')
                    return

                self.create_endpoint.reqDataSubform.hide()

                if not getattr(self, 'only_resp_combo', False):
                    self.create_endpoint.endpointUrl.clear()
                    self.create_endpoint.transports.clear()
                    self.create_endpoint.sampleData.clear()
                    self.create_endpoint.pbParamKey.clear()
                    self.create_endpoint.parsePbCheckbox.setChecked(False)

                    for name, meta in transports.items():
                        item = QListWidgetItem(meta['desc'],
                                               self.create_endpoint.transports)
                        item.setData(Qt.UserRole,
                                     (name, meta.get('ui_data_form')))

                elif getattr(self, 'saved_transport_choice'):
                    self.create_endpoint.transports.setCurrentItem(
                        self.saved_transport_choice)
                    self.pick_transport(self.saved_transport_choice)
                    self.saved_transport_choice = None

                self.only_resp_combo = False
                self.set_view(self.create_endpoint)
Ejemplo n.º 3
0
Archivo: gui.py Proyecto: wflk/pbtk
    def launch_fuzzer(self, item):
        if type(item) == int:
            data, sample_id = self.fuzzer.comboBox.itemData(item)
        else:
            data, sample_id = item.data(Qt.UserRole), 0

        if data and assert_installed(self.view, binaries=['protoc']):
            self.current_req_proto = BASE_PATH / 'protos' / data['request'][
                'proto_path']

            self.pb_request = load_proto_msgs(self.current_req_proto)
            self.pb_request = dict(
                self.pb_request)[data['request']['proto_msg']]()

            if data.get('response') and data['response']['format'] == 'raw_pb':
                self.pb_resp = load_proto_msgs(BASE_PATH / 'protos' /
                                               data['response']['proto_path'])
                self.pb_resp = dict(
                    self.pb_resp)[data['response']['proto_msg']]

            self.pb_param = data['request'].get('pb_param')
            self.base_url = data['request']['url']
            self.endpoint = data

            self.transport_meta = transports[data['request']['transport']]
            self.transport = self.transport_meta['func'](self.pb_param,
                                                         self.base_url)

            sample = ''
            if data['request'].get('samples'):
                sample = data['request']['samples'][sample_id]
            self.get_params = self.transport.load_sample(
                sample, self.pb_request)

            # Get initial data into the Protobuf tree view
            self.fuzzer.pbTree.clear()
            self.parse_desc(self.pb_request.DESCRIPTOR, self.fuzzer.pbTree)
            self.parse_fields(self.pb_request)

            # Do the same for transport-specific data
            self.fuzzer.getTree.clear()
            if self.transport_meta.get('ui_tab'):
                self.fuzzer.tabs.setTabText(1, self.transport_meta['ui_tab'])
                if self.get_params:
                    for key, val in self.get_params.items():
                        ProtocolDataItem(self.fuzzer.getTree, key, val, self)
            else:
                self.fuzzer.tabs.setTabText(1, '(disabled)')
                # how to hide it ?

            # Fill the request samples combo box if we're loading a new
            # endpoint.
            if type(item) != int:
                if len(data['request'].get('samples', [])) > 1:
                    self.fuzzer.comboBox.clear()
                    for sample_id, sample in enumerate(
                            data['request']['samples']):
                        self.fuzzer.comboBox.addItem(
                            sample[self.pb_param] if self.pb_param else
                            str(sample), (data, sample_id))
                    self.fuzzer.comboBoxLabel.show()
                    self.fuzzer.comboBox.show()
                else:
                    self.fuzzer.comboBoxLabel.hide()
                    self.fuzzer.comboBox.hide()

                self.set_view(self.fuzzer)

            self.fuzzer.frame.setUrl(QUrl("about:blank"))
            self.update_fuzzer()