unified2 0.1.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.
- data/.document +3 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.rdoc +9 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +61 -0
- data/Rakefile +39 -0
- data/example/classification.config +67 -0
- data/example/example.rb +43 -0
- data/example/gen-msg.map +391 -0
- data/example/sid-msg.map +15806 -0
- data/example/unified2 +0 -0
- data/gemspec.yml +14 -0
- data/lib/unified2/classification.rb +14 -0
- data/lib/unified2/construct.rb +54 -0
- data/lib/unified2/core_ext/string.rb +8 -0
- data/lib/unified2/core_ext.rb +1 -0
- data/lib/unified2/event.rb +315 -0
- data/lib/unified2/event_ip4.rb +26 -0
- data/lib/unified2/event_ip6.rb +23 -0
- data/lib/unified2/exceptions/file_not_found.rb +4 -0
- data/lib/unified2/exceptions/file_not_readable.rb +4 -0
- data/lib/unified2/exceptions/unknown_load_type.rb +4 -0
- data/lib/unified2/exceptions.rb +2 -0
- data/lib/unified2/packet.rb +16 -0
- data/lib/unified2/payload.rb +32 -0
- data/lib/unified2/primitive/ipv4.rb +19 -0
- data/lib/unified2/primitive.rb +1 -0
- data/lib/unified2/record_header.rb +10 -0
- data/lib/unified2/sensor.rb +26 -0
- data/lib/unified2/signature.rb +24 -0
- data/lib/unified2/version.rb +4 -0
- data/lib/unified2.rb +206 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/unified2_spec.rb +8 -0
- data/unified2.gemspec +15 -0
- metadata +148 -0
data/lib/unified2.rb
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
require 'bindata'
|
|
2
|
+
require 'socket'
|
|
3
|
+
# http://cvs.snort.org/viewcvs.cgi/snort/src/output-plugins/spo_unified2.c?rev=1.3&content-type=text/vnd.viewcvs-markup
|
|
4
|
+
|
|
5
|
+
require 'unified2/construct'
|
|
6
|
+
require 'unified2/core_ext'
|
|
7
|
+
require 'unified2/event'
|
|
8
|
+
require 'unified2/exceptions'
|
|
9
|
+
require 'unified2/version'
|
|
10
|
+
|
|
11
|
+
module Unified2
|
|
12
|
+
|
|
13
|
+
TYPES = [
|
|
14
|
+
:signatures,
|
|
15
|
+
:generators,
|
|
16
|
+
:classifications
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
attr_accessor :signatures, :generators,
|
|
21
|
+
:sensor, :hostname, :interface,
|
|
22
|
+
:classifications
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.configuration(options={}, &block)
|
|
26
|
+
@sensor ||= Sensor.new
|
|
27
|
+
self.instance_eval(&block)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.sensor(options={}, &block)
|
|
31
|
+
if block
|
|
32
|
+
@sensor.instance_eval(&block)
|
|
33
|
+
end
|
|
34
|
+
@sensor.update(options)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.load(type, path)
|
|
38
|
+
|
|
39
|
+
unless TYPES.include?(type.to_sym)
|
|
40
|
+
raise UnknownLoadType, "Error - #{type} is unknown."
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
if File.exists?(path)
|
|
44
|
+
instance_variable_set("@#{type}", {})
|
|
45
|
+
else
|
|
46
|
+
raise FileNotFound, "Error - #{path} not found."
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if File.readable?(path)
|
|
50
|
+
file = File.open(path)
|
|
51
|
+
|
|
52
|
+
case type.to_sym
|
|
53
|
+
when :classifications
|
|
54
|
+
|
|
55
|
+
count = 0
|
|
56
|
+
file.each_line do |line|
|
|
57
|
+
next if line[/^\#/]
|
|
58
|
+
next unless line[/^config\s/]
|
|
59
|
+
count += 1
|
|
60
|
+
|
|
61
|
+
# attempted-dos,Attempted Denial of Service,2
|
|
62
|
+
data = line.gsub!(/config classification: /, '')
|
|
63
|
+
short, name, priority = data.to_s.split(',')
|
|
64
|
+
|
|
65
|
+
@classifications[count.to_s] = {
|
|
66
|
+
:short => short,
|
|
67
|
+
:name => name,
|
|
68
|
+
:priority => priority.to_i
|
|
69
|
+
}
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
when :generators
|
|
73
|
+
|
|
74
|
+
file.each_line do |line|
|
|
75
|
+
next if line[/^\#/]
|
|
76
|
+
generator_id, alert_id, name = line.split(' || ')
|
|
77
|
+
id = "#{generator_id}.#{alert_id}"
|
|
78
|
+
|
|
79
|
+
@generators[id] = {
|
|
80
|
+
:generator_id => generator_id,
|
|
81
|
+
:name => name,
|
|
82
|
+
:alert_id => alert_id
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
when :signatures
|
|
87
|
+
|
|
88
|
+
file.each_line do |line|
|
|
89
|
+
next if line[/^\#/]
|
|
90
|
+
id, body, *references = line.split(' || ')
|
|
91
|
+
@signatures[id] = {
|
|
92
|
+
:id => id,
|
|
93
|
+
:name => body,
|
|
94
|
+
:references => references
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.watch(path, position=:last, &block)
|
|
104
|
+
|
|
105
|
+
unless File.exists?(path)
|
|
106
|
+
raise FileNotFound, "Error - #{path} not found."
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
if File.readable?(path)
|
|
110
|
+
io = File.open(path)
|
|
111
|
+
|
|
112
|
+
case position
|
|
113
|
+
when Integer, Fixnum
|
|
114
|
+
|
|
115
|
+
event_id = position.to_i.zero? ? 1 : position.to_i
|
|
116
|
+
@event = Event.new(event_id)
|
|
117
|
+
|
|
118
|
+
when Symbol, String
|
|
119
|
+
|
|
120
|
+
case position.to_sym
|
|
121
|
+
when :last
|
|
122
|
+
|
|
123
|
+
until io.eof?
|
|
124
|
+
event = Unified2::Construct.read(io)
|
|
125
|
+
event_id = event.data.event_id if event
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
@event = Event.new(event_id + 1)
|
|
129
|
+
|
|
130
|
+
# set event_id to false to catch
|
|
131
|
+
# beginning loop and process
|
|
132
|
+
event_id = false
|
|
133
|
+
|
|
134
|
+
when :first
|
|
135
|
+
|
|
136
|
+
first_open = File.open(path)
|
|
137
|
+
first_event = Unified2::Construct.read(first_open)
|
|
138
|
+
first_open.close
|
|
139
|
+
event_id = first_event.data.event_id
|
|
140
|
+
@event = Event.new(event_id)
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
loop do
|
|
146
|
+
begin
|
|
147
|
+
event = Unified2::Construct.read(io)
|
|
148
|
+
|
|
149
|
+
if event_id
|
|
150
|
+
if event.data.event_id.to_i > (event_id - 1)
|
|
151
|
+
check_event(event, block)
|
|
152
|
+
end
|
|
153
|
+
else
|
|
154
|
+
check_event(event, block)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
rescue EOFError
|
|
158
|
+
sleep 5
|
|
159
|
+
retry
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
else
|
|
164
|
+
raise FileNotReadable, "Error - #{path} not readable."
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def self.read(path, &block)
|
|
169
|
+
|
|
170
|
+
unless File.exists?(path)
|
|
171
|
+
raise FileNotFound, "Error - #{path} not found."
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
if File.readable?(path)
|
|
175
|
+
io = File.open(path)
|
|
176
|
+
|
|
177
|
+
first_open = File.open(path)
|
|
178
|
+
first_event = Unified2::Construct.read(first_open)
|
|
179
|
+
first_open.close
|
|
180
|
+
|
|
181
|
+
@event = Event.new(first_event.data.event_id)
|
|
182
|
+
|
|
183
|
+
until io.eof?
|
|
184
|
+
event = Unified2::Construct.read(io)
|
|
185
|
+
check_event(event, block)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
else
|
|
189
|
+
raise FileNotReadable, "Error - #{path} not readable."
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
private
|
|
195
|
+
|
|
196
|
+
def self.check_event(event, block)
|
|
197
|
+
if @event.id == event.data.event_id
|
|
198
|
+
@event.load(event)
|
|
199
|
+
else
|
|
200
|
+
block.call(@event)
|
|
201
|
+
@event = Event.new(event.data.event_id)
|
|
202
|
+
@event.load(event)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/unified2.gemspec
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
Ore::Specification.new do |gemspec|
|
|
5
|
+
# custom logic here
|
|
6
|
+
end
|
|
7
|
+
rescue NameError
|
|
8
|
+
begin
|
|
9
|
+
require 'ore/specification'
|
|
10
|
+
retry
|
|
11
|
+
rescue LoadError
|
|
12
|
+
STDERR.puts "The '#{__FILE__}' file requires Ore."
|
|
13
|
+
STDERR.puts "Run `gem install ore-core` to install Ore."
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: unified2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.1.1
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Dustin Willis Webber
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2011-03-09 00:00:00 -05:00
|
|
14
|
+
default_executable:
|
|
15
|
+
dependencies:
|
|
16
|
+
- !ruby/object:Gem::Dependency
|
|
17
|
+
name: bindata
|
|
18
|
+
prerelease: false
|
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
20
|
+
none: false
|
|
21
|
+
requirements:
|
|
22
|
+
- - ~>
|
|
23
|
+
- !ruby/object:Gem::Version
|
|
24
|
+
version: 1.3.1
|
|
25
|
+
type: :development
|
|
26
|
+
version_requirements: *id001
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: hexdump
|
|
29
|
+
prerelease: false
|
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
31
|
+
none: false
|
|
32
|
+
requirements:
|
|
33
|
+
- - ~>
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: 0.1.0
|
|
36
|
+
type: :development
|
|
37
|
+
version_requirements: *id002
|
|
38
|
+
- !ruby/object:Gem::Dependency
|
|
39
|
+
name: ore-tasks
|
|
40
|
+
prerelease: false
|
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ~>
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: "0.4"
|
|
47
|
+
type: :development
|
|
48
|
+
version_requirements: *id003
|
|
49
|
+
- !ruby/object:Gem::Dependency
|
|
50
|
+
name: rspec
|
|
51
|
+
prerelease: false
|
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
53
|
+
none: false
|
|
54
|
+
requirements:
|
|
55
|
+
- - ~>
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "2.4"
|
|
58
|
+
type: :development
|
|
59
|
+
version_requirements: *id004
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: yard
|
|
62
|
+
prerelease: false
|
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
64
|
+
none: false
|
|
65
|
+
requirements:
|
|
66
|
+
- - ~>
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.6.0
|
|
69
|
+
type: :development
|
|
70
|
+
version_requirements: *id005
|
|
71
|
+
description: A ruby interface for unified2 output. rUnified2 allows you to manipulate unified2 output for custom storage and/or analysis.
|
|
72
|
+
email:
|
|
73
|
+
- dustin.webber@gmail.com
|
|
74
|
+
executables: []
|
|
75
|
+
|
|
76
|
+
extensions: []
|
|
77
|
+
|
|
78
|
+
extra_rdoc_files:
|
|
79
|
+
- README.rdoc
|
|
80
|
+
- ChangeLog.rdoc
|
|
81
|
+
- LICENSE.txt
|
|
82
|
+
files:
|
|
83
|
+
- .document
|
|
84
|
+
- .rspec
|
|
85
|
+
- .yardopts
|
|
86
|
+
- ChangeLog.rdoc
|
|
87
|
+
- LICENSE.txt
|
|
88
|
+
- README.rdoc
|
|
89
|
+
- Rakefile
|
|
90
|
+
- example/classification.config
|
|
91
|
+
- example/example.rb
|
|
92
|
+
- example/gen-msg.map
|
|
93
|
+
- example/sid-msg.map
|
|
94
|
+
- example/unified2
|
|
95
|
+
- gemspec.yml
|
|
96
|
+
- lib/unified2.rb
|
|
97
|
+
- lib/unified2/classification.rb
|
|
98
|
+
- lib/unified2/construct.rb
|
|
99
|
+
- lib/unified2/core_ext.rb
|
|
100
|
+
- lib/unified2/core_ext/string.rb
|
|
101
|
+
- lib/unified2/event.rb
|
|
102
|
+
- lib/unified2/event_ip4.rb
|
|
103
|
+
- lib/unified2/event_ip6.rb
|
|
104
|
+
- lib/unified2/exceptions.rb
|
|
105
|
+
- lib/unified2/exceptions/file_not_found.rb
|
|
106
|
+
- lib/unified2/exceptions/file_not_readable.rb
|
|
107
|
+
- lib/unified2/exceptions/unknown_load_type.rb
|
|
108
|
+
- lib/unified2/packet.rb
|
|
109
|
+
- lib/unified2/payload.rb
|
|
110
|
+
- lib/unified2/primitive.rb
|
|
111
|
+
- lib/unified2/primitive/ipv4.rb
|
|
112
|
+
- lib/unified2/record_header.rb
|
|
113
|
+
- lib/unified2/sensor.rb
|
|
114
|
+
- lib/unified2/signature.rb
|
|
115
|
+
- lib/unified2/version.rb
|
|
116
|
+
- spec/spec_helper.rb
|
|
117
|
+
- spec/unified2_spec.rb
|
|
118
|
+
- unified2.gemspec
|
|
119
|
+
has_rdoc: yard
|
|
120
|
+
homepage: https://github.com/mephux/unified2
|
|
121
|
+
licenses:
|
|
122
|
+
- MIT
|
|
123
|
+
post_install_message:
|
|
124
|
+
rdoc_options: []
|
|
125
|
+
|
|
126
|
+
require_paths:
|
|
127
|
+
- lib
|
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
|
+
none: false
|
|
130
|
+
requirements:
|
|
131
|
+
- - ">="
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: "0"
|
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
|
+
none: false
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: "0"
|
|
140
|
+
requirements: []
|
|
141
|
+
|
|
142
|
+
rubyforge_project: unified2
|
|
143
|
+
rubygems_version: 1.6.1
|
|
144
|
+
signing_key:
|
|
145
|
+
specification_version: 3
|
|
146
|
+
summary: A ruby interface for unified2 output.
|
|
147
|
+
test_files:
|
|
148
|
+
- spec/unified2_spec.rb
|