- Регистрация
- 20.01.2011
- Сообщения
- 7,665
- Розыгрыши
- 0
- Реакции
- 135
PowerView is evil, but PowerVi and ew are legit, right? - Missing signature-based detections due to PowerShell Script Block Logging Fragmentation
TL;DR: Sigma rules and similar signature-based threat detection measures may miss malicious PowerShell scripts due to unpredictable fragmentation of script block logs.Introduction
Для просмотра ссылки ВойдиI know this is a lot, but bear with me as I tell you the whole story. If you are only interested in the juicy part, you can skip to ‘The case of split “PowerVi/ew”’.
The Uncertainty of Script Block Logging
Для просмотра ссылки ВойдиRun | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
# Blocks | 54 | 76 | 57 | 49 | 64 | 57 | 55 | 69 | 39 | 47 |
More script blocks -> More alerts?
Now, when using Sigma rules that operate on single logged ScriptBlockTexts, the number of generated alerts might differ because the number of logged blocks differs. More specific, the number of generated alerts usually increases with increasing number of blocks, because the malicious/suspicious strings were found in more blocks. Using “all rules” from Sigma release Для просмотра ссылки ВойдиBlocks | 39 | 47 | 49 | 54 | 55 | 57 | 57 | 64 | 69 | 76 |
---|---|---|---|---|---|---|---|---|---|---|
Alarms | 79 | 91 | 94 | 103 | 99 | 106 | 107 | 110 | 119 | 126 |
… raised on … blocks | 39 | 46 | 48 | 53 | 53 | 56 | 56 | 60 | 65 | 70 |
More script blocks -> Less alerts??
To investigate how the number of blocks influences the number of generated alerts, we further looked into the generated alarms. Below, the number of generated alerts for each triggered rule is listed for each of the 10 runs.Rule / Run#Blocks | 9#39 | 10#47 | 4#49 | 1#54 | 7#55 | 3#57 | 6#57 | 5#64 | 8#69 | 2#76 | AVG |
---|---|---|---|---|---|---|---|---|---|---|---|
Total | 79 | 91 | 94 | 103 | 99 | 106 | 107 | 110 | 119 | 126 | 103.4 |
Execute Invoke-command on Remote Host | 5 | 6 | 6 | 6 | 6 | 7 | 6 [2] | 7 | 7 | 7 | 6.3 |
Malicious PowerShell Commandlets - ScriptBlock | 35 | 42 | 43 | 49 | 46 | 51 | 51 | 53 | 58 | 61 | 48.9 |
Malicious PowerShell Keywords | 3 | 2 | 2 | 2 | 2 | 2 | 3 | 2 | 3 | 2 | 2.3 |
Manipulation of User Computer or Group Security Principals Across AD | 4 | 4 | 4 | 6 [3] | 4 | 4 | 4 | 4 | 4 | <5> | 4.3 |
Potential In-Memory Execution Using Reflection.Assembly | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Potential Suspicious PowerShell Keywords | 1 [1] | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1.9 |
PowerView PowerShell Cmdlets - ScriptBlock | 27 | 30 | 32 | 34 | 35 | 35 | 36 | 38 | 40 | 45 | 35.2 |
Request A Single Ticket via PowerShell | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | <2> +1 because of script block cut-off | 1 | 1.1 |
Usage Of Web Request Commands And Cmdlets - ScriptBlock | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
[1] Potential Suspicious PowerShell Keywords: When having only 39 script block fragments, only 1 alarm is generated because all the “suspicious” strings fitted into the first block - because it is larger compared to the other cases.
[2] Execute Invoke-command on Remote Host: Goes from 5 to 7 raised alerts - increasing with the number of blocks because the search strings are found in more blocks. Only run 6 with 57 blocks is an outlier, producing less alerts than run 3 with the same amount of 57 blocks. This is getting suspicious..
[3] Manipulation of User Computer or Group Security Principals Across AD: In all but two runs exactly 4 alarms are generated. The run that raised 5 alarms was the one with the largest number of blocks - so this behavior is expected - but the one with the most alarms (6) only created 54 blocks. Further investigation showed that this is the result of the “random” script fragmentation, where all 6 “suspicious” strings were found in 6 different blocks, where in the other runs multiple strings where found in a single block resulting in less alerts.
Okay, so these results are kind of expected and not too bad. So we should be fine, right?
Well, when investigating the results of the rule Для просмотра ссылки Войди
The case of split “PowerVi/ew”
Among others, the rule Для просмотра ссылки Войди
Код:
Add-Member Noteproperty 'Comment' $Info.lgrpi1_comment\n
$LocalGroup.PSObject.TypeNames.Insert(0, 'PowerVi
And the beginning of script block 39 of 57:
Код:
ew.LocalGroup.API')\n
So, in this case the PowerView script was fragmented in such a way, that a string that should have been detected was no longer detected, i.e., “PowerView” was split into “PowerVi” and “ew”. (To be fair, script block 38 still raised an alarm because the string “PowerView” occures in it multiple times, but still this example illustrates the problem at hand.)
Losing alerts
This shows, that depending on the fragmentation of script blocks, we can indeed lose alerts and miss contents of scripts that should be detected, e.g., by strings split into two parts in two different blocks. But there are other cases: Rules like Для просмотра ссылки ВойдиConclusion
We learned that loading the PowerView script multiple times results in fragmentations of it ranging from 39 to 76 blocks. The alerts raised on these script blocks showed the trend of increasing number of alerts with increasing number of script blocks. Although this behavior adds uncertainty to the generation of alerts, it is of no critical nature. But, another example showed, that the fragmentation of scripts into blocks might result in suspicious/malicious strings being split into two blocks, resulting in a case where the search strings could not be found and the detection is completely missed. Furthermore, when searching for multiple strings in a single block, the fragmentation of scripts might result in these strings being split into two different blocks - where detection is also no longer possible.Is there a remedy? Maybe re-combining script fragments (Для просмотра ссылки Войди
Sidenote: To add, this behavior might also be leveraged by malicious actors to avoid detection…
The described findings were observed on a Windows 10 host with PowerShell Version 5.1 and PowerShell logging configurations according to the Для просмотра ссылки Войди
Для просмотра ссылки Войди