你有没有遇到这样的问题,linux登录时间长了,忘记了自己的登录密码?
下面教你怎样使用finalShell找回linux密码
1.首先,前提是你之前使用FinalShell登陆过该服务器
2. 导出之后,搜索下关键字“password”找到对应的加密字符串
3. 使用以下代码解析,拿到密码
package com.wasu.utils;
import java.util.Base64;
import java.util.Random;
import javax.crypto.Cipher;
import java.io.IOException;
import java.math.BigInteger;
import javax.crypto.SecretKey;
import java.io.DataOutputStream;
import java.security.SecureRandom;
import java.security.MessageDigest;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.SecretKeyFactory;
import java.io.ByteArrayOutputStream;
import java.security.NoSuchAlgorithmException;
public class Test{
public static void main(String[] args) throws Exception {
System.out.println(decode("YjsGE05qZQR4wnUf93+59Q=="));
}
private static String decode(String str) throws Exception {
if (str == null) {
return null;
} else {
byte[] buf = Base64.getDecoder().decode(str);
byte[] head = new byte[8];
System.arraycopy(buf, 0, head, 0, head.length);
byte[] d = new byte[buf.length - head.length];
System.arraycopy(buf, head.length, d, 0, d.length);
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(ranDomKey(head));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(2, securekey, sr);
byte[] bt = cipher.doFinal(d);
return new String(bt);
}
}
private static byte[] ranDomKey(byte[] head) {
long ks = 3680984568597093857L / (long) (new Random((long) head[5])).nextInt(127);
Random random = new Random(ks);
int t = head[0];
for (int i = 0; i < t; ++i) {
random.nextLong();
}
long n = random.nextLong();
Random r2 = new Random(n);
long[] ld = new long[]{(long) head[4], r2.nextLong(), (long) head[7], (long) head[3], r2.nextLong(), (long) head[1], random.nextLong(), (long) head[2]};
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
for (long l : ld) {
try {
dos.writeLong(l);
} catch (IOException var18) {
var18.printStackTrace();
}
}
try {
dos.close();
} catch (IOException var17) {
var17.printStackTrace();
}
byte[] keyData = bos.toByteArray();
keyData = md5(keyData);
return keyData;
}
private static byte[] md5(byte[] data) {
byte[] res = null;
try {
MessageDigest m;
m = MessageDigest.getInstance("MD5");
m.update(data, 0, data.length);
res = m.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return res;
}
}