Skip to content

Commit

Permalink
Rebuild code and add default filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonymousUser committed Nov 26, 2020
1 parent 7b5027a commit 2ce57f8
Show file tree
Hide file tree
Showing 12 changed files with 464 additions and 272 deletions.
371 changes: 99 additions & 272 deletions burp/BurpExtender.java

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions burp/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package burp;

public class Config {
public static String initConfigContent = "{\"Email\":{\"loaded\":true,\"scope\":\"response\",\"regex\":\"([\\\\w-]+(?:\\\\.[\\\\w-]+)*@(?:[\\\\w](?:[\\\\w-]*[\\\\w])?\\\\.)+[\\\\w](?:[\\\\w-]*[\\\\w])?)\",\"action\":\"any\",\"color\":\"yellow\"}}";
public static String[] colorArray = new String[] {"red", "orange", "yellow", "green", "cyan", "blue", "pink", "magenta", "gray"};
public static String[] scopeArray = new String[] {"any", "response", "request"};
public static String[] actionArray = new String[] {"any", "extract", "highight"};
public static String excludeSuffix = "7z|aif|aifc|aiff|au|bmp|cmx|cod|css|doc|docx|gif|gz|ico|ief|jfif|jpe|jpeg|jpg|m3u|mid|mp2|mp3|mpa|mpe|mpeg|mpg|mpp|mpv2|otf|pbm|pdf|pgm|png|pnm|ppm|ra|ram|rar|ras|rgb|rmi|snd|svg|tar|tif|tiff|ttf|wav|woff|woff2|xbm|xpm|xwd|zip";
public static String[] excludeMIME = new String[] {"application/msword", "application/vnd.ms-project", "application/x-gzip", "application/x-tar", "application/zip", "audio/basic", "audio/mid", "audio/mpeg", "audio/x-aiff", "audio/x-mpegurl", "audio/x-pn-realaudio", "audio/x-wav", "image/bmp", "image/cis-cod", "image/gif", "image/ief", "image/jpeg", "image/png", "image/pipeg", "image/svg+xml", "image/tiff", "image/x-cmu-raster", "image/x-cmx", "image/x-icon", "image/x-portable-anymap", "image/x-portable-bitmap", "image/x-portable-graymap", "image/x-portable-pixmap", "image/x-rgb", "image/x-xbitmap", "image/x-xpixmap", "image/x-xwindowdump", "text/css", "video/mpeg", "video/mpeg", "application/font-woff"};
public static String outputTplString = "[%s]\n%s\n\n";
}
34 changes: 34 additions & 0 deletions burp/action/DoAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package burp.action;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.json.JSONObject;

import burp.Config;

public class DoAction {
public String extractString(JSONObject jsonObj) {
String result = "";
Iterator<String> k = jsonObj.keys();
while (k.hasNext()) {
String name = k.next();
JSONObject jsonObj1 = new JSONObject(jsonObj.get(name).toString());
String tmpStr = String.format(Config.outputTplString, name, jsonObj1.getString("data")).intern();
result += tmpStr;
}
return result;
}

public List<String> highlightList(JSONObject jsonObj) {
List<String> colorList = new ArrayList<String>();
Iterator<String> k = jsonObj.keys();
while (k.hasNext()) {
String name = k.next();
JSONObject jsonObj2 = new JSONObject(jsonObj.get(name).toString());
colorList.add(jsonObj2.getString("color"));
}
return colorList;
}
}
67 changes: 67 additions & 0 deletions burp/action/ExtractContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package burp.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import org.json.JSONObject;

import burp.file.ReadFile;
import jregex.Matcher;
import jregex.Pattern;

public class ExtractContent {
ReadFile rf = new ReadFile();
public JSONObject matchRegex(byte[] content, String scopeString, String actionString, String configFilePath) {
JSONObject tabContent = new JSONObject();
// 正则匹配提取内容
try {
String jsonStr = rf.readFileContent(configFilePath);
JSONObject jsonObj = new JSONObject(jsonStr);
Iterator<String> k = jsonObj.keys();
// 遍历json数组
while (k.hasNext()) {
String contentString = new String(content, "UTF-8").intern();
String name = k.next();
JSONObject jsonObj1 = new JSONObject(jsonObj.get(name).toString());
JSONObject jsonData = new JSONObject();
String regex = jsonObj1.getString("regex");
boolean isLoaded = jsonObj1.getBoolean("loaded");
String scope = jsonObj1.getString("scope");
String action = jsonObj1.getString("action");
String color = jsonObj1.getString("color");
List<String> result = new ArrayList<String>();

if(isLoaded && (scope.equals(scopeString) || scope.equals("any")) && (action.equals(actionString) || action.equals("any"))) {
Pattern pattern = new Pattern(regex);
Matcher matcher = pattern.matcher(contentString);
while (matcher.find()) {
// 添加匹配数据至list
// 强制用户使用()包裹正则
result.add(matcher.group(1));
}

// 去除重复内容
HashSet tmpList = new HashSet(result);
result.clear();
result.addAll(tmpList);

if (!result.isEmpty()) {
jsonData.put("color", color);
jsonData.put("data", String.join("\n", result));
jsonData.put("loaded", isLoaded);
// 初始化格式
tabContent.put(name, jsonData);
}
}

}


} catch (Exception e) {}

return tabContent;
}
}
36 changes: 36 additions & 0 deletions burp/action/MatchHTTP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package burp.action;

import java.util.Arrays;
import java.util.List;

import burp.Config;
import jregex.Matcher;
import jregex.Pattern;
import jregex.REFlags;

