def toFileButtonAction(self, event): fileChooser = JFileChooser() fileChooser.dialogTitle = 'Save Payloads' fileChooser.fileSelectionMode = JFileChooser.FILES_ONLY if (fileChooser.showSaveDialog( self.mainPanel) == JFileChooser.APPROVE_OPTION): file = fileChooser.getSelectedFile() self.extender.generatePayloads() result = '\n'.join(self.extender.tamperedPayloads) with open(file.getAbsolutePath(), 'w') as writer: writer.writelines(result.encode('utf-8')) self.showMessage('{} url encoded payload written to file'.format( len(self.extender.tamperedPayloads)))
def loadPayloadButtonAction(self, event): fileChooser = JFileChooser() fileChooser.dialogTitle = 'Choose Payload List' fileChooser.fileSelectionMode = JFileChooser.FILES_ONLY if (fileChooser.showOpenDialog( self.mainPanel) == JFileChooser.APPROVE_OPTION): file = fileChooser.getSelectedFile() with open(file.getAbsolutePath(), 'r') as reader: for line in reader.readlines(): self.extender.PayloadList.append(line.strip('\n')) self.listPayloads.setListData(self.extender.PayloadList) self.showMessage('{} payloads loaded'.format( len(self.extender.PayloadList))) self.writePayloadsListFile()
def dirBrowseButtonButtonAction(self, event): fileChooser = JFileChooser() fileChooser.dialogTitle = 'Choose Directory' fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY if (fileChooser.showOpenDialog( self.mainPanel) == JFileChooser.APPROVE_OPTION): file = fileChooser.getSelectedFile() varName = 'SQLiQueryTampering_PayloadsDirectory' path = file.getAbsolutePath() self.extender.callbacks.saveExtensionSetting(varName, path) self.textPayloadsDir.text = path self.extender.PayloadList = self.readPayloadsFromDir(path) self.listPayloads.setListData(self.extender.PayloadList) self.showMessage('{} payloads loaded'.format( len(self.extender.PayloadList)))
def saveFileDialog(parent, startingDir=None, title=None, extension=None): # type: (java.awt.Component, str, str, str) -> (java.io.File, str) """Creates a fileChooser.showSaveDialog and returns the selected file. Args: * parent (java.awt.Component): Parent component. * startingDir (str): Starting directory. * title (str): Title of the dialog. * fileFilter (str): Extension (without the dot) of the file to look for. E.g., "json" Returns java.io.File and a string containing the last used directory.""" fileChooser = JFileChooser() if startingDir is not None: startingPath = File(startingDir) fileChooser.setCurrentDirectory(startingPath) if title is not None: fileChooser.dialogTitle = title # FileNameExtensionFilter # https://docs.oracle.com/javase/8/docs/api/javax/swing/filechooser/FileNameExtensionFilter.html if extension is not None: extensionFilterString = "%s Files (*.%s)" % (extension.upper(), extension) extensionFilterList = [extension] fil = FileNameExtensionFilter(extensionFilterString, extensionFilterList) fileChooser.fileFilter = fil fileChooser.addChoosableFileFilter(fil) fileChooser.fileSelectionMode = JFileChooser.FILES_ONLY returnVal = fileChooser.showSaveDialog(parent) if returnVal != JFileChooser.APPROVE_OPTION: # export cancelled or there was an error return None, "" # store the used directory lastDir = fileChooser.getCurrentDirectory().toString() # get file path selectedFile = fileChooser.getSelectedFile() return selectedFile, lastDir