-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFortifyRuleDecrypter.java
64 lines (57 loc) · 2.35 KB
/
FortifyRuleDecrypter.java
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
import java.io.*;
import static com.fortify.util.CryptoUtil.decryptCompressed;
public class FortifyRuleDecrypter {
private String ruleDir;
private String saveDir;
FortifyRuleDecrypter(String ruleDir,String saveDir){
this.ruleDir = ruleDir;
this.saveDir = saveDir;
}
public void doDecrypt(){
File encryptRule = new File(ruleDir);
// 传入的是文件
if(encryptRule.isFile()) {
if(encryptRule.getName().endsWith(".bin")) {
decryptRule(encryptRule, new File(saveDir + File.separator + encryptRule.getName() + ".xml"));
}else{
System.out.println("[-] The rule file suffix is.bin!");
System.exit(0);
}
}
//传入是目录
if (encryptRule.isDirectory()) {
File[] listFile = encryptRule.listFiles();
for(File file:listFile){
if(file.getName().endsWith(".bin")){
File saveName = new File(saveDir + File.separator + file.getName().replace(".bin","") + ".xml");
decryptRule(file,saveName);
}
}
}
}
public void decryptRule(File encFile, File decFile){
try {
//调用decryptCompressed()对规则库进行解密
InputStream ruleStream = decryptCompressed(new FileInputStream(encFile), null);
OutputStream outputStream = new FileOutputStream(decFile);
byte[] b = new byte[1024];
while ((ruleStream.read(b)) != -1) {
outputStream.write(b);
}
ruleStream.close();
outputStream.close();
System.out.println(String.format("[+] success %s -> %s",encFile.getName(),decFile.getAbsolutePath()));
}catch (Exception e){
System.out.println(String.format("[-] fail %s -> %s",encFile.getName(),decFile.getAbsolutePath()));
e.printStackTrace();
}
}
public static void main(String[] args) {
if(args.length != 2){
System.out.println("Usage: java -jar FortifyRuleDecrypter.jar [rule_dir|rule_file] <save_dir>");
System.exit(0);
}
FortifyRuleDecrypter decrypter = new FortifyRuleDecrypter(args[0],args[1]);
decrypter.doDecrypt();
}
}