一個N久的服務,維護的人換了好幾個了,今天忽然想進去看看裏面datasource,一問沒人知道密碼。。。因而就上網小抄了一段程序,用於破解weblogic console的用戶名和密碼。html
首先在weblogic安裝目錄下找到兩個文件SerializedSystemIni.dat、 boot.properties,位置你們能夠本身搜索一下。java
而後上代碼:node
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 WebLogicDecryptor { 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("E:/weblogic10").getAbsolutePath())); File file = new File("E:/weblogic10/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: " + ces.decrypt((String)encrypted) + "\n"); } }
以上代碼來自http://www.cnblogs.com/alfredxiao/archive/2010/09/16/weblogic_lost_password2.html稍加修改。web
直接運行代碼(注意代碼中需加入weblogic.jar包,weblogic版本不同可能加的jar包不一樣)dom
查看打印結果:ui
其實 boot.properties裏面存放的就是加密過的用戶名密碼,SerializedSystemIni.dat裏面存放的是加解密的密匙來的。加密
若是能在weblogic環境下運行上面代碼就最好了,若是不能則要注意SerializedSystemIni.dat的拷貝了,特別是從Linux環境下拷貝過來的時候。lua
上面方法試過weblogic8和10都是沒有問題的。code