logstash-filter-spamhaus 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTORS +10 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +79 -0
- data/lib/logstash/filters/spamhaus.rb +46 -0
- data/logstash-filter-spamhaus.gemspec +25 -0
- data/spec/filters/spamhaus_spec.rb +47 -0
- data/spec/spec_helper.rb +2 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 57ef1072ecdea8b4c4f5ef566ce7b2abd4bff8a2
|
4
|
+
data.tar.gz: 6fbabf9d0a966f85130bf6b7a0cf7c2e718c4104
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2e89dab957e11cd0c067ae70076d776cf3dfb8e45f0717059a45bcbb7df468c8a211efa747fd5a81cf1ec98c196530d323b45af36465b2dbf7eb27da3736c53
|
7
|
+
data.tar.gz: 6d4c7d27f5f75b2513ec2a2d35b49849d3086cca92304f3b5259dcf36c508023d5f82db4dd8e550fef088e87b6b3f0ffc7b2dcbe8e91dafb8d745b0f54f37f7c
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Fabio 'MrWHO' Torchetti (fabbari)
|
6
|
+
|
7
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
+
open source awesome.
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2015–2015 ElaWedjaa Inc <http://www.wedjaa.net>
|
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,79 @@
|
|
1
|
+
# Logstash SpamHaus Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
This filter allows you to lookup an IP address in the SpamHaus ZEN list. This list includes all of the SpamHaus blacklists.
|
10
|
+
|
11
|
+
This filter can be used in the simplest form as follows:
|
12
|
+
|
13
|
+
```
|
14
|
+
spamhaus {}
|
15
|
+
```
|
16
|
+
|
17
|
+
It will run with the following defaults:
|
18
|
+
|
19
|
+
* It will loookup the IP address in the `clientip` field
|
20
|
+
* It will tag IPs in the blacklist as `spamhaus_blacklisted`
|
21
|
+
* It will tag IPs not in the blacklist as `spamhaus_whitelisted`
|
22
|
+
|
23
|
+
If an IP is blacklisted it will add a `spamhaus` object to the event with the following properties:
|
24
|
+
* `code`: it's the SpamHaus code for the blocking reason
|
25
|
+
* `blocklist`: it's the SpamHaus blacklist name where this IP was found
|
26
|
+
|
27
|
+
## Configuration
|
28
|
+
|
29
|
+
The filter accepts the following configuration options:
|
30
|
+
|
31
|
+
* `ip` - It's the field that contains the IP address to resolve. *Default: `clientip`*.
|
32
|
+
* `tag_blacklisted` - The tag to add to the event in case the IP is blacklisted. *Default: `spamhaus_blacklisted`*.
|
33
|
+
* `tag_whitelisted` - The tag to add to the event in case the IP is not in any blacklist. *Default: `spamhaus_whitelisted`*.
|
34
|
+
|
35
|
+
A more involved filter configuration could look like:
|
36
|
+
|
37
|
+
```
|
38
|
+
spamhaus {
|
39
|
+
ip => 'client_ip'
|
40
|
+
tag_blacklisted => 'blacklisted'
|
41
|
+
tag_whitelisted => 'whitelisted'
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
45
|
+
## Missing functionality
|
46
|
+
|
47
|
+
This is a bare minimum implementation of the filter. Some things could be good to implement:
|
48
|
+
|
49
|
+
* Lookup multiple IPs
|
50
|
+
* Select the blacklists to lookup
|
51
|
+
|
52
|
+
## Compiling and testing
|
53
|
+
|
54
|
+
Compiling, deploying and testing this plugin requires JRuby. Not only - you want to make sure that the bundle, rake and rspec commands are run using JRuby.
|
55
|
+
|
56
|
+
If you start seeing errors that look like:
|
57
|
+
|
58
|
+
```
|
59
|
+
Could not find gem 'logstash-devutils (>= 0.0.18) ruby' in any of the gem sources listed in your Gemfile or available on this machine.
|
60
|
+
```
|
61
|
+
|
62
|
+
*notice the `ruby` bit after the version* - try and make it explicit that you want to use the JRuby versions of the commands:
|
63
|
+
|
64
|
+
```
|
65
|
+
alias rspec="jruby -S rspec"
|
66
|
+
alias rake="jruby -S rake"
|
67
|
+
alias bundle="jruby -S bundle"
|
68
|
+
```
|
69
|
+
|
70
|
+
Once you specified these aliases things should start working as expected -- unless you don't have jruby in your path.
|
71
|
+
|
72
|
+
Test it our by running `bundle install && bundle exec rspec` - it should produce some output, ending with the test results:
|
73
|
+
|
74
|
+
```
|
75
|
+
Finished in 0.382 seconds (files took 4.03 seconds to load)
|
76
|
+
2 examples, 0 failures
|
77
|
+
|
78
|
+
Randomized with seed xxxxx
|
79
|
+
```
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require 'charon'
|
5
|
+
|
6
|
+
# This filter will populate the 'spamhaus' field in the event
|
7
|
+
# with information about the IP extracted from the event. The
|
8
|
+
# IP field can be specified in the configuration of the filter
|
9
|
+
# by setting 'ip' to the field name.
|
10
|
+
class LogStash::Filters::SpamHaus < LogStash::Filters::Base
|
11
|
+
|
12
|
+
config_name "spamhaus"
|
13
|
+
|
14
|
+
config :ip, :validate => :string, :default => "clientip"
|
15
|
+
config :tag_blacklisted, :validate => :string, :default => "spamhaus_blacklisted"
|
16
|
+
config :tag_notfound, :validate => :string, :default => "spamhaus_whitelisted"
|
17
|
+
|
18
|
+
|
19
|
+
public
|
20
|
+
def register
|
21
|
+
# Add instance variables
|
22
|
+
end # def register
|
23
|
+
|
24
|
+
public
|
25
|
+
def filter(event)
|
26
|
+
|
27
|
+
if @ip
|
28
|
+
lookupip = event[@ip]
|
29
|
+
if lookupip && lookupip =~ /^(\d{1,3}[\.]{0,1}){4}$/
|
30
|
+
event['tags'] ||= []
|
31
|
+
result = Charon.query lookupip
|
32
|
+
if result
|
33
|
+
event['spamhaus'] = {
|
34
|
+
"code" => result[0],
|
35
|
+
"blocklist" => result[1]
|
36
|
+
}
|
37
|
+
event['tags'] << @tag_blacklisted
|
38
|
+
else
|
39
|
+
event['tags'] << @tag_notfound
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
filter_matched(event)
|
45
|
+
end # def filter
|
46
|
+
end # class LogStash::Filters::SpamHaus
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-spamhaus'
|
3
|
+
# s.platform = 'java'
|
4
|
+
s.version = '1.0.1'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "This filter will lookup a given IP in the SpamHaus ZEN list and populate the event with the information found on the list."
|
7
|
+
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
8
|
+
s.authors = ["Wedjaa"]
|
9
|
+
s.email = 'info@wedjaa.net'
|
10
|
+
s.homepage = "http://github.com/WedjaaOpen/logstash-filter-spamhaus"
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
15
|
+
# Tests
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
|
18
|
+
# Special flag to let us know this is actually a logstash plugin
|
19
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
20
|
+
|
21
|
+
# Gem dependencies
|
22
|
+
s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
|
23
|
+
s.add_runtime_dependency "charon", "~> 1.0"
|
24
|
+
s.add_development_dependency 'logstash-devutils', '>= 0.0.18'
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require "logstash/filters/spamhaus"
|
4
|
+
|
5
|
+
describe LogStash::Filters::SpamHaus do
|
6
|
+
describe "Spamhaus should fail on local addresses" do
|
7
|
+
let(:config) do <<-CONFIG
|
8
|
+
filter {
|
9
|
+
spamhaus {
|
10
|
+
ip => "client_ip"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
CONFIG
|
14
|
+
end
|
15
|
+
|
16
|
+
sample('client_ip' => '192.168.66.1' ) do
|
17
|
+
expect(subject).to include("client_ip")
|
18
|
+
expect(subject['client_ip']).to eq('192.168.66.1')
|
19
|
+
expect(subject).to include("tags")
|
20
|
+
expect(subject['tags']).to include('spamhaus_whitelisted')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Spamhaus should report 185.106.92.33 as blacklisted" do
|
25
|
+
let(:config) do <<-CONFIG
|
26
|
+
filter {
|
27
|
+
spamhaus {
|
28
|
+
ip => "client_ip"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
CONFIG
|
32
|
+
end
|
33
|
+
|
34
|
+
sample('client_ip' => '185.106.92.33' ) do
|
35
|
+
expect(subject).to include("client_ip")
|
36
|
+
expect(subject['client_ip']).to eq('185.106.92.33')
|
37
|
+
expect(subject).to include('spamhaus')
|
38
|
+
expect(subject['spamhaus']).to include('code')
|
39
|
+
expect(subject['spamhaus']['code']).to eq(4)
|
40
|
+
expect(subject['spamhaus']).to include('blocklist')
|
41
|
+
expect(subject['spamhaus']['blocklist']).to eq('Exploits Block List')
|
42
|
+
expect(subject).to include("tags")
|
43
|
+
expect(subject['tags']).to include('spamhaus_blacklisted')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-spamhaus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wedjaa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: charon
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: logstash-devutils
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.0.18
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.0.18
|
61
|
+
description: This gem is a logstash plugin required to be installed on top of the
|
62
|
+
Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
|
63
|
+
a stand-alone program
|
64
|
+
email: info@wedjaa.net
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- CHANGELOG.md
|
70
|
+
- CONTRIBUTORS
|
71
|
+
- DEVELOPER.md
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE
|
74
|
+
- NOTICE.TXT
|
75
|
+
- README.md
|
76
|
+
- lib/logstash/filters/spamhaus.rb
|
77
|
+
- logstash-filter-spamhaus.gemspec
|
78
|
+
- spec/filters/spamhaus_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: http://github.com/WedjaaOpen/logstash-filter-spamhaus
|
81
|
+
licenses:
|
82
|
+
- Apache License (2.0)
|
83
|
+
metadata:
|
84
|
+
logstash_plugin: 'true'
|
85
|
+
logstash_group: filter
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: This filter will lookup a given IP in the SpamHaus ZEN list and populate
|
106
|
+
the event with the information found on the list.
|
107
|
+
test_files:
|
108
|
+
- spec/filters/spamhaus_spec.rb
|
109
|
+
- spec/spec_helper.rb
|