Skip to content

根据印象中用过的密码片段 生成的排列组合依次测试

  • 修改盘符
  • 添加印象中的组合(如果是字母会添加首字符大小写的组合)
run.js
js
const { execFile } = require('child_process');
const fs = require('fs');
const path = require('path');


function getAllPermutationsWithFixedFirst(arr, fixedIndex) {
    // 确保 fixedIndex 在有效范围内
    if (fixedIndex < 0 || fixedIndex >= arr.length) {
        throw new Error('fixedIndex 超出数组索引范围');
    }

    const fixedElement = arr[fixedIndex];
    const remainingElements = arr.filter((_, index) => index !== fixedIndex); // 剩余需要排列的元素
    const result = [];

    function backtrack(path, options) {
        if (options.length === 0) {
            result.push(fixedElement + path.join('')); // 固定元素 + 排列
            return;
        }

        for (let i = 0; i < options.length; i++) {
            // 选择当前项
            const newPath = [...path, options[i]];
            const newOptions = options.slice(0, i).concat(options.slice(i + 1));

            // 继续递归
            backtrack(newPath, newOptions);
        }
    }

    backtrack([], remainingElements);
    return result;
}

function getAllUniquePasswords(inputGroups, fixedIndex = 0) {
    const passwordSet = new Set();

    for (const group of inputGroups) {
        const permutations = getAllPermutationsWithFixedFirst(group, fixedIndex);
        permutations.forEach(p => passwordSet.add(p));
    }

    return Array.from(passwordSet);
}

function tryUnlockWithPassword(driveLetter, password) {
    return new Promise((resolve, reject) => {
        const ps = execFile('powershell.exe', [
            '-NoProfile',
            '-ExecutionPolicy', 'Bypass',
            '-Command', `
                $ErrorActionPreference = "Stop"
                try {
                    Unlock-BitLocker -MountPoint "${driveLetter}:" -Password (ConvertTo-SecureString '${password}' -AsPlainText -Force)
                    exit 0
                } catch {
                    Write-Output "ERROR: $_"
                    exit 1
                }
            `
        ]);
        let stdout = '';
        let stderr = '';

        ps.stdout.on('data', data => {
            stdout += data;
        });

        ps.stderr.on('data', data => {
            stderr += data;
        });

        ps.on('close', code => {
            if (code !== 0 || stderr.includes('HRESULT:0x80310027') || stdout.includes('Failed')) {
                // 解锁失败
                console.log(`尝试密码失败: ${password}`);
                resolve(false);
            } else {
                // 解锁成功
                console.log(`成功解锁! 使用的密码: ${password}`);
                resolve(false);
            }
        });

        ps.on('error', err => {
            console.error(`执行出错: ${err.message}`);
            reject(err);
        });
    });
}

async function attemptUnlockSerially(driveLetter, passwords) {
    console.log(`共 ${passwords.length} 个唯一密码待尝试`);

    for (const password of passwords) {
        console.log(`尝试密码: ${password}`);

        const success = await tryUnlockWithPassword(driveLetter, password);
        if (success) {
            console.log(`找到正确密码: ${password}`);
            process.exit(0);
        }
    }

    console.log("所有密码尝试完毕,未找到正确密码");
}


/// 这里组合密码
/// node run.js   要用power shell管理员模式执行
const PANFU = "F"
const passwords = [ 
    ['密码片段1', "密码片段2", "密码片段3"], 
] 


const uniquePasswords = getAllUniquePasswords(passwords);
attemptUnlockSerially(PANFU, uniquePasswords);

window 管理员运行

unlock-bitlocker.ps1
shell
param (
    [string]$driveLetter,
    [string]$password
)

try {
    $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
    Unlock-BitLocker -MountPoint "$driveLetter`:" -Password $securePassword
    Write-Output "成功解锁: $password"
    exit 0 # 成功退出
} catch {
    Write-Error "解锁失败: $password"
    exit 1 # 失败退出
}

TIP

印象片段的所有组合都试过还解不开那就完犊子,找找密钥吧