天天看點

MacOS 登入密碼設定檔案 kcpassword 的加解密算法

加密分析

使用了一組魔數 125, 137, 82, 35, 210, 188, 221, 234, 163, 185, 31

登入密碼明文按位依次循環與魔數進行異或,最後加上 35 181 122 180 153 242 70 85 145 160 十個位元組做辨別

解密腳本

#!/usr/bin/python3
import struct
import sys

# Function to decrypt the kcpassword
def decrypt_kcpassword():
    key = [125, 137, 82, 35, 210, 188, 221, 234, 163, 185, 31]
    length = len(key)
    f = open(sys.argv[1], "rb")
    byte = list(f.read())
    f.close()
    
    end = False
    kcpassword = []
    for i in range(len(byte)):
        if byte[i]^key[i%length] == 0 :
            end = True

        if end == False :
            kcpassword.append(str(chr(byte[i]^key[i%length])))
            
    print(''.join(map(str,kcpassword)))

# Function main
def main():
    if len(sys.argv) < 2 :
        print('usage : ./decode-kcpassword.py KCPASSWORD_PATH')
        exit()
    decrypt_kcpassword()

# Call to main
if __name__ == '__main__':
    main()