Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the behavior of recording event log #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

herosi
Copy link

@herosi herosi commented Nov 14, 2023

  1. Added MaxSize to avoid missing event log records if their message sizes are too big
    Although powershell-protect can record events to Application event log on Windows, if the message size of an event is too big, the message will not be recorded due to a limitation or a bug while block and file actions work correctly.
    I confirmed it when It detected some of powershell empire agent and modules such as Invoke-Empire and Invoke-Mimikatz.
    To avoid this problem, I implemented maxSize for each event. Currently, I only limit the size of Script field.

  2. Changed event log IDs
    In the original code, all event IDs will be 0. I changed the behavior according to the event type.

1. Added MaxSize to avoid missing event log records if their message sizes too big
Although powershell-protect can record events to Application event log on Windows, if the message size of an event is too big, the message will not be recorded due to a limitation or a bug while block and file actions work correctly.
I confirmed it when It detected some of powershell empire agent and modules such as Invoke-Empire and Invoke-Mimikatz.
To avoid this problem, I implemented maxSize for each event. Currently, I only limit the size of Script field.

2. Changed event log IDs
In the original code, all event IDs will be 0. I changed the behavior according to the event type.
To avoid an exception if a string is null.
An exception occurs when a script content or other parts are null. This occurs a rule without checking script contents. For example, if we create a rule like this.
```
    <Rule>
        <Name>Non-standard powershell executable</Name>
        <Conditions>
            <Condition>
                <Property>ApplicationName</Property>
                <Operator>NotContains</Operator>
                <Value>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Value>
            </Condition>
        </Conditions>
        <Actions>
            <ActionRef>
                <Name>File</Name>
            </ActionRef>
        </Actions>
    </Rule>
```

And it occurs when an application name is WMI and DotNet. And the message is here.
```
Failed to analyze script. Object reference not set to an instance of an object.
   at Engine.ScriptContext.get_Members()
   at Engine.Analyze.Conditions.ListCondition.Analyze(ScriptContext context, Condition condition)
   at Engine.Analyzer.Analyze(ScriptContext scriptContext)
   at Engine.ProtectEngine.Analyze(String script, String path, String app)
```

To avoid this, I added additional checks if the contents are null or not.
@herosi
Copy link
Author

herosi commented Dec 1, 2023

I have changed the code to fix another problem occuring an exception. See the issue #8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant