logstash-filter-hex_to_ascii 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTORS +5 -0
- data/Gemfile +11 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +98 -0
- data/lib/logstash/filters/hex_to_ascii.rb +89 -0
- data/logstash-filter-hex_to_ascii.gemspec +23 -0
- data/spec/filters/hex_to_ascii_spec.rb +73 -0
- data/spec/spec_helper.rb +2 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4cf217f87a64f977f273e73510fa111a13cb08c4
|
4
|
+
data.tar.gz: 2d02b90d2f00d82345061f545d538d04a1684203
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67e904b72b3d68bd9d56905c46966de57d6a3f0c4bc99449364999cf50cc2809e4f8c016c3fe9f898bc895bcfae40fd05c90c1bb43a7761a5381cff61e46b0ba
|
7
|
+
data.tar.gz: 8bcfebe2a9638ab092298f4a552fdc568464be600b8a55828d8eb153ba49630fcd3553caec3c3fb22610bd710b63deed7791be3687c79f94e1cae9a3fddfabcb
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
|
6
|
+
use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
|
7
|
+
|
8
|
+
if Dir.exist?(logstash_path) && use_logstash_source
|
9
|
+
gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
|
10
|
+
gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
|
11
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2017 Pantheon Systems <https://pantheon.io>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/NOTICE.TXT
ADDED
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/pantheon-systems/logstash-filter-hex_to_ascii.svg)](https://travis-ci.org/pantheon-systems/logstash-filter-hex_to_ascii)
|
4
|
+
|
5
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
|
+
|
7
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
8
|
+
|
9
|
+
## Documentation
|
10
|
+
|
11
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
12
|
+
|
13
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
14
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
15
|
+
|
16
|
+
## Need Help?
|
17
|
+
|
18
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
19
|
+
|
20
|
+
## Developing
|
21
|
+
|
22
|
+
### 1. Plugin Developement and Testing
|
23
|
+
|
24
|
+
#### Code
|
25
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
26
|
+
|
27
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
28
|
+
|
29
|
+
- Install dependencies
|
30
|
+
```sh
|
31
|
+
bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Test
|
35
|
+
|
36
|
+
- Update your dependencies
|
37
|
+
|
38
|
+
```sh
|
39
|
+
bundle install
|
40
|
+
```
|
41
|
+
|
42
|
+
- Run tests
|
43
|
+
|
44
|
+
```sh
|
45
|
+
bundle exec rspec
|
46
|
+
```
|
47
|
+
|
48
|
+
### 2. Running your unpublished Plugin in Logstash
|
49
|
+
|
50
|
+
#### 2.1 Run in a local Logstash clone
|
51
|
+
|
52
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
53
|
+
```ruby
|
54
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
55
|
+
```
|
56
|
+
- Install plugin
|
57
|
+
```sh
|
58
|
+
# Logstash 2.3 and higher
|
59
|
+
bin/logstash-plugin install --no-verify
|
60
|
+
|
61
|
+
# Prior to Logstash 2.3
|
62
|
+
bin/plugin install --no-verify
|
63
|
+
|
64
|
+
```
|
65
|
+
- Run Logstash with your plugin
|
66
|
+
```sh
|
67
|
+
bin/logstash -e 'filter {awesome {}}'
|
68
|
+
```
|
69
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
70
|
+
|
71
|
+
#### 2.2 Run in an installed Logstash
|
72
|
+
|
73
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
74
|
+
|
75
|
+
- Build your plugin gem
|
76
|
+
```sh
|
77
|
+
gem build logstash-filter-awesome.gemspec
|
78
|
+
```
|
79
|
+
- Install the plugin from the Logstash home
|
80
|
+
```sh
|
81
|
+
# Logstash 2.3 and higher
|
82
|
+
bin/logstash-plugin install --no-verify
|
83
|
+
|
84
|
+
# Prior to Logstash 2.3
|
85
|
+
bin/plugin install --no-verify
|
86
|
+
|
87
|
+
```
|
88
|
+
- Start Logstash and proceed to test the plugin
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
93
|
+
|
94
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
95
|
+
|
96
|
+
It is more important to the community that you are able to contribute.
|
97
|
+
|
98
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Convert hex-encoded strings to their ASCII representations.
|
4
|
+
#
|
5
|
+
# This plugin was originally intended to assist with auditd logs which sometimes
|
6
|
+
# log certain values as hex-encoded pieces of data. It may be useful for other
|
7
|
+
# situations where you need to convert hex-encoded strings back to ASCII.
|
8
|
+
#
|
9
|
+
# The plugin will look for one or more strings in the specified field ('message' by default)
|
10
|
+
# and attempt to convert them to Encoding::ASCII_8BIT format. Any string
|
11
|
+
# prefixed with `0x` will be considered hex-encoded. The match prefix can be
|
12
|
+
# changed with the `prefix` config option.
|
13
|
+
#
|
14
|
+
# Quick demo:
|
15
|
+
#
|
16
|
+
# echo '0x6364202F6F70742F' | logstash -e 'input{stdin{}} filter{hex_to_ascii{}} output{stdout{codec => rubydebug}}'
|
17
|
+
# {
|
18
|
+
# "@timestamp" => 2017-08-02T20:01:52.179Z,
|
19
|
+
# "message" => "cd /opt/"
|
20
|
+
# }
|
21
|
+
#
|
22
|
+
# Example decoding the 'cmd=' string emitted by auditd:
|
23
|
+
#
|
24
|
+
# $ echo '<audit-1123> pid=13334 uid=987 auid=4294967295 ses=4294967295 msg=cwd="/" cmd=2F62696E2F66696E64 terminal=? res=success' \
|
25
|
+
# | logstash -e 'input{stdin{}} filter{hex_to_ascii{prefix => "cmd="}} output{stdout{codec => rubydebug}}'
|
26
|
+
#
|
27
|
+
# {
|
28
|
+
# "@timestamp" => 2017-08-02T20:14:02.267Z,
|
29
|
+
# "message" => "<audit-1123> pid=13334 uid=987 auid=4294967295 ses=4294967295 msg=cwd=\"/\" /bin/find terminal=? res=success"
|
30
|
+
# }
|
31
|
+
#
|
32
|
+
# Example decoding the 'data=' string emitted by auditd + pam_tty_audit:
|
33
|
+
#
|
34
|
+
# $ echo 'tty pid=8106 uid=5520 auid=5520 ses=38 major=136 minor=0 comm="bash" data=6364202F6F70742F' \
|
35
|
+
# | logstash -e 'input{stdin{}} filter{hex_to_ascii{prefix => "data="}} output{stdout{codec => rubydebug}}'
|
36
|
+
#
|
37
|
+
#
|
38
|
+
|
39
|
+
require 'logstash/filters/base'
|
40
|
+
|
41
|
+
class LogStash::Filters::HexToAscii < LogStash::Filters::Base
|
42
|
+
config_name 'hex_to_ascii'
|
43
|
+
|
44
|
+
# The field to operate on
|
45
|
+
config :field, :validate => :string, :default => 'message'
|
46
|
+
|
47
|
+
# A hex value may be embedded with other values, some of which may appear to be
|
48
|
+
# hex values but should not be decoded. In order to limit the scope of the search,
|
49
|
+
# set a prefix. The default prefix is `0x`. Other possibilities are `data=` which
|
50
|
+
# is useful for some type of auditd log messages that encode data eg:
|
51
|
+
# `data=654FBAC98C`, which would be converted to `data=df ; ls`
|
52
|
+
config :prefix, :validate => :string, :default => '0x'
|
53
|
+
|
54
|
+
# remove the prefix after successful conversion. default `true`
|
55
|
+
# eg: when true: `0x6466` => `df`
|
56
|
+
# when false: `0x6466` => `0xdf`
|
57
|
+
config :remove_prefix, :validate => :boolean, :default => true
|
58
|
+
|
59
|
+
public
|
60
|
+
def register
|
61
|
+
# Nothing to do
|
62
|
+
end #def register
|
63
|
+
|
64
|
+
public
|
65
|
+
def filter(event)
|
66
|
+
return unless filter?(event)
|
67
|
+
|
68
|
+
event.set(@field, hex_to_ascii(event.get(@field), @prefix, @remove_prefix))
|
69
|
+
filter_matched(event)
|
70
|
+
end # def filter
|
71
|
+
|
72
|
+
# unhexlify a hex value. Some values may not convert to printable UTF-8 characters
|
73
|
+
# in which case ruby will return an ASCII-8BIT (binary) encoded value. In this case
|
74
|
+
# we will use .inspect to return an escaped version of the string
|
75
|
+
# in UTF-8 format otherwise Logstash will throw exceptions.
|
76
|
+
private
|
77
|
+
def unhexlify(msg)
|
78
|
+
string = msg.scan(/../).collect { |c| c.to_i(16).chr }.join
|
79
|
+
(string.encoding == Encoding::ASCII_8BIT) ? string.inspect : string
|
80
|
+
end # def unhexlify
|
81
|
+
|
82
|
+
# find all hex values with the given prefix and attempt to convert to ascii
|
83
|
+
private
|
84
|
+
def hex_to_ascii(value, prefix, strip_prefix)
|
85
|
+
value.gsub(/#{prefix}([0-9A-Fa-f]+)/) do |m|
|
86
|
+
strip_prefix ? unhexlify($1) : prefix + unhexlify($1)
|
87
|
+
end
|
88
|
+
end # def hex_to_ascii
|
89
|
+
end # class LogStash::Filters::HexToAscii
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-hex_to_ascii'
|
3
|
+
s.version = '0.2.0'
|
4
|
+
s.licenses = ['Apache-2.0']
|
5
|
+
s.summary = 'Convert hex-encoded string fields to ASCII'
|
6
|
+
s.description = 'Convert hex-encoded string fields to ASCII'
|
7
|
+
s.homepage = 'https://github.com/pantheon-systems/logstash-filter-hex_to_ascii'
|
8
|
+
s.authors = ['Pantheon']
|
9
|
+
s.email = 'joe@pantheon.io'
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*', 'spec/**/*', 'vendor/**/*', '*.gemspec', '*.md', 'CONTRIBUTORS', 'Gemfile', 'LICENSE', 'NOTICE.TXT']
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'input' }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency 'logstash-core-plugin-api', '>= 1.60', '<= 2.99'
|
22
|
+
s.add_development_dependency 'logstash-devutils', '~> 1.0'
|
23
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'logstash/devutils/rspec/spec_helper'
|
4
|
+
require 'logstash/filters/hex_to_ascii'
|
5
|
+
|
6
|
+
describe 'LogStash::Filters::HexToAscii' do
|
7
|
+
|
8
|
+
describe 'should convert a single hex value to ascii and remove the hex prefix' do
|
9
|
+
config <<-CONFIG
|
10
|
+
filter {
|
11
|
+
hex_to_ascii {
|
12
|
+
field => 'message'
|
13
|
+
prefix => '0x'
|
14
|
+
remove_prefix => 'true'
|
15
|
+
}
|
16
|
+
}
|
17
|
+
CONFIG
|
18
|
+
|
19
|
+
sample '0x666F6F626172' do
|
20
|
+
insist { subject.get('message') } == 'foobar'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'should return an unchanged string if no hex digits found' do
|
25
|
+
config <<-CONFIG
|
26
|
+
filter { hex_to_ascii {} }
|
27
|
+
CONFIG
|
28
|
+
|
29
|
+
sample 'a string with no hex' do
|
30
|
+
insist { subject.get('message') } == 'a string with no hex'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'converts a hex value while leaving the prefix' do
|
35
|
+
config <<-CONFIG
|
36
|
+
filter {
|
37
|
+
hex_to_ascii {
|
38
|
+
prefix => 'data='
|
39
|
+
remove_prefix => 'false'
|
40
|
+
}
|
41
|
+
}
|
42
|
+
CONFIG
|
43
|
+
|
44
|
+
sample 'data=666F6F' do
|
45
|
+
insist { subject.get('message') } == 'data=foo'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'converts multiple hex values' do
|
50
|
+
config <<-CONFIG
|
51
|
+
filter {
|
52
|
+
hex_to_ascii {
|
53
|
+
prefix => 'data='
|
54
|
+
remove_prefix => 'false'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
CONFIG
|
58
|
+
|
59
|
+
sample 'data=666F6F and data=626172' do
|
60
|
+
insist { subject.get('message') } == 'data=foo and data=bar'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'converts unprintable binary characters to printable' do
|
65
|
+
config <<-CONFIG
|
66
|
+
filter { hex_to_ascii {} }
|
67
|
+
CONFIG
|
68
|
+
|
69
|
+
sample '0x66F6F' do
|
70
|
+
insist { subject.get('message') } == '"f\\xF6"'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-hex_to_ascii
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pantheon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.60'
|
19
|
+
- - "<="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.99'
|
22
|
+
name: logstash-core-plugin-api
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.60'
|
30
|
+
- - "<="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.99'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - "~>"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.0'
|
39
|
+
name: logstash-devutils
|
40
|
+
prerelease: false
|
41
|
+
type: :development
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
description: Convert hex-encoded string fields to ASCII
|
48
|
+
email: joe@pantheon.io
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- CHANGELOG.md
|
54
|
+
- CONTRIBUTORS
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- NOTICE.TXT
|
58
|
+
- README.md
|
59
|
+
- lib/logstash/filters/hex_to_ascii.rb
|
60
|
+
- logstash-filter-hex_to_ascii.gemspec
|
61
|
+
- spec/filters/hex_to_ascii_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
homepage: https://github.com/pantheon-systems/logstash-filter-hex_to_ascii
|
64
|
+
licenses:
|
65
|
+
- Apache-2.0
|
66
|
+
metadata:
|
67
|
+
logstash_plugin: 'true'
|
68
|
+
logstash_group: input
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.4.8
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Convert hex-encoded string fields to ASCII
|
89
|
+
test_files:
|
90
|
+
- spec/filters/hex_to_ascii_spec.rb
|
91
|
+
- spec/spec_helper.rb
|