由于我需要实现类似的解决方案,因此我非常感兴趣的是要了解这里使用哪种技术来保存合理的数据。这是一个示例连接配置和生成的导出片段:
<?xml version = '1.0' encoding = 'UTF-8'?>
<References xmlns="http://xmlns.oracle.com/adf/jndi">
<Reference name="My Connection" className="oracle.jdeveloper.db.adapter.DatabaseProvider" xmlns="">
<Factory className="oracle.jdeveloper.db.adapter.DatabaseProviderFactory"/>
<RefAddresses>
<StringRefAddr addrType="user">
<Contents>username</Contents>
</StringRefAddr>
<StringRefAddr addrType="password">
<Contents>054D4844D8549C0DB78EE1A98FE4E085B8A484D20A81F7DCF8</Contents>
</StringRefAddr>
<SKIPPED />
</RefAddresses>
</Reference>
</References>
任何建议都会非常感激。
对于好奇的人,你实际看到的是与加密密码连接的密钥。例如,我尝试使用以下方法加密密码“SAILBOAT”:
DatabaseProviderHelper.goingOut("SAILBOAT")
在这个特定的例子中,结果是:
0527C290B40C41D71139B5E7A4446E94D7678359087249A463
第一个字节是常量:
05
接下来的8个字节表示随机生成的密钥(对于DES密码):
27C290B40C41D711
其余字节是加密密码:
39B5E7A4446E94D7678359087249A463
因此,要解密密码,您只需使用:
public static byte[] decryptPassword(byte[] result) throws GeneralSecurityException {
byte constant = result[0];
if (constant != 5) {
throw new IllegalArgumentException();
}
byte[] secretKey = new byte[8];
System.arraycopy(result, 1, secretKey, 0, 8);
byte[] encryptedPassword = new byte[result.length - 9];
System.arraycopy(result, 9, encryptedPassword, 0, encryptedPassword.length);
byte[] iv = new byte[8];
for (int i = 0; i < iv.length; i++) {
iv[i] = 0;
}
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(secretKey, "DES"), new IvParameterSpec(iv));
return cipher.doFinal(encryptedPassword);
}
散列的长度是50个十六进制字符,即200位,因此它可能是带有盐的密码的哈希值,前面加上盐,如:
salt | hash(salt | password)
哪里|意思是连接。
只是猜测。我的猜测是40位盐和SHA-1哈希值,因为SHA-1产生160位哈希值。
提供一些输入/输出测试数据来检查是有帮助的!
仅供参考,密码'apps_ro'加密为:
<StringRefAddr addrType="password">
<Contents>051DC8A88C574538CC4AEE32D326E9480659C06CEC271EA6D7</Contents>
</StringRefAddr>
请注意,Tim上面的密码哈希不适用于“apps_ro” - 可能是他剪切并粘贴在错误的地方......我不会发布真实密码,以防万一他不想共享!
我遇到了类似的问题,试图集中存储我的数据库凭据(对于非安全数据库!),然后导出sql developer xml文件。我不知道算法是什么 - 但是,你真的不需要知道算法,因为你可以自己调用Oracle java API。如果您有SQLDeveloper,只需获取正确的Jar文件:
cp /Applications/SQLDeveloper.App/Contents/Resources/sqldeveloper/BC4J/lib/db-ca.jar .
cp /Applications/SQLDeveloper.App/Contents/Resources/sqldeveloper/jlib/ojmisc.jar .
然后在Java应用程序中加载它们,或像我一样使用类似JRuby的东西:
$jirb
> require 'java'
> require 'ojmisc.jar'
> require 'db-ca.jar'
> Java::oracle.jdevimpl.db.adapter.DatabaseProviderHelper.goingOut("password")
=> "059D45F5EB78C99875F6F6E3C3F66F71352B0EB4668D7DEBF8"
> Java::oracle.jdevimpl.db.adapter.DatabaseProviderHelper.goingOut("password")
=> "055CBB58B69B477714239157A1F95FDDD6E5B453BEB69E5D49"
> Java::oracle.jdevimpl.db.adapter.DatabaseProviderHelper.comingIn("059D45F5EB78C99875F6F6E3C3F66F71352B0EB4668D7DEBF8")
=> "password"
> Java::oracle.jdevimpl.db.adapter.DatabaseProviderHelper.comingIn("055CBB58B69B477714239157A1F95FDDD6E5B453BEB69E5D49")
=> "password"
请注意,算法,无论它是什么,都有一个随机因子,因此使用两次相同的密码可以生成两个不同的十六进制字符串。
这个解决方案对我很有用...复制自:http://www.mischiefblog.com/?p=912
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
/**
* Decrypt passwords stored in Oracle SQL Developer. This is intended for
* password recovery.
*
* Passwords are stored in
* ~/.sqldeveloper/system2.1.1.64.39/o.jdeveloper.db.connection
* .11.1.1.2.36.55.30/connections.xml
*/
public class Decrypt {
public static byte[] decryptPassword(byte[] result)
throws GeneralSecurityException {
byte constant = result[0];
if (constant != (byte) 5) {
throw new IllegalArgumentException();
}
byte[] secretKey = new byte[8];
System.arraycopy(result, 1, secretKey, 0, 8);
byte[] encryptedPassword = new byte[result.length - 9];
System.arraycopy(result, 9, encryptedPassword, 0,
encryptedPassword.length);
byte[] iv = new byte[8];
for (int i = 0; i < iv.length; i++) {
iv[i] = 0;
}
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(secretKey, "DES"),
new IvParameterSpec(iv));
return cipher.doFinal(encryptedPassword);
}
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: java Decrypt <password>");
System.exit(1);
}
if (args[0].length() % 2 != 0) {
System.err
.println("Password must consist of hex pairs. Length is odd (not even).");
System.exit(2);
}
byte[] secret = new byte[args[0].length() / 2];
for (int i = 0; i < args[0].length(); i += 2) {
String pair = args[0].substring(i, i + 2);
secret[i / 2] = (byte) (Integer.parseInt(pair, 16));
}
try {
System.out.println(new String(decryptPassword(secret)));
} catch (GeneralSecurityException e) {
e.printStackTrace();
System.exit(3);
}
}
}
鉴于解决方案太旧,只适用于版本2.x但现在不适用。因为Oracle SQL Developer在版本3.x和4.x中更改了加密算法。
版本3
密码以加密方式存储在以下位置的connections.xml文件中:
Windows: C:\Users\<USER>\AppData\Roaming\SQL Developer\system<VERSION>\o.jdeveloper.db.connection.<VERSION>\connections.xml
Linux: ~/.sqldeveloper/system<VERSION>/o.jdeveloper.db.connection.<VERSION>/connections.xml
版本4
密码以前面提到的connections.xml文件加密存储,但加密密钥在product-preferences.xml文件中使用机器唯一值db.system.id,可在此处访问:
Windows: C:\Users\<USER>\AppData\Roaming\SQL Developer\system<VERSION>\o.sqldeveloper.<VERSION>\product-preferences.xml
Linux: ~/.sqldeveloper/system<VERSION>/o.sqldeveloper.<VERSION>/product-preferences.xml
要解密最新的加密文件,您可以使用SQL Developer的Show me password扩展。或用SQL Developer password decryptor解密文件
与kornelissietsma相同的代码已经给出了,但写在java上:
import oracle.jdevimpl.db.adapter.DatabaseProviderHelper;
class Decode {
String pass = "";
public Decode() {
pass = DatabaseProviderHelper.comingIn("HASH");
System.out.println(pass);
}
public static void main(String[] args){
new Decode();
}
}
可以执行如下:
# javac -classpath .:/full/path/to/sqldeveloper/BC4J/lib/db-ca.jar:/full/path/to/sqldeveloper/jlib/ojmisc.jar sqldeveloper_hash_decode.java
# java -classpath .:/full/path/to/sqldeveloper/BC4J/lib/db-ca.jar:/full/path/to/sqldeveloper/jlib/ojmisc.jar Decode
遗憾的是,其他答案中描述的方法在SQL Developer 4.x中不起作用。有适用于3.x和4.x版本的扩展,它非常易于使用:
我不确定这一点,但我一直认为哈希不能被解密,只与另一个哈希相比。 MD5生成哈希。 SQL Developer中保存的密码需要解密并发送到服务器。因此dbms_obfuscation_toolkit包中的DES3Encrypt和DES3Decrypt过程是更好的选择。但是在连接到数据库之前应该调用解密,所以它可能是一个带有DES方法的Java加密包。
这是一个python片段,如果有人有兴趣。这是上面的Adam Paynter's例子的翻译。它使用pyDes
import os
import pyDes
import binascii
if __name__ == '__main__':
# Encrypt example
zero = '\0\0\0\0\0\0\0\0'
key = os.urandom(8)
plainText = 'open sesame'
cipher = pyDes.des(key, mode=pyDes.CBC, IV=zero, padmode=pyDes.PAD_PKCS5)
cipherText = '\5%s%s' % (key, cipher.encrypt(plainText))
cipherHex = binascii.hexlify(cipherText)
# This is what SQLDeveloper stores in XML
print cipherHex
# Decrypt above
cipherText = binascii.unhexlify(cipherHex)
assert cipherHex[0:2] == '05'
key = cipherText[1:1+8]
cipher = pyDes.des(key, mode=pyDes.CBC, IV=zero, padmode=pyDes.PAD_PKCS5)
print cipher.decrypt(cipherText[1+8:])
我不知道,但如果使用像这样的DBMS_OBFUSCATION_TOOLKIT,我不会感到惊讶:
l_hash := dbms_obfuscation_toolkit.md5(input_string=>:username||:password);