55import burp .vaycore .common .layout .VLayout ;
66import burp .vaycore .common .utils .JsonUtils ;
77import burp .vaycore .common .utils .StringUtils ;
8- import burp .vaycore .common .utils .Utils ;
98import burp .vaycore .onescan .bean .FpData ;
109import burp .vaycore .onescan .manager .FpManager ;
1110import burp .vaycore .onescan .ui .widget .FpTestResultPanel ;
1514import java .nio .charset .StandardCharsets ;
1615import java .util .ArrayList ;
1716import java .util .List ;
18- import java .util .Map ;
1917import java .util .Vector ;
20- import java .util .concurrent .ConcurrentHashMap ;
2118
2219/**
2320 * OneScan 信息辅助面板
@@ -28,8 +25,6 @@ public class OneScanInfoTab implements IMessageEditorTab {
2825
2926 private final IExtensionHelpers mHelpers ;
3027 private final JTabbedPane mTabPanel ;
31- private static final Map <String , Boolean > sEnabledMap = new ConcurrentHashMap <>();
32- private static final Map <String , MessageCacheBean > sMessageCacheMap = new ConcurrentHashMap <>();
3328 private final IMessageEditorController mController ;
3429
3530 private JList <String > mJsonKeyList ;
@@ -52,91 +47,66 @@ public Component getUiComponent() {
5247
5348 @ Override
5449 public boolean isEnabled (byte [] content , boolean isRequest ) {
55- String key = Utils .md5 (content );
56- if (!isRequest && sEnabledMap .containsKey (key )) {
57- return sEnabledMap .get (key );
58- }
59- boolean state = checkEnabled (content , isRequest );
60- // 请求包直接返回状态(只缓存响应包数据)
6150 if (isRequest ) {
62- return state ;
51+ return checkReqEnabled (content );
52+ } else {
53+ return checkRespEnabled (content );
6354 }
64- sEnabledMap .put (key , state );
65- return state ;
6655 }
6756
6857 /**
69- * 检测是否启用信息辅助面板
58+ * 检测当前请求是否需要启用信息辅助面板
7059 *
71- * @param content 请求/响应数据包
72- * @param isRequest 是否请求包
60+ * @param content 请求数据包
7361 * @return true=启用;false=不启用
7462 */
75- private boolean checkEnabled (byte [] content , boolean isRequest ) {
76- boolean hasJsonEnabled = false ;
77- boolean hasFingerprint = false ;
78- if (isRequest ) {
79- // 解析请求包数据
80- IRequestInfo info = mHelpers .analyzeRequest (content );
81- // 请求包中是否包含 JSON 数据格式
63+ private boolean checkReqEnabled (byte [] content ) {
64+ boolean hasEnabled = false ;
65+ // 解析请求包数据
66+ IRequestInfo info = mHelpers .analyzeRequest (content );
67+ // 是否存在指纹识别历史记录
68+ if (FpManager .getHistoryCount () > 0 ) {
69+ String host = getRequestHost (info );
70+ List <FpData > historyResults = FpManager .findHistoryByHost (host );
71+ hasEnabled = historyResults != null && !historyResults .isEmpty ();
72+ }
73+ // 如果未启用,检测请求包是否存在指纹识别数据
74+ if (!hasEnabled ) {
75+ List <FpData > results = FpManager .check (content , mController .getResponse ());
76+ hasEnabled = results != null && !results .isEmpty ();
77+ }
78+ // 如果未启用,检测请求包中是否包含 JSON 数据格式
79+ if (!hasEnabled ) {
8280 String body = getReqBody (info , content );
83- hasJsonEnabled = JsonUtils .hasJson (body );
84- // 是否存在指纹识别历史记录
85- if (FpManager .getHistoryCount () > 0 ) {
86- String host = getRequestHost (info );
87- List <FpData > list = FpManager .findHistoryByHost (host );
88- hasFingerprint = list != null && !list .isEmpty ();
89- } else {
90- // 请求包是否存在指纹识别数据
91- List <FpData > results = FpManager .check (content , mController .getResponse ());
92- hasFingerprint = results != null && !results .isEmpty ();
93- }
94- } else {
95- // 解析响应包数据
96- IResponseInfo info = mHelpers .analyzeResponse (content );
97- // 响应包中是否包含 JSON 数据格式
98- String body = getRespBody (info , content );
99- hasJsonEnabled = JsonUtils .hasJson (body );
100- // 响应包是否存在指纹识别数据
101- List <FpData > results = FpManager .check (mController .getRequest (), content );
102- hasFingerprint = results != null && !results .isEmpty ();
81+ hasEnabled = JsonUtils .hasJson (body );
10382 }
104- return hasJsonEnabled || hasFingerprint ;
83+ return hasEnabled ;
84+ }
85+
86+ /**
87+ * 检测当前响应是否需要启用信息辅助面板
88+ *
89+ * @param content 响应数据包
90+ * @return true=启用;false=不启用
91+ */
92+ private boolean checkRespEnabled (byte [] content ) {
93+ boolean hasEnabled = false ;
94+ // 解析响应包数据
95+ IResponseInfo info = mHelpers .analyzeResponse (content );
96+ // 检测响应包中是否包含 JSON 数据格式
97+ String body = getRespBody (info , content );
98+ hasEnabled = JsonUtils .hasJson (body );
99+ return hasEnabled ;
105100 }
106101
107102 @ Override
108103 public void setMessage (byte [] content , boolean isRequest ) {
109104 mTabPanel .removeAll ();
110- String key = Utils .md5 (content );
111- // 如果响应包存在缓存(只缓存响应包数据)
112- if (!isRequest && sMessageCacheMap .containsKey (key )) {
113- loadCacheMessage (key );
114- return ;
115- }
116- // 无缓存,进入数据提取流程
105+ // 根据当前数据类型,进入数据提取流程
117106 if (isRequest ) {
118107 handleReqMessage (content );
119108 } else {
120- handleRespMessage (content , key );
121- }
122- }
123-
124- /**
125- * 加载缓存信息
126- *
127- * @param key 缓存 key
128- */
129- private void loadCacheMessage (String key ) {
130- MessageCacheBean bean = sMessageCacheMap .get (key );
131- // 指纹识别结果
132- List <FpData > results = bean .getResults ();
133- if (results != null && !results .isEmpty ()) {
134- mTabPanel .addTab ("Fingerprint" , new FpTestResultPanel (results ));
135- }
136- // Json 字段
137- List <String > jsonKeys = bean .getJsonKeys ();
138- if (jsonKeys != null && !jsonKeys .isEmpty ()) {
139- mTabPanel .addTab ("Json" , newJsonInfoPanel (jsonKeys ));
109+ handleRespMessage (content );
140110 }
141111 }
142112
@@ -176,26 +146,17 @@ private void handleReqMessage(byte[] content) {
176146 *
177147 * @param content 数据包
178148 */
179- private void handleRespMessage (byte [] content , String key ) {
180- MessageCacheBean bean = new MessageCacheBean ();
149+ private void handleRespMessage (byte [] content ) {
181150 // 解析响应包数据
182151 IResponseInfo info = mHelpers .analyzeResponse (content );
183- // 识别响应包的指纹
184- List <FpData > results = FpManager .check (mController .getRequest (), content );
185- if (results != null && !results .isEmpty ()) {
186- bean .setResults (results );
187- mTabPanel .addTab ("Fingerprint" , new FpTestResultPanel (results ));
188- }
189152 // 提取响应包 Json 字段数据展示
190153 String body = getRespBody (info , content );
191154 if (JsonUtils .hasJson (body )) {
192155 ArrayList <String > keys = JsonUtils .findAllKeysByJson (body );
193156 if (!keys .isEmpty ()) {
194- bean .setJsonKeys (keys );
195157 mTabPanel .addTab ("Json" , newJsonInfoPanel (keys ));
196158 }
197159 }
198- sMessageCacheMap .put (key , bean );
199160 }
200161
201162 private JPanel newJsonInfoPanel (List <String > keys ) {
@@ -248,14 +209,14 @@ private String getRespBody(IResponseInfo info, byte[] content) {
248209 }
249210
250211 private String getRequestHost (IRequestInfo info ) {
251- if (info == null ) {
252- return null ;
253- }
254212 // 优先使用从 IHttpService 获取的 Host 值
255213 String host = getRequestHost ();
256214 if (StringUtils .isNotEmpty (host )) {
257215 return host ;
258216 }
217+ if (info == null ) {
218+ return null ;
219+ }
259220 // 从 HTTP 请求头中获取 Host 值
260221 List <String > headers = info .getHeaders ();
261222 for (String header : headers ) {
@@ -283,56 +244,4 @@ private String getRequestHost() {
283244 }
284245 return host + ":" + port ;
285246 }
286-
287- /**
288- * 清除缓存
289- */
290- public static void clearCache () {
291- if (!sEnabledMap .isEmpty ()) {
292- sEnabledMap .clear ();
293- }
294- if (!sMessageCacheMap .isEmpty ()) {
295- sMessageCacheMap .clear ();
296- }
297- }
298-
299- /**
300- * 信息缓存实体类
301- */
302- private static class MessageCacheBean {
303-
304- private List <FpData > mResults ;
305- private List <FpData > mHistoryResults ;
306- private List <String > mJsonKeys ;
307-
308- public List <FpData > getResults () {
309- return mResults ;
310- }
311-
312- public void setResults (List <FpData > mResults ) {
313- this .mResults = mResults ;
314- }
315-
316- public List <FpData > getHistoryResults () {
317- return mHistoryResults ;
318- }
319-
320- public void setHistoryResults (List <FpData > mHistoryResults ) {
321- this .mHistoryResults = mHistoryResults ;
322- }
323-
324- public List <String > getJsonKeys () {
325- return mJsonKeys ;
326- }
327-
328- public void setJsonKeys (List <String > mJsonKeys ) {
329- this .mJsonKeys = mJsonKeys ;
330- }
331-
332- public boolean isNotEmpty () {
333- return mResults != null && !mResults .isEmpty () &&
334- mHistoryResults != null && !mHistoryResults .isEmpty () &&
335- mJsonKeys != null && !mJsonKeys .isEmpty ();
336- }
337- }
338247}
0 commit comments