Lack of error checking on calls to UTF8toUTF16, rule filter bypass
还没有人认领这个 Issue。
评估
调研方向
从 rules.c 中两个 UTF8toUTF16 调用附近开始,检查 linuxWideChar.c 中的转换实现,然后检查 xml.cpp 中相关的解析路径。重现无效的 UTF-8 输入,并验证过滤既不会访问无效的堆数据,也不会绕过预期规则;通过有针对性的测试或最小复现来确认转换失败时的行为。
由索引模型根据 Issue 内容生成。
描述
Summary
Event filtering in Sysmon For Linux incorrectly assumes event data, such as executable image paths, will be valid UTF-8 and that conversion to UTF-16 will always succeed. This can result in incorrect filtering results and event logging bypass.
Details
Event filtering on Linux makes two calls to UTF8toUTF16 before comparing event data against filter rules:
#if defined __linux__
// on Linux, convert data to UTF16, on heap
size_t fieldValueLen = UTF8toUTF16( NULL, (PCHAR)fieldValue, 0 );
WCHAR *fieldValueUTF16 = (WCHAR *)malloc(fieldValueLen * sizeof(WCHAR));
if (fieldValueUTF16 == NULL) {
printf("Out of memory\n");
return Failed;
}
UTF8toUTF16( fieldValueUTF16, (PCHAR)fieldValue, fieldValueLen );
fieldValue = fieldValueUTF16;
#endif
The first call to it is done in such a way that it just computes the length of the would-be converted string, the value of which is then used in a call to malloc, where the second call performs actual conversion on the newly allocated heap space.
The issue is that Linux paths are not required to be UTF-8 and calls to UTF8toUTF16 can fail, which is not accounted for:
- The first call to
UTF8toUTF16results in error, with returns zero. https://github.com/Sysinternals/SysmonForLinux/blob/f5d6219ec099acf61c1d3b3eecdabaed69faefe4/linuxWideChar.c#L38 mallocis then called with argument0(fieldValueLen * sizeof(WCHAR)), which can return a valid pointer on the heap.UTF8toUTF16is called again to perform the conversion on this newly allocated heap space, but no data will be written because the argument tolenis zero https://github.com/Sysinternals/SysmonForLinux/blob/f5d6219ec099acf61c1d3b3eecdabaed69faefe4/linuxWideChar.c#L58- The code continues to call
MatchFilterOnSpecificRulewith our pointer on the heap, which will result in either comparing against invalid heap data or aNULLpointer dereference.
This could be used to bypass filter rules where a match should be found for an event. For example, an executable at path /tmp/� (where the “�” is hex FF) with the following filter rule:
...
<ProcessCreate onmatch="include">
<Image condition="begin with">/tmp</Image>
</ProcessCreate>
...
On Fixing
The invalid heap access could be resolved by checking for errors from UTF8toUTF16. For example: https://github.com/inickles/SysmonCommon/commit/01a772320d385146cd91a71b186e9eaa7c912963
However, this does not fully mitigate the issue of being a potential event filter bypass. FilterEventRules will default to excluding events if no matches were found and there are multiple rules defined:
https://github.com/Sysinternals/SysmonCommon/blob/73ae2ac398dcba2ae01c2e40664f662c9fc270c8/rules.c#L1968
It seems the conversion to UTF-16 is done to be able to code shared with the Windows version, but in do so Sysmon For Linux apparently assumes these conversions will always succeed, which won’t always be the case.
Other issues in assuming UTF8toUTF16 will succeed can be found in Sysmon For Linux config parsing in https://github.com/Sysinternals/SysmonCommon/blob/73ae2ac398dcba2ae01c2e40664f662c9fc270c8/xml.cpp, though these are seemingly less serious, where a filter value might be terminated earlier than expected.
- 主要语言
- C
- 星标
- 2.2k
- 派生
- 222
- 平均合并
- 4 小时 50 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/Sysmon-Linux 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 68/100
microsoft/Sysmon-Linux#253 ·
-
难度 3/5 1-2 天 新手友好度 72/100
microsoft/Sysmon-Linux#252 ·
-
难度 3/5 1-2 天 新手友好度 55/100
microsoft/Sysmon-Linux#247 ·
-
难度 1/5 1 小时以内 新手友好度 12/100
microsoft/Sysmon-Linux#246 · 3 条评论 ·
-
Sysmon service executable remains `(deleted)` after restart, causing repeated needrestart restarts and systemd start-limit-hit可能重新可做 @MarioHewardt 于 31 天前认领,目前没有进行中的 PR。 未关闭
microsoft/Sysmon-Linux#244 · 已指派 1 人 ·
查看 microsoft/Sysmon-Linux 的全部 Issue
相似的 Issue
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 82/100
-
bug multiplayer status: planned
难度 2/5 1-3 小时 新手友好度 67/100
ChupathingyCE/chupathingyce#851 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 73/100
HigherOrderCO/Bend#2104 ·
-
research-radar
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
good first issue help wanted program
难度 2/5 1-3 小时 新手友好度 83/100
hffgzktbcc-blip/ounce-core#297 ·
维护者通常 1 天内回复