Lack of error checking on calls to UTF8toUTF16, rule filter bypass
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Comece em rules.c, nas proximidades das duas chamadas a UTF8toUTF16, e revise a implementação da conversão em linuxWideChar.c; em seguida, inspecione os caminhos de análise relacionados em xml.cpp. Reproduza uma entrada UTF-8 inválida e verifique se a filtragem não acessa dados inválidos do heap nem contorna a regra pretendida; confirme o comportamento em caso de falhas de conversão com testes focados ou uma reprodução mínima.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- C
- Estrelas
- 2.2k
- Forks
- 224
- Merge médio
- 4h 50min
- PRs com merge (30d)
- 3
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de microsoft/Sysmon-Linux
-
ProcessCreate: ParentImage is empty when the parent starts the process from a non-main threadAberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
microsoft/Sysmon-Linux#253 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
microsoft/Sysmon-Linux#252 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
microsoft/Sysmon-Linux#247 ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 12/100
microsoft/Sysmon-Linux#246 · 3 comentários ·
-
Sysmon service executable remains `(deleted)` after restart, causing repeated needrestart restarts and systemd start-limit-hitTalvez livre de novo @MarioHewardt assumiu há 31 dias e não há nenhum pull request aberto. Aberta
microsoft/Sysmon-Linux#244 · 1 responsável ·
Todas as issues de microsoft/Sysmon-Linux
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
ly05010419/MacNativeGames#2001 ·
Mantenedores costumam responder em até 1 dia
-
area/docdb kind/bug priority/medium status/awaiting-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
yugabyte/yugabyte-db#37426 ·
Mantenedores costumam responder em até 1 dia
-
area/documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
obsproject/obs-studio#14184 ·
Mantenedores costumam responder em até 1 dia
-
extension-modules type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
30-minutes algorithm any-language beginner-friendly c community cpp csharp data-structures go good first issue hacktoberfest help wanted kotlin learning leetcode php ruby rust swift
Dificuldade 2/5 Menos de uma hora Facilidade para iniciantes 85/100
Huerte/algo-solutions-python#211 ·
Mantenedores costumam responder em até 1 dia