PyWxDump/pywxdump/wx_info/get_wx_info.py

99 lines
3.7 KiB
Python
Raw Normal View History

2023-08-21 23:55:59 +08:00
# -*- coding: utf-8 -*-#
# -------------------------------------------------------------------------------
# Name: getwxinfo.py
# Description:
# Author: xaoyaoo
# Date: 2023/08/21
# -------------------------------------------------------------------------------
import json
import ctypes
2023-10-11 14:16:03 +08:00
from win32com.client import Dispatch
2023-08-21 23:55:59 +08:00
import psutil
2023-10-08 23:05:04 +08:00
ReadProcessMemory = ctypes.windll.kernel32.ReadProcessMemory
void_p = ctypes.c_void_p
2023-08-21 23:55:59 +08:00
2023-10-10 21:16:13 +08:00
# 读取内存中的字符串(非key部分)
def get_info_without_key(h_process, address, n_size=64):
2023-10-08 23:05:04 +08:00
array = ctypes.create_string_buffer(n_size)
2023-10-10 21:16:13 +08:00
if ReadProcessMemory(h_process, void_p(address), array, n_size, 0) == 0: return "None"
2023-10-08 23:05:04 +08:00
array = bytes(array).split(b"\x00")[0] if b"\x00" in array else bytes(array)
text = array.decode('utf-8', errors='ignore')
return text.strip() if text.strip() != "" else "None"
2023-08-21 23:55:59 +08:00
2023-10-10 21:16:13 +08:00
# 读取内存中的key
2023-10-08 23:05:04 +08:00
def get_key(h_process, address):
2023-08-21 23:55:59 +08:00
array = ctypes.create_string_buffer(8)
2023-10-08 23:05:04 +08:00
if ReadProcessMemory(h_process, void_p(address), array, 8, 0) == 0: return "None"
key = ctypes.create_string_buffer(32)
address = int.from_bytes(array, byteorder='little') # 逆序转换为int地址key地址
if ReadProcessMemory(h_process, void_p(address), key, 32, 0) == 0: return "None"
key_string = bytes(key).hex()
return key_string
2023-08-21 23:55:59 +08:00
2023-10-10 21:16:13 +08:00
# 读取微信信息(key, name, account, mobile, mail)
2023-08-22 00:16:06 +08:00
def read_info(version_list):
2023-10-08 23:05:04 +08:00
wechat_process = []
result = []
2023-08-21 23:55:59 +08:00
for process in psutil.process_iter(['name', 'exe', 'pid', 'cmdline']):
if process.name() == 'WeChat.exe':
2023-10-08 23:05:04 +08:00
wechat_process.append(process)
if len(wechat_process) == 0:
2023-08-21 23:55:59 +08:00
return "[-] WeChat No Run"
2023-10-08 23:05:04 +08:00
for process in wechat_process:
tmp_rd = {}
2023-10-08 23:07:39 +08:00
tmp_rd['pid'] = process.pid
2023-10-11 14:16:03 +08:00
tmp_rd['version'] = Dispatch("Scripting.FileSystemObject").GetFileVersion(process.exe())
support_list = version_list.get(tmp_rd['version'], None)
if not isinstance(support_list, list):
return f"[-] WeChat Current Version {tmp_rd['version']} Is Not Supported"
2023-10-08 23:05:04 +08:00
wechat_base_address = 0
for module in process.memory_maps(grouped=False):
if module.path and 'WeChatWin.dll' in module.path:
wechat_base_address = int(module.addr, 16)
break
if wechat_base_address == 0:
return f"[-] WeChat WeChatWin.dll Not Found"
Handle = ctypes.windll.kernel32.OpenProcess(0x1F0FFF, False, process.pid)
name_baseaddr = wechat_base_address + support_list[0]
account__baseaddr = wechat_base_address + support_list[1]
mobile_baseaddr = wechat_base_address + support_list[2]
mail_baseaddr = wechat_base_address + support_list[3]
key_baseaddr = wechat_base_address + support_list[4]
tmp_rd['account'] = get_info_without_key(Handle, account__baseaddr, 32)
tmp_rd['mobile'] = get_info_without_key(Handle, mobile_baseaddr, 64)
tmp_rd['name'] = get_info_without_key(Handle, name_baseaddr, 64)
tmp_rd['mail'] = get_info_without_key(Handle, mail_baseaddr, 64) if support_list[3] != 0 else "None"
tmp_rd['key'] = get_key(Handle, key_baseaddr)
result.append(tmp_rd)
return result
2023-08-21 23:55:59 +08:00
2023-08-21 23:55:59 +08:00
if __name__ == "__main__":
2023-10-10 21:16:13 +08:00
# 读取微信各版本偏移
version_list = json.load(open("../version_list.json", "r", encoding="utf-8"))
2023-10-10 21:16:13 +08:00
result = read_info(version_list) # 读取微信信息
print("=" * 32)
if isinstance(result, str): # 输出报错
2023-10-08 23:05:04 +08:00
print(result)
2023-10-10 21:16:13 +08:00
else: # 输出结果
for i, rlt in enumerate(result):
for k, v in rlt.items():
2023-10-08 23:05:04 +08:00
print(f"[+] {k:>7}: {v}")
2023-10-10 21:16:13 +08:00
print(end="-" * 32 + "\n" if i != len(result) - 1 else "")
print("=" * 32)