From cffc81db9ae1f6ceab7c61ba5407e517165d1414 Mon Sep 17 00:00:00 2001 From: Lee Hinman <57081003+leehinman@users.noreply.github.com> Date: Wed, 28 Oct 2020 12:19:14 -0500 Subject: [PATCH] protect against accessing undefined variables in sysmon module (#22236) Closes #22219 --- CHANGELOG.next.asciidoc | 1 + .../module/sysmon/config/winlogbeat-sysmon.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 874fa29264a..1a3e1623533 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -397,6 +397,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix invalid IP addresses in DNS query results from Sysmon data. {issue}18432[18432] {pull}18436[18436] - Fields from Winlogbeat modules were not being included in index templates and patterns. {pull}18983[18983] - Add source.ip validation for event ID 4778 in the Security module. {issue}19627[19627] +- Protect against accessing undefined variables in Sysmon module. {issue}22219[22219] {pull}22236[22236] *Functionbeat* diff --git a/x-pack/winlogbeat/module/sysmon/config/winlogbeat-sysmon.js b/x-pack/winlogbeat/module/sysmon/config/winlogbeat-sysmon.js index d5921722210..9523b9171f6 100644 --- a/x-pack/winlogbeat/module/sysmon/config/winlogbeat-sysmon.js +++ b/x-pack/winlogbeat/module/sysmon/config/winlogbeat-sysmon.js @@ -303,6 +303,9 @@ var sysmon = (function () { return; } var exe = evt.Get(pathField); + if (!exe) { + return; + } evt.Put(nameField, path.basename(exe)); }; @@ -327,7 +330,11 @@ var sysmon = (function () { }; var addUser = function (evt) { - var userParts = evt.Get("winlog.event_data.User").split("\\"); + var userParts = evt.Get("winlog.event_data.User"); + if (!userParts) { + return; + } + userParts = userParts.split("\\"); if (userParts.length === 2) { evt.Delete("user"); evt.Put("user.domain", userParts[0]); @@ -406,6 +413,9 @@ var sysmon = (function () { // in the specified namespace. It also adds all the hashes to 'related.hash'. var addHashes = function (evt, namespace, hashField) { var hashes = evt.Get(hashField); + if (!hashes) { + return; + } evt.Delete(hashField); hashes.split(",").forEach(function (hash) { var parts = hash.split("=");