public class MatchHTTP {
// 匹配后缀
public boolean matchSuffix(String str) {
Pattern pattern = new Pattern(String.format("[\\w]+[\\.](%s)", Config.excludeSuffix), REFlags.IGNORE_CASE);
Matcher matcher = pattern.matcher(str);
if(matcher.find()){
return true;
}else{
return false;
}
}

// 匹配MIME
public boolean matchMIME(List<String> mimeList) {
for (String headerString : mimeList) {
if (headerString.toLowerCase().startsWith("content-type")) {
for (String mime : Arrays.asList(Config.excludeMIME)) {
if (headerString.contains(mime)) {
return true;
}
}
}
}
return false;
}
}
23 changes: 23 additions & 0 deletions burp/color/GetColorKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package burp.color;

import java.util.ArrayList;
import java.util.List;

public class GetColorKey {
/*
* 颜色下标获取
*/
public List<Integer> getColorKeys(List<String> keys, String[] colorArray){
List<Integer> result = new ArrayList<Integer>();
int size = colorArray.length;
// 根据颜色获取下标
for (int x = 0; x < keys.size(); x++) {
for (int v = 0; v < size; v++) {
if (colorArray[v].equals(keys.get(x))) {
result.add(v);
}
}
}
return result;
}
}
53 changes: 53 additions & 0 deletions burp/color/UpgradeColor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package burp.color;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;

public class UpgradeColor {

private String endColor = "";
/*
* 颜色升级递归算法
*/
private String colorUpgrade(List<Integer> colorList, String[] colorArray) {
int colorSize = colorList.size();
colorList.sort(Comparator.comparingInt(Integer::intValue));
int i = 0;
List<Integer> stack = new ArrayList<Integer>();
while (i < colorSize) {
if (stack.isEmpty()) {
stack.add(colorList.get(i));
i++;
} else {
if (colorList.get(i) != stack.stream().reduce((first, second) -> second).orElse(99999999)) {
stack.add(colorList.get(i));
i++;
} else {
stack.set(stack.size() - 1, stack.get(stack.size() - 1) - 1);
i++;
}
}

}
// 利用HashSet删除重复元素
HashSet tmpList = new HashSet(stack);
if (stack.size() == tmpList.size()) {
stack.sort(Comparator.comparingInt(Integer::intValue));
if(stack.get(0).equals(-1)) {
this.endColor = colorArray[0];
} else {
this.endColor = colorArray[stack.get(0)];
}
} else {
this.colorUpgrade(stack, colorArray);
}
return "";
}

public String getEndColor(List<Integer> colorList, String[] colorArray) {
colorUpgrade(colorList, colorArray);
return endColor;
}
}
18 changes: 18 additions & 0 deletions burp/file/FileExists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package burp.file;

import java.io.File;

public class FileExists {

/*
* 判断文件是否存在
*/
public Boolean fileExists(String fileName) {
File file = new File(fileName);
if(file.exists()){
return true;
}
return false;
}

}
36 changes: 36 additions & 0 deletions burp/file/ReadFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package burp.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class ReadFile {
/*
* 获取文件内容
*/
public String readFileContent(String fileName) {
File file = new File(fileName);
BufferedReader reader = null;
StringBuffer sbf = new StringBuffer();
try {
reader = new BufferedReader(new FileReader(file));
String tempStr;
while ((tempStr = reader.readLine()) != null) {
sbf.append(tempStr);
}
reader.close();
return sbf.toString();
} catch (IOException e) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException err) {
err.printStackTrace();
}
}
}
return sbf.toString();
}
}
22 changes: 22 additions & 0 deletions burp/file/RemoveContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package burp.file;

import javax.swing.JOptionPane;

import org.json.JSONObject;

public class RemoveContent {
WriteFile w = new WriteFile();
ReadFile r = new ReadFile();
/*
* 删除某文件内容
*/
public void removeFileContent(String key, String configFilePath) {
String jsonStr = r.readFileContent(configFilePath);
JSONObject jsonObj = new JSONObject(jsonStr);
jsonObj.remove(key);

if (w.writeFileContent(configFilePath, jsonObj.toString())) {
JOptionPane.showMessageDialog(null, "Delete Successfully!", "Info", JOptionPane.INFORMATION_MESSAGE);
}
}
}
21 changes: 21 additions & 0 deletions burp/file/WriteFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package burp.file;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class WriteFile {
/*
* 写入文件内容
*/
public boolean writeFileContent(String fileName, String fileContent) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
out.write(fileContent);
out.close();
return true;
} catch (IOException e) {
return false;
}
}
}
44 changes: 44 additions & 0 deletions burp/ui/FillTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package burp.ui;

import java.util.Iterator;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import org.json.JSONObject;

import burp.file.ReadFile;

public class FillTable {
ReadFile rf = new ReadFile();
/*
* 初始化表格内容
*/
public void fillTable(String configFilePath, JTable table) {
DefaultTableModel dtm=(DefaultTableModel) table.getModel();
dtm.setRowCount(0);
String jsonStr = rf.readFileContent(configFilePath);
JSONObject jsonObj = new JSONObject(jsonStr);
Iterator<String> k = jsonObj.keys();
// 遍历json数组
while (k.hasNext()) {
String name = k.next();
JSONObject jsonObj1 = new JSONObject(jsonObj.get(name).toString());
boolean loaded = jsonObj1.getBoolean("loaded");
String regex = jsonObj1.getString("regex");
String color = jsonObj1.getString("color");
String scope = jsonObj1.getString("scope");
String action = jsonObj1.getString("action");
// 填充数据
Vector rules = new Vector();
rules.add(loaded);
rules.add(name);
rules.add(regex);
rules.add(color);
rules.add(scope);
rules.add(action);
dtm.addRow(rules);
}
}
}

0 comments on commit 2ce57f8

Please sign in to comment.