-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Winlogbeat] Sysmon and Security "modules" for Winlogbeat #11651
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5cde80
Add pipelines for the Security and Sysmon event logs
andrewkroh ee9c315
Set to fail_on_error instead of ignore_failure
andrewkroh 69769f9
Use CommandLineToArgv to parse command line args
andrewkroh 6429222
Add doc.go so the package is not empty on non-windows
andrewkroh 9cf8908
Use UTC timezone if golden files
andrewkroh ac6f257
Remove host specific user info from golden data
andrewkroh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
winlogbeat | ||
/winlogbeat | ||
|
||
# Folders | ||
_obj | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
winlogbeat/processors/script/javascript/module/winlogbeat/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// Package winlogbeat registers the winlogbeat module with the javascript script | ||
// processor. The module has utilities specific to Winlogbeat like parsing | ||
// Windows command lines. | ||
package winlogbeat |
82 changes: 82 additions & 0 deletions
82
winlogbeat/processors/script/javascript/module/winlogbeat/winlogbeat.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// +build windows | ||
|
||
package winlogbeat | ||
|
||
import ( | ||
"syscall" | ||
"unsafe" | ||
|
||
"github.com/dop251/goja" | ||
"github.com/dop251/goja_nodejs/require" | ||
) | ||
|
||
// SplitCommandLine splits a string into a list of space separated arguments. | ||
// See Window's CommandLineToArgvW for more details. | ||
func SplitCommandLine(cmd string) []string { | ||
args, err := commandLineToArgvW(cmd) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return args | ||
} | ||
|
||
func commandLineToArgvW(in string) ([]string, error) { | ||
ptr, err := syscall.UTF16PtrFromString(in) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var numArgs int32 | ||
argsWide, err := syscall.CommandLineToArgv(ptr, &numArgs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Free memory allocated for CommandLineToArgvW arguments. | ||
defer syscall.LocalFree((syscall.Handle)(unsafe.Pointer(argsWide))) | ||
|
||
args := make([]string, numArgs) | ||
for idx := range args { | ||
args[idx] = syscall.UTF16ToString(argsWide[idx][:]) | ||
} | ||
return args, nil | ||
} | ||
|
||
// Require registers the winlogbeat module that has utilities specific to | ||
// Winlogbeat like parsing Windows command lines. It can be accessed using: | ||
// | ||
// // javascript | ||
// var winlogbeat = require('winlogbeat'); | ||
// | ||
func Require(vm *goja.Runtime, module *goja.Object) { | ||
o := module.Get("exports").(*goja.Object) | ||
|
||
o.Set("splitCommandLine", SplitCommandLine) | ||
} | ||
|
||
// Enable adds path to the given runtime. | ||
func Enable(runtime *goja.Runtime) { | ||
runtime.Set("winlogbeat", require.Require(runtime, "winlogbeat")) | ||
} | ||
|
||
func init() { | ||
require.RegisterNativeModule("winlogbeat", Require) | ||
} |
57 changes: 57 additions & 0 deletions
57
winlogbeat/processors/script/javascript/module/winlogbeat/winlogbeat_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// +build windows | ||
|
||
package winlogbeat | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const quotedCommandLine = `"C:\Program Files (x86)\Steam\bin\cef\cef.win7x64\steamwebhelper.exe" "-lang=en_US" "-cachedir=C:\Users\jimmy\AppData\Local\Steam\htmlcache" "-steampid=796" "-buildid=1546909276" "-steamid=0" "-steamuniverse=Dev" "-clientui=C:\Program Files (x86)\Steam\clientui" --disable-spell-checking --disable-out-of-process-pac --enable-blink-features=ResizeObserver,Worklet,AudioWorklet --disable-features=TouchpadAndWheelScrollLatching,AsyncWheelEvents --enable-media-stream --disable-smooth-scrolling --num-raster-threads=4 --enable-direct-write "--log-file=C:\Program Files (x86)\Steam\logs\cef_log.txt"` | ||
|
||
func TestSplitCommandLine(t *testing.T) { | ||
args := SplitCommandLine(quotedCommandLine) | ||
|
||
for _, a := range args { | ||
t.Log(a) | ||
} | ||
|
||
expected := []string{ | ||
`C:\Program Files (x86)\Steam\bin\cef\cef.win7x64\steamwebhelper.exe`, | ||
`-lang=en_US`, | ||
`-cachedir=C:\Users\jimmy\AppData\Local\Steam\htmlcache`, | ||
`-steampid=796`, | ||
`-buildid=1546909276`, | ||
`-steamid=0`, | ||
`-steamuniverse=Dev`, | ||
`-clientui=C:\Program Files (x86)\Steam\clientui`, | ||
`--disable-spell-checking`, | ||
`--disable-out-of-process-pac`, | ||
`--enable-blink-features=ResizeObserver,Worklet,AudioWorklet`, | ||
`--disable-features=TouchpadAndWheelScrollLatching,AsyncWheelEvents`, | ||
`--enable-media-stream`, | ||
`--disable-smooth-scrolling`, | ||
`--num-raster-threads=4`, | ||
`--enable-direct-write`, | ||
`--log-file=C:\Program Files (x86)\Steam\logs\cef_log.txt`, | ||
} | ||
assert.Equal(t, expected, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
x-pack/winlogbeat/module/security/config/winlogbeat-security.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
var security = (function () { | ||
var path = require("path"); | ||
var processor = require("processor"); | ||
var winlogbeat = require("winlogbeat"); | ||
|
||
var addAuthSuccess = new processor.AddFields({ | ||
fields: { | ||
"event.category": "authentication", | ||
"event.type": "authentication_success", | ||
}, | ||
target: "", | ||
}); | ||
|
||
var addAuthFailed = new processor.AddFields({ | ||
fields: { | ||
"event.category": "authentication", | ||
"event.type": "authentication_failed", | ||
}, | ||
target: "", | ||
}); | ||
|
||
var convertAuthentication = new processor.Convert({ | ||
fields: [ | ||
{from: "winlog.event_data.TargetUserSid", to: "user.id"}, | ||
{from: "winlog.event_data.TargetUserName", to: "user.name"}, | ||
{from: "winlog.event_data.TargetDomainName", to: "user.domain"}, | ||
{from: "winlog.event_data.ProcessId", to: "process.pid", type: "long"}, | ||
{from: "winlog.event_data.ProcessName", to: "process.executable"}, | ||
{from: "winlog.event_data.IpAddress", to: "source.ip", type: "ip"}, | ||
{from: "winlog.event_data.IpPort", to: "source.port", type: "long"}, | ||
{from: "winlog.event_data.WorkstationName", to: "source.domain"}, | ||
], | ||
mode: "rename", | ||
ignore_missing: true, | ||
fail_on_error: false, | ||
}); | ||
|
||
var setProcessNameUsingExe = function(evt) { | ||
var name = evt.Get("process.name"); | ||
if (name) { | ||
return; | ||
} | ||
var exe = evt.Get("process.executable"); | ||
evt.Put("process.name", path.basename(exe)); | ||
}; | ||
|
||
var logonSuccess = new processor.Chain() | ||
.Add(addAuthSuccess) | ||
.Add(convertAuthentication) | ||
.Add(setProcessNameUsingExe) | ||
.Build(); | ||
|
||
var logonFailed = new processor.Chain() | ||
.Add(addAuthFailed) | ||
.Add(convertAuthentication) | ||
.Add(setProcessNameUsingExe) | ||
.Build(); | ||
|
||
return { | ||
// 4624 - An account was successfully logged on. | ||
4624: logonSuccess.Run, | ||
|
||
// 4625 - An account failed to log on. | ||
4625: logonFailed.Run, | ||
|
||
// 4648 - A logon was attempted using explicit credentials. | ||
4648: logonSuccess.Run, | ||
|
||
process: function(evt) { | ||
var event_id = evt.Get("winlog.event_id"); | ||
var processor = this[event_id]; | ||
if (processor === undefined) { | ||
return; | ||
} | ||
processor(evt); | ||
}, | ||
}; | ||
})(); | ||
|
||
function process(evt) { | ||
return security.process(evt); | ||
} |
15 changes: 15 additions & 0 deletions
15
x-pack/winlogbeat/module/security/test/security_windows_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elastic/beats/x-pack/winlogbeat/module" | ||
) | ||
|
||
func TestSecurity(t *testing.T) { | ||
module.TestPipeline(t, "testdata/*.evtx", "../config/winlogbeat-security.js") | ||
} |
Binary file added
BIN
+68 KB
x-pack/winlogbeat/module/security/test/testdata/security-windows2012r2-logon.evtx
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gosigar has
ByteSliceToStringSlice
undersys/windows
, that uses winapi CommandLineToArgvW to parse command lines. It has more complicated semantics:I'm unsure if this used at all. I understand that paths can't have quote characters, maybe it's used for command-lines that use quotes as part of their arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the module to use
CommandLineToArgvW
in its implementation. Thanks for letting me know about that function.