Skip to content

Commit dcd4e3a

Browse files
authored
Merge pull request #9 from Chave0v0/dev
修复已知bug
2 parents ab6a298 + b97f0e5 commit dcd4e3a

File tree

10 files changed

+260
-141
lines changed

10 files changed

+260
-141
lines changed

src/main/java/com/chave/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ public void initialize(MontoyaApi montoyaApi) {
2222
Logging log = API.logging();
2323

2424
API.extension().setName("API Highlighter");
25-
log.logToOutput("API Highlighter v1.0.0\n\n" +
25+
log.logToOutput("API Highlighter v2.1.0\n\n" +
2626
"Rebuild: Chave\n" +
2727
"GitHub: https://github.com/Chave0v0/API-Highlighter\n");
2828

2929
// 初始化ui
3030
UI = new MainUI();
3131
API.userInterface().registerSuiteTab("API Highlighter", UI.getMainTabbedPane());
3232
API.http().registerHttpHandler(new APIHighLighterHandler());
33+
// 添加敏感信息展示Tab
3334
API.userInterface().registerHttpRequestEditorProvider(new RequestEditor());
3435
API.userInterface().registerHttpResponseEditorProvider(new ResponseEditor());
3536

src/main/java/com/chave/config/APIConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public class APIConfig {
99

1010
public static final HashMap ITEM_FIELD = new HashMap();
1111

12+
public static final String SENSITIVE_INFO_RESULT = "存在敏感信息";
13+
1214
static {
1315
ITEM_FIELD.put(0, "method");
1416
ITEM_FIELD.put(1, "path");
1517
ITEM_FIELD.put(2, "result");
1618
ITEM_FIELD.put(3, "state");
1719
ITEM_FIELD.put(4, "note");
18-
ITEM_FIELD.put(5, "domain");
20+
ITEM_FIELD.put(5, "isFound");
1921
}
2022

2123
}

src/main/java/com/chave/editor/RequestEditor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
import burp.api.montoya.ui.editor.extension.HttpRequestEditorProvider;
99
import com.chave.Main;
1010
import com.chave.config.SensitiveInfoConfig;
11-
import com.chave.config.UserConfig;
12-
import com.chave.service.APIMatchService;
1311
import com.chave.service.SensitiveInfoMatchService;
12+
import com.chave.utils.Util;
1413

1514
import javax.swing.*;
1615
import javax.swing.table.DefaultTableCellRenderer;
1716
import javax.swing.table.DefaultTableModel;
1817
import javax.swing.table.JTableHeader;
1918
import javax.swing.table.TableCellRenderer;
2019
import java.awt.*;
21-
import java.lang.reflect.Method;
2220
import java.util.ArrayList;
2321
import java.util.HashMap;
2422
import java.util.Set;
@@ -32,7 +30,6 @@ public ExtensionProvidedHttpRequestEditor provideHttpRequestEditor(EditorCreatio
3230
private static class Editor implements ExtensionProvidedHttpRequestEditor {
3331
private HttpRequestResponse requestResponse;
3432
private final JTabbedPane jTabbedPane = new JTabbedPane();
35-
private APIMatchService apiMatchService = new APIMatchService();
3633
private SensitiveInfoMatchService sensitiveInfoMatchService = new SensitiveInfoMatchService();
3734

3835
public Editor() {
@@ -52,8 +49,9 @@ public void setRequestResponse(HttpRequestResponse requestResponse) {
5249
public boolean isEnabledFor(HttpRequestResponse requestResponse) {
5350
HttpRequest request = requestResponse.request();
5451
try {
55-
Method matchMethod = APIMatchService.class.getMethod(UserConfig.MATCH_MOD.name(), HttpRequest.class);
56-
if ((Boolean) matchMethod.invoke(apiMatchService, request) && SensitiveInfoConfig.IS_CHECK_SENSITIVE_INFO) {
52+
HashMap apiMatchResult = Util.getAPIMatchResult(request);
53+
boolean isMatched = (boolean) apiMatchResult.get("isMatched");
54+
if (isMatched && SensitiveInfoConfig.IS_CHECK_SENSITIVE_INFO) {
5755
HashMap result = sensitiveInfoMatchService.sensitiveInfoMatch(request);
5856
if (!result.isEmpty()) {
5957
genreateEditorUI(result);

src/main/java/com/chave/editor/ResponseEditor.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
import burp.api.montoya.ui.editor.extension.*;
88
import com.chave.Main;
99
import com.chave.config.SensitiveInfoConfig;
10-
import com.chave.config.UserConfig;
11-
import com.chave.service.APIMatchService;
1210
import com.chave.service.SensitiveInfoMatchService;
11+
import com.chave.utils.Util;
1312

1413
import javax.swing.*;
1514
import javax.swing.table.DefaultTableCellRenderer;
1615
import javax.swing.table.DefaultTableModel;
1716
import javax.swing.table.JTableHeader;
1817
import javax.swing.table.TableCellRenderer;
1918
import java.awt.*;
20-
import java.lang.reflect.Array;
21-
import java.lang.reflect.Method;
2219
import java.util.ArrayList;
2320
import java.util.HashMap;
2421
import java.util.Set;
@@ -33,7 +30,6 @@ public ExtensionProvidedHttpResponseEditor provideHttpResponseEditor(EditorCreat
3330
private static class Editor implements ExtensionProvidedHttpResponseEditor {
3431
private HttpRequestResponse requestResponse;
3532
private final JTabbedPane jTabbedPane = new JTabbedPane();
36-
private APIMatchService apiMatchService = new APIMatchService();
3733
private SensitiveInfoMatchService sensitiveInfoMatchService = new SensitiveInfoMatchService();
3834

3935
public Editor() {
@@ -54,8 +50,9 @@ public boolean isEnabledFor(HttpRequestResponse requestResponse) {
5450
HttpResponse response = requestResponse.response();
5551
HttpRequest request = requestResponse.request();
5652
try {
57-
Method matchMethod = APIMatchService.class.getMethod(UserConfig.MATCH_MOD.name(), HttpRequest.class);
58-
if ((Boolean) matchMethod.invoke(apiMatchService, request) && SensitiveInfoConfig.IS_CHECK_SENSITIVE_INFO) {
53+
HashMap apiMatchResult = Util.getAPIMatchResult(request);
54+
boolean isMatched = (boolean) apiMatchResult.get("isMatched");
55+
if (isMatched && SensitiveInfoConfig.IS_CHECK_SENSITIVE_INFO) {
5956
HashMap result = sensitiveInfoMatchService.sensitiveInfoMatch(response);
6057
if (!result.isEmpty()) {
6158
genreateEditorUI(result);

src/main/java/com/chave/handler/APIHighLighterHandler.java

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,96 @@
44
import burp.api.montoya.http.message.requests.HttpRequest;
55
import burp.api.montoya.logging.Logging;
66
import com.chave.Main;
7+
import com.chave.config.APIConfig;
78
import com.chave.config.Color;
8-
import com.chave.config.UserConfig;
9-
import com.chave.service.APIMatchService;
9+
import com.chave.config.SensitiveInfoConfig;
10+
import com.chave.pojo.APIItem;
1011
import com.chave.service.SensitiveInfoMatchService;
1112
import com.chave.utils.Util;
12-
import java.lang.reflect.Method;
13-
import java.util.ArrayList;
1413
import java.util.HashMap;
1514

1615
public class APIHighLighterHandler implements HttpHandler {
1716
private Logging log;
18-
private APIMatchService apiMatchService;
1917
private SensitiveInfoMatchService sensitiveInfoMatchService;
20-
private ArrayList<Integer> messageIdList;
18+
private HashMap<Integer, HttpRequest> messageIdList;
2119

2220
public APIHighLighterHandler() {
2321
this.log = Main.API.logging();
24-
this.apiMatchService = new APIMatchService();
2522
this.sensitiveInfoMatchService = new SensitiveInfoMatchService();
26-
this.messageIdList = new ArrayList<>();
23+
this.messageIdList = new HashMap<>();
2724
}
2825

2926
@Override
3027
public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent requestToBeSent) {
3128
try {
32-
Method matchMethod = APIMatchService.class.getMethod(UserConfig.MATCH_MOD.name(), HttpRequest.class);
33-
if ((Boolean) matchMethod.invoke(apiMatchService, requestToBeSent)) {
29+
HashMap apiMatchResult = Util.getAPIMatchResult(requestToBeSent);
30+
boolean isMatched = (boolean) apiMatchResult.get("isMatched");
31+
APIItem matchedItem = (APIItem) apiMatchResult.get("api");
32+
33+
if (isMatched) {
3434
// 添加到arraylist中 为了检查对应response
35-
messageIdList.add(requestToBeSent.messageId());
35+
if (messageIdList.get(requestToBeSent.messageId()) == null) {
36+
messageIdList.put(requestToBeSent.messageId(), requestToBeSent);
37+
}
38+
39+
// 对匹配到的接口进行标记
40+
Util.setAPIFound(matchedItem.getPath(), requestToBeSent);
3641

3742
// 匹配到进行高亮处理
3843
Util.setHighlightColor(requestToBeSent, Color.YELLOW);
3944

40-
// 只对匹配到的接口进行敏感信息检查
41-
HashMap result = sensitiveInfoMatchService.sensitiveInfoMatch(requestToBeSent);
42-
if (!result.isEmpty()) {
43-
// 对history进行红色高亮处理
44-
Util.setHighlightColor(requestToBeSent, Color.ORANGE);
45+
if (SensitiveInfoConfig.IS_CHECK_SENSITIVE_INFO) {
46+
// 只对匹配到的接口进行敏感信息检查
47+
HashMap sensitiveInfoMatchResult = sensitiveInfoMatchService.sensitiveInfoMatch(requestToBeSent);
48+
if (!sensitiveInfoMatchResult.isEmpty()) {
49+
// 对history进行红色高亮处理
50+
Util.setHighlightColor(requestToBeSent, Color.ORANGE);
51+
52+
// 标记result 存在敏感信息
53+
Util.setAPIResult(APIConfig.SENSITIVE_INFO_RESULT, matchedItem.getPath(), requestToBeSent);
4554

46-
if (APIMatchService.MATCHED_ITEM.getResult() != null && !APIMatchService.MATCHED_ITEM.getResult().contains("敏感信息")) {
47-
APIMatchService.MATCHED_ITEM.setResult(APIMatchService.MATCHED_ITEM.getResult() + "/存在敏感信息");
48-
} else {
49-
APIMatchService.MATCHED_ITEM.setResult("存在敏感信息");
5055
}
56+
}
5157

52-
// 刷新列表
53-
Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable());
5458

55-
}
59+
// 刷新列表
60+
Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable());
5661
}
5762

5863
} catch (Exception e) {
59-
log.logToError(e);
64+
log.logToError("request handler异常");
6065
}
6166
return null;
6267
}
6368

6469
@Override
6570
public ResponseReceivedAction handleHttpResponseReceived(HttpResponseReceived responseReceived) {
6671
try {
67-
if (messageIdList.contains(responseReceived.messageId())) {
68-
HashMap result = sensitiveInfoMatchService.sensitiveInfoMatch(responseReceived);
69-
if (!result.isEmpty()) {
70-
// 对history进行红色高亮处理
71-
Util.setHighlightColor(responseReceived, Color.ORANGE);
72-
73-
if (APIMatchService.MATCHED_ITEM.getResult() != null && !APIMatchService.MATCHED_ITEM.getResult().contains("存在敏感信息")) {
74-
APIMatchService.MATCHED_ITEM.setResult(APIMatchService.MATCHED_ITEM.getResult() + "/存在敏感信息");
75-
} else {
76-
APIMatchService.MATCHED_ITEM.setResult("存在敏感信息");
77-
}
72+
if (SensitiveInfoConfig.IS_CHECK_SENSITIVE_INFO) {
73+
// 查询当前response对应的request是否被匹配
74+
HttpRequest request = messageIdList.get(responseReceived.messageId());
75+
if (request != null) {
76+
HashMap sensitiveInfoMatch = sensitiveInfoMatchService.sensitiveInfoMatch(responseReceived);
77+
78+
if (!sensitiveInfoMatch.isEmpty()) {
79+
// 对history进行红色高亮处理
80+
Util.setHighlightColor(responseReceived, Color.ORANGE);
81+
82+
// 重新匹配一次 找到对应的apiItem
83+
HashMap apiMatchResult = Util.getAPIMatchResult(request);
84+
APIItem matchedItem = (APIItem) apiMatchResult.get("api");
7885

79-
// 刷新列表
80-
Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable());
86+
// 标记result 存在敏感信息
87+
Util.setAPIResult(APIConfig.SENSITIVE_INFO_RESULT, matchedItem.getPath(), request);
8188

89+
// 刷新列表
90+
Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable());
91+
92+
}
8293
}
8394
}
8495
} catch (Exception e) {
85-
log.logToError(e);
96+
log.logToError("response handler异常");
8697
}
8798

8899
return null;

src/main/java/com/chave/pojo/APIItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class APIItem {
1313
private String result;
1414
private Boolean state = Boolean.FALSE;
1515
private String note;
16-
private String domain;
16+
private String isFound;
1717

1818
public APIItem(String path) {
1919
this.path = path;

0 commit comments

Comments
 (0)