diff --git a/src/GUI/OptionsPanel.java b/src/GUI/OptionsPanel.java index df36611..5898a0b 100644 --- a/src/GUI/OptionsPanel.java +++ b/src/GUI/OptionsPanel.java @@ -1,15 +1,21 @@ package GUI; import java.awt.Color; +import java.awt.Desktop; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; +import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; +import burp.BurpExtender; + public class OptionsPanel extends JPanel { private static JTextField nucleiTemplatesPath; @@ -25,30 +31,69 @@ public static void setNucleiTemplatesPath(JTextField nucleiTemplatesPath) { OptionsPanel(){ - GridBagLayout gbl_fourFourthPanel = new GridBagLayout(); - gbl_fourFourthPanel.columnWidths = new int[]{215, 215, 0}; - gbl_fourFourthPanel.rowHeights = new int[]{27, 0, 0, 0, 27, 0, 0, 0, 0, 0, 27, 27, 27, 27, 0, 0, 0, 0}; - gbl_fourFourthPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; - gbl_fourFourthPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; - setLayout(gbl_fourFourthPanel); JLabel lblNewLabel = new JLabel("nuclei-templates directory:"); - GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); - gbc_lblNewLabel.fill = GridBagConstraints.BOTH; - gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5); - gbc_lblNewLabel.gridx = 0; - gbc_lblNewLabel.gridy = 0; - add(lblNewLabel, gbc_lblNewLabel); + nucleiTemplatesPath = new JTextField(); - GridBagConstraints gbc_BrowserPath = new GridBagConstraints(); - gbc_BrowserPath.fill = GridBagConstraints.BOTH; - gbc_BrowserPath.insets = new Insets(0, 0, 5, 0); - gbc_BrowserPath.gridx = 1; - gbc_BrowserPath.gridy = 0; - add(nucleiTemplatesPath, gbc_BrowserPath); nucleiTemplatesPath.setColumns(50); nucleiTemplatesPath.getDocument().addDocumentListener(new TextFieldListener()); + + + JButton buttonCreateFolder = new JButton("Create Folder"); + buttonCreateFolder.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + String folderPath = nucleiTemplatesPath.getText(); + File folder = new File(folderPath); + if (!folder.exists()) { + // 创建文件夹 + if (folder.mkdirs()) { + saveToConfigFromGUI(); + } + } + } + }); + + JButton btOpenFolder = new JButton("Open Folder"); + btOpenFolder.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + String folderPath = nucleiTemplatesPath.getText(); + Desktop.getDesktop().open(new File(folderPath)); + } catch (Exception Exception) { + Exception.printStackTrace(BurpExtender.getStderr()); + } + } + }); + + + GridBagLayout layout = new GridBagLayout(); + setLayout(layout); + + //查找提取类 + int rowIndex = 0; + int cloumnIndex = 0; + + add(lblNewLabel, new bagLayout(++rowIndex, ++cloumnIndex)); + add(nucleiTemplatesPath, new bagLayout(rowIndex, ++cloumnIndex)); + + add(buttonCreateFolder, new bagLayout(++rowIndex, ++cloumnIndex)); + add(btOpenFolder, new bagLayout(++rowIndex, ++cloumnIndex)); + } + + class bagLayout extends GridBagConstraints { + /** + * 采用普通的行列计数,从1开始 + * + * @param row + * @param column + */ + bagLayout(int row, int column) { + this.fill = GridBagConstraints.BOTH; + this.insets = new Insets(0, 0, 5, 5); + this.gridx = column - 1; + this.gridy = row - 1; + } } diff --git a/src/PoC/LineEntry.java b/src/PoC/LineEntry.java index 5af4f6c..d8e0164 100644 --- a/src/PoC/LineEntry.java +++ b/src/PoC/LineEntry.java @@ -16,7 +16,8 @@ public class LineEntry { //{"#", "filename", "VulnApp", "VulnVersion", "VulnURL","VulnParameter","VulnType","VulnDescription","Refrence","isPoCVerified", "22","33"}; private String pocFileFullPath = ""; //PoC文件完整路径,用于定位文件进行编辑。不显示。 - private String pocfile = ""; //PoC文件名称,用于显示 + private String pocFileName = ""; //PoC文件名称,用于显示 + private String pocName = ""; //PoC内容中info部分的name字段 private String VulnApp = ""; //存在漏的目标应用程序名称 private String VulnVersion = "";//存在漏洞的版本 private String VulnURL = "";//存在漏洞的URL地址 @@ -57,12 +58,20 @@ public void setPocFileFullPath(String pocFileFullPath) { this.pocFileFullPath = pocFileFullPath; } - public String getPocfile() { - return pocfile; + public String getPocFileName() { + return pocFileName; } - public void setPocfile(String pocfile) { - this.pocfile = pocfile; + public void setPocFileName(String pocFileName) { + this.pocFileName = pocFileName; + } + + public String getPocName() { + return pocName; + } + + public void setPocName(String pocName) { + this.pocName = pocName; } public String getVulnApp() { diff --git a/src/PoC/LineEntryMenu.java b/src/PoC/LineEntryMenu.java index 0f3a800..7a92f15 100644 --- a/src/PoC/LineEntryMenu.java +++ b/src/PoC/LineEntryMenu.java @@ -134,24 +134,25 @@ public void actionPerformed(ActionEvent actionEvent) { } }); - - /** * nuclei -u 127.0.0.1 -t CVE-2020-3580.yaml */ - JMenuItem genSinglePoCCmd = new JMenuItem(new AbstractAction("Generate Command Of This PoC") { + JMenuItem genSinglePoCCmd = new JMenuItem(new AbstractAction("Generate Command Of Selected PoC") { @Override public void actionPerformed(ActionEvent actionEvent) { - LineEntry entry = lineTable.getLineTabelModel().getLineEntries().getValueAtIndex(rows[0]); - String path = entry.getPocFileFullPath(); - List targets = Commons.getLinesFromTextArea(PoCPanel.getTitleTable().getTextAreaTarget()); - - String Command; - if (entry.isWorkflow()) { - Command = RunNucleiAction.genWorkflowCommand(targets, path); - }else { - Command = RunNucleiAction.genCommand(targets, path); + List paths = new ArrayList(); + List workflowPaths = new ArrayList(); + for (int row:rows) { + LineEntry entry = lineTable.getLineTabelModel().getLineEntries().getValueAtIndex(row); + String path = entry.getPocFileFullPath(); + if (entry.isWorkflow()) { + workflowPaths.add(path); + }else { + paths.add(path); + } } + List targets = Commons.getLinesFromTextArea(PoCPanel.getTitleTable().getTextAreaTarget()); + String Command = RunNucleiAction.genSeletedPoCCommand(targets, paths,workflowPaths); Commons.writeToClipboard(Command.trim()); } @@ -160,19 +161,22 @@ public void actionPerformed(ActionEvent actionEvent) { /** * nuclei -u 127.0.0.1 -t CVE-2020-3580.yaml */ - JMenuItem runSinglePoC = new JMenuItem(new AbstractAction("Run This PoC") { + JMenuItem runSinglePoC = new JMenuItem(new AbstractAction("Run Selected PoC") { @Override public void actionPerformed(ActionEvent actionEvent) { - LineEntry entry = lineTable.getLineTabelModel().getLineEntries().getValueAtIndex(rows[0]); - String path = entry.getPocFileFullPath(); - List targets = Commons.getLinesFromTextArea(PoCPanel.getTitleTable().getTextAreaTarget()); - String Command; - if (entry.isWorkflow()) { - Command = RunNucleiAction.genWorkflowCommand(targets, path); - }else { - Command = RunNucleiAction.genCommand(targets, path); + List paths = new ArrayList(); + List workflowPaths = new ArrayList(); + for (int row:rows) { + LineEntry entry = lineTable.getLineTabelModel().getLineEntries().getValueAtIndex(row); + String path = entry.getPocFileFullPath(); + if (entry.isWorkflow()) { + workflowPaths.add(path); + }else { + paths.add(path); + } } - + List targets = Commons.getLinesFromTextArea(PoCPanel.getTitleTable().getTextAreaTarget()); + String Command = RunNucleiAction.genSeletedPoCCommand(targets, paths,workflowPaths); RunNucleiAction.run(Command); } }); diff --git a/src/PoC/LineTableModel.java b/src/PoC/LineTableModel.java index 5f06f41..dffd4a4 100644 --- a/src/PoC/LineTableModel.java +++ b/src/PoC/LineTableModel.java @@ -245,7 +245,7 @@ public void addNewLineEntry(LineEntry lineEntry){ } synchronized (lineEntries) { int oldsize = lineEntries.size(); - String key = lineEntry.getPocfile(); + String key = lineEntry.getPocFileName(); lineEntries.put(key,lineEntry); int newsize = lineEntries.size(); int index = lineEntries.IndexOfKey(key); diff --git a/src/PoC/PoCPanel.java b/src/PoC/PoCPanel.java index 1e44529..4d5dd27 100644 --- a/src/PoC/PoCPanel.java +++ b/src/PoC/PoCPanel.java @@ -10,6 +10,7 @@ import java.io.PrintWriter; import java.util.Base64; import java.util.Collection; +import java.util.Map; import javax.swing.JButton; import javax.swing.JLabel; @@ -17,6 +18,7 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; +import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; import org.apache.commons.io.FileUtils; @@ -26,7 +28,6 @@ import GUI.MainGUI; import PoC.search.SearchTextField; import PoCParser.NucleiParser; -import PoCParser.PoctParser; import burp.BurpExtender; import burp.Commons; import burp.GlobalConfig; @@ -49,7 +50,8 @@ public class PoCPanel extends JPanel { private static JTextField textFieldSearch; public static JRadioButton rdbtnUseRobotInput; public static JLabel lblStatus; - public static JButton buttonFresh; + public static JButton buttonUpdate; + public static JButton buttonReload; public static JTextField getTextFieldSearch() { return textFieldSearch; @@ -99,7 +101,8 @@ public PoCPanel(String poctRootPath) {//构造函数 * @param dir * @return */ - public IndexedLinkedHashMap scanPoCFiles(String dir) { + @Deprecated + public IndexedLinkedHashMap scanPoctFiles(String dir) { IndexedLinkedHashMap lineEntries = new IndexedLinkedHashMap(); if (null==dir || !new File(dir).exists()){ return lineEntries; @@ -108,14 +111,14 @@ public IndexedLinkedHashMap scanPoCFiles(String dir) { for (File file:files) { //System.out.println(file.toString()); if (file.exists() && file.isFile() && !file.getName().startsWith("__")) { - LineEntry entry = PoctParser.Parser(file.toString()); - lineEntries.put(file.toString(), entry); + //LineEntry entry = PoctParser.Parser(file.toString()); + //lineEntries.put(file.toString(), entry); } } return lineEntries; } + /** - * 默认路径 /Users/bit4woo * @param dir * @return */ @@ -191,7 +194,7 @@ public void actionPerformed(ActionEvent e) { try { if (null != destFile) { FileUtils.copyFile(srcFile, destFile); - PoCPanel.buttonFresh.doClick(); + PoCPanel.buttonReload.doClick(); Commons.editWithVSCode(destFile.getAbsolutePath()); } }catch (FileNotFoundException e1) { @@ -200,7 +203,7 @@ public void actionPerformed(ActionEvent e) { try { if (null != destFile) { FileUtils.writeByteArrayToFile(destFile,Base64.getDecoder().decode(content)); - PoCPanel.buttonFresh.doClick(); + PoCPanel.buttonReload.doClick(); Commons.editWithVSCode(destFile.getAbsolutePath()); } } catch (IOException e2) { @@ -251,19 +254,52 @@ public void actionPerformed(ActionEvent e) { } }); buttonPanel.add(buttonSearch); + + buttonUpdate = new JButton("Update PoCs"); + buttonPanel.add(buttonUpdate); + buttonUpdate.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SwingWorker worker = new SwingWorker() { + @Override + protected Map doInBackground() throws Exception { + setEnabled(false); + updateTemplate(); + return null; + } - buttonFresh = new JButton("Fresh"); - buttonPanel.add(buttonFresh); - buttonFresh.addActionListener(new ActionListener() { + @Override + protected void done() { + setEnabled(true); + } + }; + worker.execute(); + } + }); + + buttonReload = new JButton("Reload PoCs"); + buttonPanel.add(buttonReload); + buttonReload.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - updateTemplate(); - LoadData(MainGUI.getGlobalConfig().getPoctRootPath()); - lblStatus.setText(titleTableModel.getStatusSummary()); - buttonSearch.doClick(); + SwingWorker worker = new SwingWorker() { + @Override + protected Map doInBackground() throws Exception { + setEnabled(false); + LoadData(MainGUI.getGlobalConfig().getPoctRootPath()); + lblStatus.setText(titleTableModel.getStatusSummary()); + buttonSearch.doClick(); + return null; + } + + @Override + protected void done() { + setEnabled(true); + } + }; + worker.execute(); } }); - JButton buttonProxy = new JButton("Proxy"); + JButton buttonProxy = new JButton("Set Proxy"); buttonPanel.add(buttonProxy); buttonProxy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { diff --git a/src/PoCParser/NucleiParser.java b/src/PoCParser/NucleiParser.java index 794f882..bea4e21 100644 --- a/src/PoCParser/NucleiParser.java +++ b/src/PoCParser/NucleiParser.java @@ -34,7 +34,7 @@ public static LineEntry Parser(String pocfile) { if (poc.exists() && poc.isFile()) { try { result.setPocFileFullPath(pocfile); - result.setPocfile(poc.getName()); + result.setPocFileName(poc.getName()); String content = FileUtils.readFileToString(poc); @@ -44,7 +44,7 @@ public static LineEntry Parser(String pocfile) { result.setCVE(bean.getId()); YamlInfo info = bean.getInfo(); - result.setPocfile(info.getName()); + result.setPocName(info.getName()); result.setAuthor(info.getAuthor()); result.setSeverity(info.getSeverity()); result.setVulnDescription(info.getDescription()); @@ -159,7 +159,5 @@ public static YamlBeanFromJson yamlToBeanWithFastJson(String yamlFile) throws Ex public static void main (String[] args) throws Exception { yamlToBeanWithGson("C:\\Users\\P52\\nuclei-templates\\cves\\2014\\CVE-2014-2321.yaml"); yamlToBeanWithFastJson("C:\\Users\\P52\\nuclei-templates\\cves\\2014\\CVE-2014-2321.yaml"); -// YamlBeanFromJson bean = yamlToBean("/Users/liwenjun/nuclei-templates/cves/2007/CVE-2007-4556.yaml"); -// int a=1; } } diff --git a/src/PoCParser/PoctParser.java b/src/PoCParser/PoctParser.java deleted file mode 100644 index 9167892..0000000 --- a/src/PoCParser/PoctParser.java +++ /dev/null @@ -1,91 +0,0 @@ -package PoCParser; - -import java.io.File; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.io.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import PoC.LineEntry; - -/** - * 解析PoC-T中的脚本,返回一个LineEntry对象。 - * @author liwenjun - * - */ -public class PoctParser { - private static final Logger log=LogManager.getLogger(PoctParser.class); - - public static LineEntry Parser(String pocfile) { - LineEntry result = new LineEntry(); - File poc = new File(pocfile); - if (poc.exists() && poc.isFile()) { - try { - result.setPocFileFullPath(pocfile); - result.setPocfile(poc.getName()); - - String content = FileUtils.readFileToString(poc); - - //final String DOMAIN_NAME_PATTERN = "__.*__s+=s+\\\"\\\"\\\".*\\\"\\\"\\\""; - //有问号的是非贪婪模式,不带问号就是贪婪模式,直到最后一个三引号。 - final String DOMAIN_NAME_PATTERN = "__.*?__.*?\\\"\\\"\\\"[\\s\\S]*?\\\"\\\"\\\""; - Pattern pDomainNameOnly = Pattern.compile(DOMAIN_NAME_PATTERN); - Matcher matcher = pDomainNameOnly.matcher(content); - while (matcher.find()) {//多次查找 - String found = matcher.group(); - //System.out.println(found); - if (!(found.startsWith("__") && found.contains("="))) { - continue; - } - if (found.startsWith("__author__")) { - result.setAuthor(fetchValue(found)); - } - if (found.startsWith("__CVE__")) { - result.setCVE(fetchValue(found)); - } - if (found.startsWith("__VulnApp__")) { - result.setVulnApp(fetchValue(found)); - } - if (found.startsWith("__VulnVersion__")) { - result.setVulnVersion(fetchValue(found)); - } - if (found.startsWith("__VulnURL__")) { - result.setVulnURL(fetchValue(found)); - } - if (found.startsWith("__VulnParameter__")) { - result.setVulnParameter(fetchValue(found)); - } - if (found.startsWith("__VulnType__")) { - result.setVulnType(fetchValue(found)); - } - if (found.startsWith("__VulnDescription__")) { - result.setVulnDescription(fetchValue(found)); - } - if (found.startsWith("__Reference__")) { - result.setReference(fetchValue(found)); - } - if (found.startsWith("__isPoCVerified__")) { - result.setIsPoCVerified(fetchValue(found)); - } - } - return result; - }catch(Exception e) { - log.error(e); - } - } - return null; - } - - public static String fetchValue(String line) { - line = line.split("=",2)[1].trim(); - if (line.startsWith("\'\'\'") || line.startsWith("\"\"\"")) { - line = line.substring(3, line.length()-3); - }else if (line.startsWith("\'") || line.startsWith("\"")) { - line = line.substring(1, line.length()-1); - } - return line; - } - -} diff --git a/src/PoCParser/YamlBeanFromJson.java b/src/PoCParser/YamlBeanFromJson.java index aa2db31..07a5982 100644 --- a/src/PoCParser/YamlBeanFromJson.java +++ b/src/PoCParser/YamlBeanFromJson.java @@ -1,7 +1,5 @@ package PoCParser; -import java.util.List; - /** * 对应nuclei的yaml poc文件的java bean * diff --git a/src/PoCParser/YamlBeanFromMap.java b/src/PoCParser/YamlBeanFromMap.java index 6f4349e..ac62347 100644 --- a/src/PoCParser/YamlBeanFromMap.java +++ b/src/PoCParser/YamlBeanFromMap.java @@ -1,6 +1,5 @@ package PoCParser; -import java.util.List; import java.util.Map; /** diff --git a/src/burp/Commons.java b/src/burp/Commons.java index 06acf02..0555e6a 100644 --- a/src/burp/Commons.java +++ b/src/burp/Commons.java @@ -306,6 +306,6 @@ public static void editWithVSCode(String filepath) { } public static void main(String args[]) { - editWithVSCode("/Users/liwenjun/Documents/github/POC-T/script/F5-BIG-IP-bufferOverflow.py"); + } } diff --git a/src/run/RunNucleiAction.java b/src/run/RunNucleiAction.java index e8fd218..2cbc2e5 100644 --- a/src/run/RunNucleiAction.java +++ b/src/run/RunNucleiAction.java @@ -27,6 +27,24 @@ public static String genPara(String paraKey, String paraValue) { String result = paraKey + " " + paraValue; return result.trim(); } + + + public static String genPara(String paraKey, List paraValues) { + if (paraKey == null ||paraKey.isBlank() ||paraValues == null || paraValues.isEmpty()) { + return ""; + } + paraKey = paraKey.trim(); + + String result = paraKey + " "; + for (String paraValue:paraValues) { + paraValue = paraValue.trim(); + if (paraValue.contains(" ")) { + paraValue = "\"" + paraValue + "\""; + } + result +=","+paraValue; + } + return result.trim(); + } public static String prepareTargets(List targets) { if (targets.size() <= 0) { @@ -73,35 +91,17 @@ public static String genCommandRunAll(List targets) { } } - - public static String genCommand(List targets, String poc) { + public static String genSeletedPoCCommand(List targets, List poc, List workflowPoc) { try { String para = ""; - poc = genPara("-t",poc); - String target = prepareTargets(targets); - String proxy = prepareProxy(); - para = poc+" "+target; - if (targets.toString().toLowerCase().contains("http://") - || targets.toString().toLowerCase().contains("https://")) { - para = para+" "+proxy; - } - - String command = TerminalExec.genCmd(null, "nuclei", para); - return command; - } catch (Exception e1) { - e1.printStackTrace(); - return null; - } - } - - public static String genWorkflowCommand(List targets, String poc) { - try { - String para = ""; - poc = genPara("-w",poc); + String pocPara = genPara("-t",poc); + String workflowPocPara = genPara("-w",workflowPoc); + String target = prepareTargets(targets); String proxy = prepareProxy(); - para = poc+" "+target; + + para = pocPara+" "+workflowPocPara+" "+target; if (targets.toString().toLowerCase().contains("http://") || targets.toString().toLowerCase().contains("https://")) {