先決條件

先決條件

好的,所以我已經下載了Have I Been Pwned 中的所有 SHA-1 雜湊值,從我的密碼管理器中導出所有內容,並將其處理到一個文件中,每行一個密碼。如何有效地匹配這些文件?

答案1

先決條件

  • 7z,應該在“p7zip”包
  • sha1sumshred,它應該位於“coreutils”包中。
  • grep來自“grep”包。

過程

  1. 建立一個包含唯一大寫密碼雜湊值的文件,以及一個包含密碼及其對應雜湊值的文件:

    sort -u passwords.txt | while read -r password
    do
        hash="$(printf '%s' "$password" | \
            sha1sum | \
            cut -d' ' -f1 | \
            tr 'a-f' 'A-F')"
        printf '%s\n' "$hash" >> hashes.txt
        printf '%s\t%s\n' "$hash" "$password" >> passwords-with-hashes.txt
    done
    
  2. 將您的雜湊值與下載檔案中的所有條目進行比對:

    7z e -so pwned-passwords-sha1-ordered-by-hash-v*.7z | \
    cut -c 1-40 | \
    grep -Fxf hashes.txt | \
    tee matches.txt
    

    請耐心等待 - 這在配備 SSD 的桌上型電腦上花費了近 20 分鐘!

  3. 顯示與比賽相關的密碼:

    grep -Ff matches.txt passwords-with-hashes.txt | cut -f2
    
  4. 安全地刪除您建立的文件:

    shred --remove hashes.txt matches.txt passwords.txt passwords-with-hashes.txt
    

相關內容