|
4 | 4 | import burp.api.montoya.http.message.requests.HttpRequest; |
5 | 5 | import burp.api.montoya.logging.Logging; |
6 | 6 | import com.chave.Main; |
| 7 | +import com.chave.config.APIConfig; |
7 | 8 | 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; |
10 | 11 | import com.chave.service.SensitiveInfoMatchService; |
11 | 12 | import com.chave.utils.Util; |
12 | | -import java.lang.reflect.Method; |
13 | | -import java.util.ArrayList; |
14 | 13 | import java.util.HashMap; |
15 | 14 |
|
16 | 15 | public class APIHighLighterHandler implements HttpHandler { |
17 | 16 | private Logging log; |
18 | | - private APIMatchService apiMatchService; |
19 | 17 | private SensitiveInfoMatchService sensitiveInfoMatchService; |
20 | | - private ArrayList<Integer> messageIdList; |
| 18 | + private HashMap<Integer, HttpRequest> messageIdList; |
21 | 19 |
|
22 | 20 | public APIHighLighterHandler() { |
23 | 21 | this.log = Main.API.logging(); |
24 | | - this.apiMatchService = new APIMatchService(); |
25 | 22 | this.sensitiveInfoMatchService = new SensitiveInfoMatchService(); |
26 | | - this.messageIdList = new ArrayList<>(); |
| 23 | + this.messageIdList = new HashMap<>(); |
27 | 24 | } |
28 | 25 |
|
29 | 26 | @Override |
30 | 27 | public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent requestToBeSent) { |
31 | 28 | 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) { |
34 | 34 | // 添加到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); |
36 | 41 |
|
37 | 42 | // 匹配到进行高亮处理 |
38 | 43 | Util.setHighlightColor(requestToBeSent, Color.YELLOW); |
39 | 44 |
|
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); |
45 | 54 |
|
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("存在敏感信息"); |
50 | 55 | } |
| 56 | + } |
51 | 57 |
|
52 | | - // 刷新列表 |
53 | | - Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable()); |
54 | 58 |
|
55 | | - } |
| 59 | + // 刷新列表 |
| 60 | + Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable()); |
56 | 61 | } |
57 | 62 |
|
58 | 63 | } catch (Exception e) { |
59 | | - log.logToError(e); |
| 64 | + log.logToError("request handler异常"); |
60 | 65 | } |
61 | 66 | return null; |
62 | 67 | } |
63 | 68 |
|
64 | 69 | @Override |
65 | 70 | public ResponseReceivedAction handleHttpResponseReceived(HttpResponseReceived responseReceived) { |
66 | 71 | 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"); |
78 | 85 |
|
79 | | - // 刷新列表 |
80 | | - Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable()); |
| 86 | + // 标记result 存在敏感信息 |
| 87 | + Util.setAPIResult(APIConfig.SENSITIVE_INFO_RESULT, matchedItem.getPath(), request); |
81 | 88 |
|
| 89 | + // 刷新列表 |
| 90 | + Util.flushAPIList(Main.UI.getHighlighterMainUI().getApiTable()); |
| 91 | + |
| 92 | + } |
82 | 93 | } |
83 | 94 | } |
84 | 95 | } catch (Exception e) { |
85 | | - log.logToError(e); |
| 96 | + log.logToError("response handler异常"); |
86 | 97 | } |
87 | 98 |
|
88 | 99 | return null; |
|
0 commit comments