如何在Linux中的Python中解密Chrome Cookie
我想解密铬饼干。 铬版-103.0.5060.53 我在此stackoverflow文章中尝试了代码:
https://stackoverflow.com/questions/23153159/23153159/decrypting-chromium-cookies/23727331#23727331
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import PBKDF2
import sqlite3
# Function to get rid of padding
def clean(x):
return x[:-x[-1]].decode('utf8')
def get_encrypted_value():
import sqlite3
path = '/home/hasan/.config/BraveSoftware/Brave-Browser/Default/Cookies'
db = sqlite3.connect(path)
cursor = db.cursor()
cursor.execute('SELECT encrypted_value FROM cookies WHERE name = "cf_clearance";')
ENCRYPTED_VALUE = cursor.fetchall()[0][0]
print(ENCRYPTED_VALUE)
return ENCRYPTED_VALUE
# replace with your encrypted_value from sqlite3
encrypted_value = get_encrypted_value()
# Trim off the 'v10' that Chrome/ium prepends
encrypted_value = encrypted_value[3:]
# Default values used by both Chrome and Chromium in OSX and Linux
salt = b'saltysalt'
iv = b' ' * 16
length = 16
# On Mac, replace MY_PASS with your password from Keychain
# On Linux, replace MY_PASS with 'peanuts'
my_pass = 'peanuts'
my_pass = my_pass.encode('utf8')
# 1003 on Mac, 1 on Linux
iterations = 1
key = PBKDF2(my_pass, salt, length, iterations)
cipher = AES.new(key, AES.MODE_CBC, IV=iv)
decrypted = cipher.decrypt(encrypted_value)
print(clean(decrypted))
”此错误:
b'v11J\xf6=Z\xe5\xef\x0f\xf6Wi\xcc\x80KL\xa3U\x06\xdag\xb5*\xbeS\x17\xbb\xa5\xa9\x0e\xa5\xdb}&\xfcJ\x03[\xc3:\x1d\x1c*\xfd\x1b\xf4\xa4\xbd\x93\xd0\xf2Y\xbe\x1ef\x87\r\xec\xb2g?\x84mi\xd6\x87'
Traceback (most recent call last):
File "/home/hasan/test.py", line 42, in <module>
print(clean(decrypted))
File "/home/hasan/test.py", line 6, in clean
return x[:-x[-1]].decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 1: invalid start byte
I want to decrypt chrome cookies.
chromium version - 103.0.5060.53
I tried the code in this stackoverflow post: Decrypting Chromium cookies
my code:
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import PBKDF2
import sqlite3
# Function to get rid of padding
def clean(x):
return x[:-x[-1]].decode('utf8')
def get_encrypted_value():
import sqlite3
path = '/home/hasan/.config/BraveSoftware/Brave-Browser/Default/Cookies'
db = sqlite3.connect(path)
cursor = db.cursor()
cursor.execute('SELECT encrypted_value FROM cookies WHERE name = "cf_clearance";')
ENCRYPTED_VALUE = cursor.fetchall()[0][0]
print(ENCRYPTED_VALUE)
return ENCRYPTED_VALUE
# replace with your encrypted_value from sqlite3
encrypted_value = get_encrypted_value()
# Trim off the 'v10' that Chrome/ium prepends
encrypted_value = encrypted_value[3:]
# Default values used by both Chrome and Chromium in OSX and Linux
salt = b'saltysalt'
iv = b' ' * 16
length = 16
# On Mac, replace MY_PASS with your password from Keychain
# On Linux, replace MY_PASS with 'peanuts'
my_pass = 'peanuts'
my_pass = my_pass.encode('utf8')
# 1003 on Mac, 1 on Linux
iterations = 1
key = PBKDF2(my_pass, salt, length, iterations)
cipher = AES.new(key, AES.MODE_CBC, IV=iv)
decrypted = cipher.decrypt(encrypted_value)
print(clean(decrypted))
but I get this error:
b'v11J\xf6=Z\xe5\xef\x0f\xf6Wi\xcc\x80KL\xa3U\x06\xdag\xb5*\xbeS\x17\xbb\xa5\xa9\x0e\xa5\xdb}&\xfcJ\x03[\xc3:\x1d\x1c*\xfd\x1b\xf4\xa4\xbd\x93\xd0\xf2Y\xbe\x1ef\x87\r\xec\xb2g?\x84mi\xd6\x87'
Traceback (most recent call last):
File "/home/hasan/test.py", line 42, in <module>
print(clean(decrypted))
File "/home/hasan/test.py", line 6, in clean
return x[:-x[-1]].decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 1: invalid start byte
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论