class FileView: """ SplitPane containing an editoresque (Sublime-alike) filetree+editor widget """ def __init__(self, dir=None, filetree_label=None, texteditor_factory=None): if not dir: dir = os.getcwd() self._filetree = FileTree(dir=dir, label=filetree_label) self._payloadview = PayloadView(texteditor_factory=texteditor_factory) self.this = JSplitPane(JSplitPane.HORIZONTAL_SPLIT, self._filetree.this, self._payloadview.this) self.this.setOneTouchExpandable(True) self._filetree.add_tree_selection_listener(self._tree_listener) self.this.getRightComponent().setVisible(False) def _tree_listener(self, e): """ Listen for tree selection and fill the payloadview :param e: unused :return: None """ try: fpath = os.path.join(*[str(p) for p in e.getPath().getPath()][1:]) if fpath.endswith('.html'): self.this.getRightComponent().setVisible(False) return with open(fpath, 'r') as f: payload = f.read() self._payloadview.set_editable(True) self._payloadview.refresh(payload) self.this.getRightComponent().setVisible(True) self.this.setDividerLocation(0.25) except IOError: pass def addTreeListener(self, action): """ Add a new Tree ActionListener :param action: actionListener lambda :return: """ self._filetree.add_tree_selection_listener(action) def addPayloadListener(self, action): """ Add a new PayloadView Listener :param action: actionListener lambda :return: """ self._payloadview.add_listener(action) def refresh(self): self._filetree.refresh()
def __init__(self, kconfig_file="Kconfig", config_file=".config", systemLogger=None): """[summary] Parameters ---------- kconfig_file : string (default: "Kconfig") The Kconfig configuration file config_file : string (default: ".config") The save file which will be used for loading and saving the settings systemLogger (default: None) A system logger object. If None then print statements are used for logging. """ global log if systemLogger: log = systemLogger # Load Kconfig configuration files self.kconfig = Kconfig(kconfig_file) setKConfig(self.kconfig) if os.path.isfile(config_file): log.info(self.kconfig.load_config(config_file)) elif os.path.isfile(".config"): log.info(self.kconfig.load_config(".config")) self.tree = KConfigTree(self.kconfig) self.tree.addTreeSelectionListener(self.treeSelectionChanged) jTreeSP = JScrollPane(self.tree) self.jta = JTextArea() self.jta.setEditable(False) jTextSP = JScrollPane(self.jta) toolPanel = JPanel() toolPanel.setLayout(BoxLayout(toolPanel, BoxLayout.X_AXIS)) toolPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0)) toolPanel.add(JLabel("Search: ")) jSearchPanel = JPanel() jSearchPanel.setLayout(BoxLayout(jSearchPanel, BoxLayout.X_AXIS)) self.jSearchField = JTextField() jSearchPanel.setBackground(self.jSearchField.getBackground()) jSearchPanel.setBorder(self.jSearchField.getBorder()) self.jSearchField.setBorder(None) self.jSearchField.getDocument().addDocumentListener( SearchListener(self.tree)) jSearchPanel.add(self.jSearchField) clearSearchButton = JButton(u'\u00d7', actionPerformed=self.clearSearch) d = clearSearchButton.getPreferredSize() clearSearchButton.setPreferredSize(Dimension(d.height, d.height)) clearSearchButton.setBackground(self.jSearchField.getBackground()) clearSearchButton.setBorder(None) clearSearchButton.setOpaque(False) clearSearchButton.setContentAreaFilled(False) clearSearchButton.setFocusPainted(False) jSearchPanel.add(clearSearchButton) toolPanel.add(jSearchPanel) self.showAllCheckBox = JCheckBox("Show all", actionPerformed=self.OnShowAllCheck) toolPanel.add(self.showAllCheckBox) splitPane = JSplitPane(JSplitPane.VERTICAL_SPLIT, jTreeSP, jTextSP) splitPane.setOneTouchExpandable(True) splitPane.setDividerLocation(300) treePanel = JPanel(BorderLayout()) treePanel.add(toolPanel, BorderLayout.NORTH) treePanel.add(splitPane, BorderLayout.CENTER) loadSavePanel = JPanel() loadSavePanel.setLayout(BoxLayout(loadSavePanel, BoxLayout.X_AXIS)) loadSavePanel.add( JButton("Load", actionPerformed=self.loadConfigDialog)) loadSavePanel.add( JButton("Save as", actionPerformed=self.writeConfigDialog)) self.rootPanel = JPanel() self.rootPanel.setLayout(BorderLayout()) self.rootPanel.add(loadSavePanel, BorderLayout.PAGE_START) self.rootPanel.add(treePanel, BorderLayout.CENTER)
class BobGui(JFrame): def __init__(self): super(BobGui, self).__init__('BobPy') # IJ.log('okay?') # print('okay??') self.setLayout(BorderLayout()) self.main_panel = JPanel() # self.main_panel.setLayout(MigLayout('insets 1 10 1 1')) self.main_panel.setLayout(MigLayout()) dir_panel = JPanel() dir_panel.setLayout(BoxLayout(dir_panel, BoxLayout.X_AXIS)) dir_label = JLabel('Experiment Folder:') dir_panel.add(dir_label) self.dir_text_field = JTextField(10) self.dir_text_field.addActionListener( ActionListenerFactory(self, self.text_field_al)) dir_panel.add(self.dir_text_field) dir_button = JButton('open') dir_button.addActionListener( ActionListenerFactory(self, self.choose_dir_al)) dir_panel.add(dir_button) self.main_panel.add(dir_panel, 'wrap, growx, spanx, pushx') add_key_args(self.main_panel, 'close_w', ActionListenerFactory(self, self.close_al), KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) self.add(self.main_panel, BorderLayout.CENTER) self.setPreferredSize(Dimension(650, 600)) self.pack() self.setLocationRelativeTo(None) self.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) self.setVisible(True) def show_exper_info(self): chf_panel = self.make_chf_panel() hseg_tree_panel = self.make_hseg_tree_panel() self.split_pane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) self.split_pane.setOneTouchExpandable(True) self.split_pane.setContinuousLayout(True) self.split_pane.setResizeWeight(0.5) self.split_pane.add(chf_panel) self.split_pane.add(hseg_tree_panel) self.main_panel.add(self.split_pane, 'grow, wrap') # self.log_text = JTextArea() self.main_panel.add(self.log_text, 'grow, wrap') self.log_text.setLineWrap(True) self.log_text.setWrapStyleWord(True) self.revalidate() def make_chf_panel(self): """ chf --> common hseg files """ chf_panel = JPanel() chf_panel.setLayout(MigLayout('insets 0')) chf_files_label = JLabel('Hemisegment cells') chf_files_text = JTextArea( BobGui.archetype_to_str( self.exper.hseg_cell_files_cab().archetype)) chf_panel.add(chf_files_label, 'growx, wrap') chf_panel.add(chf_files_text, 'grow, wrap') chf_files_label = JLabel('Hemisegment binary image files') chf_files_text = JTextArea( BobGui.archetype_to_str(self.exper.hseg_bin_files_cab().archetype)) chf_panel.add(chf_files_label, 'growx, wrap') chf_panel.add(chf_files_text, 'grow, wrap') chf_files_label = JLabel('Intensity Image Files') # chf_files_text = JTextArea(BobGui.archetype_to_str(self.exper.hseg_intens_im_files_cab().archetype)) # print(self.exper.hseg_intens_im_files_cab().archetype) # chf_panel.add(chf_files_label, 'growx, wrap') # chf_panel.add(chf_files_text, 'grow, wrap') self.intens_im_boxes = [] intens_im_panel = JPanel() intens_im_panel.setLayout(MigLayout('insets 0')) for poss_im_file in self.exper.hseg_intens_im_files_cab().archetype: self.intens_im_boxes.append(JCheckBox(poss_im_file)) intens_im_panel.add(self.intens_im_boxes[-1], 'wrap') chf_panel.add(chf_files_label, 'growx, wrap') chf_panel.add(intens_im_panel, 'grow, wrap') mdf_create_button = JButton( 'Create meta_data file from default outline') # mdf_create_button = JButton('<html>Create meta_data file<br>from default outline</html>') mdf_create_button.addActionListener( ActionListenerFactory(self, self.mdf_create_al)) mdf_open_button = JButton('Open existing meta_data file') mdf_open_button.addActionListener( ActionListenerFactory(self, self.mdf_open_al)) # meta_data_file_buttton = JButton('Open/Create meta_data file') # meta_data_file_buttton.addActionListener(ActionListenerFactory(self, self.meta_data_al)) # chf_panel.add(meta_data_file_buttton) chf_panel.add(mdf_create_button, 'wrap') chf_panel.add(mdf_open_button, 'wrap') chf_scroll_pane = JScrollPane() chf_scroll_pane.getViewport().setView(chf_panel) return chf_scroll_pane @staticmethod def archetype_to_str(archetype): at_str = '' for val in archetype: at_str += str(val) + '\n' return at_str def make_hseg_tree_panel(self): root = DefaultMutableTreeNode(self.exper.name) for hseg in self.exper.hsegs(): hseg_node = DefaultMutableTreeNode(hseg.name) root.add(hseg_node) hseg_at_deviations = self.exper.hseg_files_cab( ).archetype_deviations if len(hseg_at_deviations[hseg.name]) > 0: for definer, file_names in hseg_at_deviations[ hseg.name].items(): for file_name in file_names: node_str = definer + ': ' + file_name temp = DefaultMutableTreeNode(node_str) hseg_node.add(temp) hseg_tree = JTree(root) hseg_tree.setCellRenderer(BobPyTreeCellRenderer()) hseg_scroll_pane = JScrollPane() hseg_scroll_pane.getViewport().setView((hseg_tree)) hseg_panel = JPanel(MigLayout('insets 0')) hseg_panel.add(hseg_scroll_pane, 'grow, span, push, wrap') run_button = JButton('Run') run_button.addActionListener(ActionListenerFactory(self, self.run_al)) rerun_button = JButton('Rerun') rerun_button.addActionListener( ActionListenerFactory(self, self.rerun_al)) hseg_panel.add(run_button) hseg_panel.add(rerun_button) return hseg_panel def log(self, text): self.log_text.append(str(text) + '\n') def text_field_al(self, e): # self.dir_path = self.got_exper(self.dir_text_field.getText()) def choose_dir_al(self, e): dc = DirectoryChooser('Choose a bob_py experiment folder') # self.dir_path = dc.getDirectory() # self.dir_text_field.setText(self.dir_path) # self.dir_text_field.setText('blerg') # IJ.log('blerg') # print('boop') self.got_exper(dc.getDirectory()) def close_al(self, e): self.dispatchEvent(WindowEvent(self, WindowEvent.WINDOW_CLOSING)) def run_al(self, e): # dt = br.dtic('Processed experiment {}'.format(self.exper.name)) t = br.tic() self.exper.make_data() self.exper.output_cell_cols_def() self.exper.output_nuc_cols_def() self.exper.output_new_hdings() self.exper.log('Processed experiment {} in {:.3f} seconds'.format( self.exper.name, br.toc(t))) # br.dtoc(dt) def rerun_al(self, e): # dt = br.dtic('Processed experiment {}'.format(self.exper.name)) # t = br.tic() self.exper = None self.got_exper(self.dir_path) self.run_al(None) # self.exper = # self.exper.make_data() # self.exper.output_cell_cols_def() # self.exper.output_nuc_cols_def() # self.exper.output_new_hdings() # # self.exper.log('Created and processed experiment {} in {:.3f} seconds'.format(self.exper.name, br.toc(t))) # br.dtoc(dt) # def meta_data_al(self, e) : # meta_data_path = self.exper.meta_data_path() # if not os.path.exists(meta_data_path) : # txt = make_meta_data_str(self.exper) # with open(meta_data_path, 'w') as f : # f.write(txt) # # IJ.open(meta_data_path) def mdf_create_al(self, e): meta_data_path = self.exper.meta_data_path() # if not os.path.exists(meta_data_path) : intens_im_list = [] for check_box in self.intens_im_boxes: if check_box.isSelected(): intens_im_list.append(check_box.getLabel()) txt = make_meta_data_str2(self.exper, intens_im_list) with open(meta_data_path, 'w') as f: f.write(txt) # IJ.open(meta_data_path) def mdf_open_al(self, e): meta_data_path = self.exper.meta_data_path() IJ.open(meta_data_path) def got_exper(self, dir_path): # IJ.log('exper') self.dir_path = dir_path self.dir_text_field.setText(self.dir_path) self.log_text = JTextArea() self.exper = bob_py.Exper(dir_path, gui=self) self.show_exper_info()
class BurpExtender(IBurpExtender, IContextMenuFactory, ITab, IHttpListener, IMessageEditorController, AbstractTableModel): def registerExtenderCallbacks(self, callbacks): self.messages = [] self._callbacks = callbacks self._helpers = callbacks.getHelpers() self._callbacks.setExtensionName('TPLogScan') self._log = ArrayList() self._lock = Lock() self.jSplitPaneV = JSplitPane(JSplitPane.VERTICAL_SPLIT, True) self.jSplitPaneV.setDividerLocation(300) self.jSplitPaneV.setOneTouchExpandable(True) self.jPanel_top = JPanel() self.jTabbedPane = JTabbedPane(JTabbedPane.TOP) self.iRequestTextEditor = self._callbacks.createMessageEditor(self, False) self.iResponseTextEditor = self._callbacks.createMessageEditor(self, False) self.jTable = CustomTable(self) self.jTable.setShowGrid(True) self.jTable.setAutoCreateRowSorter(True) self.jTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS) first_column_model = self.jTable.getColumnModel().getColumn(0) first_column_model.setPreferredWidth(60); first_column_model.setMaxWidth(60) first_column_model.setMinWidth(60) self.jTable.getColumnModel().getColumn(1).setPreferredWidth(300) third_column_model = self.jTable.getColumnModel().getColumn(2) third_column_model.setPreferredWidth(100) third_column_model.setMinWidth(100) self.jTable.getColumnModel().getColumn(3).setPreferredWidth(600) self.jTable.getColumnModel().getColumn(4).setPreferredWidth(100) self.jTable.getColumnModel().getColumn(5).setPreferredWidth(100) self.jScrollPane1 = JScrollPane(self.jTable) self.jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED) self.jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED) self.jTabbedPane.addTab("Log", self.jScrollPane1) self.jPanel_top.add(self.jTabbedPane) self.jPanel_top.setLayout(GridLayout(1,1)) self.jSplitPaneInfo = JSplitPane(JSplitPane.HORIZONTAL_SPLIT, True) self.jSplitPaneInfo.setDividerLocation(650) self.jSplitPaneInfo.setOneTouchExpandable(True) self.jPanel_reqInfo_left = JPanel() self.jPanel_respInfo_right = JPanel() self.jPanel_reqInfo_left.setLayout(BorderLayout()) self.jPanel_respInfo_right.setLayout(BorderLayout()) self.jPanel_reqInfo_left.add(self.iRequestTextEditor.getComponent(), BorderLayout.CENTER) self.jPanel_respInfo_right.add(self.iResponseTextEditor.getComponent(), BorderLayout.CENTER) self.jSplitPaneInfo.add(self.jPanel_reqInfo_left, JSplitPane.LEFT) self.jSplitPaneInfo.add(self.jPanel_respInfo_right, JSplitPane.RIGHT) self.jSplitPaneV.add(self.jPanel_top, JSplitPane.TOP) self.jSplitPaneV.add(self.jSplitPaneInfo, JSplitPane.BOTTOM) self._callbacks.customizeUiComponent(self.jSplitPaneV) self._callbacks.customizeUiComponent(self.jPanel_top) self._callbacks.customizeUiComponent(self.jTabbedPane) self._callbacks.customizeUiComponent(self.jTable) self._callbacks.customizeUiComponent(self.jScrollPane1) self._callbacks.customizeUiComponent(self.jSplitPaneInfo) self._callbacks.customizeUiComponent(self.jPanel_reqInfo_left) self._callbacks.customizeUiComponent(self.jPanel_respInfo_right) self._callbacks.addSuiteTab(self) self._callbacks.registerHttpListener(self) self._callbacks.registerContextMenuFactory(self) return def getTabCaption(self): return 'TPLogScan' def getUiComponent(self): return self.jSplitPaneV def getRowCount(self): try: return self._log.size() except: return 0 def getColumnCount(self): return 6 def getColumnName(self, columnIndex): if columnIndex == 0: return "#" if columnIndex == 1: return "Host" if columnIndex == 2: return "Method" if columnIndex == 3: return "URL" if columnIndex == 4: return "Status" if columnIndex == 5: return "Length" return "" def getValueAt(self, rowIndex, columnIndex): logEntry = self._log.get(rowIndex) url = logEntry._url.toString() url_parse = urlparse.urlparse(url) if url_parse.netloc.find(':') != -1: netloc = url_parse.netloc[:url_parse.netloc.find(':')] host = url_parse.scheme + '://' + netloc path = url_parse.path if columnIndex == 0: return rowIndex+1 if columnIndex == 1: return host if columnIndex == 2: return logEntry._method if columnIndex == 3: return path if columnIndex == 4: return logEntry._status_code if columnIndex == 5: return logEntry._length return "" def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo): # tool_name = self._callbacks.getToolName(toolFlag) # if tool_name != 'Extender': if toolFlag != 1024: return if messageIsRequest: return request_info = self._helpers.analyzeRequest(messageInfo) response_info = self._helpers.analyzeResponse(messageInfo.getResponse()) response_headers = response_info.getHeaders() response_length = 0 for header in response_headers: header = header.encode('utf-8') if header.startswith("Content-Length"): response_length = int(header.replace('Content-Length: ', '')) length = response_length if response_length > 0 else 0 self._lock.acquire() row = self._log.size() self._log.add(LogEntry(toolFlag, self._callbacks.saveBuffersToTempFiles(messageInfo), request_info.getUrl(),request_info.getMethod(),response_info.getStatusCode(),length)) self.fireTableRowsInserted(row, row) self._lock.release() def getHttpService(self): return self._currentlyDisplayedItem.getHttpService() def getRequest(self): return self._currentlyDisplayedItem.getRequest() def getResponse(self): return self._currentlyDisplayedItem.getResponse() def loadMenus(self): self.menus = [] self.mainMenu = JMenu("TPLogScan") self.menus.append(self.mainMenu) menu = JMenuItem('ThinkPHP v3', None, actionPerformed=lambda x: self.eventHandler(x)) self.mainMenu.add(menu) menu = JMenuItem('ThinkPHP v5', None, actionPerformed=lambda x: self.eventHandler(x)) self.mainMenu.add(menu) def createMenuItems(self, invocation): self.loadMenus() self.messages = invocation.getSelectedMessages() return self.menus if self.menus else None def eventHandler(self, x): menuName = x.getSource().text if menuName == 'ThinkPHP v3': version = 3 elif menuName == 'ThinkPHP v5': version = 5 else: print("chose error") return for message in self.messages: url = str(self._helpers.analyzeRequest(message).getUrl()) url_parse = urlparse.urlparse(url) url = url_parse.scheme + '://' + url_parse.netloc print("[*] url: {}".format(url)) datetime_now = datetime.datetime.now() year = (datetime_now - datetime.timedelta(days=30)).year month = (datetime_now - datetime.timedelta(days=30)).month day = (datetime_now - datetime.timedelta(days=30)).day tplogscan = TPLogScan(url, version, year, month, day) log_path = tplogscan.checkLogPath() if not log_path: print("[-] {} can't get log file! ".format(url)) self._callbacks.issueAlert("{} can't get log file".format(url)) return filename_list = tplogscan.genFileName() t = threading.Thread(target=self.logScan, args=(message, version, log_path, filename_list)) t.start() def logScan(self, message, version, log_path, filename_list): http_service = message.getHttpService() old_request = self._helpers.bytesToString(message.getRequest()) old_path = self._helpers.analyzeRequest(message).getUrl().getPath() for filename in filename_list: try: new_request = old_request.replace(" " + old_path + " HTTP/", " " + log_path+filename + " HTTP/") response, status_code = self.sendRequest(http_service, new_request) if status_code != 200: continue tmp_filename = filename now_filename = '' pattern = re.compile(r"\[ (\d{4}-\d{2}-\d{2})T((\d{2}:){2}\d{2})\+08:00 \]") flag = True while flag: match_result = pattern.search(response) if not match_result: break time_str = match_result.group(1) + ' ' + match_result.group(2) timeArray = time.strptime(time_str, "%Y-%m-%d %H:%M:%S") timestamp = int(time.mktime(timeArray)) timestamp_list = [str(timestamp), str(timestamp-1), str(timestamp-2), str(timestamp-3)] for timestamp in timestamp_list: if version == 3: tmp_filename = timestamp + '-' + filename else: tmp_filename = filename[:filename.find('/')] + '/' + timestamp + '-' + filename[filename.find('/')+1:] if tmp_filename == now_filename: flag = False break new_request = old_request.replace(" " + old_path + " HTTP/", " " + log_path+tmp_filename + " HTTP/") response, status_code = self.sendRequest(http_service, new_request) if status_code == 200: now_filename = tmp_filename break except Exception as e: print("[-] error: {}".format(e)) print('[*] Log Scan complete!') def sendRequest(self, http_service, new_request): checkRequestResponse = self._callbacks.makeHttpRequest(http_service, self._helpers.stringToBytes(new_request)) status_code = self._helpers.analyzeResponse(checkRequestResponse.getResponse()).getStatusCode() print('[*] {} | {}'.format(self._helpers.analyzeRequest(checkRequestResponse).getUrl(), status_code)) return self._helpers.bytesToString(checkRequestResponse.getResponse()), status_code
class BobGui(JFrame): def __init__(self): super(BobGui, self).__init__('BobPy') # cls = self.getClass() # print(cls) # self.setLayout(MigLayout()) self.setLayout(BorderLayout()) self.main_panel = JPanel() self.main_panel.setLayout(MigLayout()) dir_panel = JPanel() dir_panel.setLayout(BoxLayout(dir_panel, BoxLayout.X_AXIS)) dir_label = JLabel('Experiment Folder:') dir_panel.add(dir_label) self.dir_text_field = JTextField(10) self.dir_text_field.addActionListener( ActionListenerFactory(self, self.text_field_al)) dir_panel.add(self.dir_text_field) dir_button = JButton('open') dir_button.addActionListener( ActionListenerFactory(self, self.choose_dir_al)) dir_panel.add(dir_button) self.main_panel.add(dir_panel, 'growx, spanx, pushx, wrap') add_key_args(self.main_panel, 'close_w', ActionListenerFactory(self, self.close_al), KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) self.add(self.main_panel, BorderLayout.CENTER) self.setPreferredSize(Dimension(500, 400)) self.pack() self.setLocationRelativeTo(None) self.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) self.setVisible(True) def show_exper_info_old(self): # sb = br.SimilarityBuilder() cab = br.CollectionArchetypeBuilder() for hseg in self.exper.hsegs(): all_file_dict = hseg.file_dict() all_file_dict.update(hseg.cell_file_dict()) all_file_dict.update(hseg.bin_file_dict()) cab.add_collection(hseg.name, all_file_dict) hseg_at, hseg_at_deviations = cab.get_archetype_info() at_str = '' for val in hseg_at: at_str += str(val) + '\n' chf_panel = self.make_chf_panel(at_str) hseg_tree_panel = self.make_hseg_tree_panel(hseg_at_deviations) self.split_pane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) self.split_pane.setOneTouchExpandable(True) self.split_pane.setContinuousLayout(True) self.split_pane.setResizeWeight(0.5) self.split_pane.add(chf_panel) self.split_pane.add(hseg_tree_panel) self.main_panel.add(self.split_pane, 'grow') self.revalidate() def show_exper_info(self): # sb = br.SimilarityBuilder() # cab = br.CollectionArchetypeBuilder() # # for hseg in self.exper.hsegs() : # all_file_dict = hseg.file_dict() # all_file_dict.update(hseg.cell_file_dict()) # all_file_dict.update(hseg.bin_file_dict()) # cab.add_collection(hseg.name, all_file_dict) # # hseg_at, hseg_at_deviations = cab.get_archetype_info() # # at_str = '' # for val in hseg_at : # at_str += str(val) + '\n' chf_panel = self.make_chf_panel() hseg_tree_panel = self.make_hseg_tree_panel() self.split_pane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT) self.split_pane.setOneTouchExpandable(True) self.split_pane.setContinuousLayout(True) self.split_pane.setResizeWeight(0.5) self.split_pane.add(chf_panel) self.split_pane.add(hseg_tree_panel) self.main_panel.add(self.split_pane, 'grow') self.revalidate() def make_chf_panel_old(self, at_str): """ cf --> common hseg files """ chf_panel = JPanel() # chf_panel.setLayout(BoxLayout(chf_panel, BoxLayout.Y_AXIS)) chf_panel.setLayout(MigLayout('insets 0')) # chf_panel.setAlignmentX(Component.LEFT_ALIGNMENT) chf_label = JLabel('Common Hemeisegment Files') # chf_label.setAlignmentX(Component.LEFT_ALIGNMENT) chf_panel.add(chf_label, 'grow, wrap') chf_text_area = JTextArea(at_str) chf_panel.add(chf_text_area, 'grow, push, span') return chf_panel def make_chf_panel(self): """ chf --> common hseg files """ chf_panel = JPanel() # chf_panel.setLayout(BoxLayout(chf_panel, BoxLayout.Y_AXIS)) chf_panel.setLayout(MigLayout('insets 0')) # chf_panel.setAlignmentX(Component.LEFT_ALIGNMENT) chf_files_label = JLabel('Hemisegment cells') chf_files_text = JTextArea( BobGui.archetype_to_str( self.exper.hseg_cell_files_cab().archetype)) chf_panel.add(chf_files_label, 'growx, wrap') chf_panel.add(chf_files_text, 'grow, wrap') chf_files_label = JLabel('Hemisegment binary image files') chf_files_text = JTextArea( BobGui.archetype_to_str(self.exper.hseg_bin_files_cab().archetype)) chf_panel.add(chf_files_label, 'growx, wrap') chf_panel.add(chf_files_text, 'grow, wrap') chf_files_label = JLabel('Other hemisegment files') chf_files_text = JTextArea( BobGui.archetype_to_str(self.exper.hseg_files_cab().archetype)) chf_panel.add(chf_files_label, 'growx, wrap') chf_panel.add(chf_files_text, 'grow') # chf_label = JLabel('Common Hemeisegment Files') # # chf_label.setAlignmentX(Component.LEFT_ALIGNMENT) # # chf_panel.add(chf_label, 'grow, wrap') # # chf_text_area = JTextArea(at_str) # chf_panel.add(chf_text_area, 'grow, push, span') return chf_panel @staticmethod def archetype_to_str(archetype): at_str = '' for val in archetype: at_str += str(val) + '\n' return at_str # def make_hseg_tree_panel(self, hseg_at_deviations) : def make_hseg_tree_panel(self): root = DefaultMutableTreeNode(self.exper.name) for hseg in self.exper.hsegs(): hseg_node = DefaultMutableTreeNode(hseg.name) root.add(hseg_node) hseg_at_deviations = self.exper.hseg_all_files_cab( ).archetype_deviations if len(hseg_at_deviations[hseg.name]) > 0: for definer, file_names in hseg_at_deviations[ hseg.name].items(): for file_name in file_names: node_str = definer + ': ' + file_name temp = DefaultMutableTreeNode(node_str) hseg_node.add(temp) hseg_tree = JTree(root) hseg_tree.setCellRenderer(BobPyTreeCellRenderer()) hseg_scroll_pane = JScrollPane() hseg_scroll_pane.getViewport().setView((hseg_tree)) return hseg_scroll_pane def text_field_al(self, e): self.dir_path = self.dir_text_field.getText() self.got_exper(self.dir_path) def choose_dir_al(self, e): dc = DirectoryChooser('Choose a bob_py experiment folder') self.dir_path = dc.getDirectory() self.dir_text_field.setText(self.dir_path) self.got_exper(self.dir_path) def close_al(self, e): self.dispatchEvent(WindowEvent(self, WindowEvent.WINDOW_CLOSING)) def got_exper(self, dir_path): self.exper = bob_py.Exper(dir_path) self.show_exper_info()
class BurpExtender(IBurpExtender, IContextMenuFactory, ActionListener, IMessageEditorController, ITab, ITextEditor, IHttpService, IScanIssue, IHttpRequestResponseWithMarkers): def __init__(self): self.menuItem = JMenuItem('Generate Finding') self.menuItem.addActionListener(self) # implement IBurpExtender def registerExtenderCallbacks(self, callbacks): # keep a reference to our callbacks object (Burp Extensibility Feature) self._callbacks = callbacks self._helpers = callbacks.getHelpers() # set our extension name callbacks.setExtensionName("Generate Finding") callbacks.registerContextMenuFactory(self) # -- Request Response Viewers -- # # create the lower half for the Request Response tabs... # Request and response from selection self._tabbedPane = JTabbedPane() tabs = self._tabbedPane self._requestViewer = callbacks.createMessageEditor(self, True) self._responseViewer = callbacks.createMessageEditor(self, True) self._requestHighlight = callbacks.createTextEditor() self._responseHighlight = callbacks.createTextEditor() tabs.addTab("Supporting Request", self._requestViewer.getComponent()) tabs.addTab("Supporting Response", self._responseViewer.getComponent()) tabs.addTab("Request Marker Selection", self._requestHighlight.getComponent()) tabs.addTab("Response Marker Selection", self._responseHighlight.getComponent()) #self._mainFrame.setRightComponent(tabs) # set to the lower split pane print "*" * 60 print "[+] Request/Response tabs created" # -- Define Issue Details GUI & Layout-- # # Labels and Input boxes... # Issue Name self.issueNameLabel = JLabel(" Issue Name:") self.issueNameValue = JTextArea(text = str(issueNamePlaceholder), editable = True, wrapStyleWord = True, lineWrap = True, alignmentX = Component.LEFT_ALIGNMENT, size = (1, 20) ) # Issue Detail self.issueDetailLabel = JLabel(" Issue Detail:") #self.issueDetailValue = JTextField(str(issueDetailPlaceholder), 15) self.issueDetailValue = JTextArea(text = str(issueDetailPlaceholder), editable = True, wrapStyleWord = True, lineWrap = True, alignmentX = Component.LEFT_ALIGNMENT, size = (100, 20) ) # IssueBackground self.issueBackgroundLabel = JLabel(" Issue Background:") self.issueBackgroundValue = JTextArea(text = str(issueBackgroundPlaceholder), editable = True, wrapStyleWord = True, lineWrap = True, alignmentX = Component.LEFT_ALIGNMENT, size = (100, 20) ) # Remediation Detail self.issueRemediationLabel = JLabel(" Remediation Detail:") self.issueRemediationValue = JTextArea(text = str(remediationDetailPlaceholder), editable = True, wrapStyleWord = True, lineWrap = True, alignmentX = Component.LEFT_ALIGNMENT, size = (100, 20) ) # Remediation Background self.issueRemBackgroundLabel = JLabel(" Remediation Background:") self.issueRemBackgroundValue = JTextArea(text = str(remediationBackgroundPlaceholder), editable = True, wrapStyleWord = True, lineWrap = True, alignmentX = Component.LEFT_ALIGNMENT, size = (100, 20) ) # Issue URL self.issueURLLabel = JLabel(" URL (path = http://domain/path):") self.issueURLValue = JTextArea(text = str(issueURLPlaceholder), editable = True, wrapStyleWord = True, lineWrap = True, alignmentX = Component.LEFT_ALIGNMENT, size = (1, 20) ) # Issue Port self.issuePortLabel = JLabel(" Port:") self.issuePortValue = JTextArea(text = str(issuePortPlaceholder), editable = True, wrapStyleWord = True, lineWrap = True, alignmentX = Component.LEFT_ALIGNMENT, size = (1, 20) ) # Confidence self.confidenceValuesList = ("Certain","Firm","Tentative") self.issueConfienceLabel = JLabel(" Confidence [Certain, Firm or Tentative]") self.issueConfidenceValue = JComboBox(self.confidenceValuesList) # Severity self.severityValuesList = ("High","Medium","Low","Information") self.issueSeverityLabel = JLabel(" Severity [High, Medium Low or Informational]") self.issueSeverityValue = JComboBox(self.severityValuesList) # Add Finding button self.addFindingButton = JButton("Generate Finding", actionPerformed=self.createScanIssue, alignmentX=Component.CENTER_ALIGNMENT) # -- Group items for display -- # # Group items self.grpIssueSummary = JPanel(GridLayout(0,1)) self.grpIssueSummary.add(self.issueNameLabel) self.grpIssueSummary.add(self.issueNameValue) self.grpIssueSummary.add(self.issueDetailLabel) self.grpIssueSummary.add(self.issueDetailValue) self.grpIssueSummary.add(self.issueBackgroundLabel) self.grpIssueSummary.add(self.issueBackgroundValue) self.grpIssueSummary.add(self.issueRemediationLabel) self.grpIssueSummary.add(self.issueRemediationValue) self.grpIssueSummary.add(self.issueRemBackgroundLabel) self.grpIssueSummary.add(self.issueRemBackgroundValue) self.grpIssueSummary.add(self.issueURLLabel) self.grpIssueSummary.add(self.issueURLValue) self.grpIssueSummary.add(self.issuePortLabel) self.grpIssueSummary.add(self.issuePortValue) self.grpIssueSummary.add(self.issueURLLabel) self.grpIssueSummary.add(self.issueURLValue) self.grpIssueSummary.add(self.issuePortLabel) self.grpIssueSummary.add(self.issuePortValue) self.grpRatingBoxes = JPanel() self.grpRatingBoxes.add(self.issueSeverityLabel) self.grpRatingBoxes.add(self.issueSeverityValue) self.grpRatingBoxes.add(self.issueConfienceLabel) self.grpRatingBoxes.add(self.issueConfidenceValue) self.grpRatingBoxes.add(self.addFindingButton) # add grps to details frame self._detailsPanel = JPanel(GridLayout(0,1)) self._detailsPanel.add(self.grpIssueSummary) self._detailsPanel.add(self.grpRatingBoxes) self._findingDetailsPane = JScrollPane(self._detailsPanel) # create the main frame to hold details self._detailsViewer = self._findingDetailsPane # creates a form for details #tabs.addTab("Finding Details", self._detailsViewer) self._mainFrame = JSplitPane(JSplitPane.VERTICAL_SPLIT, self._detailsViewer, tabs) self._mainFrame.setOneTouchExpandable(True); self._mainFrame.setDividerLocation(0.5) self._mainFrame.setResizeWeight(0.50) print "[+] Finding details panel created" print "[+] Rendering..." # customize our UI components callbacks.customizeUiComponent(self._mainFrame) callbacks.customizeUiComponent(self._tabbedPane) callbacks.customizeUiComponent(self._detailsPanel) callbacks.customizeUiComponent(tabs) # add the custom tab to Burp's UI callbacks.addSuiteTab(self) print "[+] Done" print "[!] Added suite tab initialize complete!" return def getTabCaption(self): return "Generate Finding" def getUiComponent(self): return self._mainFrame # initiaizes when button is clicked in 'Generate Finding Tab' def createScanIssue(self, event): print "[!] Finding Detail: " print "\t[+] Name:\n\t\t", self.issueNameValue.getText().strip() name = self.issueNameValue.getText() print "\t[+] Description:\n\t\t", self.issueDetailValue.getText().strip() description = self.issueDetailValue.getText() print "\t[+] Background:\n\t\t", self.issueBackgroundValue.getText().strip() background = self.issueBackgroundValue.getText() print "\t[+] Remediation:\n\t\t", self.issueRemediationValue.getText().strip() remediation = self.issueRemediationValue.getText() print "\t[+] Remediation Background:\n\t\t", self.issueRemBackgroundValue.getText().strip() remBackground = self.issueRemBackgroundValue.getText() print "\t[+] URL Detail:\n\t\t", self.issueURLValue.getText() urlDetail = self.issueURLValue.getText() print "\t[+] Port Number:\n\t\t", self.issuePortValue.getText() portNumber = self.issuePortValue.getText() print "\t[+] Confidence Rating:\n\t\t", self.issueConfidenceValue.getSelectedItem() confidenceRating = self.issueConfidenceValue.getSelectedItem() print "\t[+] Severity Rating:\n\t\t", self.issueSeverityValue.getSelectedItem() severityRating = self.issueSeverityValue.getSelectedItem() #print "\t[+] Payload Markers:\n\t\t", self.getSelectionBounds() # get highlighted data from request/response tabs in 'Generate Finding' #print "[!] Request Selected data:", self._requestViewer.getSelectedData() #highRequest = self._requestViewer.getSelectedData() #print "converted:", self._helpers.bytesToString(highRequest) #print "[!] Response Selected data:", self._responseViewer.getSelectedData() #highResponse = self._responseViewer.getSelectedData() #print "converted:", self._helpers.bytesToString(highResponse) # current message is used - should work as long as menu item 'Generate Finding' is not reset or used before finding has been generated. requestResponse = self.current_message print "\t[+] RequestResponse:\n\t\t", requestResponse print "\t[+] Service:\n\t\t", requestResponse.getHttpService() # Collect request and Response Markers... #print "[**] Request Bounds: ", self._requestHighlight.getSelectionBounds() requestBounds = self._requestHighlight.getSelectionBounds() #print "[**] Response Bounds: ", self._responseHighlight.getSelectionBounds() responseBounds = self._responseHighlight.getSelectionBounds() # applyMarkers to request/response # callbacks.applyMarkers(requestResponse, None, [array('i', (data[1], data[2]))]) self.reqMarkers = [requestBounds[0],requestBounds[1]] print "\t[+] Request Reporting Markers:\n\t\t", self.reqMarkers self.resMarkers = [responseBounds[0],responseBounds[1]] print "\t[+] Response Reporting Markers:\n\t\t", self.resMarkers print "*" * 60 print "[!] Attempting to create custom scan issue." # Call AddScanItem class to create scan issue!! finding_array = [urlDetail, name, 134217728, severityRating, confidenceRating, background, remBackground, description, remediation, requestResponse] issue = ScanIssue(self, finding_array, self.current_message, self.reqMarkers, self.resMarkers, self._helpers, self._callbacks) self._callbacks.addScanIssue(issue) # Done print "[+] Finding Generated!" def getRequestResponseText(self): messages = self.ctxMenuInvocation.getSelectedMessages() # parses currently selected finding to a string if len(messages) == 1 : for self.m in messages: requestResponse = self.m # add requestResponseWithMarkers to be global so can be included in scanIssue self.current_message = requestResponse # get request data and convert to string requestDetail = requestResponse.getRequest() try: requestData = self._helpers.bytesToString(requestDetail) # converts & Prints out the entire request as string except: requestData = '[-] No Request Detail in this RequestResponse' pass # get response data and convert to string responseDetail = requestResponse.getResponse() try: responseData = self._helpers.bytesToString(responseDetail) # converts & Prints out the entire request as string except: responseData = '[-] No Response Detail in this RequestResponse' pass requestData = self._helpers.bytesToString(requestDetail) # converts & Prints out the entire request as string # send request string to 'Supporting Request' tab - 'True' because it is a request! self._requestViewer.setMessage(requestData, True) # for higlighting markers.. self._requestHighlight.setText(requestData) # send response string to 'Supporting Response' tab self._responseViewer.setMessage(responseData, False) # set False as is a response not request... # for higlighting markers.. self._responseHighlight.setText(responseData) def getFindingDetails(self): messages = self.ctxMenuInvocation.getSelectedMessages() print "*" * 60 print "[+] Handling selected request: ", self.current_message if len(messages) == 1: for m in messages: # URL #print "[!] Selected Request's URL: \n", self._helpers.analyzeRequest(m).getUrl() self.issueURLValue.setText(str(self._helpers.analyzeRequest(m).getUrl())) # update finding info # Protocol #print "[!] Request's Protocol: \n", m.getProtocol() # Request Port #print "[!] Request's Port: \n", m.getPort() self.issuePortValue.setText(str(m.getPort())) # update finding info print "*" * 60 # API hook... def getHttpMessages(self): return [self.m] # Actions on menu click... def actionPerformed(self, actionEvent): print "*" * 60 print "[+] Request sent to 'Generate Finding'" try: # When clicked!! self.getRequestResponseText() self.getFindingDetails() except: tb = traceback.format_exc() print tb # create Menu def createMenuItems(self, ctxMenuInvocation): self.ctxMenuInvocation = ctxMenuInvocation return [self.menuItem]