fluent-plugin-modsecurity 0.1.2
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/.gitignore +50 -0
- data/.travis.yml +12 -0
- data/CHANGELOG +0 -0
- data/Gemfile +10 -0
- data/LICENSE +21 -0
- data/README.md +57 -0
- data/README.rdoc +0 -0
- data/Rakefile +11 -0
- data/fluent-plugin-modsecurity.gemspec +30 -0
- data/lib/fluent/plugin/filter_modsecurity.rb +36 -0
- data/test/helper.rb +24 -0
- data/test/plugin/test_filter_modsecurity.rb +23 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db0d869f49d5a7d562f6eb8fb70622246224f47d
|
4
|
+
data.tar.gz: 2773e9590c6c25cfd7298def65a81382db6aa248
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f35e35ae50132b6cc4ba39a3cef68a04f2862ee32520947653c3a82c8f0876c4a028f576cda1273a57b860901665b89588d1b73674ed9cc1cf99e96f5449328
|
7
|
+
data.tar.gz: 2f2dbedaef76ea31bcf1d17351f0a17d57e9b00b20a4b51d381a204817273f295cbe31e10762c940565b9c5008a3c73a4a467a7f1bcf9654137f726845bbc615
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
File without changes
|
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in fluent-plugin-elasticsearch.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'simplecov', require: false
|
7
|
+
gem 'coveralls', require: false
|
8
|
+
gem 'strptime', require: false if RUBY_ENGINE == "ruby" && RUBY_VERSION =~ /^2/
|
9
|
+
|
10
|
+
gem "fluent-plugin-modsecurity", :git => "https://github.com/kaija/fluent-plugin-modsecurity.git"
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 kaija
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# fluent-plugin-modsecurity
|
2
|
+
fluentd plugin for modsecurity log
|
3
|
+
|
4
|
+
[](https://travis-ci.org/kaija/fluent-plugin-modsecurity)
|
5
|
+
|
6
|
+
|
7
|
+
# td-agent config
|
8
|
+
|
9
|
+
|
10
|
+
```
|
11
|
+
# (1) Consume the input by tail and tag modsecurity
|
12
|
+
<source>
|
13
|
+
type tail
|
14
|
+
tag modsecurity
|
15
|
+
format /^(?<host>[^ ]*) (?<remote_addr>[^ ]*) (?<remote_user>[^ ]*) (?<local_user>[^ ]*) \[(?<timestamp>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*) +\S*)?" (?<status_code>[^ ]*) (?<body_bytes_sent>[^ ]*) "(?<message>.*)$/
|
16
|
+
time_format %d/%b/%Y:%H:%M:%S %z
|
17
|
+
pos_file /var/log/td-agent/modsec_audit2.log.pos
|
18
|
+
path /var/log/modsec/audit.log
|
19
|
+
</source>
|
20
|
+
|
21
|
+
# (2) retreive detail log from each record and append back to record
|
22
|
+
<filter modsecurity>
|
23
|
+
type modsecurity
|
24
|
+
path_prefix /var/log
|
25
|
+
</filter>
|
26
|
+
|
27
|
+
# (3) append geoip information (optional)
|
28
|
+
<match modsecurity>
|
29
|
+
type geoip
|
30
|
+
geoip_lookup_key transaction.client_ip
|
31
|
+
enable_key_country_code geoip_country
|
32
|
+
enable_key_city geoip_city
|
33
|
+
enable_key_latitude geoip_lat
|
34
|
+
enable_key_longitude geoip_lon
|
35
|
+
remove_tag_prefix test.
|
36
|
+
add_tag_prefix geoip.
|
37
|
+
flush_interval 5s
|
38
|
+
</match>
|
39
|
+
|
40
|
+
# (3) Output
|
41
|
+
|
42
|
+
<match geoip.modsecurity>
|
43
|
+
type elasticsearch
|
44
|
+
include_tag_key true
|
45
|
+
log_level info
|
46
|
+
logstash_format true
|
47
|
+
logstash_prefix modsecurity_geo
|
48
|
+
type_name blocked
|
49
|
+
buffer_chunk_limit 1M
|
50
|
+
buffer_queue_limit 32
|
51
|
+
flush_interval 30s
|
52
|
+
host 192.168.1.2
|
53
|
+
port 9200
|
54
|
+
</match>
|
55
|
+
```
|
56
|
+
|
57
|
+
|
data/README.rdoc
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'fluent-plugin-modsecurity'
|
6
|
+
s.version = '0.1.2'
|
7
|
+
s.authors = ['kaija']
|
8
|
+
s.email = ['kaija.chang@gmail.com']
|
9
|
+
s.description = %q{modsecurity filter plugin for Fluent detail log}
|
10
|
+
s.summary = %q{modsecurity filter plugin}
|
11
|
+
s.homepage = 'https://github.com/kaija/fluent-plugin-modsecurity'
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split($/)
|
15
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
|
20
|
+
|
21
|
+
s.add_runtime_dependency 'fluentd', '~> 0.10'
|
22
|
+
s.extra_rdoc_files = [
|
23
|
+
"CHANGELOG",
|
24
|
+
"README.rdoc"
|
25
|
+
]
|
26
|
+
|
27
|
+
s.add_development_dependency 'rake', '~> 0'
|
28
|
+
s.add_development_dependency 'test-unit', '~> 3.1'
|
29
|
+
s.add_development_dependency 'minitest', '~> 5.8'
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Fluent::ModsecurityFilter < Fluent::Filter
|
5
|
+
|
6
|
+
Fluent::Plugin.register_filter('modsecurity', self)
|
7
|
+
|
8
|
+
desc "Path prefix of the detail log"
|
9
|
+
config_param :path_prefix, :string, default: "/var/log"
|
10
|
+
|
11
|
+
def configure(conf)
|
12
|
+
super
|
13
|
+
@path_prefix = conf['path_prefix']
|
14
|
+
end
|
15
|
+
|
16
|
+
def filter(tag, time, record)
|
17
|
+
log_path = ""
|
18
|
+
record.each{ |key, value|
|
19
|
+
token = value.split(" ")
|
20
|
+
token.each { |v|
|
21
|
+
if v.start_with?(@path_prefix)
|
22
|
+
log_path = v
|
23
|
+
break
|
24
|
+
end
|
25
|
+
}
|
26
|
+
}
|
27
|
+
#find detail log and append to record
|
28
|
+
unless log_path.to_s.strip.empty?
|
29
|
+
file = File.read(log_path)
|
30
|
+
data_hash = JSON.parse(file)
|
31
|
+
#copy transaction object to original record
|
32
|
+
record['transaction'] = data_hash['transaction']
|
33
|
+
end
|
34
|
+
record
|
35
|
+
end
|
36
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter do |src|
|
4
|
+
!(src.filename =~ /^#{SimpleCov.root}\/lib/)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'coveralls'
|
9
|
+
Coveralls.wear!
|
10
|
+
|
11
|
+
# needs to be after simplecov but before test/unit, because fluentd sets default
|
12
|
+
# encoding to ASCII-8BIT, but coverall might load git data which could contain a
|
13
|
+
# UTF-8 character
|
14
|
+
at_exit do
|
15
|
+
Encoding.default_internal = 'UTF-8' if defined?(Encoding) && Encoding.respond_to?(:default_internal)
|
16
|
+
Encoding.default_external = 'UTF-8' if defined?(Encoding) && Encoding.respond_to?(:default_external)
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'test/unit'
|
20
|
+
require 'fluent/test'
|
21
|
+
require 'minitest/pride'
|
22
|
+
|
23
|
+
#require 'webmock/test_unit'
|
24
|
+
#WebMock.disable_net_connect!
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ModsecurityFilter < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
require 'fluent/plugin/filter_modsecurity'
|
8
|
+
@driver = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def driver(tag='test', config='')
|
12
|
+
@driver ||= Fluent::Test::FilterTestDriver.new(Fluent::ModsecurityFilter, tag).configure(config)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_configure
|
16
|
+
config = %{
|
17
|
+
path_prefix /var/log
|
18
|
+
}
|
19
|
+
instance = driver('test', config).instance
|
20
|
+
path = instance.path_prefix
|
21
|
+
assert_equal "/var/log", path
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-modsecurity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kaija
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.8'
|
69
|
+
description: modsecurity filter plugin for Fluent detail log
|
70
|
+
email:
|
71
|
+
- kaija.chang@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- CHANGELOG
|
76
|
+
- README.rdoc
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CHANGELOG
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- README.rdoc
|
85
|
+
- Rakefile
|
86
|
+
- fluent-plugin-modsecurity.gemspec
|
87
|
+
- lib/fluent/plugin/filter_modsecurity.rb
|
88
|
+
- test/helper.rb
|
89
|
+
- test/plugin/test_filter_modsecurity.rb
|
90
|
+
homepage: https://github.com/kaija/fluent-plugin-modsecurity
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: modsecurity filter plugin
|
114
|
+
test_files:
|
115
|
+
- test/helper.rb
|
116
|
+
- test/plugin/test_filter_modsecurity.rb
|