-
Notifications
You must be signed in to change notification settings - Fork 5k
Add translate_sid processor to Winlogbeat #16013
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
Merged
andrewkroh
merged 5 commits into
elastic:master
from
andrewkroh:feature/wlb/translate-sid
Feb 26, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1dd73df
Add translate_sid processor to Winlogbeat
andrewkroh ac61984
Add windows build constraint
andrewkroh fbec5ca
Fix comment
andrewkroh ecba36c
Undo breaking change to SIDType
andrewkroh 63c5787
Make processor available to all Beats
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,41 @@ | ||
| // 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 translate_sid | ||
|
|
||
| import "github.com/pkg/errors" | ||
|
|
||
| type config struct { | ||
| Field string `config:"field" validate:"required"` | ||
| AccountNameTarget string `config:"account_name_target"` | ||
| AccountTypeTarget string `config:"account_type_target"` | ||
| DomainTarget string `config:"domain_target"` | ||
| IgnoreMissing bool `config:"ignore_missing"` | ||
| IgnoreFailure bool `config:"ignore_failure"` | ||
| } | ||
|
|
||
| func (c *config) Validate() error { | ||
| if c.AccountNameTarget == "" && c.AccountTypeTarget == "" && c.DomainTarget == "" { | ||
| return errors.New("at least one target field must be configured " + | ||
| "(set account_name_target, account_type_target, and/or domain_target)") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func defaultConfig() config { | ||
| return config{} | ||
| } |
This file contains hidden or 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,20 @@ | ||
| // 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 translate_sid provides a Beat processor for converting Windows | ||
| // security identifiers (SIDs) to account names. | ||
| package translate_sid |
46 changes: 46 additions & 0 deletions
46
libbeat/processors/translate_sid/docs/translate_sid.asciidoc
This file contains hidden or 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,46 @@ | ||
| [[processor-translate-sid]] | ||
| === Translate SID | ||
|
|
||
| beta[] | ||
|
|
||
| The `translate_sid` processor translates a Windows security identifier (SID) | ||
| into an account name. It retrieves the name of the account associated with the | ||
| SID, the first domain on which the SID is found, and the type of account. This | ||
| is only available on Windows. | ||
|
|
||
| Every account on a network is issued a unique SID when the account is first | ||
| created. Internal processes in Windows refer to an account's SID rather than | ||
| the account's user or group name and these values sometimes appear in logs. | ||
|
|
||
| If the SID is invalid (malformed) or does not map to any account on the local | ||
| system or domain then this will result in the processor returning an error | ||
| unless `ignore_failure` is set. | ||
|
|
||
| [source,yaml] | ||
| ---- | ||
| processors: | ||
| - translate_sid: | ||
| field: winlog.event_data.MemberSid | ||
| account_name_target: user.name | ||
| domain_target: user.domain | ||
| ignore_missing: true | ||
| ignore_failure: true | ||
| ---- | ||
|
|
||
| The `translate_sid` processor has the following configuration settings: | ||
|
|
||
| .Translate SID options | ||
| [options="header"] | ||
| |====== | ||
| | Name | Required | Default | Description | ||
| | `field` | yes | | Source field containing a Windows security identifier (SID). | ||
| | `account_name_target` | yes* | | Target field for the account name value. | ||
| | `account_type_target` | yes* | | Target field for the account type value. | ||
| | `domain_target` | yes* | | Target field for the domain value. | ||
| | `ignore_missing` | no | false | Ignore errors when the source field is missing. | ||
| | `ignore_failure` | no | false | Ignore all errors produced by the processor. | ||
| |====== | ||
|
|
||
| * At least one of `account_name_target`, `account_type_target`, and | ||
| `domain_target` is required to be configured. | ||
|
|
This file contains hidden or 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,124 @@ | ||
| // 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 translate_sid | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "go.uber.org/multierr" | ||
| "golang.org/x/sys/windows" | ||
|
|
||
| "github.com/elastic/beats/libbeat/beat" | ||
| "github.com/elastic/beats/libbeat/common" | ||
| "github.com/elastic/beats/libbeat/logp" | ||
| "github.com/elastic/beats/libbeat/processors" | ||
| jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor" | ||
| "github.com/elastic/beats/winlogbeat/sys" | ||
| ) | ||
|
|
||
| const logName = "processor.translate_sid" | ||
|
|
||
| var errInvalidType = errors.New("SID field value is not a string") | ||
|
|
||
| func init() { | ||
| processors.RegisterPlugin("translate_sid", New) | ||
| jsprocessor.RegisterPlugin("TranslateSID", New) | ||
| } | ||
|
|
||
| type processor struct { | ||
| config | ||
| log *logp.Logger | ||
| } | ||
|
|
||
| // New returns a new translate_sid processor for converting windows SID values | ||
| // to names. | ||
| func New(cfg *common.Config) (processors.Processor, error) { | ||
| c := defaultConfig() | ||
| if err := cfg.Unpack(&c); err != nil { | ||
| return nil, errors.Wrap(err, "fail to unpack the translate_sid configuration") | ||
| } | ||
|
|
||
| return newFromConfig(c) | ||
| } | ||
|
|
||
| func newFromConfig(c config) (*processor, error) { | ||
| return &processor{ | ||
| config: c, | ||
| log: logp.NewLogger(logName), | ||
| }, nil | ||
| } | ||
|
|
||
| func (p *processor) String() string { | ||
| return fmt.Sprintf("translate_sid=[field=%s, account_name_target=%s, account_type_target=%s, domain_target=%s]", | ||
| p.Field, p.AccountNameTarget, p.AccountTypeTarget, p.DomainTarget) | ||
| } | ||
|
|
||
| func (p *processor) Run(event *beat.Event) (*beat.Event, error) { | ||
| err := p.translateSID(event) | ||
| if err == nil || p.IgnoreFailure || (p.IgnoreMissing && common.ErrKeyNotFound == errors.Cause(err)) { | ||
| return event, nil | ||
| } | ||
| return event, err | ||
| } | ||
|
|
||
| func (p *processor) translateSID(event *beat.Event) error { | ||
| v, err := event.GetValue(p.Field) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| sidString, ok := v.(string) | ||
| if !ok { | ||
| return errInvalidType | ||
| } | ||
|
|
||
| // All SIDs starting with S-1-15-3 are capability SIDs. Active Directory | ||
| // does not resolve them so don't try. | ||
| // Reference: https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems | ||
| if strings.HasPrefix(sidString, "S-1-15-3-") { | ||
| return windows.ERROR_NONE_MAPPED | ||
|
|
||
| } | ||
|
|
||
| sid, err := windows.StringToSid(sidString) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // XXX: May want to introduce an in-memory cache if the lookups are time consuming. | ||
| account, domain, accountType, err := sid.LookupAccount("") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Do all operations even if one fails. | ||
| var errs []error | ||
| if _, err = event.PutValue(p.AccountNameTarget, account); err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| if _, err = event.PutValue(p.AccountTypeTarget, sys.SIDType(accountType).String()); err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| if _, err = event.PutValue(p.DomainTarget, domain); err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| return multierr.Combine(errs...) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.