audit_log_parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +6 -0
- data/audit_log_parser.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/audit_log_parser/version.rb +3 -0
- data/lib/audit_log_parser.rb +86 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0202a0ebca9afb91aba76841cc3bf2907112c90fed14b0301cf59012ebcc1678
|
4
|
+
data.tar.gz: a6266d08657b1f5ba0a24d6127a5043e08eef71355584910c9c91ea1f29844e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 630ce72caaffc1dd3e0dd09a1985a53a85e48dfabdc8554218c59e5a2ae7509af5ea425e76238369520113e35ba53f1d25907d447a4318af10bc5f29fdf186d3
|
7
|
+
data.tar.gz: 5c50af811818572d925753b44956e5d3b868dc51e7bf45184833534002c0aa163132b8d47df63828d60fa99f8d385b5fbc33cc133778a6200a7001e9cc3dc121
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 winebarrel
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# audit_log_parser
|
2
|
+
|
3
|
+
It is a library for parsing [linux's audit log](https://github.com/linux-audit/audit-documentation/wiki).
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/audit_log_parser.svg)](http://badge.fury.io/rb/audit_log_parser)
|
6
|
+
[![Build Status](https://travis-ci.org/winebarrel/audit_log_parser.svg?branch=master)](https://travis-ci.org/winebarrel/audit_log_parser)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'audit_log_parser'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install audit_log_parser
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
#!/usr/bin/env ruby
|
28
|
+
require 'audit_log_parser'
|
29
|
+
require 'pp'
|
30
|
+
|
31
|
+
audit_log = <<EOS
|
32
|
+
type=SYSCALL msg=audit(1364481363.243:24287): arch=c000003e syscall=2 success=no exit=-13 a0=7fffd19c5592 a1=0 a2=7fffd19c4b50 a3=a items=1 ppid=2686 pid=3538 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts0 ses=1 comm="cat" exe="/bin/cat" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="sshd_config"
|
33
|
+
EOS
|
34
|
+
|
35
|
+
pp AuditLogParser.parse(data)
|
36
|
+
#=> {"header"=>{"type"=>"SYSCALL", "msg"=>"audit(1364481363.243:24287)"},
|
37
|
+
# "body"=>
|
38
|
+
# {"arch"=>"c000003e",
|
39
|
+
# "syscall"=>"2",
|
40
|
+
# "success"=>"no",
|
41
|
+
# "exit"=>"-13",
|
42
|
+
# "a0"=>"7fffd19c5592",
|
43
|
+
# "a1"=>"0",
|
44
|
+
# "a2"=>"7fffd19c4b50",
|
45
|
+
# "a3"=>"a",
|
46
|
+
# "items"=>"1",
|
47
|
+
# "ppid"=>"2686",
|
48
|
+
# "pid"=>"3538",
|
49
|
+
# "auid"=>"500",
|
50
|
+
# "uid"=>"500",
|
51
|
+
# "gid"=>"500",
|
52
|
+
# "euid"=>"500",
|
53
|
+
# "suid"=>"500",
|
54
|
+
# "fsuid"=>"500",
|
55
|
+
# "egid"=>"500",
|
56
|
+
# "sgid"=>"500",
|
57
|
+
# "fsgid"=>"500",
|
58
|
+
# "tty"=>"pts0",
|
59
|
+
# "ses"=>"1",
|
60
|
+
# "comm"=>"\"cat\"",
|
61
|
+
# "exe"=>"\"/bin/cat\"",
|
62
|
+
# "subj"=>"unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023",
|
63
|
+
# "key"=>"\"sshd_config\""}}
|
64
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'audit_log_parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'audit_log_parser'
|
8
|
+
spec.version = AuditLogParser::VERSION
|
9
|
+
spec.authors = ['winebarrel']
|
10
|
+
spec.email = ['sugawara@winebarrel.jp']
|
11
|
+
|
12
|
+
spec.summary = %q{It is a library for parsing.}
|
13
|
+
spec.description = %q{It is a library for parsing.}
|
14
|
+
spec.homepage = 'https://github.com/winebarrel/audit_log_parser'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler'
|
27
|
+
spec.add_development_dependency 'rake'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "audit_log_parser"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
require 'audit_log_parser/version'
|
3
|
+
|
4
|
+
class AuditLogParser
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
def self.parse(src)
|
8
|
+
src.each_line.map do |line|
|
9
|
+
parse_line(line)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parse_line(line)
|
14
|
+
line = line.strip
|
15
|
+
|
16
|
+
if line !~ /type=\w+ msg=audit\([\d.:]+\): /
|
17
|
+
raise Error, "Invalid audit log header: #{line}"
|
18
|
+
end
|
19
|
+
|
20
|
+
header, body = line.split(/: /, 2)
|
21
|
+
header.chomp!(': ')
|
22
|
+
header = parse_header(header)
|
23
|
+
body = parse_body(body)
|
24
|
+
|
25
|
+
{
|
26
|
+
'header' => header,
|
27
|
+
'body' => body,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.parse_header(header)
|
32
|
+
result = {}
|
33
|
+
|
34
|
+
header.split(' ').each do |kv|
|
35
|
+
key, value = kv.split('=', 2)
|
36
|
+
result[key] = value
|
37
|
+
end
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
private_class_method :parse_header
|
42
|
+
|
43
|
+
def self.parse_body(body)
|
44
|
+
unless body.include?('=')
|
45
|
+
raise Error, "Invalid audit log body: #{body}"
|
46
|
+
end
|
47
|
+
|
48
|
+
result = {}
|
49
|
+
ss = StringScanner.new(body)
|
50
|
+
|
51
|
+
while key = ss.scan_until(/=/)
|
52
|
+
if key.include?(', ')
|
53
|
+
msg, key = key.split(', ', 2)
|
54
|
+
result['_message'] = msg.strip
|
55
|
+
end
|
56
|
+
|
57
|
+
key.chomp!('=').strip!
|
58
|
+
value = ss.getch
|
59
|
+
|
60
|
+
case value
|
61
|
+
when nil
|
62
|
+
break
|
63
|
+
when ' '
|
64
|
+
next
|
65
|
+
when '"'
|
66
|
+
value << ss.scan_until(/"/)
|
67
|
+
when "'"
|
68
|
+
nest = ss.scan_until(/'/)
|
69
|
+
nest.chomp!("'")
|
70
|
+
value = nest
|
71
|
+
else
|
72
|
+
value << ss.scan_until(/( |\z)/)
|
73
|
+
value.chomp!(' ')
|
74
|
+
end
|
75
|
+
|
76
|
+
result[key] = value
|
77
|
+
end
|
78
|
+
|
79
|
+
unless ss.rest.empty?
|
80
|
+
raise "must not happen: #{body}"
|
81
|
+
end
|
82
|
+
|
83
|
+
result
|
84
|
+
end
|
85
|
+
private_class_method :parse_body
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: audit_log_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- winebarrel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: It is a library for parsing.
|
56
|
+
email:
|
57
|
+
- sugawara@winebarrel.jp
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- audit_log_parser.gemspec
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/audit_log_parser.rb
|
73
|
+
- lib/audit_log_parser/version.rb
|
74
|
+
homepage: https://github.com/winebarrel/audit_log_parser
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.7.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: It is a library for parsing.
|
98
|
+
test_files: []
|