Skip to content

Commit 0437776

Browse files
authored
Merge pull request #12 from Chave0v0/dev
修复已知bug
2 parents d367533 + 5ea29f2 commit 0437776

File tree

8 files changed

+114
-48
lines changed

8 files changed

+114
-48
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2022-2023. PortSwigger Ltd. All rights reserved.
3+
*
4+
* This code may be used to extend the functionality of Burp Suite Community Edition
5+
* and Burp Suite Professional, provided that this usage does not violate the
6+
* license terms for those products.
7+
*/
8+
9+
package burp.api.montoya.core;
10+
11+
/**
12+
* Tools in Burp Suite.
13+
*/
14+
public enum ToolType
15+
{
16+
SUITE("Suite"),
17+
TARGET("Target"),
18+
PROXY("Proxy"),
19+
SCANNER("Scanner"),
20+
INTRUDER("Intruder"),
21+
REPEATER("Repeater"),
22+
LOGGER("Logger"),
23+
SEQUENCER("Sequencer"),
24+
DECODER("Decoder"),
25+
COMPARER("Comparer"),
26+
EXTENSIONS("Extensions"),
27+
RECORDED_LOGIN_REPLAYER("Recorded login replayer"),
28+
ORGANIZER("Organizer");
29+
30+
private final String toolName;
31+
32+
ToolType(String toolName)
33+
{
34+
this.toolName = toolName;
35+
}
36+
37+
/**
38+
* @return The tool name.
39+
*/
40+
public String toolName()
41+
{
42+
return toolName;
43+
}
44+
45+
/**
46+
* @return The tool name.
47+
*/
48+
@Override
49+
public String toString()
50+
{
51+
return toolName;
52+
}
53+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.chave.editor.ResponseEditor;
99
import com.chave.handler.APIHighLighterHandler;
1010
import com.chave.ui.MainUI;
11-
1211
import java.io.*;
1312

1413
public class Main implements BurpExtension {
@@ -22,7 +21,7 @@ public void initialize(MontoyaApi montoyaApi) {
2221
Logging log = API.logging();
2322

2423
API.extension().setName("API Highlighter");
25-
log.logToOutput("API Highlighter v2.1.0\n\n" +
24+
log.logToOutput("API Highlighter v2.1.1\n\n" +
2625
"Rebuild: Chave\n" +
2726
"GitHub: https://github.com/Chave0v0/API-Highlighter\n");
2827

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import com.chave.config.SensitiveInfoConfig;
1111
import com.chave.service.SensitiveInfoMatchService;
1212
import com.chave.utils.Util;
13-
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.*;
19+
import java.lang.reflect.InvocationTargetException;
2020
import java.util.ArrayList;
2121
import java.util.HashMap;
2222
import java.util.Set;
@@ -48,6 +48,12 @@ public void setRequestResponse(HttpRequestResponse requestResponse) {
4848
@Override
4949
public boolean isEnabledFor(HttpRequestResponse requestResponse) {
5050
HttpRequest request = requestResponse.request();
51+
52+
// 防止空指针
53+
if (request == null) {
54+
return false;
55+
}
56+
5157
try {
5258
HashMap apiMatchResult = Util.getAPIMatchResult(request);
5359
boolean isMatched = (boolean) apiMatchResult.get("isMatched");
@@ -60,6 +66,8 @@ public boolean isEnabledFor(HttpRequestResponse requestResponse) {
6066
} else {
6167
return false;
6268
}
69+
} catch (InvocationTargetException invocationTargetException) {
70+
// 预期内异常
6371
} catch (Exception e) {
6472
Main.API.logging().logToError(e);
6573
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import com.chave.config.SensitiveInfoConfig;
1010
import com.chave.service.SensitiveInfoMatchService;
1111
import com.chave.utils.Util;
12-
1312
import javax.swing.*;
1413
import javax.swing.table.DefaultTableCellRenderer;
1514
import javax.swing.table.DefaultTableModel;
1615
import javax.swing.table.JTableHeader;
1716
import javax.swing.table.TableCellRenderer;
1817
import java.awt.*;
18+
import java.lang.reflect.InvocationTargetException;
1919
import java.util.ArrayList;
2020
import java.util.HashMap;
2121
import java.util.Set;
@@ -49,6 +49,12 @@ public void setRequestResponse(HttpRequestResponse requestResponse) {
4949
public boolean isEnabledFor(HttpRequestResponse requestResponse) {
5050
HttpResponse response = requestResponse.response();
5151
HttpRequest request = requestResponse.request();
52+
53+
// 防止空指针
54+
if (response == null || request == null) {
55+
return false;
56+
}
57+
5258
try {
5359
HashMap apiMatchResult = Util.getAPIMatchResult(request);
5460
boolean isMatched = (boolean) apiMatchResult.get("isMatched");
@@ -61,9 +67,10 @@ public boolean isEnabledFor(HttpRequestResponse requestResponse) {
6167
} else {
6268
return false;
6369
}
70+
} catch (InvocationTargetException invocationTargetException) {
71+
// 预期内异常
6472
} catch (Exception e) {
6573
Main.API.logging().logToError(e);
66-
return false;
6774
}
6875
return false;
6976
}

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

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.chave.handler;
22

3+
import burp.api.montoya.core.ToolType;
34
import burp.api.montoya.http.handler.*;
45
import burp.api.montoya.http.message.requests.HttpRequest;
56
import burp.api.montoya.logging.Logging;
@@ -26,43 +27,43 @@ public APIHighLighterHandler() {
2627
@Override
2728
public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent requestToBeSent) {
2829
try {
29-
HashMap apiMatchResult = Util.getAPIMatchResult(requestToBeSent);
30-
boolean isMatched = (boolean) apiMatchResult.get("isMatched");
31-
APIItem matchedItem = (APIItem) apiMatchResult.get("api");
32-
33-
if (isMatched) {
34-
// 添加到arraylist中 为了检查对应response
35-
if (messageIdList.get(requestToBeSent.messageId()) == null) {
36-
messageIdList.put(requestToBeSent.messageId(), requestToBeSent);
37-
}
38-
39-
// 对匹配到的接口进行标记
40-
Util.setAPIFound(matchedItem.getPath(), requestToBeSent);
41-
42-
// 匹配到进行高亮处理
43-
Util.setHighlightColor(requestToBeSent, Color.YELLOW);
44-
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);
54-
30+
// 只监听来自proxy与repeter的流量 减小检测量
31+
if (requestToBeSent.toolSource().isFromTool(ToolType.PROXY) || requestToBeSent.toolSource().isFromTool(ToolType.REPEATER)) {
32+
HashMap apiMatchResult = Util.getAPIMatchResult(requestToBeSent);
33+
boolean isMatched = (boolean) apiMatchResult.get("isMatched");
34+
APIItem matchedItem = (APIItem) apiMatchResult.get("api");
35+
36+
if (isMatched) {
37+
// 添加到arraylist中 为了检查对应response
38+
if (messageIdList.get(requestToBeSent.messageId()) == null) {
39+
messageIdList.put(requestToBeSent.messageId(), requestToBeSent);
5540
}
56-
}
5741

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

59-
// 刷新列表
60-
Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable());
59+
// 刷新列表
60+
Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable());
61+
}
6162
}
62-
6363
} catch (Exception e) {
6464
log.logToError("request handler异常");
6565
}
66+
6667
return null;
6768
}
6869

src/main/java/com/chave/service/APIMatchService.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.chave.config.UserConfig;
88
import com.chave.pojo.APIItem;
99
import com.chave.utils.Util;
10-
1110
import java.util.HashMap;
1211
import java.util.regex.Matcher;
1312
import java.util.regex.Pattern;
@@ -50,7 +49,7 @@ public HashMap<String, Object> exactMatch(HttpRequest request) {
5049
}
5150
} else {
5251
// 处理有 PathVariable 的情况
53-
Pattern pattern = Pattern.compile("^" + Util.convertPathToRegex(apiItem.getPath()) + "$");
52+
Pattern pattern = Pattern.compile("^" + Util.convertPathToRegex(apiItem.getPath()) + "$", Pattern.CASE_INSENSITIVE);
5453
Matcher matcher = pattern.matcher(path);
5554
if (isMatched = matcher.matches()) {
5655
if (UserConfig.IS_CHECK_HTTP_METHOD && apiItem.getMethod() != null) {
@@ -95,14 +94,14 @@ public HashMap<String, Object> semiFuzzMatch(HttpRequest request) {
9594

9695
try {
9796
// 声明没有 PathVariable 情况下的正则
98-
pattern = Pattern.compile("^(/[^/]+)?" + apiItem.getPath() + "(/.*)?$");
97+
pattern = Pattern.compile("^(/[^/]+)?" + apiItem.getPath() + "(/.*)?$", Pattern.CASE_INSENSITIVE);
9998
} catch (Exception e) {
10099
// 如果正则编译捕获异常,并且有"{",认为是有PathVariable的情况,重新生成正则。
101100
if (apiItem.getPath().contains("{")) {
102-
pattern = Pattern.compile("^(/[^/]+)?" + Util.convertPathToRegex(apiItem.getPath()) + "(/.*)?$");
101+
pattern = Pattern.compile("^(/[^/]+)?" + Util.convertPathToRegex(apiItem.getPath()) + "(/.*)?$", Pattern.CASE_INSENSITIVE);
103102
} else {
104103
// 其他情况认为是预期外的异常,直接输出log
105-
log.logToError(e);
104+
log.logToError("半精确匹配出现异常" + e.getCause());
106105
}
107106
}
108107

@@ -146,9 +145,9 @@ public HashMap<String, Object> fuzzMatch(HttpRequest request) {
146145
}
147146

148147
if (UserConfig.IS_ANALYZE_PATHVARIABLE) {
149-
pattern = Pattern.compile(".*" + Util.convertPathToRegex(apiItem.getPath()) + ".*");
148+
pattern = Pattern.compile(".*" + Util.convertPathToRegex(apiItem.getPath()) + ".*", Pattern.CASE_INSENSITIVE);
150149
} else {
151-
pattern = Pattern.compile(".*" + Pattern.quote(apiItem.getPath()) + ".*");
150+
pattern = Pattern.compile(".*" + Pattern.quote(apiItem.getPath()) + ".*", Pattern.CASE_INSENSITIVE);
152151
}
153152

154153

src/main/java/com/chave/ui/HighlighterMainUI.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ public void actionPerformed(ActionEvent e) {
213213
try {
214214
APIItem item;
215215
if (method == null) {
216-
item = new APIItem(path.toLowerCase());
216+
item = new APIItem(path);
217217
} else {
218-
item = new APIItem(method.toUpperCase(), path.toLowerCase());
218+
item = new APIItem(method.toUpperCase(), path);
219219
}
220220
if (!Util.checkAPIItemExist(item)) {
221221
APIConfig.TARGET_API.add(item);
222222
}
223223
} catch (Exception exception) {
224-
log.logToError(exception);
224+
log.logToError("导入api出现异常" + exception.getCause());
225225
continue;
226226
}
227227

@@ -232,7 +232,7 @@ public void actionPerformed(ActionEvent e) {
232232
}
233233

234234
try {
235-
APIItem item = new APIItem(line.trim().toLowerCase());
235+
APIItem item = new APIItem(line.trim());
236236
if (!Util.checkAPIItemExist(item)) {
237237
APIConfig.TARGET_API.add(item);
238238
}
@@ -250,7 +250,7 @@ public void actionPerformed(ActionEvent e) {
250250
userInputTextArea.setText("");
251251
Util.flushAPIList(apiTable);
252252
} catch (Exception exception) {
253-
System.out.println(exception);
253+
log.logToError("导入api后刷新异常" + exception.getCause());
254254
}
255255

256256
}

src/main/java/com/chave/utils/Util.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.chave.service.APIMatchService;
1313
import org.yaml.snakeyaml.DumperOptions;
1414
import org.yaml.snakeyaml.Yaml;
15-
1615
import javax.swing.*;
1716
import javax.swing.table.DefaultTableModel;
1817
import java.io.*;

0 commit comments

Comments
 (0)