Ctftool是一款交互式的命令行工具,可以帮助安全研究人员对CTF(Windows平台下用于实现文本服务的协议)进行安全测试。在Ctftool的帮助下,安全研究人员可以轻松对Windows内部运行和调试文本输入处理器的复杂问题进行分析,并检测目标Windows系统的安全性。
除此之外,Ctftool还允许研究人员根据自己的需要来编写一些简单的脚本来实现与CTF客户端或服务器端的自动化交互,以及执行简单的模糊测试任务。
工具下载
广大研究人员可以使用下列命令将项目源码克隆至本地:
git clone https://github.com/taviso/ctftool.git
项目构建
注意:如果你不想自己构建项目源码的话,你可以直接访问该项目的Release页面来下载编译好的版本。
我们使用了GNU make和Visual Studio 2019来开发Ctftool,目前该项目仅支持32位版本,但是该工具支持在Windows x86和x64平台上运行。
安装好所有的依赖组件之后,直接在开发者命令行终端中输入“make”命令即可完成项目构建。
这里,我使用的构建工具是一个变种版本的Visual Studio,构建时我只选择了MSVC、MSBuild、CMake和SDK。
这个项目使用了子模块来处理部分依赖,你可以使用下列命令来获取所需的依赖代码:
git submodule update --init --recursive
工具使用
Ctftool目前已在Windows 7、Windows 8和Windows 10上进行了测试,并且支持32位和64位版本。
广大演技人员可以使用“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 \BaseNamedObjects\msctf.serverDefault1
NtAlpcConnectPort("\BaseNamedObjects\msctf.serverDefault1") => 0
Connected to CTF server@\BaseNamedObjects\msctf.serverDefault1, 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)接下来,我们就可以通过向服务器端发送或接受命令,来对已连接的客户端进行测试。
漏洞利用
该工具可以用来扫描和发现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 .\scripts\ctf-consent-system.ctf
实际上,漏洞利用代码会分为两个阶段运行,因此我们也可以单独执行这两个阶段的代码。比如说,你可能想要入侵的进程属于不同会话上的同一个用户,此时可以使用connect命令的可选参数。
接下来,你可以建立一条会话链接,选择一个需要入侵的客户端,然后运行下列命令:
ctf> script .\scripts\ctf-exploit-common-win10.ctf
监控劫持
由于CTF协议中的客户端跟服务器端之间不需要身份认证,那么如果攻击者有权限写入/BaseNamedObjects的话,他就可以创建CTF ALPC端口,并伪装成监控器。
此时,攻击者将能够绕过监视器以及所有限制来执行任何操作。
使用“hijack”命令即可实现:
An interactive ctf exploration tool by @taviso.
Type "help" for available commands.
ctf> hijack Default 1
NtAlpcCreatePort("\BaseNamedObjects\msctf.serverDefault1") => 0 00000218
NtAlpcSendWaitReceivePort("\BaseNamedObjects\msctf.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("\BaseNamedObjects\msctf.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("\BaseNamedObjects\msctf.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".
项目地址
Ctftool:【GitHub传送门】
参考资料
https://googleprojectzero.blogspot.com/2019/08/down-rabbit-hole.html
https://www.freebuf.com/sectool/227330.html
- CTF
- flag
- it2021
- it2021.com
- shell
- 命令行工具
- 安全测试
- 漏洞利用






1F
看起来挺复杂的,新手想入门有推荐的学习路径吗?
福建 泉州 2F
感觉比之前用的工具方便点,至少命令挺全
3F
跨会话攻击听着牛,但实际能干啥?🤔
4F
新手别碰,光装依赖就劝退了
5F
脚本路径大小写敏感?我Windows下老报错
6F
模块基址都能查,调试时省事不少
7F
求问这工具在Win10 20H2还能用不?
8F
之前被360一刀毙了,换虚拟机才跑起来
9F
hijack要是能限制权限就好了,太危险
10F
这个工具之前有听说过,好像能绕过不少安全限制
山西 吕梁 11F
不太懂具体原理,但感觉挺厉害的🤔
12F
这玩意坑不少吧?之前搞类似的搞了半天没弄明白
B1
@ 烈日 别提了,我也卡在submodule那步,init半天不动。
13F
有人试过在win11上跑吗?兼容性怎么样?
B1
@ 虚拟领航员 win11没测过,但看代码依赖ALPC应该能跑,就是得关Defender
B1
@ 虚拟领航员 win11上试过,启动报错一堆,估计得自己编译才行。
14F
脚本那部分没太看懂,能再解释下不?
B1
@ 小鹿王子 脚本部分就是自动化执行命令,多看几遍就懂了
15F
跨会话攻击那块有点意思,实际应用场景多吗?
B1
@ 冥界吟唱 跨会话在企业环境应该挺有用
16F
工具是开源的,可以去GitHub上看看源码
17F
命令行交互的,对新手可能不太友好
B1
@ 灵契约 命令行习惯了就好,其实比图形界面灵活
B1
@ 灵契约 连help都得先connect,新手真容易懵
18F
看截图感觉界面还挺简洁的,不知道实际用起来怎么样?
19F
感觉这个工具挺实用的,适合日常测试用
B1
@ 流云客 日常用的话哪些功能比较常用?
20F
之前用过类似工具,配置起来有点麻烦
21F
这个能绕过UAC吗?
22F
看介绍好像权限要求挺高的
23F
GitHub上star数多少啊?
B1
@ 软糯小团 快两千star了,不过最近没更新有点慌。
B1
@ 软糯小团 star数好像才几百,比较小众
24F
win7还能用不?现在系统都更新了
B1
@ 社交过山车 win7早没官方支持了,能跑就不错了别指望稳定
浙江 宁波 25F
有中文文档吗?英文看着费劲
26F
这种工具会不会被安全软件误报?
27F
试了下连接命令,确实能扫到进程
B1
@ 影界统治者 扫到进程只是第一步,后面callstub才容易崩,我试了三次挂俩
28F
感觉比之前用的工具方便点
29F
这工具对权限要求太高了,普通用户根本玩不转
B1
@ 船夫王 权限确实是个坎,普通用户得先学提权
30F
hijack那块太骚了,直接冒充服务端?微软咋想的
B1
@ 暮光祭司 hijack这操作也太野了,微软没做认证?
31F
脚本里那个ctf-consent-system.ctf真能提权?求实测反馈
32F
新手别碰,连connect都搞不明白还玩啥模糊测试
33F
GitHub上issue区一堆人问win11兼容性,作者回得挺慢
B1
@ 铁锈术士 win11兼容性真头疼,等作者回复等到花儿都谢了
34F
之前用类似工具被火绒当成木马删了,心累
四川 广元 35F
UAC绕过看着香,但实际得配合其他漏洞吧?🤔
36F
ctf-consent-system那个脚本真能弹UAC?我这没反应啊
B1
@ 烘焙甜心 我跑ctf-consent-system.ctf根本弹不出UAC,是不是得特定版本?
37F
之前搞过这个,确实折腾了好久才跑通环境
B1
@ 记忆巷口 同折腾一整天,最后发现是VS版本不对
38F
hijack命令太狠了,相当于直接抢服务器控制权?
39F
新手劝退系列,光依赖就装了一小时
40F
看这工具来头不小,taviso大神出品必属精品
41F
能不能出个中文教程啊,英文文档看着头大
42F
模块加载地址都能查,这功能有点实用
43F
这工具对做Windows内核安全的人帮助挺大
B1
@ TheQuirkyQuokka 对,调试内核问题时用它挺方便的。
44F
这个connect命令的用法挺多的
45F
hijack功能有点吓人,直接劫持服务器?
B1
@ 像素魔法师 这哪是劫持,简直是直接坐上服务器驾驶座了😂
46F
之前装依赖搞了半天,各种版本不兼容
47F
win11有人试过没?我这老是报错
广东 潮州 48F
这种工具容易被杀软误杀吧
49F
UAC绕过实际成功率咋样?
湖南 岳阳 50F
看命令列表感觉功能挺全的
51F
源码编译起来麻烦不?
52F
脚本路径写错了吧?我这提示找不到文件
53F
之前搞CTF环境被360删了三次,心累
54F
win11上connect直接报错,有人解决了吗?
浙江 杭州 55F
跨会话攻击那段挺有意思
56F
工具功能挺全的,就是编译有点折腾
57F
hijack命令实测有点卡,大家遇到过吗
58F
脚本功能挺实用的