dorothy2 0.0.3 → 1.0.0
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/README.md +30 -6
- data/TODO +21 -0
- data/bin/dorothy_start +7 -6
- data/bin/dparser_start +13 -1
- data/etc/ddl/dorothive.ddl +2 -31
- data/lib/doroParser.rb +30 -23
- data/lib/dorothy2/BFM.rb +5 -13
- data/lib/dorothy2/do-utils.rb +4 -5
- data/lib/dorothy2/version.rb +1 -1
- data/lib/dorothy2.rb +5 -8
- data/lib/mu/xtractr/about.rb +57 -0
- data/lib/mu/xtractr/content.rb +68 -0
- data/lib/mu/xtractr/field.rb +178 -0
- data/lib/mu/xtractr/flow.rb +162 -0
- data/lib/mu/xtractr/flows.rb +118 -0
- data/lib/mu/xtractr/host.rb +87 -0
- data/lib/mu/xtractr/packet.rb +138 -0
- data/lib/mu/xtractr/packets.rb +122 -0
- data/lib/mu/xtractr/service.rb +77 -0
- data/lib/mu/xtractr/stream/http.rb +103 -0
- data/lib/mu/xtractr/stream.rb +132 -0
- data/lib/mu/xtractr/term.rb +73 -0
- data/lib/mu/xtractr/test/stream/tc_http.rb +53 -0
- data/lib/mu/xtractr/test/tc_field.rb +140 -0
- data/lib/mu/xtractr/test/tc_flow.rb +79 -0
- data/lib/mu/xtractr/test/tc_flows.rb +94 -0
- data/lib/mu/xtractr/test/tc_host.rb +116 -0
- data/lib/mu/xtractr/test/tc_packet.rb +110 -0
- data/lib/mu/xtractr/test/tc_packets.rb +84 -0
- data/lib/mu/xtractr/test/tc_service.rb +66 -0
- data/lib/mu/xtractr/test/tc_stream.rb +56 -0
- data/lib/mu/xtractr/test/tc_term.rb +59 -0
- data/lib/mu/xtractr/test/tc_views.rb +118 -0
- data/lib/mu/xtractr/test/tc_xtractr.rb +151 -0
- data/lib/mu/xtractr/test/test.rb +19 -0
- data/lib/mu/xtractr/views.rb +204 -0
- data/lib/mu/xtractr.rb +257 -0
- metadata +32 -4
@@ -0,0 +1,79 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Flow
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@xtractr = Xtractr.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_Flow
|
29
|
+
assert(Flow.ancestors.include?(Enumerable), "Flow doesn't mixin Enumerable")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_attributes
|
33
|
+
flow = xtractr.flows('flow.service:HTTP').first
|
34
|
+
assert_equal(2, flow.id)
|
35
|
+
assert_equal(0.264773, flow.time)
|
36
|
+
assert_equal(30.2019, flow.duration)
|
37
|
+
assert_kind_of(Host, flow.src)
|
38
|
+
assert_equal('192.168.1.10', flow.src.address)
|
39
|
+
assert_kind_of(Host, flow.dst)
|
40
|
+
assert_equal('8.18.65.67', flow.dst.address)
|
41
|
+
assert_equal(6, flow.proto)
|
42
|
+
assert_equal(49163, flow.sport)
|
43
|
+
assert_equal(80, flow.dport)
|
44
|
+
assert_kind_of(Service, flow.service)
|
45
|
+
assert_equal('HTTP', flow.service.name)
|
46
|
+
assert_equal('GET /WebObjects/MZStore.woa/wa/viewGrouping?id=39 HTTP/1.1 ', flow.title)
|
47
|
+
assert_equal(28, flow.packets)
|
48
|
+
assert_equal(19791, flow.bytes)
|
49
|
+
assert_equal(1, flow.cmsgs)
|
50
|
+
assert_equal(1, flow.smsgs)
|
51
|
+
assert_equal(3, flow.instance_variable_get(:@first_id))
|
52
|
+
assert_equal(300, flow.instance_variable_get(:@last_id))
|
53
|
+
assert_kind_of(Packet, flow.first)
|
54
|
+
assert_equal(3, flow.first.id)
|
55
|
+
assert_kind_of(Packet, flow.last)
|
56
|
+
assert_equal(300, flow.last.id)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_each
|
60
|
+
flow = xtractr.flows('flow.service:HTTP').first
|
61
|
+
v = flow.each { |pkt| assert_kind_of(Packet, pkt) }
|
62
|
+
assert_equal(flow, v)
|
63
|
+
v = flow.each_packet { |pkt| assert_kind_of(Packet, pkt) }
|
64
|
+
assert_equal(flow, v)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_contents
|
68
|
+
flow = xtractr.flows('flow.service:HTTP').first
|
69
|
+
contents = flow.contents
|
70
|
+
assert_equal(1, contents.size)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_inspect
|
74
|
+
assert_nothing_raised { xtractr.flows.inspect }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end # Flow
|
78
|
+
end # Xtractr
|
79
|
+
end # Mu
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Flows
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@xtractr = Xtractr.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_Flows
|
29
|
+
assert(Flows.ancestors.include?(Enumerable), "Flows doesn't mixin Enumerable")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_q
|
33
|
+
flows = xtractr.flows
|
34
|
+
assert_equal('*', flows.q)
|
35
|
+
|
36
|
+
flows = xtractr.flows 'flow.service:DNS'
|
37
|
+
assert_equal('flow.service:DNS', flows.q)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_each
|
41
|
+
flows = xtractr.flows 'flow.service:DNS'
|
42
|
+
v = flows.each { |f| assert_kind_of(Flow, f) }
|
43
|
+
assert_equal(flows, v)
|
44
|
+
|
45
|
+
v = flows.each_flow { |f| assert_kind_of(Flow, f) }
|
46
|
+
assert_equal(flows, v)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_first
|
50
|
+
flows = xtractr.flows 'flow.service:DNS'
|
51
|
+
flow = flows.first
|
52
|
+
assert_kind_of(Flow, flow)
|
53
|
+
|
54
|
+
flow = xtractr.flows('flow.service:blah').first
|
55
|
+
assert_nil(flow)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_count
|
59
|
+
flows = xtractr.flows 'flow.service:DNS'
|
60
|
+
counts = flows.count 'dns.qry.name'
|
61
|
+
assert_equal(4, counts.size)
|
62
|
+
counts.each { |c| assert_kind_of(Views::Count, c) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_values
|
66
|
+
flows = xtractr.flows 'flow.service:DNS'
|
67
|
+
values = flows.values 'dns.qry.name'
|
68
|
+
assert_equal(4, values.size)
|
69
|
+
values.each { |v| assert_kind_of(Field::Value, v) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_sum
|
73
|
+
flows = xtractr.flows 'flow.service:DNS'
|
74
|
+
sums = flows.sum 'dns.qry.name', 'flow.bytes'
|
75
|
+
assert_equal(4, sums.size)
|
76
|
+
sums.each { |s| assert_kind_of(Views::Sum, s) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_save
|
80
|
+
filename = '/tmp/foo.pcap'
|
81
|
+
xtractr.flows(1..3).save(filename)
|
82
|
+
assert_equal(true, File.exist?(filename))
|
83
|
+
assert_equal(20898, File.size(filename))
|
84
|
+
ensure
|
85
|
+
File.unlink filename
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_inspect
|
89
|
+
assert_nothing_raised { xtractr.flows.inspect }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end # Flows
|
93
|
+
end # Xtractr
|
94
|
+
end # Mu
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Host
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@xtractr = Xtractr.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_clients
|
29
|
+
host = xtractr.host('192.168.1.10')
|
30
|
+
assert_equal(true, host.clients.empty?)
|
31
|
+
|
32
|
+
host = xtractr.host('8.18.65.32')
|
33
|
+
assert_equal(1, host.clients.size)
|
34
|
+
assert_equal('192.168.1.10', host.clients[0].value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_servers
|
38
|
+
host = xtractr.host('8.18.65.32')
|
39
|
+
assert_equal(true, host.servers.empty?)
|
40
|
+
|
41
|
+
host = xtractr.host('192.168.1.10')
|
42
|
+
assert_equal(11, host.servers.size)
|
43
|
+
assert_equal('4.2.2.1', host.servers[0].value)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_services
|
47
|
+
host = xtractr.host('192.168.1.10')
|
48
|
+
services = host.services
|
49
|
+
assert_equal(3, services.size)
|
50
|
+
assert_equal('HTTP', services[0].value)
|
51
|
+
assert_equal('DNS', services[1].value)
|
52
|
+
assert_equal('MDNS', services[2].value)
|
53
|
+
|
54
|
+
services = host.services :client
|
55
|
+
assert_equal(3, services.size)
|
56
|
+
assert_equal('HTTP', services[0].value)
|
57
|
+
assert_equal('DNS', services[1].value)
|
58
|
+
assert_equal('MDNS', services[2].value)
|
59
|
+
|
60
|
+
services = host.services :server
|
61
|
+
assert_equal(true, services.empty?)
|
62
|
+
|
63
|
+
host = xtractr.host('4.2.2.1')
|
64
|
+
services = host.services
|
65
|
+
assert_equal(1, services.size)
|
66
|
+
assert_equal('DNS', services[0].value)
|
67
|
+
|
68
|
+
services = host.services :client
|
69
|
+
assert_equal(true, services.empty?)
|
70
|
+
|
71
|
+
services = host.services :server
|
72
|
+
assert_equal(1, services.size)
|
73
|
+
assert_equal('DNS', services[0].value)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_flows
|
77
|
+
host = xtractr.host('192.168.1.10')
|
78
|
+
flows = host.flows
|
79
|
+
assert_equal("flow.src|flow.dst:\"192.168.1.10\"", flows.q)
|
80
|
+
|
81
|
+
flows = host.flows :any
|
82
|
+
assert_equal("flow.src|flow.dst:\"192.168.1.10\"", flows.q)
|
83
|
+
|
84
|
+
flows = host.flows :client
|
85
|
+
assert_equal("flow.src:\"192.168.1.10\"", flows.q)
|
86
|
+
|
87
|
+
flows = host.flows :server
|
88
|
+
assert_equal("flow.dst:\"192.168.1.10\"", flows.q)
|
89
|
+
|
90
|
+
assert_raise(ArgumentError) { host.flows :blah }
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_packets
|
94
|
+
host = xtractr.host('192.168.1.10')
|
95
|
+
packets = host.packets
|
96
|
+
assert_equal("pkt.src|pkt.dst:\"192.168.1.10\"", packets.q)
|
97
|
+
|
98
|
+
packets = host.packets :any
|
99
|
+
assert_equal("pkt.src|pkt.dst:\"192.168.1.10\"", packets.q)
|
100
|
+
|
101
|
+
packets = host.packets :client
|
102
|
+
assert_equal("pkt.src:\"192.168.1.10\"", packets.q)
|
103
|
+
|
104
|
+
packets = host.packets :server
|
105
|
+
assert_equal("pkt.dst:\"192.168.1.10\"", packets.q)
|
106
|
+
|
107
|
+
assert_raise(ArgumentError) { host.packets :blah }
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_inspect
|
111
|
+
assert_nothing_raised { xtractr.hosts.first.inspect }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end # Host
|
115
|
+
end # Xtractr
|
116
|
+
end # Mu
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Packet
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@xtractr = Xtractr.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_Packet
|
29
|
+
assert(Packet.ancestors.include?(Enumerable), "Packet doesn't mixin Enumerable")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_attributes
|
33
|
+
pkt = xtractr.packets('pkt.service:HTTP').first
|
34
|
+
assert_equal(6, pkt.id)
|
35
|
+
assert_equal(606, pkt.offset)
|
36
|
+
assert_equal(412, pkt.length)
|
37
|
+
assert_equal(0.313968, pkt.time)
|
38
|
+
assert_equal(0, pkt.dir)
|
39
|
+
assert_kind_of(Host, pkt.src)
|
40
|
+
assert_equal('192.168.1.10', pkt.src.address)
|
41
|
+
assert_kind_of(Host, pkt.dst)
|
42
|
+
assert_equal('8.18.65.67', pkt.dst.address)
|
43
|
+
assert_kind_of(Service, pkt.service)
|
44
|
+
assert_equal('HTTP', pkt.service.name)
|
45
|
+
assert_equal('GET /WebObjects/MZStore.woa/wa/viewGrouping?id=39 HTTP/1.1 ', pkt.title)
|
46
|
+
|
47
|
+
assert_equal(2, pkt.instance_variable_get(:@flow_id))
|
48
|
+
assert_nil(pkt.instance_variable_get(:@flow))
|
49
|
+
flow = pkt.flow
|
50
|
+
assert_kind_of(Flow, flow)
|
51
|
+
assert_equal(2, flow.id)
|
52
|
+
assert_not_nil(pkt.instance_variable_get(:@flow))
|
53
|
+
flow2 = pkt.flow
|
54
|
+
assert_equal(flow.__id__, flow2.__id__)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_bytes
|
58
|
+
pkt = xtractr.packets('pkt.service:HTTP').first
|
59
|
+
bytes = pkt.bytes
|
60
|
+
assert_equal(412, bytes.size)
|
61
|
+
assert_match(/WebObjects/, bytes)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_payload
|
65
|
+
pkt = xtractr.packets('pkt.service:HTTP').first
|
66
|
+
payload = pkt.payload
|
67
|
+
assert_equal(346, payload.size)
|
68
|
+
assert_match(/^GET/, payload)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_each
|
72
|
+
pkt = xtractr.packets('pkt.service:HTTP').first
|
73
|
+
pkt.each { |fv| assert_kind_of(Field::Value, fv) }
|
74
|
+
pkt.each(/ip.ttl/) do |fv|
|
75
|
+
assert_kind_of(Field::Value, fv)
|
76
|
+
assert_match(/ip\.ttl/, fv.field.name)
|
77
|
+
end
|
78
|
+
pkt.each_field { |fv| assert_kind_of(Field::Value, fv) }
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_field
|
82
|
+
pkt = xtractr.packets('pkt.service:HTTP').first
|
83
|
+
values = pkt['http.request.method']
|
84
|
+
assert_kind_of(Array, values)
|
85
|
+
assert_equal(1, values.size)
|
86
|
+
assert_equal("GET", values[0])
|
87
|
+
|
88
|
+
values = pkt.field 'http.request.method'
|
89
|
+
assert_kind_of(Array, values)
|
90
|
+
assert_equal(1, values.size)
|
91
|
+
assert_equal("GET", values[0])
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_save
|
95
|
+
filename = '/tmp/foo.pcap'
|
96
|
+
pkt = xtractr.packets('pkt.service:HTTP').first
|
97
|
+
pkt.save filename
|
98
|
+
assert_equal(true, File.exist?(filename))
|
99
|
+
assert_equal(452, File.size(filename))
|
100
|
+
ensure
|
101
|
+
File.unlink filename
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_inspect
|
105
|
+
assert_nothing_raised { xtractr.packets('pkt.service:DNS').first.inspect }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end # Packet
|
109
|
+
end # Xtractr
|
110
|
+
end # Mu
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Packets
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@xtractr = Xtractr.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_Packets
|
29
|
+
assert(Packets.ancestors.include?(Enumerable), "Packets doesn't mixin Enumerable")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_each
|
33
|
+
pkts = xtractr.packets(1..10)
|
34
|
+
pkts.each { |pkt| assert_kind_of(Packet, pkt) }
|
35
|
+
pkts.each_packet { |pkt| assert_kind_of(Packet, pkt) }
|
36
|
+
pkts.each_with_index { |pkt, i| assert_equal(i+1, pkt.id) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_first
|
40
|
+
pkt = xtractr.packets(1..10).first
|
41
|
+
assert_kind_of(Packet, pkt)
|
42
|
+
assert_equal(1, pkt.id)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_count
|
46
|
+
counts = xtractr.packets(1..10).count('pkt.src')
|
47
|
+
assert_equal(3, counts.size)
|
48
|
+
counts.each { |c| assert_kind_of(Views::Count, c) }
|
49
|
+
assert_equal(true, counts[0].count > counts[-1].count)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_values
|
53
|
+
values = xtractr.packets(1..10).values('pkt.src')
|
54
|
+
assert_equal(3, values.size)
|
55
|
+
values.each do |v|
|
56
|
+
assert_kind_of(Field::Value, v)
|
57
|
+
assert_equal('pkt.src', v.field.name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_sum
|
62
|
+
sums = xtractr.packets(1..10).sum('pkt.src', 'pkt.length')
|
63
|
+
assert_equal(3, sums.size)
|
64
|
+
sums.each { |s| assert_kind_of(Views::Sum, s) }
|
65
|
+
assert_equal(true, sums[0].sum > sums[-1].sum)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_save
|
69
|
+
filename = '/tmp/foo.pcap'
|
70
|
+
pkts = xtractr.packets('pkt.service:HTTP pkt.dir:0')
|
71
|
+
pkts.save filename
|
72
|
+
assert_equal(true, File.exist?(filename))
|
73
|
+
assert_equal(53015, File.size(filename))
|
74
|
+
ensure
|
75
|
+
File.unlink filename
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_inspect
|
79
|
+
assert_nothing_raised { xtractr.packets(1..10).inspect }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end # Packets
|
83
|
+
end # Xtractr
|
84
|
+
end # Mu
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Service
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@xtractr = Xtractr.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_clients
|
29
|
+
service = xtractr.service('DNS')
|
30
|
+
clients = service.clients
|
31
|
+
assert_equal(1, clients.size)
|
32
|
+
assert_equal('192.168.1.10', clients[0].value)
|
33
|
+
|
34
|
+
service = xtractr.service('DNS')
|
35
|
+
clients = service.clients 'flow.src:192.168.1.1'
|
36
|
+
assert_equal(0, clients.size)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_servers
|
40
|
+
service = xtractr.service('HTTP')
|
41
|
+
servers = service.servers
|
42
|
+
assert_equal(9, servers.size)
|
43
|
+
|
44
|
+
servers = service.servers 'flow.dst:8.18*'
|
45
|
+
assert_equal(8, servers.size)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_flows
|
49
|
+
service = xtractr.service('HTTP')
|
50
|
+
flows = service.flows
|
51
|
+
assert_equal("flow.service:\"HTTP\"", flows.q)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_packets
|
55
|
+
service = xtractr.service('HTTP')
|
56
|
+
packets = service.packets
|
57
|
+
assert_equal("pkt.service:\"HTTP\"", packets.q)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_inspect
|
61
|
+
assert_nothing_raised { xtractr.services.first.inspect }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end # Service
|
65
|
+
end # Xtractr
|
66
|
+
end # Mu
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Stream
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
attr_reader :stream
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@xtractr = Xtractr.new
|
27
|
+
@stream = xtractr.flows('flow.service:HTTP').first.stream
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_Stream
|
31
|
+
assert(Stream.ancestors.include?(Enumerable), "Stream doesn't mixin Enumerable")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_flow
|
35
|
+
assert_kind_of(Flow, stream.flow)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_each
|
39
|
+
assert_equal(stream.method(:each), stream.method(:each_message))
|
40
|
+
assert_equal(2, stream.messages.size)
|
41
|
+
stream.each_with_index do |m, i|
|
42
|
+
assert_kind_of(Stream::Message, m)
|
43
|
+
assert_equal(i, m.index)
|
44
|
+
assert_equal(stream.__id__, m.stream.__id__)
|
45
|
+
assert_equal(true, m.dir == 0 || m.dir == 1)
|
46
|
+
assert_nothing_raised { m.inspect }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_inspect
|
51
|
+
assert_nothing_raised { stream.inspect }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end # Stream
|
55
|
+
end # Xtractr
|
56
|
+
end # Mu
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
2
|
+
# Mu[http://www.mudynamics.com] wrote this file. As long as you retain this
|
3
|
+
# notice you can do whatever you want with this stuff. If we meet some day,
|
4
|
+
# and you think this stuff is worth it, you can buy us a beer in return.
|
5
|
+
#
|
6
|
+
# All about pcapr
|
7
|
+
# * http://www.pcapr.net
|
8
|
+
# * http://groups.google.com/group/pcapr-forum
|
9
|
+
# * http://twitter.com/pcapr
|
10
|
+
#
|
11
|
+
# Mu Dynamics
|
12
|
+
# * http://www.mudynamics.com
|
13
|
+
# * http://labs.mudynamics.com
|
14
|
+
|
15
|
+
require 'mu/xtractr'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
module Mu
|
19
|
+
class Xtractr
|
20
|
+
class Term
|
21
|
+
class Test < Test::Unit::TestCase
|
22
|
+
attr_reader :xtractr
|
23
|
+
attr_reader :term
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@xtractr = Xtractr.new
|
27
|
+
@term = xtractr.field('http.request.method').terms.first
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_Term
|
31
|
+
assert(Term.ancestors.include?(Enumerable), "Term doesn't mixin Enumerable")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_attributes
|
35
|
+
assert_kind_of(Field, term.field)
|
36
|
+
assert_equal('get', term.value)
|
37
|
+
assert_equal(116, term.frequency)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_each
|
41
|
+
assert_equal(term.method(:each), term.method(:each_packet))
|
42
|
+
term.each_with_index do |pkt, i|
|
43
|
+
assert_kind_of(Packet, pkt)
|
44
|
+
break if i < 16
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_packets
|
49
|
+
packets = term.packets
|
50
|
+
assert_equal("http.request.method:get", packets.q)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_inspect
|
54
|
+
assert_nothing_raised { term.inspect }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end # Term
|
58
|
+
end # Xtractr
|
59
|
+
end # Mu
|