Version: 2.0 Update
This commit is contained in:
19
src/main/java/burp/yaml/Config.java
Normal file
19
src/main/java/burp/yaml/Config.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package burp.yaml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author LinChen
|
||||
*/
|
||||
|
||||
public class Config {
|
||||
public List<Rules> rules;
|
||||
|
||||
public List<Rules> getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public void setRules(List<Rules> rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
}
|
||||
86
src/main/java/burp/yaml/LoadConfigFile.java
Normal file
86
src/main/java/burp/yaml/LoadConfigFile.java
Normal file
@@ -0,0 +1,86 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/main/java/burp/yaml/LoadRule.java
Normal file
89
src/main/java/burp/yaml/LoadRule.java
Normal file
@@ -0,0 +1,89 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
86
src/main/java/burp/yaml/Rule.java
Normal file
86
src/main/java/burp/yaml/Rule.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package burp.yaml;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* @author LinChen
|
||||
*/
|
||||
|
||||
public class Rule {
|
||||
private String Name;
|
||||
private Boolean Loaded;
|
||||
private String Regex;
|
||||
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;
|
||||
}
|
||||
|
||||
public String getEngine() {
|
||||
return Engine;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public String getRegex() {
|
||||
return Regex;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return Scope;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.Color = color;
|
||||
}
|
||||
|
||||
public void setEngine(String engine) {
|
||||
this.Engine = engine;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
public void setRegex(String regex) {
|
||||
this.Regex = regex;
|
||||
}
|
||||
|
||||
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);
|
||||
r.put("Name",Name);
|
||||
r.put("Regex",Regex);
|
||||
r.put("Color",Color);
|
||||
r.put("Scope",Scope);
|
||||
r.put("Engine",Engine);
|
||||
return r;
|
||||
}
|
||||
public String toString(){
|
||||
return "{ \nLoaded: "+Loaded+"\nName: "+Name+"\nRegex: "+Regex+"\nColor: "+Color+"\nScope: "+Scope+"\nEngine: "+Engine+"\n}";
|
||||
}
|
||||
}
|
||||
35
src/main/java/burp/yaml/Rules.java
Normal file
35
src/main/java/burp/yaml/Rules.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package burp.yaml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author LinChen
|
||||
*/
|
||||
|
||||
public class Rules {
|
||||
private String type;
|
||||
public List<Rule> rule;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<Rule> getRule() {
|
||||
return rule;
|
||||
}
|
||||
|
||||
public void setRule(List<Rule> rule) {
|
||||
this.rule = rule;
|
||||
}
|
||||
|
||||
public void setRuleObj(){
|
||||
|
||||
}
|
||||
public String toString(){
|
||||
return "{ type: "+type+"\n config: "+ rule +"}\n";
|
||||
}
|
||||
}
|
||||
109
src/main/java/burp/yaml/SetRuleConfig.java
Normal file
109
src/main/java/burp/yaml/SetRuleConfig.java
Normal file
@@ -0,0 +1,109 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user