随笔 - 750  文章 - 1  评论 - 107  阅读 - 34万

[转]Java 读取 FinalShell 已保存的密码

转自:https://blog.csdn.net/Linkaias/article/details/133805438

也可以找一些在线解密网站来查看密码。

 

FinalShell 可用来连接到 Linux 服务器,官网:https://www.hostbuf.com/?install_fs

复制代码
package org.example;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.Random;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

public class Main {
    public static void main(String[] args) throws Exception {
        String pass = "P0ozS3J4AWkNuqb4kAgtdw==";
        String depass = decodePass(pass);

        System.out.println("The Password is : " + depass);
    }

    static byte[] decryptDes(byte[] data, byte[] key) throws Exception {
        SecureRandom secureRandom = new SecureRandom();
        DESKeySpec desKeySpec = new DESKeySpec(key);
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
        Cipher cipher = Cipher.getInstance("DES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey, secureRandom);

        return cipher.doFinal(data);
    }

    static String decodePass(String data) throws Exception {
        if (data == null) {
            return null;
        } else {
            byte[] decodedData = Base64.getDecoder().decode(data);
            byte[] head = new byte[8];
            System.arraycopy(decodedData, 0, head, 0, head.length);

            byte[] encryptedData = new byte[decodedData.length - head.length];
            System.arraycopy(decodedData, head.length, encryptedData, 0, encryptedData.length);

            byte[] decryptedData = decryptDes(encryptedData, generateRandomKey(head));
            return new String(decryptedData);
        }
    }

    static byte[] generateRandomKey(byte[] head){
        long seed = 3680984568597093857L / (long)(new Random((long)head[5])).nextInt(127);
        Random random = new Random(seed);
        int t = head[0];

        for(int i=0;i<t;++i){
            random.nextLong();
        }

        long n = random.nextLong();
        Random random2 = new Random(n);

        long[] keyData = {(long) head[4],random2.nextLong(),(long)head[7],(long)head[3],random2.nextLong(),
                (long)head[1],random.nextLong(),(long) head[2]};

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);

        for(long l : keyData){
            try {
                dos.writeLong(l);
            } catch (IOException e){
                e.printStackTrace();
            }
        }

        try {
            dos.close();
        } catch (IOException e){
            e.printStackTrace();
        }

        byte[] key = bos.toByteArray();
        return md5Hash(key);
    }

    static byte[] md5Hash(byte[] data){
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(data,0,data.length);
            byte[] result = messageDigest.digest();
            return result;
        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
            return null;
        }
    }
}
复制代码

 

posted on   z5337  阅读(226)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2018-11-30 [转]Linux 基本操作(RM 删除)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示