Recover Weblogic Admin Password
If Weblogic admin password been forgotten, then no worries we can recover the password without reset / recreating the domain.
WebLogicDecryptor.java
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.*;
public class WebLogicDecryptor {
private static final String PREFIX = "{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 {
if (args.length < 2) {
throw new Exception("Usage: [domainDir] [configFile]");
}
ces = new ClearOrEncryptedService(SerializedSystemIni.getEncryptionService(new File(args[0]).getAbsolutePath()));
File file = new File(args[1]);
if (file.getName().endsWith(".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");
}
}
Note: Check the boot.properties fie, if the Prefix is {AES} or {3DES}—update it in the above file (Highlighted in yellow color)
Procedure to execute the code:
- Set the env variables using setWLSenv.sh / Cmd
- Javac WeblogicDecryptor.java
- Run the code > java WeblogicDecryptor <Domain Dir> <Config file / boot. Properties path>
Ex: Option 1
C:\Prem\Weblogic>java WebLogicDecryptor C:\Oracle\Middleware\user_projects\domains\base_domain C:\Oracle\Middleware\user_projects\domains\base_domain\config\config.xml
Node name: credential-encrypted
Encrypted: {AES}EQOhDn+NVCtsijzTycEERvyX4+4wGo5j734YIzUsQQDILIKP74eMyXXBk6QX7gpD
1AA856/lAaCjMtgYHvIWF0QUj2xeTTJj6+HGUGb5xB+p2Ix4+bTGOLAqzVdmvaQm
Decrypted: 0xa944c5ffe3abb7dab194e9467d1e8e2961077202a92e6c8a87c1fc7a334d4d39
Node name: node-manager-password-encrypted
Encrypted: {AES}aXCNpPXYnNr5n8kFZ1/xjDjAyif5g7vS2ct/jP97g5A=
Decrypted: weblogic12345
Node name: credential-encrypted
Encrypted: {AES}fPAWbE94I7oKthMYyNgz90KBLmMFq2+NEAJy9KxjG+WME3r4dPcrBuLajdU+KPf7
Decrypted: 0x870d791c7277889e17b55a87d5
C:\Prem\Weblogic>javac WebLogicDecryptor.java
Ex: Option 2
C:\Prem\Weblogic>java WebLogicDecryptor C:\Oracle\Middleware\user_projects\domains\base_domain C:\Oracle\Middleware\user_projects\domains\base_domain\boot.properties
Node name: password
Encrypted: {AES}41WaOikOJ/bVjBrWCVlnVa11b/PirQh1izkTcYowqyw=
Decrypted: weblogic12345
Node name: username
Encrypted: {AES}hGG2itFJJXaqyzhU5UH7SUZjoWpa+PssIMqzY1zyENs=
Decrypted: weblogic
Happy Troubleshooting !!! :-)
Thanks
Prem
Comments
Post a Comment