Files
HaE/src/main/java/burp/rule/utils/RuleTool.java

53 lines
2.0 KiB
Java
Raw Normal View History

2023-10-12 21:38:27 +08:00
package burp.rule.utils;
2023-10-19 22:42:54 +08:00
import burp.*;
2023-10-12 21:38:27 +08:00
import java.io.FileOutputStream;
2023-10-19 22:42:54 +08:00
import java.net.URL;
import java.util.Arrays;
2023-10-12 21:38:27 +08:00
import javax.swing.JOptionPane;
/**
* @author EvilChen
*/
public class RuleTool {
private String rulesFilePath;
2023-10-25 16:02:07 +08:00
private boolean isSuccess;
2023-10-12 21:38:27 +08:00
public RuleTool(String rulesFilePath) {
this.rulesFilePath = rulesFilePath;
}
public void getRulesFromSite() {
2023-10-19 22:42:54 +08:00
// 以独立线程使用BurpSuite官方请求接口获取规则
Thread t = new Thread(()->{
try {
URL url = new URL("https://cdn.jsdelivr.net/gh/gh0stkey/HaE@gh-pages/Rules.yml");
IHttpService iHttpService = BurpExtender.helpers.buildHttpService(url.getHost(), 443, true);
IHttpRequestResponse iHttpRequestResponse = BurpExtender.callbacks.makeHttpRequest(iHttpService, BurpExtender.helpers.buildHttpRequest(url));
byte[] responseByte = iHttpRequestResponse.getResponse();
IResponseInfo iResponseInfo = BurpExtender.helpers.analyzeResponse(responseByte);
int bodyOffset = iResponseInfo.getBodyOffset();
byte[] responseBodyByte = Arrays.copyOfRange(responseByte, bodyOffset, responseByte.length);
FileOutputStream fileOutputStream = new FileOutputStream(this.rulesFilePath);
fileOutputStream.write(responseBodyByte);
fileOutputStream.close();
2023-10-25 16:02:07 +08:00
isSuccess = true;
2023-10-19 22:42:54 +08:00
} catch (Exception e) {
2023-10-25 16:02:07 +08:00
isSuccess = false;
2023-10-19 22:42:54 +08:00
}
});
t.start();
2023-10-12 21:38:27 +08:00
try {
2023-10-25 16:02:07 +08:00
t.join(10000);
2023-10-19 22:42:54 +08:00
} catch (Exception e) {
2023-10-25 16:02:07 +08:00
isSuccess = false;
}
if (isSuccess) {
JOptionPane.showMessageDialog(null, "Rules update successfully!", "Info", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Rule update failed, please check the network!", "Error", JOptionPane.ERROR_MESSAGE);
2023-10-12 21:38:27 +08:00
}
}
}