Repository navigation
Expand file tree
/
Copy pathExtensionTab.java
More file actions
271 lines (229 loc) · 8.81 KB
/
Copy pathExtensionTab.java
File metadata and controls
271 lines (229 loc) · 8.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package burp.ui;
import burp.*;
import burp.utils.Constants;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class ExtensionTab extends AbstractTableModel implements ITab, IMessageEditorController {
private final String tagName;
private JSplitPane mainSplitPane;
private IMessageEditor requestTextEditor;
private IMessageEditor responseTextEditor;
private IHttpRequestResponse currentlyDisplayedItem;
private JScrollPane upScrollPane;
private JSplitPane downSplitPane;
private JTabbedPane requestPanel;
private JTabbedPane responsePanel;
private JSplitPane upSplitPane;
private ConfigPanel configPanel;
private ApiTable apiTable;
public ExtensionTab(String name) {
IBurpExtenderCallbacks callbacks = BurpExtender.getCallbacks();
this.tagName = name;
// 创建用户界面
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// 主分隔面板
mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
//上方面板
upSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
upSplitPane.setEnabled(false); // 禁止拖动
// 配置面板
configPanel = new ConfigPanel();
BurpExtender.setConfigPanel(configPanel);
// 任务栏面板
apiTable = new ApiTable(ExtensionTab.this);
upScrollPane = new JScrollPane(apiTable);
// 前两列设置宽度 30px
for (int i = 0; i < 2; i++) {
apiTable.getColumnModel().getColumn(i).setMaxWidth(30);
}
apiTable.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (isSelected) {
c.setBackground(Color.decode(Constants.TAB_COLOR_SELECTED));
} else {
ExtensionTab apiTable = (ExtensionTab) table.getModel();
ApiTableData apiTableData = apiTable.getApiTable().getTableData().get(row);
if (apiTableData.isSubData) {
c.setBackground(Color.decode(Constants.TAB_COLOR_SUB_DATA));
} else {
c.setBackground(Color.decode(Constants.TAB_COLOR_MAIN_DATA));
}
}
return c;
}
});
// 请求与响应界面的分隔面板规则
downSplitPane = new JSplitPane();
downSplitPane.setResizeWeight(0.5D);
// 请求的面板
requestPanel = new JTabbedPane();
requestTextEditor = callbacks.createMessageEditor(ExtensionTab.this, false);
requestPanel.addTab("Request", requestTextEditor.getComponent());
// 响应的面板
responsePanel = new JTabbedPane();
responseTextEditor = callbacks.createMessageEditor(ExtensionTab.this, false);
responsePanel.addTab("Response", responseTextEditor.getComponent());
// 自定义程序UI组件
downSplitPane.add(requestPanel, "left");
downSplitPane.add(responsePanel, "right");
upSplitPane.add(configPanel, "left");
upSplitPane.add(upScrollPane, "right");
mainSplitPane.add(upSplitPane, "left");
mainSplitPane.add(downSplitPane, "right");
callbacks.customizeUiComponent(mainSplitPane);
// 将自定义选项卡添加到Burp的UI
callbacks.addSuiteTab(ExtensionTab.this);
}
});
}
@Override
public String getTabCaption() {
return this.tagName;
}
@Override
public Component getUiComponent() {
return mainSplitPane;
}
@Override
public int getRowCount() {
return this.getApiTable().getTableData().size();
}
@Override
public int getColumnCount() {
return 7;
}
@Override
public String getColumnName(int columnIndex) {
switch (columnIndex) {
case 0:
return " ";
case 1:
return "#";
case 2:
return "URL";
case 3:
return "Status Code";
case 4:
return "Event Name";
case 5:
return "Unauth";
case 6:
return "Scan Time";
}
return null;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
return String.class;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
ApiTableData data = this.getApiTable().getTableData().get(rowIndex);
switch (columnIndex) {
case 0:
return data.treeStatus;
case 1:
return data.id;
case 2:
return data.url;
case 3:
return data.statusCode;
case 4:
return data.apiType;
case 5:
return data.unauth;
case 6:
return data.scanTime;
}
return null;
}
@Override
public byte[] getRequest() {
return currentlyDisplayedItem.getRequest();
}
@Override
public byte[] getResponse() {
return currentlyDisplayedItem.getResponse();
}
@Override
public IHttpService getHttpService() {
return currentlyDisplayedItem.getHttpService();
}
/**
* 新增任务至任务栏面板
*/
public void add(ApiDocumentListTree apiDocumentListTree) {
synchronized (this.apiTable) {
this.apiTable.getTableData().add(apiDocumentListTree.getMainApiData());
int _id = this.apiTable.getTableData().size();
fireTableRowsInserted(_id, _id);
}
}
public ApiTable getApiTable() {
return this.apiTable;
}
/**
* 界面显示数据存储模块
*/
public static class ApiTableData {
final String id;
final String url;
final String statusCode;
final String apiType;
final String unauth;
final IHttpRequestResponse requestResponse;
final String scanTime;
final Boolean isSubData;
final ApiDocumentListTree parentListTree;
private String treeStatus = "";
public ApiTableData(Boolean isSubData, ApiDocumentListTree parentListTree, String id, String url, String statusCode, String apiType, String unauth, IHttpRequestResponse requestResponse, String scanTime) {
this.isSubData = isSubData;
this.parentListTree = parentListTree;
this.id = id;
this.url = url;
this.statusCode = statusCode;
this.apiType = apiType;
this.unauth = unauth;
this.requestResponse = requestResponse;
this.scanTime = scanTime;
}
public void setTreeStatus(String treeStatus) {
this.treeStatus = treeStatus;
}
}
/**
* 自定义Table
*/
public class ApiTable extends JTable {
private final List<ApiTableData> tableData = new ArrayList<ApiTableData>();
public ApiTable(TableModel tableModel) {
super(tableModel);
}
public List<ApiTableData> getTableData() {
return this.tableData;
}
public void changeSelection(int row, int col, boolean toggle, boolean extend) {
ApiTableData dataEntry = ExtensionTab.ApiTable.this.tableData.get(convertRowIndexToModel(row));
if (!dataEntry.isSubData) { // 切换状态
if (dataEntry.parentListTree.getExpandStatus()) {
dataEntry.parentListTree.collapse();
} else {
dataEntry.parentListTree.expand();
}
}
requestTextEditor.setMessage(dataEntry.requestResponse.getRequest(), true);
responseTextEditor.setMessage(dataEntry.requestResponse.getResponse(), false);
currentlyDisplayedItem = dataEntry.requestResponse;
super.changeSelection(row, col, toggle, extend);
}
}
}