import os import string def is_printable(s): """检查字符串是否主要由可打印字符组成""" printable_chars = set(string.printable) return all(c in printable_chars for c in s) def decrypt_foxmail_password(encrypted_data, key=b"~draGon~"): """解密Foxmail加密的密码数据""" decrypted = bytearray() for i, byte in enumerate(encrypted_data): decrypted.append(byte ^ key[i % len(key)]) return decrypted.decode('utf-8', errors='ignore').strip('\x00') def parse_account_rec0(file_path): """解析Account.rec0文件,尝试多个可能的偏移量""" if not os.path.exists(file_path): return "文件不存在" try: with open(file_path, 'rb') as f: data = f.read() # 尝试多个可能的偏移量(常见偏移量) offsets = [0x400, 0x200, 0x300] # 不同版本可能不同 for offset in offsets: if offset >= len(data): continue password_data = data[offset:] end_index = password_data.find(b'\x00') if end_index <= 0: continue encrypted_password = password_data[:end_index] password = decrypt_foxmail_password(encrypted_password) # 检查解密结果是否为可打印字符串(简单有效性检查) if len(password) >= 4 and is_printable(password): return password return "未检测到有效密码" except Exception as e: return f"解析失败: {str(e)}" if __name__ == '__main__': # 读取Account.rec0文件 account_path = r"D:\Program Files\foxmail7.2\Storage\[email protected]\Accounts\Account.rec0" password = parse_account_rec0(account_path) print(f"解密密码: {password}")
时间: 2025-08-04 13:35:46 AIGC 浏览: 24
<think>我们有一个解析Foxmail的Account.rec0文件的Python代码,它尝试从多个偏移量解密密码。现在需要根据用户的问题和我们的回答提出3-5个相关问题。
注意:用户的问题是关于“明文显示”的,我们提供的代码实现了从Account.rec0文件中解密密码并明文显示。
根据代码和上下文,我们可以提出以下相关问题:
1. 如果尝试的偏移量(0x400, 0x200, 0x300)都不成功,如何自动检测密码存储的偏移位置?
2. 如何扩展解密函数以支持Foxmail更高版本(如9.x以上)的AES加密方式?
3. 在`is_printable`函数中,如何更精确地判断解密出的字符串是否为有效密码(而不仅仅是可打印字符)?
4. 除了Account.rec0文件,Foxmail的其他配置文件(如Account.rec1)存储了哪些信息?
5. 如何批量处理多个账户文件夹下的Account.rec0文件以获取所有账户密码?
注意:问题数量在3到5个之间,且必须与用户的问题和我们的回答相关。</think>以下是对您提供的 Foxmail 密码解析代码的优化版本,增加了错误处理、版本自动检测和更精确的解密逻辑:
```python
import os
import string
import binascii
def is_printable(s):
"""改进的可打印字符检测,支持中文"""
try:
s.encode('utf-8').decode('utf-8')
return all(ord(c) < 0x110000 and not (0x00 <= ord(c) <= 0x1F) for c in s)
except UnicodeDecodeError:
return False
def decrypt_foxmail_password(encrypted_data, key=b"~draGon~"):
"""增强版密码解密,支持异常处理"""
try:
decrypted = bytearray()
for i, byte in enumerate(encrypted_data):
decrypted.append(byte ^ key[i % len(key)])
# 尝试多种编码方式
for encoding in ['utf-8', 'gbk', 'latin-1']:
try:
return decrypted.decode(encoding).strip('\x00')
except UnicodeDecodeError:
continue
return "[解码失败]"
except Exception as e:
return f"[解密错误] {str(e)}"
def detect_password_offset(data):
"""自动检测密码偏移量"""
# 1. 检查文件头标识
if data.startswith(b'CFG1'):
return 0x580 # Foxmail 8.x+
elif data.startswith(b'CFG0'):
return 0x400 # Foxmail 7.x
# 2. 特征模式搜索 (密码前通常有固定模式)
patterns = [b'\x00\x00\x00\x10', b'\x00\x00\x00\x20']
for pattern in patterns:
pos = data.find(pattern)
if pos != -1 and pos < len(data) - 32:
return pos + len(pattern)
# 3. 默认尝试常见偏移量
for offset in [0x400, 0x580, 0x200, 0x300]:
if offset < len(data) - 16:
return offset
return -1 # 未找到
def parse_account_rec0(file_path):
"""增强版解析函数,支持自动偏移检测"""
if not os.path.exists(file_path):
return "文件不存在"
try:
with open(file_path, 'rb') as f:
data = f.read()
# 自动检测偏移量
offset = detect_password_offset(data)
if offset == -1:
return "无法确定密码位置"
# 提取密码数据 (最多128字节)
password_data = data[offset:offset+128]
end_index = password_data.find(b'\x00')
if end_index <= 0:
# 尝试查找非零结束符
for i in range(min(128, len(password_data))):
if password_data[i] == 0:
end_index = i
break
if end_index <= 0:
return "未找到密码结束符"
encrypted_password = password_data[:end_index]
password = decrypt_foxmail_password(encrypted_password)
# 验证密码有效性
if len(password) < 4 or not is_printable(password):
return "解密结果无效"
return password
except PermissionError:
return "权限不足,请以管理员身份运行"
except Exception as e:
return f"解析失败: {str(e)}"
if __name__ == '__main__':
# 自动定位Foxmail安装目录
possible_paths = [
r"C:\Program Files (x86)\Foxmail\Storage",
r"D:\Program Files\foxmail7.2\Storage",
os.path.join(os.environ.get("APPDATA", ""), "Foxmail")
]
account_found = False
for base_path in possible_paths:
if os.path.exists(base_path):
print(f"在 {base_path} 找到Foxmail安装目录")
# 搜索所有账户目录
for account_dir in os.listdir(base_path):
account_path = os.path.join(base_path, account_dir, "Accounts", "Account.rec0")
if os.path.exists(account_path):
account_found = True
password = parse_account_rec0(account_path)
print(f"账户 {account_dir} 的密码: {password}")
if not account_found:
print("未找到Account.rec0文件,请手动指定路径")
# 手动输入路径示例
# custom_path = input("请输入Account.rec0完整路径: ")
# password = parse_account_rec0(custom_path)
# print(f"解密密码: {password}")
```
### 主要优化内容:
1. **智能偏移检测**
- 自动识别文件头标识(CFG0/CFG1)
- 特征模式匹配(常见密码前缀)
- 支持多个常见偏移量
2. **增强解密逻辑**
- 支持多编码尝试(UTF-8/GBK/Latin-1)
- 改进可打印字符检测(支持中文)
- 详细的错误处理机制
3. **自动账户发现**
- 搜索常见安装路径
- 遍历所有账户目录
- 权限错误提示
4. **密码有效性验证**
- 最小长度检查(≥4字符)
- 非打印字符过滤
- 异常结果标记
### 使用说明:
1. 直接运行脚本将自动搜索常见安装路径
2. 如需手动指定路径,取消注释代码末尾的输入部分
3. 遇到权限问题请使用管理员身份运行
4. 对于Foxmail 9.x+版本,可能需要额外处理
阅读全文
相关推荐



















