dnscmd.exe 功能的 Beacon Object File (BOF) 实现,用于通过利用 ServerLevelPluginDll 边缘1 2 3 并使用 MS-DNSP 4 在 ADIDNS 服务器上获得远程代码执行。利用此漏洞需要访问属于 DnsAdmins 组成员的用户帐户。
[!NOTE] 由于 BOF 本身不支持 C 异常,此扩展会挂钩
RtlRaiseException方法,并在 RPC 调用期间将控制流返回给 BOF。虽然这种方法有些粗糙,但由于 Microsoft 的 RPC 实现大量使用 RpcTryExcept 进行控制流处理,因此这是必要的。这在测试环境中运行良好,但请注意,此技术可能导致 beacon 不稳定。
要编译该项目,您可以在安装了 MinGW 的系统上使用 make:
make
或者,如果您在 Windows 上使用 Visual Studio 的 x64 本机工具命令提示符,可以使用 .\build.bat:
.\build.bat
两种编译步骤都会生成 .o 文件以及 .exe 文件,以便在实验室环境中测试 BOF 功能。
已创建以下 BOF 用于与 ADIDNS 服务器交互:
dnsrpc_probe - 检查 ADIDNS 服务器是否存活dnsrpc_info - 获取当前 ADIDNS 服务器设置dnsrpc_coerce_write - 强制 ADIDNS 服务器将文件写入网络共享的实用程序,用于在通过 dnsrpc_set_plugin_dll 插件破坏 DC 之前测试 DC 是否可以访问给定的网络共享。dnsrpc_set_plugin_dll - 配置服务器重启时要加载的 DLLdnsrpc_restart_server - 发出 ADIDNS 服务器重启命令dnsrpc_cleanup - 清理 dnsrpc_coerce_write 和 dnsrpc_set_plugin_dll 命令留下的注册表痕迹。必须在域控制器本身上执行。此外,在 dnssrv_plugin.c 中提供了一个示例载荷。
[!WARNING] 如果 DC 由于某种原因无法访问您通过
dnsrpc_set_pugin_dll指定的 DLL 载荷,它将拒绝重新启动,您很可能会瘫痪整个域。建议先使用dnsrpc_coerce_write测试 DC 是否确实可以连接到您的共享,然后再意外摧毁目标。当 DNS 宕机时,人们往往会非常愤怒。此外,
dnsrpc_restart_server将导致两分钟的 DNS 停机。多次调用该 BOF 会导致超时时间每次增加,因此请谨慎使用。
要在开发环境中测试 BOF,您可以使用 TrustedSec 的 COFFLoader 等工具,该工具可以在 Windows 上按如下方式编译:
cl.exe /W4 /DCOFF_STANDALONE /DDEBUG beacon_compatibility.c COFFLoader.c /Fe:COFFLoader.exe /link advapi32.lib
然后执行 BOF(例如:dnsrpc_info BOF),生成参数并将其传递给 COFFLoader:
> python beacon_generate.py
Beacon Argument Generator
Beacon>addWString DC01
Beacon>generate
b'0e0000000a00000044004300300031000000'
Beacon> exit
> cl.exe /c /GS- dnsrpc_info.c /Fo:dist\dnsrpc_info.o
> COFFLoader.exe go dist\dnsrpc_info.o 0e0000000a00000044004300300031000000
...
$SG77912
: Section: 3, Value: 0xA08
$SG77914H
: Section: 3, Value: 0xA48
$SG77915X
: Section: 3, Value: 0xA58
.chks64: Section: 11, Value: 0x0
X: Section: 0, Value: 0x0
Back
Returning
Ran/parsed the coff
Outdata Below:
server name: DC01.research.lan
server version: 4F7C000A (10.0 build 20348)
rpc structure version: 2 (longhorn)
directory services available: yes
admin configured: yes
allow update: yes
is read-only domain controller: no
boot method: 3 (registry)
no recursion: no
round robin: yes
secure responses: yes
forward timeout: 3
recursion retry: 3
recursion timeout: 8
max cache ttl: 86400
directory services polling interval: 180
scavenging interval: 0
log level: 0x00000000
directory services container: cn=MicrosoftDNS,cn=System,DC=research,DC=lan
domain name: research.lan
forest name: research.lan
log file path: (none)
server addresses: fe80:0000:0000:0000:4cbe:0281:82dd:76ed, 172.16.50.107
listen addresses: (none)
forwarders: 8.8.8.8, 1.1.1.1
要重新编译 IDL 定义,可以使用以下命令:
midl /W1 /char signed /env x64 /target NT100 /Oicf dnsrpc.idl
在开发过程中,_DEBUG 标志会向最终二进制文件添加 wmain,而 _VERBOSE 标志用于包含额外的调试日志记录。有关更多信息,请参阅 build.bat 和 Makefile。
本项目根据 MIT 许可证授权 - 有关详细信息,请参阅 LICENSE 文件。对于因使用此工具而造成的任何误用或损害,我不承担任何责任。请仅在您获得明确许可的环境中使用它。
https://raw.githubusercontent.com/paradoxis/dnsrpc-bof/HEAD/%3Chttps:/medium.com/@esnesenon/feature-not-bug-dnsadmin-to-dc-compromise-in-one-line-a0f779b8dc83%3E ↩
https://raw.githubusercontent.com/paradoxis/dnsrpc-bof/HEAD/%3Chttps:/www.semperis.com/blog/dnsadmins-revisited/%3E ↩
https://raw.githubusercontent.com/paradoxis/dnsrpc-bof/HEAD/%3Chttps:/www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/from-dnsadmins-to-system-to-domain-compromise%3E ↩
https://raw.githubusercontent.com/paradoxis/dnsrpc-bof/HEAD/%3Chttps:/learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/9500a7e8-165d-4b13-be86-0ddc43100eef%3E ↩