/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.util.*;
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import org.w3c.dom.*;
import weblogic.security.internal.*; // requires weblogic.jar in the class path
import weblogic.security.internal.encryption.*;
/**
*
* weblogic密碼忘記破解方法
* 獲取到weblogic安裝目錄下的兩個文件 SerializedSystemIni.dat、 boot.properties
* (weblogic8上面兩個文件在的bea/user_projects/domains/mydomain 目錄下)
* (welogic10 SerializedSystemIni.dat在bea/user_projects/domains/base_domain/security中)
* (welogic10 boot.properties在bea/user_projects/domains/base_domain/servers/AdminServer/security中)
* 加入weblogic.jar (weblogic安裝目錄中尋找,不同版本有可能不同)文件添加至構建路徑,
* welogic10以上版本如果運行還缺少別的類可以把weblogic的/wlserver_10.3/server/lib下的jar都添加到構建路徑
* @author
*
*/
public class JavaApplication1 {
private static final String PREFIX = "{AES}";//查看boot.properties文件 加密方式{3DES}或者{AES}
private static final String XPATH_EXPRESSION
= "//node()[starts-with(text(), '" + PREFIX + "')] | //@*[starts-with(., '" + PREFIX + "')]";
private static ClearOrEncryptedService ces;
public static void main(String[] args) throws Exception {
//E:/weblogic10 中的SerializedSystemIni.dat存放目錄
ces = new ClearOrEncryptedService(SerializedSystemIni.getEncryptionService(new File("/Users/z/Desktop/").getAbsolutePath()));
File file = new File("/Users/z/Desktop/boot.properties");
if (file.getName().endsWith(".xml")) {//有些可能是xml文件來的?
processXml(file);
}
else if (file.getName().endsWith(".properties")){
processProperties(file);
}
}
private static void processXml(File file) throws Exception {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
XPathExpression expr = XPathFactory.newInstance().newXPath().compile(XPATH_EXPRESSION);
NodeList nodes = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
print(node.getNodeName(), node.getTextContent());
}
}
private static void processProperties(File file) throws Exception {
Properties properties = new Properties();
properties.load(new FileInputStream(file));
for (Map.Entry p : properties.entrySet()) {
if (p.getValue().toString().startsWith(PREFIX)) {
print(p.getKey(), p.getValue());
}
}
}
private static void print(Object attributeName, Object encrypted) {
System.out.println("Node name: " + attributeName);
System.out.println("Encrypted: " + encrypted);
System.out.println("Decrypted: " + new String( ces.decryptBytes(encrypted.toString().getBytes())) + "\n");
}
}