Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4d8743fe3 | ||
|
|
903077c830 | ||
|
|
daddf15af2 | ||
|
|
e747011ec0 | ||
|
|
f7b2e99eb2 | ||
|
|
59cd0a88b9 | ||
|
|
b16cbf5b60 | ||
|
|
4ef766dd82 | ||
|
|
5d9f590977 | ||
|
|
5c326d3ca6 | ||
|
|
62edae0ab4 | ||
|
|
562378873c | ||
|
|
5f62e9653f | ||
|
|
3fc1869a7b | ||
|
|
43fbc46b65 | ||
|
|
00a4a835b2 | ||
|
|
f872dadf46 | ||
|
|
15bbb9f1a0 | ||
|
|
89f3f6cf09 | ||
|
|
cf9f434ff8 | ||
|
|
37a907d6df | ||
|
|
83e5da2f7e | ||
|
|
e43a96b8ad | ||
|
|
a7112ad297 |
201
LICENSE
Normal file
201
LICENSE
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
17
README.md
17
README.md
@@ -1,9 +1,8 @@
|
||||
# HaE - Highlighter and Extractor
|
||||
|
||||
HaE相关作者 (来自米斯特安全团队 www.acmesec.cn) :
|
||||
核心功能作者: [@EvilChen](https://github.com/gh0stkey)
|
||||
|
||||
架构作者: [@0chencc](https://github.com/0Chencc)
|
||||
核心功能作者: [@EvilChen](https://github.com/gh0stkey)
|
||||
|
||||
## 公共规则网站
|
||||
|
||||
@@ -25,8 +24,6 @@ https://gh0st.cn/HaE/
|
||||
|
||||
初次装载`HaE`会初始化配置文件,默认配置文件内置一个正则: `Email`,初始化的配置文件会放在与`BurpSuite Jar`包同级目录下。
|
||||
|
||||

|
||||
|
||||
除了初始化的配置文件外,还有`Setting.yml`,该文件用于存储配置文件路径;`HaE`支持自定义配置文件路径,你可以通过点击`Select File`按钮进行选择自定义配置文件。
|
||||
|
||||

|
||||
@@ -39,6 +36,7 @@ https://gh0st.cn/HaE/
|
||||
4. 配置文件采用YAML格式存储,更加便于阅读和修改
|
||||
5. 内置简单缓存,在“多正则、大数据”的场景下减少卡顿现象
|
||||
6. **支持标签分页**,点击`...`即可添加新的标签页,对着标签页右键即可删除
|
||||
7. 高亮信息添加的同时添加Comment,便于查找请求
|
||||
|
||||

|
||||
|
||||
@@ -82,13 +80,16 @@ https://gh0st.cn/HaE/
|
||||
|
||||
...还有诸多使用方法等待大家去发掘。
|
||||
|
||||
## 使用视频
|
||||
|
||||
123
|
||||
|
||||
## 文末
|
||||
|
||||
随笔: 正义感是一个不可丢失的东西。
|
||||
|
||||
Github项目地址(BUG、需求、正则欢迎提交): https://github.com/gh0stkey/HaE
|
||||
|
||||
## 404StarLink 2.0 - Galaxy
|
||||
|
||||

|
||||
|
||||
`HaE` 是 404Team [星链计划2.0](https://github.com/knownsec/404StarLink2.0-Galaxy) 中的一环,如果对 `HaE` 有任何疑问又或是想要找小伙伴交流,可以参考星链计划的加群方式。
|
||||
|
||||
- [https://github.com/knownsec/404StarLink2.0-Galaxy#community](https://github.com/knownsec/404StarLink2.0-Galaxy#community)
|
||||
|
||||
@@ -5,27 +5,23 @@ import burp.ui.MainUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author EvilChen
|
||||
*/
|
||||
|
||||
public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEditorTabFactory, ITab {
|
||||
private MainUI main = new MainUI();
|
||||
private final MainUI main = new MainUI();
|
||||
private static PrintWriter stdout;
|
||||
private IBurpExtenderCallbacks callbacks;
|
||||
private static IExtensionHelpers helpers;
|
||||
private static IMessageEditorTab HaETab;
|
||||
MatchHTTP mh = new MatchHTTP();
|
||||
ExtractContent ec = new ExtractContent();
|
||||
DoAction da = new DoAction();
|
||||
GetColorKey gck = new GetColorKey();
|
||||
UpgradeColor uc = new UpgradeColor();
|
||||
ProcessMessage pm = new ProcessMessage();
|
||||
|
||||
@Override
|
||||
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks)
|
||||
@@ -33,28 +29,26 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
this.callbacks = callbacks;
|
||||
BurpExtender.helpers = callbacks.getHelpers();
|
||||
|
||||
String version = "2.0";
|
||||
String version = "2.1.4";
|
||||
callbacks.setExtensionName(String.format("HaE (%s) - Highlighter and Extractor", version));
|
||||
// 定义输出
|
||||
stdout = new PrintWriter(callbacks.getStdout(), true);
|
||||
stdout.println("@UI Author: 0chencc");
|
||||
stdout.println("@Core Author: EvilChen");
|
||||
stdout.println("@Architecture Author: 0chencc");
|
||||
stdout.println("@Github: https://github.com/gh0stkey/HaE");
|
||||
stdout.println("@Team: OverSpace Security Team");
|
||||
// UI
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initialize();
|
||||
}
|
||||
});
|
||||
SwingUtilities.invokeLater(this::initialize);
|
||||
|
||||
callbacks.registerHttpListener(BurpExtender.this);
|
||||
callbacks.registerMessageEditorTabFactory(BurpExtender.this);
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
callbacks.customizeUiComponent(main);
|
||||
callbacks.addSuiteTab(BurpExtender.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTabCaption(){
|
||||
return "HaE";
|
||||
@@ -72,44 +66,38 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo) {
|
||||
// 判断是否是响应,且该代码作用域为:REPEATER、INTRUDER、PROXY(分别对应toolFlag 64、32、4)
|
||||
if (toolFlag == 64 || toolFlag == 32 || toolFlag == 4) {
|
||||
Map<String, Map<String, Object>> obj;
|
||||
byte[] content = messageInfo.getRequest();
|
||||
// 获取报文头
|
||||
List<String> tmpHeaders = helpers.analyzeRequest(messageInfo.getHttpService(), content).getHeaders();
|
||||
String headers = String.join("\n", tmpHeaders);
|
||||
|
||||
// 获取报文主体
|
||||
int bodyOffset = helpers.analyzeRequest(messageInfo.getHttpService(), content).getBodyOffset();
|
||||
byte[] byteRequest = messageInfo.getRequest();
|
||||
byte[] body = Arrays.copyOfRange(byteRequest, bodyOffset, byteRequest.length);
|
||||
|
||||
// 流量清洗
|
||||
String urlString = helpers.analyzeRequest(messageInfo.getHttpService(), content).getUrl().toString();
|
||||
urlString = urlString.indexOf("?") > 0 ? urlString.substring(0, urlString.indexOf("?")) : urlString;
|
||||
|
||||
// 正则判断
|
||||
if (mh.matchSuffix(urlString)) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] content;
|
||||
if (messageIsRequest) {
|
||||
obj = ec.matchRegex(content, headers, body, "request");
|
||||
content = messageInfo.getRequest();
|
||||
} else {
|
||||
content = messageInfo.getResponse();
|
||||
obj = ec.matchRegex(content, headers, body, "response");
|
||||
}
|
||||
|
||||
List<String> colorList = da.highlightList(obj);
|
||||
if (colorList.size() != 0) {
|
||||
String color = uc.getEndColor(gck.getColorKeys(colorList, Config.colorArray), Config.colorArray);
|
||||
String c = new String(content, StandardCharsets.UTF_8).intern();
|
||||
List<String> result = pm.processMessageByContent(helpers, content, messageIsRequest, true);
|
||||
if (result != null && !result.isEmpty() && result.size() > 0) {
|
||||
String originalColor = messageInfo.getHighlight();
|
||||
String originalComment = messageInfo.getComment();
|
||||
List<String> colorList = new ArrayList<>();
|
||||
if (originalColor != null) {
|
||||
colorList.add(originalColor);
|
||||
}
|
||||
colorList.add(result.get(0));
|
||||
String color = uc.getEndColor(gck.getColorKeys(colorList));
|
||||
|
||||
messageInfo.setHighlight(color);
|
||||
String addComment = String.join(", ", result.get(1));
|
||||
String resComment = originalComment != null ? String.format("%s, %s", originalComment, addComment) : addComment;
|
||||
|
||||
messageInfo.setComment(resComment);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MarkInfoTab implements IMessageEditorTab {
|
||||
private ITextEditor markInfoText;
|
||||
private final ITextEditor markInfoText;
|
||||
private byte[] currentMessage;
|
||||
private final IMessageEditorController controller;
|
||||
private byte[] extractRequestContent;
|
||||
@@ -117,8 +105,8 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
|
||||
public MarkInfoTab(IMessageEditorController controller, boolean editable) {
|
||||
this.controller = controller;
|
||||
markInfoText = callbacks.createTextEditor();
|
||||
markInfoText.setEditable(editable);
|
||||
this.markInfoText = callbacks.createTextEditor();
|
||||
this.markInfoText.setEditable(editable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,63 +116,37 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
|
||||
@Override
|
||||
public Component getUiComponent() {
|
||||
return markInfoText.getComponent();
|
||||
return this.markInfoText.getComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(byte[] content, boolean isRequest) {
|
||||
try {
|
||||
// 流量清洗
|
||||
String urlString = helpers.analyzeRequest(controller.getHttpService(), controller.getRequest()).getUrl().toString();
|
||||
urlString = urlString.indexOf("?") > 0 ? urlString.substring(0, urlString.indexOf("?")) : urlString;
|
||||
// 正则判断
|
||||
if (mh.matchSuffix(urlString)) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取报文头
|
||||
List<String> tmpHeaders = helpers.analyzeRequest(controller.getHttpService(), content).getHeaders();
|
||||
String headers = String.join("\n", tmpHeaders);
|
||||
// 获取报文主体
|
||||
int bodyOffset = helpers.analyzeRequest(controller.getHttpService(), content).getBodyOffset();
|
||||
byte[] byteRequest = controller.getRequest();
|
||||
byte[] body = Arrays.copyOfRange(byteRequest, bodyOffset, byteRequest.length);
|
||||
|
||||
Map<String, Map<String, Object>> obj;
|
||||
String c = new String(content, StandardCharsets.UTF_8).intern();
|
||||
List<String> result = pm.processMessageByContent(helpers, content, isRequest, false);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
if (isRequest) {
|
||||
obj = ec.matchRegex(content, headers, body, "request");
|
||||
if (obj.size() != 0) {
|
||||
String result = da.extractString(obj);
|
||||
extractRequestContent = result.getBytes();
|
||||
return true;
|
||||
}
|
||||
this.extractRequestContent = result.get(0).getBytes();
|
||||
} else {
|
||||
obj = ec.matchRegex(content, headers, body, "response");
|
||||
if (obj.size() != 0) {
|
||||
String result = da.extractString(obj);
|
||||
extractResponseContent = result.getBytes();
|
||||
return true;
|
||||
this.extractResponseContent = result.get(0).getBytes();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessage() {
|
||||
return currentMessage;
|
||||
return this.currentMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return markInfoText.isTextModified();
|
||||
return this.markInfoText.isTextModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getSelectedData() {
|
||||
return markInfoText.getSelectedText();
|
||||
return this.markInfoText.getSelectedText();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -192,25 +154,20 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
*/
|
||||
@Override
|
||||
public void setMessage(byte[] content, boolean isRequest) {
|
||||
try {
|
||||
String c = new String(content, "UTF-8").intern();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
stdout.println(e);
|
||||
}
|
||||
String c = new String(content, StandardCharsets.UTF_8).intern();
|
||||
if (content.length > 0) {
|
||||
if (isRequest) {
|
||||
markInfoText.setText(extractRequestContent);
|
||||
this.markInfoText.setText(this.extractRequestContent);
|
||||
} else {
|
||||
markInfoText.setText(extractResponseContent);
|
||||
this.markInfoText.setText(this.extractResponseContent);
|
||||
}
|
||||
}
|
||||
currentMessage = content;
|
||||
this.currentMessage = content;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessageEditorTab createNewInstance(IMessageEditorController controller, boolean editable) {
|
||||
HaETab = new MarkInfoTab(controller, editable);
|
||||
return HaETab;
|
||||
return new MarkInfoTab(controller, editable);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ package burp;
|
||||
* @author EvilChen
|
||||
*/
|
||||
|
||||
import burp.yaml.LoadConfig;
|
||||
import java.util.Map;
|
||||
|
||||
public class Config {
|
||||
public static String excludeSuffix = "3g2|3gp|7z|aac|abw|aif|aifc|aiff|arc|au|avi|azw|bin|bmp|bz|bz2|cmx|cod|csh|css|csv|doc|docx|eot|epub|gif|gz|ico|ics|ief|jar|jfif|jpe|jpeg|jpg|m3u|mid|midi|mjs|mp2|mp3|mpa|mpe|mpeg|mpg|mpkg|mpp|mpv2|odp|ods|odt|oga|ogv|ogx|otf|pbm|pdf|pgm|png|pnm|ppm|ppt|pptx|ra|ram|rar|ras|rgb|rmi|rtf|snd|svg|swf|tar|tif|tiff|ttf|vsd|wav|weba|webm|webp|woff|woff2|xbm|xls|xlsx|xpm|xul|xwd|zip|zip";
|
||||
|
||||
@@ -35,4 +38,6 @@ public class Config {
|
||||
"magenta",
|
||||
"gray"
|
||||
};
|
||||
|
||||
public static Map<String,Object[][]> ruleConfig = LoadConfig.getRules();
|
||||
}
|
||||
@@ -21,13 +21,18 @@ public class DoAction {
|
||||
return result[0];
|
||||
}
|
||||
|
||||
public List<String> highlightList(Map<String, Map<String, Object>> obj) {
|
||||
List<String> colorList = new ArrayList<String>();
|
||||
public List<List<String>> highlightAndComment(Map<String, Map<String, Object>> obj) {
|
||||
List<String> colorList = new ArrayList<>();
|
||||
List<String> commentList = new ArrayList<>();
|
||||
List<List<String>> result = new ArrayList<>();
|
||||
obj.keySet().forEach(i->{
|
||||
Map<String, Object> tmpMap = obj.get(i);
|
||||
String color = tmpMap.get("color").toString();
|
||||
colorList.add(color);
|
||||
commentList.add(i);
|
||||
});
|
||||
return colorList;
|
||||
result.add(colorList);
|
||||
result.add(commentList);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package burp.action;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import burp.Config;
|
||||
import burp.yaml.LoadConfig;
|
||||
import dk.brics.automaton.Automaton;
|
||||
import dk.brics.automaton.AutomatonMatcher;
|
||||
import dk.brics.automaton.RegExp;
|
||||
@@ -10,25 +12,19 @@ import dk.brics.automaton.RunAutomaton;
|
||||
import jregex.Matcher;
|
||||
import jregex.Pattern;
|
||||
|
||||
import burp.yaml.LoadRule;
|
||||
import burp.yaml.LoadConfigFile;
|
||||
|
||||
/*
|
||||
* @author EvilChen
|
||||
*/
|
||||
|
||||
public class ExtractContent {
|
||||
private LoadConfigFile lcf = new LoadConfigFile();
|
||||
private LoadRule lr = new LoadRule(lcf.getConfigPath());
|
||||
|
||||
public Map<String, Map<String, Object>> matchRegex(byte[] content, String headers, byte[] body, String scopeString) {
|
||||
Map<String, Map<String, Object>> map = new HashMap<>(); // 最终返回的结果
|
||||
Map<String,Object[][]> rules = lr.getConfig();
|
||||
rules.keySet().forEach(i -> {
|
||||
Config.ruleConfig.keySet().forEach(i -> {
|
||||
String matchContent = "";
|
||||
for (Object[] objects : rules.get(i)) {
|
||||
for (Object[] objects : Config.ruleConfig.get(i)) {
|
||||
// 遍历获取规则
|
||||
List<String> result = new ArrayList<String>();
|
||||
List<String> result = new ArrayList<>();
|
||||
Map<String, Object> tmpMap = new HashMap<>();
|
||||
|
||||
String name = objects[1].toString();
|
||||
@@ -38,16 +34,12 @@ public class ExtractContent {
|
||||
String scope = objects[4].toString();
|
||||
String engine = objects[5].toString();
|
||||
// 判断规则是否开启与作用域
|
||||
if (loaded && (scopeString.contains(scope) || scope.equals("any"))) {
|
||||
if (loaded && (scope.contains(scopeString) || "any".equals(scope))) {
|
||||
switch (scope) {
|
||||
case "any":
|
||||
case "request":
|
||||
case "response":
|
||||
try {
|
||||
matchContent = new String(content, "UTF-8").intern();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
matchContent = new String(content, StandardCharsets.UTF_8).intern();
|
||||
break;
|
||||
case "request header":
|
||||
case "response header":
|
||||
@@ -55,15 +47,13 @@ public class ExtractContent {
|
||||
break;
|
||||
case "request body":
|
||||
case "response body":
|
||||
try {
|
||||
matchContent = new String(body, "UTF-8").intern();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
matchContent = new String(body, StandardCharsets.UTF_8).intern();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (engine.equals("nfa")) {
|
||||
if ("nfa".equals(engine)) {
|
||||
Pattern pattern = new Pattern(regex);
|
||||
Matcher matcher = pattern.matcher(matchContent);
|
||||
while (matcher.find()) {
|
||||
@@ -72,8 +62,8 @@ public class ExtractContent {
|
||||
result.add(matcher.group(1));
|
||||
}
|
||||
} else {
|
||||
RegExp regexpr = new RegExp(regex);
|
||||
Automaton auto = regexpr.toAutomaton();
|
||||
RegExp regexp = new RegExp(regex);
|
||||
Automaton auto = regexp.toAutomaton();
|
||||
RunAutomaton runAuto = new RunAutomaton(auto, true);
|
||||
AutomatonMatcher autoMatcher = runAuto.newMatcher(matchContent);
|
||||
while (autoMatcher.find()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package burp.action;
|
||||
|
||||
import burp.Config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,13 +12,14 @@ public class GetColorKey {
|
||||
/*
|
||||
* 颜色下标获取
|
||||
*/
|
||||
public List<Integer> getColorKeys(List<String> keys, String[] colorArray){
|
||||
List<Integer> result = new ArrayList<Integer>();
|
||||
public List<Integer> getColorKeys(List<String> keys){
|
||||
List<Integer> result = new ArrayList<>();
|
||||
String[] colorArray = Config.colorArray;
|
||||
int size = colorArray.length;
|
||||
// 根据颜色获取下标
|
||||
for (int x = 0; x < keys.size(); x++) {
|
||||
for (String key : keys) {
|
||||
for (int v = 0; v < size; v++) {
|
||||
if (colorArray[v].equals(keys.get(x))) {
|
||||
if (colorArray[v].equals(key)) {
|
||||
result.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package burp.action;
|
||||
import jregex.Matcher;
|
||||
import jregex.Pattern;
|
||||
import jregex.REFlags;
|
||||
import burp.yaml.LoadConfigFile;
|
||||
import burp.yaml.LoadConfig;
|
||||
|
||||
/*
|
||||
* @author EvilChen
|
||||
@@ -11,14 +11,10 @@ import burp.yaml.LoadConfigFile;
|
||||
|
||||
public class MatchHTTP {
|
||||
// 匹配后缀
|
||||
LoadConfigFile lc = new LoadConfigFile();
|
||||
LoadConfig lc = new LoadConfig();
|
||||
public boolean matchSuffix(String str) {
|
||||
Pattern pattern = new Pattern(String.format("[\\w]+[\\.](%s)", lc.getExcludeSuffix()), REFlags.IGNORE_CASE);
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
if(matcher.find()){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return matcher.find();
|
||||
}
|
||||
}
|
||||
|
||||
88
src/main/java/burp/action/ProcessMessage.java
Normal file
88
src/main/java/burp/action/ProcessMessage.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package burp.action;
|
||||
|
||||
import burp.IExtensionHelpers;
|
||||
import burp.IHttpService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProcessMessage {
|
||||
MatchHTTP mh = new MatchHTTP();
|
||||
ExtractContent ec = new ExtractContent();
|
||||
DoAction da = new DoAction();
|
||||
GetColorKey gck = new GetColorKey();
|
||||
UpgradeColor uc = new UpgradeColor();
|
||||
|
||||
public List<String> processMessageByContent(IExtensionHelpers helpers, byte[] content, boolean isRequest, boolean messageInfo) {
|
||||
List<String> result = new ArrayList<>();;
|
||||
Map<String, Map<String, Object>> obj;
|
||||
|
||||
if (isRequest) {
|
||||
|
||||
// 获取报文头
|
||||
List<String> requestTmpHeaders = helpers.analyzeRequest(content).getHeaders();
|
||||
String requestHeaders = String.join("\n", requestTmpHeaders);
|
||||
|
||||
try {
|
||||
// 流量清洗
|
||||
String urlString = requestTmpHeaders.get(0).split(" ")[1];
|
||||
urlString = urlString.indexOf("?") > 0 ? urlString.substring(0, urlString.indexOf("?")) : urlString;
|
||||
|
||||
// 正则判断
|
||||
if (mh.matchSuffix(urlString)) {
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 获取报文主体
|
||||
int requestBodyOffset = helpers.analyzeRequest(content).getBodyOffset();
|
||||
byte[] requestBody = Arrays.copyOfRange(content, requestBodyOffset, content.length);
|
||||
|
||||
obj = ec.matchRegex(content, requestHeaders, requestBody, "request");
|
||||
} else {
|
||||
try {
|
||||
// 流量清洗
|
||||
String inferredMimeType = String.format("hae.%s", helpers.analyzeResponse(content).getInferredMimeType().toLowerCase());
|
||||
String statedMimeType = String.format("hae.%s", helpers.analyzeResponse(content).getStatedMimeType().toLowerCase());
|
||||
// 正则判断
|
||||
if (mh.matchSuffix(statedMimeType) || mh.matchSuffix(inferredMimeType)) {
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return result;
|
||||
}
|
||||
// 获取报文头
|
||||
List<String> responseTmpHeaders = helpers.analyzeResponse(content).getHeaders();
|
||||
String responseHeaders = String.join("\n", responseTmpHeaders);
|
||||
|
||||
// 获取报文主体
|
||||
int responseBodyOffset = helpers.analyzeResponse(content).getBodyOffset();
|
||||
byte[] responseBody = Arrays.copyOfRange(content, responseBodyOffset, content.length);
|
||||
|
||||
obj = ec.matchRegex(content, responseHeaders, responseBody, "response");
|
||||
}
|
||||
|
||||
if (messageInfo) {
|
||||
List<List<String>> resultList = da.highlightAndComment(obj);
|
||||
List<String> colorList = resultList.get(0);
|
||||
List<String> commentList = resultList.get(1);
|
||||
if (colorList.size() != 0 && commentList.size() != 0) {
|
||||
String color = uc.getEndColor(gck.getColorKeys(colorList));
|
||||
result.add(color);
|
||||
result.add(String.join(", ", commentList));
|
||||
}
|
||||
} else {
|
||||
if (obj.size() > 0) {
|
||||
result.add(da.extractString(obj));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package burp.action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import burp.Config;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* @author EvilChen
|
||||
@@ -14,43 +13,40 @@ public class UpgradeColor {
|
||||
/*
|
||||
* 颜色升级递归算法
|
||||
*/
|
||||
private String colorUpgrade(List<Integer> colorList, String[] colorArray) {
|
||||
private void colorUpgrade(List<Integer> colorList) {
|
||||
int colorSize = colorList.size();
|
||||
String[] colorArray = Config.colorArray;
|
||||
colorList.sort(Comparator.comparingInt(Integer::intValue));
|
||||
int i = 0;
|
||||
List<Integer> stack = new ArrayList<Integer>();
|
||||
List<Integer> stack = new ArrayList<>();
|
||||
while (i < colorSize) {
|
||||
if (stack.isEmpty()) {
|
||||
stack.add(colorList.get(i));
|
||||
i++;
|
||||
} else {
|
||||
if (colorList.get(i) != stack.stream().reduce((first, second) -> second).orElse(99999999)) {
|
||||
if (!Objects.equals(colorList.get(i), stack.stream().reduce((first, second) -> second).orElse(99999999))) {
|
||||
stack.add(colorList.get(i));
|
||||
i++;
|
||||
} else {
|
||||
stack.set(stack.size() - 1, stack.get(stack.size() - 1) - 1);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 利用HashSet删除重复元素
|
||||
HashSet tmpList = new HashSet(stack);
|
||||
if (stack.size() == tmpList.size()) {
|
||||
stack.sort(Comparator.comparingInt(Integer::intValue));
|
||||
if(stack.get(0).equals(-1)) {
|
||||
if(stack.get(0) < 0) {
|
||||
this.endColor = colorArray[0];
|
||||
} else {
|
||||
this.endColor = colorArray[stack.get(0)];
|
||||
}
|
||||
} else {
|
||||
this.colorUpgrade(stack, colorArray);
|
||||
this.colorUpgrade(stack);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getEndColor(List<Integer> colorList, String[] colorArray) {
|
||||
colorUpgrade(colorList, colorArray);
|
||||
public String getEndColor(List<Integer> colorList) {
|
||||
colorUpgrade(colorList);
|
||||
return endColor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,8 @@ public class JTabbedPaneCloseButton extends JTabbedPane {
|
||||
|
||||
/* Button */
|
||||
public class CloseButtonTab extends JPanel {
|
||||
private Component tab;
|
||||
|
||||
public CloseButtonTab(final Component tab, String title, Icon icon) {
|
||||
this.tab = tab;
|
||||
setOpaque(false);
|
||||
FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 3, 3);
|
||||
setLayout(flowLayout);
|
||||
@@ -79,7 +77,7 @@ public class JTabbedPaneCloseButton extends JTabbedPane {
|
||||
/* ClickListener */
|
||||
public class CloseListener implements MouseListener
|
||||
{
|
||||
private Component tab;
|
||||
private final Component tab;
|
||||
|
||||
public CloseListener(Component tab){
|
||||
this.tab=tab;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package burp.ui;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import burp.yaml.LoadConfigFile;
|
||||
import burp.yaml.LoadRule;
|
||||
import burp.yaml.SetRuleConfig;
|
||||
import burp.Config;
|
||||
import burp.yaml.LoadConfig;
|
||||
import burp.yaml.SetConfig;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
@@ -20,19 +19,21 @@ import java.util.Map;
|
||||
*/
|
||||
|
||||
public class MainUI extends JPanel{
|
||||
private final LoadConfig loadConn = new LoadConfig();
|
||||
|
||||
public MainUI() {
|
||||
initComponents();
|
||||
}
|
||||
public void closeTabActionPerformed(ActionEvent e){
|
||||
if (tabbedPane1.getTabCount()>2){
|
||||
if (tabbedPane1.getSelectedIndex()!=0){
|
||||
SetRuleConfig setruleconfig = new SetRuleConfig();
|
||||
setruleconfig.deleteRules(tabbedPane1.getTitleAt(tabbedPane1.getSelectedIndex()));
|
||||
SetConfig setConn = new SetConfig();
|
||||
setConn.deleteRules(tabbedPane1.getTitleAt(tabbedPane1.getSelectedIndex()));
|
||||
tabbedPane1.remove(tabbedPane1.getSelectedIndex());
|
||||
tabbedPane1.setSelectedIndex(tabbedPane1.getSelectedIndex()-1);
|
||||
}else{
|
||||
SetRuleConfig setruleconfig = new SetRuleConfig();
|
||||
setruleconfig.deleteRules(tabbedPane1.getTitleAt(tabbedPane1.getSelectedIndex()));
|
||||
SetConfig setConn = new SetConfig();
|
||||
setConn.deleteRules(tabbedPane1.getTitleAt(tabbedPane1.getSelectedIndex()));
|
||||
tabbedPane1.remove(tabbedPane1.getSelectedIndex());
|
||||
tabbedPane1.setSelectedIndex(tabbedPane1.getSelectedIndex());
|
||||
}
|
||||
@@ -40,33 +41,25 @@ public class MainUI extends JPanel{
|
||||
}
|
||||
|
||||
private void SelectFileMouseClicked(MouseEvent e) {
|
||||
JFileChooser chooseconfig = new JFileChooser();
|
||||
chooseconfig.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
JFileChooser selectFile = new JFileChooser();
|
||||
selectFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Yaml File (.yml/.yaml)","yaml", "yml");
|
||||
chooseconfig.setFileFilter(filter);
|
||||
int selectframe = chooseconfig.showDialog(new JLabel(),"Select");
|
||||
selectFile.setFileFilter(filter);
|
||||
int selectframe = selectFile.showDialog(new JLabel(),"Select");
|
||||
if (selectframe == JFileChooser.APPROVE_OPTION){
|
||||
String configpath = chooseconfig.getSelectedFile().toString();
|
||||
reloadRule(configpath);
|
||||
loadfile.setConfigPath(configpath);
|
||||
String configpath = selectFile.getSelectedFile().toString();
|
||||
reloadRule();
|
||||
loadConn.setConfigPath(configpath);
|
||||
}
|
||||
configfilepathtext.setText(loadfile.getConfigPath());
|
||||
}
|
||||
private void reloadRule(String configfile){
|
||||
tabbedPane1.removeAll();
|
||||
LoadRule loadrule = new LoadRule(configfile);
|
||||
Map<String,Object[][]> config = loadrule.getConfig();
|
||||
ruleSwitch.setListen(false);
|
||||
config.keySet().forEach(i->tabbedPane1.addTab(i,new RulePane(config.get(i),tabbedPane1)));
|
||||
tabbedPane1.addTab("...",new JLabel());
|
||||
ruleSwitch.setListen(true);
|
||||
configFilepathtext.setText(LoadConfig.getConfigPath());
|
||||
reloadRule();
|
||||
}
|
||||
|
||||
private void reloadRule(){
|
||||
tabbedPane1.removeAll();
|
||||
LoadRule loadrule = new LoadRule(loadfile.getConfigPath());
|
||||
Map<String,Object[][]> config = loadrule.getConfig();
|
||||
ruleSwitch.setListen(false);
|
||||
config.keySet().forEach(i->tabbedPane1.addTab(i,new RulePane(config.get(i),tabbedPane1))
|
||||
Map<String,Object[][]> rules = LoadConfig.getRules();
|
||||
rules.keySet().forEach(i->tabbedPane1.addTab(i,new RulePane(Config.ruleConfig.get(i),tabbedPane1))
|
||||
);
|
||||
tabbedPane1.addTab("...",new JLabel());
|
||||
ruleSwitch.setListen(true);
|
||||
@@ -75,16 +68,16 @@ public class MainUI extends JPanel{
|
||||
private void reloadMouseClicked(MouseEvent e) {
|
||||
reloadRule();
|
||||
}
|
||||
|
||||
private void ESSaveMouseClicked(MouseEvent e) {
|
||||
// TODO add your code here
|
||||
LoadConfigFile lcf = new LoadConfigFile();
|
||||
lcf.setExcludeSuffix(EStext.getText());
|
||||
LoadConfig loadCon = new LoadConfig();
|
||||
loadCon.setExcludeSuffix(EStext.getText());
|
||||
}
|
||||
private void initComponents() {
|
||||
tabbedPane2 = new JTabbedPane();
|
||||
tabbedPane1 = new JTabbedPane();
|
||||
panel3 = new JPanel();
|
||||
configfilepathtext = new JTextField();
|
||||
configFilepathtext = new JTextField();
|
||||
label1 = new JLabel();
|
||||
SelectFile = new JButton();
|
||||
reload = new JButton();
|
||||
@@ -111,9 +104,9 @@ public class MainUI extends JPanel{
|
||||
((GridBagLayout)panel3.getLayout()).columnWeights = new double[] {0.0, 1.0, 0.0, 0.0, 1.0E-4};
|
||||
((GridBagLayout)panel3.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0E-4};
|
||||
|
||||
//---- configfilepathtext ----
|
||||
configfilepathtext.setEditable(false);
|
||||
panel3.add(configfilepathtext, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
|
||||
//---- configFilepathtext ----
|
||||
configFilepathtext.setEditable(false);
|
||||
panel3.add(configFilepathtext, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
|
||||
new Insets(5, 0, 5, 5), 0, 0));
|
||||
|
||||
@@ -175,16 +168,13 @@ public class MainUI extends JPanel{
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||
|
||||
LoadRule loadRule = new LoadRule(loadfile.getConfigPath());
|
||||
Map<String,Object[][]> config = loadRule.getConfig();
|
||||
config.keySet().forEach(i->tabbedPane1.addTab(i,new RulePane(config.get(i),tabbedPane1)));
|
||||
Config.ruleConfig.keySet().forEach(i->tabbedPane1.addTab(i,new RulePane(Config.ruleConfig.get(i),tabbedPane1)));
|
||||
|
||||
tabbedPane1.addTab("...",new JLabel());
|
||||
|
||||
//TabTitleEditListener ruleSwitch = new TabTitleEditListener(tabbedPane1);
|
||||
configfilepathtext.setText(loadfile.getConfigPath());
|
||||
LoadConfigFile lcf =new LoadConfigFile();
|
||||
EStext.setText(lcf.getExcludeSuffix());
|
||||
configFilepathtext.setText(LoadConfig.getConfigPath());
|
||||
EStext.setText(loadConn.getExcludeSuffix());
|
||||
ruleSwitch = new TabTitleEditListener(tabbedPane1);
|
||||
tabbedPane1.addChangeListener(ruleSwitch);
|
||||
tabbedPane1.addMouseListener(ruleSwitch);
|
||||
@@ -196,7 +186,7 @@ public class MainUI extends JPanel{
|
||||
private JTabbedPane tabbedPane2;
|
||||
private JTabbedPane tabbedPane1;
|
||||
private JPanel panel3;
|
||||
private JTextField configfilepathtext;
|
||||
private JTextField configFilepathtext;
|
||||
private JLabel label1;
|
||||
private JButton SelectFile;
|
||||
private JButton reload;
|
||||
@@ -207,7 +197,6 @@ public class MainUI extends JPanel{
|
||||
protected static JPopupMenu tabMenu = new JPopupMenu();
|
||||
private JMenuItem closeTab = new JMenuItem("Delete");
|
||||
private TabTitleEditListener ruleSwitch;
|
||||
private LoadConfigFile loadfile = new LoadConfigFile();
|
||||
}
|
||||
|
||||
class TabTitleEditListener extends MouseAdapter implements ChangeListener, DocumentListener {
|
||||
@@ -218,16 +207,14 @@ class TabTitleEditListener extends MouseAdapter implements ChangeListener, Docum
|
||||
protected Boolean listen = true;
|
||||
protected Dimension dim;
|
||||
protected Component tabComponent;
|
||||
protected Boolean isRenamesucc = false;
|
||||
protected LoadConfigFile loadfile = new LoadConfigFile();
|
||||
protected LoadRule lr = new LoadRule(loadfile.getConfigPath());
|
||||
protected SetRuleConfig setruleconfig = new SetRuleConfig();
|
||||
protected Boolean isRenameOk = false;
|
||||
protected SetConfig setConfig = new SetConfig();
|
||||
protected final Action startEditing = new AbstractAction() {
|
||||
@Override public void actionPerformed(ActionEvent e) {
|
||||
editingIdx = tabbedPane.getSelectedIndex();
|
||||
tabComponent = tabbedPane.getTabComponentAt(editingIdx);
|
||||
tabbedPane.setTabComponentAt(editingIdx, editor);
|
||||
isRenamesucc = true;
|
||||
isRenameOk = true;
|
||||
editor.setVisible(true);
|
||||
editor.setText(tabbedPane.getTitleAt(editingIdx));
|
||||
editor.selectAll();
|
||||
@@ -241,9 +228,9 @@ class TabTitleEditListener extends MouseAdapter implements ChangeListener, Docum
|
||||
@Override public void actionPerformed(ActionEvent e) {
|
||||
String title = editor.getText().trim();
|
||||
if (editingIdx >= 0 && !title.isEmpty()) {
|
||||
String oldname = tabbedPane.getTitleAt(editingIdx);
|
||||
String oldName = tabbedPane.getTitleAt(editingIdx);
|
||||
tabbedPane.setTitleAt(editingIdx, title);
|
||||
setruleconfig.rename(oldname,title);
|
||||
setConfig.rename(oldName,title);
|
||||
}
|
||||
cancelEditing.actionPerformed(null);
|
||||
}
|
||||
@@ -284,7 +271,7 @@ class TabTitleEditListener extends MouseAdapter implements ChangeListener, Docum
|
||||
@Override public void stateChanged(ChangeEvent e) {
|
||||
if (e.getSource() instanceof JTabbedPane && listen) {
|
||||
JTabbedPane pane = (JTabbedPane) e.getSource();
|
||||
if (!isRenamesucc){
|
||||
if (!isRenameOk){
|
||||
if (pane.getSelectedIndex() == pane.getComponentCount()-1){
|
||||
newTab();
|
||||
}
|
||||
@@ -298,9 +285,9 @@ class TabTitleEditListener extends MouseAdapter implements ChangeListener, Docum
|
||||
}
|
||||
public void newTab(){
|
||||
Object[][] data = new Object[][]{{false, "New Name", "(New Regex)", "gray", "any", "nfa"}};
|
||||
insertTab(tabbedPane,setruleconfig.newRules(),data);
|
||||
insertTab(tabbedPane, setConfig.newRules(),data);
|
||||
}
|
||||
public void insertTab(@NotNull JTabbedPane pane,String title,Object[][] data){
|
||||
public void insertTab(JTabbedPane pane,String title,Object[][] data){
|
||||
pane.addTab(title,new RulePane(data,pane));
|
||||
pane.remove(pane.getSelectedIndex());
|
||||
pane.addTab("...",new JLabel());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package burp.ui;
|
||||
|
||||
import burp.yaml.SetRuleConfig;
|
||||
import burp.yaml.SetConfig;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
@@ -20,25 +20,26 @@ public class RulePane extends JPanel {
|
||||
public RulePane(Object[][] data,JTabbedPane pane) {
|
||||
initComponents(data,pane);
|
||||
}
|
||||
private SetRuleConfig setruleconfig = new SetRuleConfig();
|
||||
private SetConfig setruleconfig = new SetConfig();
|
||||
private Boolean isEdit = false;
|
||||
private void RuleAddMouseClicked(MouseEvent e, JTabbedPane pane) {
|
||||
// TODO add your code here
|
||||
RuleSetting add = new RuleSetting();
|
||||
int isOk = JOptionPane.showConfirmDialog(null,add,"RuleSetting - Add Rule",JOptionPane.OK_OPTION);
|
||||
if(isOk == 0){
|
||||
model.addRow(new Object[0]);
|
||||
model.setValueAt(false,(model.getRowCount()-1),0);
|
||||
model.setValueAt(add.Name.getText(),(model.getRowCount()-1),1);
|
||||
model.setValueAt(add.Regex.getText(),(model.getRowCount()-1),2);
|
||||
model.setValueAt(add.ColorSelect.getSelectedItem().toString(),(model.getRowCount()-1),3);
|
||||
model.setValueAt(add.ScopeSelect.getSelectedItem().toString(),(model.getRowCount()-1),4);
|
||||
model.setValueAt(add.EngineSelect.getSelectedItem().toString(),(model.getRowCount()-1),5);
|
||||
Vector data = new Vector();
|
||||
data.add(false);
|
||||
data.add(add.Name.getText());
|
||||
data.add(add.Regex.getText());
|
||||
data.add(add.ColorSelect.getSelectedItem().toString());
|
||||
data.add(add.ScopeSelect.getSelectedItem().toString());
|
||||
data.add(add.EngineSelect.getSelectedItem().toString());
|
||||
model.insertRow(model.getRowCount(),data);
|
||||
model = (DefaultTableModel) table.getModel();
|
||||
int select = table.convertRowIndexToModel(table.getSelectedRow());
|
||||
setruleconfig.add((Vector) model.getDataVector().get(select),pane.getTitleAt(pane.getSelectedIndex()));
|
||||
setruleconfig.add(data,pane.getTitleAt(pane.getSelectedIndex()));
|
||||
}
|
||||
}
|
||||
|
||||
private void RuleEditMouseClicked(MouseEvent e,JTabbedPane pane){
|
||||
if (table.getSelectedRowCount()>=1){
|
||||
RuleSetting edit = new RuleSetting();
|
||||
@@ -60,18 +61,19 @@ public class RulePane extends JPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RuleRemoveMouseClicked(MouseEvent e,JTabbedPane pane){
|
||||
if (table.getSelectedRowCount()>=1){
|
||||
int isOk = JOptionPane.showConfirmDialog(null,"Are your sure?","RuleSetting - Delete Rule",JOptionPane.OK_OPTION);
|
||||
if (isOk==0){
|
||||
model.removeRow(table.convertRowIndexToModel(table.getSelectedRow()));
|
||||
table.remove(table.getSelectedRow());
|
||||
model = (DefaultTableModel) table.getModel();
|
||||
int select = table.convertRowIndexToModel(table.getSelectedRow());
|
||||
model.removeRow(select);
|
||||
model = (DefaultTableModel) table.getModel();
|
||||
setruleconfig.remove(select,pane.getTitleAt(pane.getSelectedIndex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RuleTableChange(TableModelEvent e,JTabbedPane pane) {
|
||||
if (e.getColumn()==0&&table.getSelectedRow()!=-1&&!isEdit){
|
||||
model = (DefaultTableModel) table.getModel();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class RuleSetting extends JPanel {
|
||||
Name = new JTextField();
|
||||
ScopeSelect = new JComboBox<>();
|
||||
EngineSelect = new JComboBox<>();
|
||||
label7 = new JLabel();
|
||||
label6 = new JLabel();
|
||||
ColorSelect = new JComboBox<>();
|
||||
|
||||
//======== this ========
|
||||
@@ -32,24 +32,24 @@ public class RuleSetting extends JPanel {
|
||||
//---- label5 ----
|
||||
label5.setText("Engine:");
|
||||
add(label5);
|
||||
label5.setBounds(10, 175, 50, 17);
|
||||
label5.setBounds(new Rectangle(new Point(10, 175), label5.getPreferredSize()));
|
||||
|
||||
//---- label4 ----
|
||||
label4.setText("Scope:");
|
||||
add(label4);
|
||||
label4.setBounds(10, 135, 50, 17);
|
||||
label4.setBounds(new Rectangle(new Point(10, 135), label4.getPreferredSize()));
|
||||
add(Regex);
|
||||
Regex.setBounds(70, 50, 265, 30);
|
||||
|
||||
//---- label3 ----
|
||||
label3.setText("Regex:");
|
||||
add(label3);
|
||||
label3.setBounds(10, 55, 50, 17);
|
||||
label3.setBounds(new Rectangle(new Point(10, 55), label3.getPreferredSize()));
|
||||
|
||||
//---- label2 ----
|
||||
label2.setText("Name:");
|
||||
add(label2);
|
||||
label2.setBounds(10, 15, 50, 17);
|
||||
label2.setBounds(new Rectangle(new Point(10, 15), label2.getPreferredSize()));
|
||||
add(Name);
|
||||
Name.setBounds(70, 10, 265, 30);
|
||||
|
||||
@@ -64,9 +64,9 @@ public class RuleSetting extends JPanel {
|
||||
EngineSelect.setBounds(70, 170, 265, EngineSelect.getPreferredSize().height);
|
||||
|
||||
//---- label7 ----
|
||||
label7.setText("Color:");
|
||||
add(label7);
|
||||
label7.setBounds(new Rectangle(new Point(10, 95), label7.getPreferredSize()));
|
||||
label6.setText("Color:");
|
||||
add(label6);
|
||||
label6.setBounds(new Rectangle(new Point(10, 95), label6.getPreferredSize()));
|
||||
|
||||
//---- ColorSelect ----
|
||||
ColorSelect.setModel(new DefaultComboBoxModel<>(Config.colorArray));
|
||||
@@ -99,7 +99,7 @@ public class RuleSetting extends JPanel {
|
||||
public JTextField Name;
|
||||
public JComboBox<String> ScopeSelect;
|
||||
public JComboBox<String> EngineSelect;
|
||||
private JLabel label7;
|
||||
private JLabel label6;
|
||||
public JComboBox<String> ColorSelect;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
}
|
||||
|
||||
157
src/main/java/burp/yaml/LoadConfig.java
Normal file
157
src/main/java/burp/yaml/LoadConfig.java
Normal file
@@ -0,0 +1,157 @@
|
||||
package burp.yaml;
|
||||
|
||||
import burp.Config;
|
||||
import burp.yaml.template.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
public class LoadConfig {
|
||||
private static final Yaml yaml = new Yaml();
|
||||
private static final String SettingPath = "Setting.yml";
|
||||
private static final String ConfigPath = "Config.yml";
|
||||
|
||||
public LoadConfig() {
|
||||
// 构造函数,初始化配置
|
||||
File yamlSetting = new File(SettingPath);
|
||||
if (!(yamlSetting.exists() && yamlSetting.isFile())) {
|
||||
initSetting();
|
||||
initRules();
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化设置信息
|
||||
public void initSetting() {
|
||||
Map<String, Object> r = new HashMap<>();
|
||||
r.put("configPath", ConfigPath);
|
||||
r.put("excludeSuffix", getExcludeSuffix());
|
||||
try {
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath), StandardCharsets.UTF_8);
|
||||
yaml.dump(r, ws);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化规则配置
|
||||
public void initRules() {
|
||||
Rule rule = new Rule();
|
||||
rule.setLoaded(true);
|
||||
rule.setName("Email");
|
||||
rule.setColor("yellow");
|
||||
rule.setEngine("nfa");
|
||||
rule.setScope("response");
|
||||
rule.setRegex("(([a-zA-Z0-9][_|\\.])*[a-zA-Z0-9]+@([a-zA-Z0-9][-|_|\\.])*[a-zA-Z0-9]+\\.((?!js|css|jpg|jpeg|png|ico)[a-zA-Z]{2,}))");
|
||||
Rules rules = new Rules();
|
||||
rules.setType("Basic Information");
|
||||
ArrayList<Rule> rl = new ArrayList<>();
|
||||
rl.add(rule);
|
||||
rules.setRule(rl);
|
||||
ArrayList<Rules> rls = new ArrayList<>();
|
||||
rls.add(rules);
|
||||
RulesConfig config = new RulesConfig();
|
||||
config.setRules(rls);
|
||||
|
||||
DumperOptions dop = new DumperOptions();
|
||||
dop.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Representer representer = new Representer();
|
||||
representer.addClassTag(Config.class, Tag.MAP);
|
||||
|
||||
Yaml yaml = new Yaml(new Constructor(),representer,dop);
|
||||
File f = new File(ConfigPath);
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8);
|
||||
yaml.dump(config,ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取配置路径
|
||||
public static String getConfigPath(){
|
||||
try {
|
||||
InputStream inorder = new FileInputStream(SettingPath);
|
||||
Map<String,Object> r = yaml.load(inorder);
|
||||
return r.get("configPath").toString();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return ConfigPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 获取不包含的后缀名
|
||||
public String getExcludeSuffix(){
|
||||
try {
|
||||
InputStream inorder = new FileInputStream(SettingPath);
|
||||
Map<String,Object> r = yaml.load(inorder);
|
||||
return r.get("excludeSuffix").toString();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return Config.excludeSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取规则配置
|
||||
public static Map<String,Object[][]> getRules(){
|
||||
InputStream inorder = null;
|
||||
{
|
||||
try {
|
||||
inorder = new FileInputStream(getConfigPath());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Yaml yaml = new Yaml(new Constructor(RulesConfig.class));
|
||||
RulesConfig rulesConfig = yaml.loadAs(inorder, RulesConfig.class);
|
||||
Map<String,Object[][]> resRule = new HashMap<>();
|
||||
rulesConfig.rules.forEach(i->{
|
||||
ArrayList<Object[]> data = new ArrayList<>();
|
||||
i.rule.forEach(j->{
|
||||
try {
|
||||
data.add(j.getRuleObject());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
resRule.put(i.getType(), data.toArray(new Object[data.size()][]));
|
||||
});
|
||||
return resRule;
|
||||
}
|
||||
|
||||
// 设置配置路径
|
||||
public void setConfigPath(String filePath){
|
||||
Map<String,Object> r = new HashMap<>();
|
||||
r.put("configPath", filePath);
|
||||
r.put("excludeSuffix", getExcludeSuffix());
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath), StandardCharsets.UTF_8);
|
||||
yaml.dump(r, ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 设置不包含的后缀名
|
||||
public void setExcludeSuffix(String excludeSuffix){
|
||||
Map<String,Object> r = new HashMap<>();
|
||||
r.put("configPath", getConfigPath());
|
||||
r.put("excludeSuffix", excludeSuffix);
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath), StandardCharsets.UTF_8);
|
||||
yaml.dump(r, ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package burp.yaml;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* @author LinChen
|
||||
*/
|
||||
|
||||
public class LoadConfigFile {
|
||||
private static Yaml yaml = new Yaml();
|
||||
private static final String SettingPath = "Setting.yml";
|
||||
private static final String ConfigPath = "Config.yml";
|
||||
|
||||
public LoadConfigFile(){
|
||||
init();
|
||||
}
|
||||
|
||||
// 初始化配置
|
||||
public void init(){
|
||||
File yamlSetting = new File(SettingPath);
|
||||
if (!(yamlSetting.exists() && yamlSetting.isFile())) {
|
||||
Map<String,Object> r = new HashMap<>();
|
||||
r.put("configPath", ConfigPath);
|
||||
r.put("excludeSuffix", getExcludeSuffix());
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath),"UTF-8");
|
||||
yaml.dump(r, ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getExcludeSuffix(){
|
||||
try {
|
||||
InputStream inorder = new FileInputStream(SettingPath);
|
||||
Map<String,Object> r;
|
||||
r = yaml.load(inorder);
|
||||
return r.get("excludeSuffix").toString();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return "css|jpeg|gif|jpg|png|pdf|rar|zip|docx|doc|svg|jpeg|ico|woff|woff2|ttf|otf";
|
||||
}
|
||||
}
|
||||
|
||||
public String getConfigPath(){
|
||||
try {
|
||||
InputStream inorder = new FileInputStream(SettingPath);
|
||||
Map<String,Object> r;
|
||||
r = yaml.load(inorder);
|
||||
return r.get("configPath").toString();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return ConfigPath;
|
||||
}
|
||||
}
|
||||
|
||||
public void setExcludeSuffix(@NotNull String excludeSuffix){
|
||||
Map<String,Object> r = new HashMap<>();
|
||||
r.put("excludeSuffix", excludeSuffix);
|
||||
r.put("configPath", getConfigPath());
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath),"UTF-8");
|
||||
yaml.dump(r, ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfigPath(@NotNull String filePath){
|
||||
Map<String,Object> r = new HashMap<>();
|
||||
r.put("configPath", filePath);
|
||||
r.put("excludeSuffix", getExcludeSuffix());
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath),"UTF-8");
|
||||
yaml.dump(r, ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package burp.yaml;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* @author LinChen
|
||||
*/
|
||||
|
||||
public class LoadRule {
|
||||
private static String filePath = "Config.yml";
|
||||
public LoadRule(String configfile){
|
||||
init();
|
||||
filePath = configfile;
|
||||
}
|
||||
|
||||
// 初始化配置
|
||||
public void init(){
|
||||
File settingyaml = new File(filePath);
|
||||
if (!(settingyaml.exists() && settingyaml.isFile())){
|
||||
Map<String,Object[][]> r = new HashMap<>();
|
||||
Rule rule = new Rule();
|
||||
rule.setLoaded(true);
|
||||
rule.setName("Email");
|
||||
rule.setColor("yellow");
|
||||
rule.setEngine("nfa");
|
||||
rule.setScope("response");
|
||||
rule.setRegex("(([a-zA-Z0-9][_|\\.])*[a-zA-Z0-9]+@([a-zA-Z0-9][-|_|\\.])*[a-zA-Z0-9]+\\.((?!js|css|jpg|jpeg|png|ico)[a-zA-Z]{2,}))");
|
||||
Rules rules = new Rules();
|
||||
rules.setType("Basic Information");
|
||||
ArrayList<Rule> rl = new ArrayList<>();
|
||||
rl.add(rule);
|
||||
rules.setRule(rl);
|
||||
ArrayList<Rules> rls = new ArrayList<>();
|
||||
rls.add(rules);
|
||||
Config config = new Config();
|
||||
config.setRules(rls);
|
||||
|
||||
DumperOptions dop = new DumperOptions();
|
||||
dop.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Representer representer = new Representer();
|
||||
representer.addClassTag(Config.class, Tag.MAP);
|
||||
|
||||
Yaml yaml = new Yaml(new Constructor(),representer,dop);
|
||||
LoadConfigFile loadfile = new LoadConfigFile();
|
||||
File f = new File(loadfile.getConfigPath());
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(f),"UTF-8");
|
||||
yaml.dump(config,ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String,Object[][]> getConfig(){
|
||||
InputStream inorder = null;
|
||||
{
|
||||
try {
|
||||
inorder = new FileInputStream(new File(filePath));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Yaml yaml = new Yaml(new Constructor(Config.class));
|
||||
Config plugin = yaml.loadAs(inorder, Config.class);
|
||||
Map<String,Object[][]> config = new HashMap<>();
|
||||
plugin.rules.forEach(i->{
|
||||
ArrayList<Object[]> data = new ArrayList<>();
|
||||
i.rule.forEach(j->{
|
||||
try {
|
||||
data.add(j.getRuleObject());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
config.put(i.getType(), data.toArray(new Object[data.size()][]));
|
||||
});
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,11 @@
|
||||
package burp.yaml;
|
||||
|
||||
import java.util.List;
|
||||
import burp.yaml.template.Rules;
|
||||
|
||||
/*
|
||||
* @author LinChen
|
||||
*/
|
||||
|
||||
public class Config {
|
||||
public class RulesConfig {
|
||||
public List<Rules> rules;
|
||||
|
||||
public List<Rules> getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public void setRules(List<Rules> rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
100
src/main/java/burp/yaml/SetConfig.java
Normal file
100
src/main/java/burp/yaml/SetConfig.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package burp.yaml;
|
||||
|
||||
import burp.Config;
|
||||
import burp.yaml.template.Rule;
|
||||
import burp.yaml.template.Rules;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
public class SetConfig {
|
||||
|
||||
public void format() {
|
||||
DumperOptions dop = new DumperOptions();
|
||||
dop.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Representer representer = new Representer();
|
||||
representer.addClassTag(RulesConfig.class, Tag.MAP);
|
||||
Yaml yaml = new Yaml(new Constructor(), representer, dop);
|
||||
RulesConfig con = new RulesConfig();
|
||||
List<Rules> rls = new ArrayList<>();
|
||||
|
||||
Config.ruleConfig.keySet().forEach(i->
|
||||
{
|
||||
Rules rlsTmp = new Rules();
|
||||
rlsTmp.setType(i);
|
||||
List<Rule> rl = new ArrayList<>();
|
||||
for (Object[] objects : Config.ruleConfig.get(i)) {
|
||||
Rule rlTmp = new Rule();
|
||||
rlTmp.setName((String) objects[1]);
|
||||
rlTmp.setLoaded((Boolean) objects[0]);
|
||||
rlTmp.setRegex((String) objects[2]);
|
||||
rlTmp.setColor((String) objects[3]);
|
||||
rlTmp.setScope((String) objects[4]);
|
||||
rlTmp.setEngine((String) objects[5]);
|
||||
rl.add(rlTmp);
|
||||
}
|
||||
rlsTmp.setRule(rl);
|
||||
rls.add(rlsTmp);
|
||||
});
|
||||
con.setRules(rls);
|
||||
File f = new File(LoadConfig.getConfigPath());
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8);
|
||||
yaml.dump(con,ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void edit(Vector data, int select, String type) {
|
||||
Config.ruleConfig.get(type)[select] = data.toArray();
|
||||
this.format();
|
||||
}
|
||||
|
||||
public void add(Vector data, String type) {
|
||||
ArrayList<Object[]> x = new ArrayList<>(Arrays.asList(Config.ruleConfig.get(type)));
|
||||
x.add(data.toArray());
|
||||
Config.ruleConfig.put(type,x.toArray(new Object[x.size()][]));
|
||||
this.format();
|
||||
}
|
||||
public void remove(int select,String type) {
|
||||
ArrayList<Object[]> x = new ArrayList<>(Arrays.asList(Config.ruleConfig.get(type)));
|
||||
x.remove(select);
|
||||
Config.ruleConfig.put(type,x.toArray(new Object[x.size()][]));
|
||||
this.format();
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) {
|
||||
Config.ruleConfig.put(newName, Config.ruleConfig.remove(oldName));
|
||||
this.format();
|
||||
}
|
||||
|
||||
public void deleteRules(String Rules) {
|
||||
Config.ruleConfig.remove(Rules);
|
||||
this.format();
|
||||
}
|
||||
public String newRules() {
|
||||
int i = 0;
|
||||
String name = "New ";
|
||||
Object[][] data = new Object[][]{
|
||||
{
|
||||
false, "New Name", "(New Regex)", "gray", "any", "nfa"
|
||||
}
|
||||
};
|
||||
while (Config.ruleConfig.containsKey(name + i)) {
|
||||
i++;
|
||||
}
|
||||
Config.ruleConfig.put(name + i, data);
|
||||
this.format();
|
||||
return name + i;
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package burp.yaml;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
public class SetRuleConfig {
|
||||
private static Yaml yaml;
|
||||
private static LoadConfigFile loadfile;
|
||||
private static LoadRule lr;
|
||||
private Map<String,Object[][]> config = lr.getConfig();
|
||||
public void format(){
|
||||
DumperOptions dop = new DumperOptions();
|
||||
dop.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Representer representer = new Representer();
|
||||
representer.addClassTag(Config.class, Tag.MAP);
|
||||
yaml = new Yaml(new Constructor(),representer,dop);
|
||||
Config con = new Config();
|
||||
List<Rules> rls = new ArrayList<>();
|
||||
|
||||
config.keySet().forEach(i->
|
||||
{
|
||||
Rules rlstmp = new Rules();
|
||||
rlstmp.setType(i);
|
||||
List<Rule> rl = new ArrayList<>();
|
||||
for (Object[] objects : config.get(i)) {
|
||||
Rule rltmp = new Rule();
|
||||
rltmp.setName((String) objects[1]);
|
||||
rltmp.setLoaded((Boolean) objects[0]);
|
||||
rltmp.setRegex((String) objects[2]);
|
||||
rltmp.setColor((String) objects[3]);
|
||||
rltmp.setScope((String) objects[4]);
|
||||
rltmp.setEngine((String) objects[5]);
|
||||
rl.add(rltmp);
|
||||
}
|
||||
rlstmp.setRule(rl);
|
||||
rls.add(rlstmp);
|
||||
});
|
||||
con.setRules(rls);
|
||||
File f = new File(loadfile.getConfigPath());
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(new FileOutputStream(f),"UTF-8");
|
||||
yaml.dump(con,ws);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void edit(Vector data,int select, String type){
|
||||
loadfile = new LoadConfigFile();
|
||||
lr = new LoadRule(loadfile.getConfigPath());
|
||||
config = lr.getConfig();
|
||||
config.get(type)[select] = data.toArray();
|
||||
this.format();
|
||||
}
|
||||
public void add(Vector data,String type){
|
||||
loadfile = new LoadConfigFile();
|
||||
lr = new LoadRule(loadfile.getConfigPath());
|
||||
config = lr.getConfig();
|
||||
ArrayList<Object[]> x = new ArrayList<Object[]>(Arrays.asList(config.get(type)));
|
||||
x.add(data.toArray());
|
||||
config.put(type,x.toArray(new Object[x.size()][]));
|
||||
this.format();
|
||||
}
|
||||
public void remove(int select,String type){
|
||||
loadfile = new LoadConfigFile();
|
||||
lr = new LoadRule(loadfile.getConfigPath());
|
||||
config = lr.getConfig();
|
||||
ArrayList<Object[]> x = new ArrayList<Object[]>(Arrays.asList(config.get(type)));
|
||||
x.remove(select);
|
||||
config.put(type,x.toArray(new Object[x.size()][]));
|
||||
this.format();
|
||||
}
|
||||
public void rename(String oldname,String newname){
|
||||
loadfile = new LoadConfigFile();
|
||||
lr = new LoadRule(loadfile.getConfigPath());
|
||||
config = lr.getConfig();
|
||||
config.put(newname,config.remove(oldname));
|
||||
this.format();
|
||||
}
|
||||
public void deleteRules(String Rules){
|
||||
loadfile = new LoadConfigFile();
|
||||
lr = new LoadRule(loadfile.getConfigPath());
|
||||
config = lr.getConfig();
|
||||
config.remove(Rules);
|
||||
this.format();
|
||||
}
|
||||
public String newRules(){
|
||||
int i = 0;
|
||||
loadfile = new LoadConfigFile();
|
||||
lr = new LoadRule(loadfile.getConfigPath());
|
||||
config = lr.getConfig();
|
||||
String name = "New ";
|
||||
Object[][] data = new Object[][]{{false,"newName","newRegex","gray","any","nfa"}};
|
||||
while (config.containsKey(name+i)){
|
||||
i++;
|
||||
}
|
||||
config.put(name+i,data);
|
||||
this.format();
|
||||
return name+i;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package burp.yaml;
|
||||
package burp.yaml.template;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -14,20 +14,10 @@ public class Rule {
|
||||
private String Color;
|
||||
private String Engine;
|
||||
private String Scope;
|
||||
private String Action;
|
||||
|
||||
public Boolean getLoaded() {
|
||||
return Loaded;
|
||||
}
|
||||
|
||||
public void setLoaded(Boolean loaded) {
|
||||
this.Loaded = loaded;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return Action;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return Color;
|
||||
}
|
||||
@@ -48,6 +38,11 @@ public class Rule {
|
||||
return Scope;
|
||||
}
|
||||
|
||||
public void setLoaded(Boolean loaded) {
|
||||
this.Loaded = loaded;
|
||||
}
|
||||
|
||||
|
||||
public void setColor(String color) {
|
||||
this.Color = color;
|
||||
}
|
||||
@@ -67,9 +62,11 @@ public class Rule {
|
||||
public void setScope(String scope) {
|
||||
this.Scope = scope;
|
||||
}
|
||||
|
||||
public Object[] getRuleObject() {
|
||||
return new Object[] { Loaded, Name, Regex, Color, Scope, Engine };
|
||||
}
|
||||
|
||||
public Map<String, Object> getRuleObjMap(){
|
||||
Map<String,Object> r = new HashMap<>();
|
||||
r.put("Loaded", Loaded);
|
||||
@@ -80,6 +77,7 @@ public class Rule {
|
||||
r.put("Engine", Engine);
|
||||
return r;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "{ \nLoaded: " + Loaded + "\nName: " + Name + "\nRegex: " + Regex + "\nColor: " + Color + "\nScope: " + Scope + "\nEngine: " + Engine + "\n}";
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
package burp.yaml;
|
||||
package burp.yaml.template;
|
||||
|
||||
import burp.yaml.template.Rule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user