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

Fix powershell error on events 40961 and 40962 #10792

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/windows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# newer versions go on top
- version: "2.0.2"
changes:
- description: Fix powershell error on events 40961 and 40962 (at minimum)
type: bugfix
link: https://github.com/elastic/integrations/pull/10792
- version: "2.0.1"
changes:
- description: Fix IPv6 cleanup step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,51 @@
},
"version": 1
}
},
{
"@timestamp": "2024-09-09T16:53:34.055Z",
"event": {
"action": "PowerShell Console Startup",
"code": "40961",
"created": "2024-09-09T17:08:14.566Z",
"kind": "event",
"provider": "Microsoft-Windows-PowerShell"
},
"host": {
"name": "vagrant"
},
"log": {
"level": "information"
},
"message": "PowerShell console is starting up",
"tags": [
"forwarded"
],
"winlog": {
"activity_id": "{9b36ffb2-ffc3-0007-7f34-379bc3ffda01}",
"api": "wineventlog",
"channel": "Microsoft-Windows-PowerShell/Operational",
"computer_name": "DESKTOP-H1QFQE0.bensdomain.com",
"event_id": "40961",
"opcode": "Start",
"process": {
"pid": 8824,
"thread": {
"id": 1472
}
},
"provider_guid": "{a0c1853b-5c40-4b15-8766-3cf1c58f985a}",
"provider_name": "Microsoft-Windows-PowerShell",
"record_id": 206,
"task": "PowerShell Console Startup",
"user": {
"domain": "NT AUTHORITY",
"identifier": "S-1-5-18",
"name": "SYSTEM",
"type": "Well Known Group"
},
"version": 1
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,67 @@
},
"version": 1
}
},
{
"@timestamp": "2024-09-09T16:53:34.055Z",
"ecs": {
"version": "8.0.0"
},
"event": {
"action": "PowerShell Console Startup",
"category": [
"process"
],
"code": "40961",
"created": "2024-09-09T17:08:14.566Z",
"kind": "event",
"provider": "Microsoft-Windows-PowerShell",
"type": [
"info"
]
},
"host": {
"name": "vagrant",
"os": {
"family": "windows",
"type": "windows"
}
},
"log": {
"level": "information"
},
"message": "PowerShell console is starting up",
"tags": [
"forwarded"
],
"user": {
"id": "S-1-5-18"
},
"winlog": {
"activity_id": "{9b36ffb2-ffc3-0007-7f34-379bc3ffda01}",
"api": "wineventlog",
"channel": "Microsoft-Windows-PowerShell/Operational",
"computer_name": "DESKTOP-H1QFQE0.bensdomain.com",
"event_id": "40961",
"opcode": "Start",
"process": {
"pid": 8824,
"thread": {
"id": 1472
}
},
"provider_guid": "{a0c1853b-5c40-4b15-8766-3cf1c58f985a}",
"provider_name": "Microsoft-Windows-PowerShell",
"record_id": "206",
"task": "PowerShell Console Startup",
"user": {
"domain": "NT AUTHORITY",
"identifier": "S-1-5-18",
"name": "SYSTEM",
"type": "Well Known Group"
},
"version": 1
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ processors:
description: Remove all empty values from event_data.
lang: painless
source: ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals(""));
if: ctx?.winlog?.event_data != null
- remove:
description: Remove empty event data.
field: winlog.event_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ processors:
description: Remove all empty values from event_data.
lang: painless
source: ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals(""));
if: ctx?.winlog?.event_data != null
- remove:
description: Remove empty event data.
field: winlog.event_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ processors:
description: Remove all empty values from event_data.
lang: painless
source: ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals("") || entry.getValue().equals("-"));
if: ctx?.winlog?.event_data != null
- remove:
description: Remove empty event data.
field: winlog.event_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ processors:
description: Remove all empty values from event_data.
lang: painless
source: ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals(""));
if: ctx?.winlog?.event_data != null
- remove:
description: Remove empty event data.
field: winlog.event_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,48 @@
},
"version": 1
}
},
{
"@timestamp": "2024-09-03T15:27:45.847Z",
"event": {
"action": "PowerShell Console Startup",
"code": "40961",
"created": "2024-09-05T20:18:14.254Z",
"kind": "event",
"provider": "Microsoft-Windows-PowerShell"
},
"host": {
"name": "vagrant"
},
"log": {
"level": "information"
},
"message": "PowerShell console is starting up",
"winlog": {
"activity_id": "{3ee7a05a-f7fc-0006-f0d2-e73efcf7da01}",
"api": "wineventlog",
"channel": "Microsoft-Windows-PowerShell/Operational",
"computer_name": "vagrant",
"event_id": "40961",
"opcode": "Start",
"process": {
"pid": 2364,
"thread": {
"id": 8092
}
},
"provider_guid": "{a0c1853b-5c40-4b15-8766-3cf1c58f985a}",
"provider_name": "Microsoft-Windows-PowerShell",
"record_id": 143,
"task": "PowerShell Console Startup",
"user": {
"domain": "NT AUTHORITY",
"identifier": "S-1-5-18",
"name": "SYSTEM",
"type": "Well Known Group"
},
"version": 1
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,60 @@
},
"version": 1
}
},
{
"@timestamp": "2024-09-03T15:27:45.847Z",
"ecs": {
"version": "8.0.0"
},
"event": {
"action": "PowerShell Console Startup",
"category": [
"process"
],
"code": "40961",
"created": "2024-09-05T20:18:14.254Z",
"kind": "event",
"provider": "Microsoft-Windows-PowerShell",
"type": [
"info"
]
},
"host": {
"name": "vagrant"
},
"log": {
"level": "information"
},
"message": "PowerShell console is starting up",
"user": {
"id": "S-1-5-18"
},
"winlog": {
"activity_id": "{3ee7a05a-f7fc-0006-f0d2-e73efcf7da01}",
"api": "wineventlog",
"channel": "Microsoft-Windows-PowerShell/Operational",
"computer_name": "vagrant",
"event_id": "40961",
"opcode": "Start",
"process": {
"pid": 2364,
"thread": {
"id": 8092
}
},
"provider_guid": "{a0c1853b-5c40-4b15-8766-3cf1c58f985a}",
"provider_name": "Microsoft-Windows-PowerShell",
"record_id": "143",
"task": "PowerShell Console Startup",
"user": {
"domain": "NT AUTHORITY",
"identifier": "S-1-5-18",
"name": "SYSTEM",
"type": "Well Known Group"
},
"version": 1
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ processors:
description: Remove all empty values from event_data.
lang: painless
source: ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals(""));
if: ctx?.winlog?.event_data != null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure we need to add this to:

forwarded/elasticsearch/ingest_pipeline/powershell_operational.yml

but it probably applies to:

  • powershell/elasticsearch/ingest_pipeline/default.yml
  • sysmon_operational/elasticsearch/ingest_pipeline/default.yml
  • forwarded/elasticsearch/ingest_pipeline/powershell.yml
  • forwarded/elasticsearch/ingest_pipeline/sysmon_operational.yml

Do you happen to have any sample events you could add to powershell_operational/_dev/test/pipeline/test-events.json ? That way the tests will catch this if we break it in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leehinman Thanks for the tips. I was able to find sample events for powershell_operational and added them to tests. I also made the analogous fix powershell and sysmon_operational as you'd suggested, but was unable to create real events that would trigger the issue for those.

- remove:
description: Remove empty event data.
field: winlog.event_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ processors:
description: Remove all empty values from event_data.
lang: painless
source: ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals("") || entry.getValue().equals("-"));
if: ctx?.winlog?.event_data != null
- remove:
description: Remove empty event data.
field: winlog.event_data
Expand Down
2 changes: 1 addition & 1 deletion packages/windows/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: windows
title: Windows
version: 2.0.1
version: 2.0.2
description: Collect logs and metrics from Windows OS and services with Elastic Agent.
type: integration
categories:
Expand Down