Version: 2.4 Update

This commit is contained in:
AnonymousUser
2022-06-23 15:34:22 +08:00
parent 7ebba02200
commit f401214524
17 changed files with 323 additions and 107 deletions

View File

@@ -1,8 +1,8 @@
package burp.action;
import burp.BurpExtender;
import java.util.HashMap;
import java.util.Map;
import burp.Config;
import java.util.ArrayList;
import java.util.List;
@@ -12,11 +12,11 @@ import java.util.List;
public class DoAction {
public Map<String, String> extractString(Map<String, Map<String, Object>> obj) {
Map<String, String> resultMap = new HashMap<String, String>();
Map<String, String> resultMap = new HashMap<>();
obj.keySet().forEach(i->{
Map<String, Object> tmpMap = obj.get(i);
String data = tmpMap.get("data").toString();
resultMap.put(i, String.format("%s\n", data).intern());
resultMap.put(i, data);
});
return resultMap;
}

View File

@@ -2,7 +2,6 @@ package burp.action;
import java.nio.charset.StandardCharsets;
import java.util.*;
import burp.Config;
import dk.brics.automaton.Automaton;
import dk.brics.automaton.AutomatonMatcher;
@@ -17,7 +16,7 @@ import jregex.Pattern;
public class ExtractContent {
public Map<String, Map<String, Object>> matchRegex(byte[] content, String headers, byte[] body, String scopeString) {
public Map<String, Map<String, Object>> matchRegex(byte[] content, String headers, byte[] body, String scopeString, String host) {
Map<String, Map<String, Object>> map = new HashMap<>(); // 最终返回的结果
Config.ruleConfig.keySet().forEach(i -> {
String matchContent = "";
@@ -61,6 +60,7 @@ public class ExtractContent {
} else {
pattern = new Pattern(regex, Pattern.IGNORE_CASE);
}
Matcher matcher = pattern.matcher(matchContent);
while (matcher.find()) {
// 添加匹配数据至list
@@ -94,6 +94,38 @@ public class ExtractContent {
}
});
// host: {Name, List}
if (!host.isEmpty()) {
map.keySet().forEach(i -> {
Map<String, Object> tmpMap = map.get(i);
List<String> dataList = Arrays.asList(tmpMap.get("data").toString().split("\n"));
// 判断Host是否存在如存在则进行数据更新反之则新增数据
if (Config.globalDataMap.containsKey(host)) {
Map<String, List<String>> gRuleMap = Config.globalDataMap.get(host);
// 判断匹配规则是否存在逻辑同Host判断
if (gRuleMap.containsKey(i)) {
List<String> gDataList = gRuleMap.get(i);
List<String> mergeDataList = new ArrayList<>();
// 合并两个List
mergeDataList.addAll(gDataList);
mergeDataList.addAll(dataList);
// 去重操作
HashSet tmpList = new HashSet(mergeDataList);
mergeDataList.clear();
mergeDataList.addAll(tmpList);
// 替换操作
gRuleMap.replace(i, gDataList, mergeDataList);
} else {
gRuleMap.put(i, dataList);
}
} else {
Map<String, List<String>> ruleMap = new HashMap<>();
ruleMap.put(i, dataList);
Config.globalDataMap.put(host, ruleMap);
}
});
}
return map;
}
}

View File

@@ -1,8 +1,6 @@
package burp.action;
import burp.IExtensionHelpers;
import burp.IHttpService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -16,7 +14,7 @@ public class ProcessMessage {
GetColorKey gck = new GetColorKey();
UpgradeColor uc = new UpgradeColor();
public List<Map<String, String>> processMessageByContent(IExtensionHelpers helpers, byte[] content, boolean isRequest, boolean messageInfo) {
public List<Map<String, String>> processMessageByContent(IExtensionHelpers helpers, byte[] content, boolean isRequest, boolean messageInfo, String host) {
List<Map<String, String>> result = new ArrayList<>();;
Map<String, Map<String, Object>> obj;
@@ -44,7 +42,7 @@ public class ProcessMessage {
int requestBodyOffset = helpers.analyzeRequest(content).getBodyOffset();
byte[] requestBody = Arrays.copyOfRange(content, requestBodyOffset, content.length);
obj = ec.matchRegex(content, requestHeaders, requestBody, "request");
obj = ec.matchRegex(content, requestHeaders, requestBody, "request", host);
} else {
try {
// 流量清洗
@@ -65,26 +63,26 @@ public class ProcessMessage {
int responseBodyOffset = helpers.analyzeResponse(content).getBodyOffset();
byte[] responseBody = Arrays.copyOfRange(content, responseBodyOffset, content.length);
obj = ec.matchRegex(content, responseHeaders, responseBody, "response");
obj = ec.matchRegex(content, responseHeaders, responseBody, "response", host);
}
if (messageInfo) {
List<List<String>> resultList = da.highlightAndComment(obj);
List<String> colorList = resultList.get(0);
List<String> commentList = resultList.get(1);
if (colorList.size() != 0 && commentList.size() != 0) {
String color = uc.getEndColor(gck.getColorKeys(colorList));
Map<String, String> colorMap = new HashMap<String, String>(){{
put("color", color);
}};
Map<String, String> commentMap = new HashMap<String, String>(){{
put("comment", String.join(", ", commentList));
}};
result.add(colorMap);
result.add(commentMap);
}
} else {
if (obj.size() > 0) {
if (obj.size() > 0) {
if (messageInfo) {
List<List<String>> resultList = da.highlightAndComment(obj);
List<String> colorList = resultList.get(0);
List<String> commentList = resultList.get(1);
if (colorList.size() != 0 && commentList.size() != 0) {
String color = uc.getEndColor(gck.getColorKeys(colorList));
Map<String, String> colorMap = new HashMap<String, String>(){{
put("color", color);
}};
Map<String, String> commentMap = new HashMap<String, String>(){{
put("comment", String.join(", ", commentList));
}};
result.add(colorMap);
result.add(commentMap);
}
} else {
result.add(da.extractString(obj));
}
}