trisulrp 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/trisulrp.rb +1 -0
- data/lib/trisulrp/keys.rb +102 -63
- data/lib/trisulrp/protocol.rb +3 -42
- data/lib/trisulrp/trp.pb.rb +40 -3
- data/lib/trisulrp/trp.proto +32 -5
- data/lib/trisulrp/utils.rb +129 -0
- data/test/helper.rb +2 -40
- data/test/test_alerts.rb +12 -29
- data/test/test_cap.rb +103 -14
- data/test/test_key_flows.rb +2 -2
- data/test/test_resources.rb +7 -7
- data/trisulrp.gemspec +3 -2
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.8
|
data/lib/trisulrp.rb
CHANGED
data/lib/trisulrp/keys.rb
CHANGED
@@ -197,72 +197,111 @@ class ASNumber
|
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
-
# convert a trisul key format into a human readable key
|
201
|
-
# [keyform] the key form
|
202
|
-
#
|
203
|
-
# ==== Typical use
|
204
|
-
#
|
205
|
-
# Used to convert an IP / Port or any other trisul key into a readable form
|
206
|
-
#
|
207
|
-
# <code>
|
208
|
-
#
|
209
|
-
# make_readable("C0.A8.0C.A0") => "192.168.12.160"
|
210
|
-
#
|
211
|
-
# make_readable("p-0016") => "Port-22"
|
212
|
-
#
|
213
|
-
# </code>
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
# Also see TrisulRP::Protocol::get_labels_for_keys to obtain a text name for the key
|
218
|
-
#
|
219
|
-
# Also see the inverse of this method make_key which convert a readable string into a key
|
220
|
-
# suitable for use in TRP request messages.
|
221
|
-
#
|
222
|
-
# If key type cannot be accurately guessed it returns the input
|
223
|
-
#
|
224
|
-
def make_readable(keyform)
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
200
|
+
# convert a trisul key format into a human readable key
|
201
|
+
# [keyform] the key form
|
202
|
+
#
|
203
|
+
# ==== Typical use
|
204
|
+
#
|
205
|
+
# Used to convert an IP / Port or any other trisul key into a readable form
|
206
|
+
#
|
207
|
+
# <code>
|
208
|
+
#
|
209
|
+
# make_readable("C0.A8.0C.A0") => "192.168.12.160"
|
210
|
+
#
|
211
|
+
# make_readable("p-0016") => "Port-22"
|
212
|
+
#
|
213
|
+
# </code>
|
214
|
+
#
|
215
|
+
#
|
216
|
+
#
|
217
|
+
# Also see TrisulRP::Protocol::get_labels_for_keys to obtain a text name for the key
|
218
|
+
#
|
219
|
+
# Also see the inverse of this method make_key which convert a readable string into a key
|
220
|
+
# suitable for use in TRP request messages.
|
221
|
+
#
|
222
|
+
# If key type cannot be accurately guessed it returns the input
|
223
|
+
#
|
224
|
+
def make_readable(keyform)
|
225
|
+
[ TrisulRP::Keys::Port,
|
226
|
+
TrisulRP::Keys::Host,
|
227
|
+
TrisulRP::Keys::HostInterface,
|
228
|
+
TrisulRP::Keys::Subnet,
|
229
|
+
TrisulRP::Keys::ASNumber
|
230
|
+
].each do |kls|
|
231
|
+
return kls.xform(keyform) if kls.is_key_form?(keyform)
|
232
|
+
end
|
233
|
+
return keyform
|
232
234
|
end
|
233
|
-
return keyform
|
234
|
-
end
|
235
235
|
|
236
236
|
|
237
|
-
# convert a key in human form into trisul key format
|
238
|
-
#
|
239
|
-
# [humanform] the human form of the key
|
240
|
-
#
|
241
|
-
# ==== Typical use
|
242
|
-
#
|
243
|
-
# Used to convert a human form key into a Trisul Key format suitable for use with TRP requests
|
244
|
-
#
|
245
|
-
#
|
246
|
-
# <code>
|
247
|
-
#
|
248
|
-
# make_key("192.168.1.1") => "C0.A8.01.01"
|
249
|
-
#
|
250
|
-
# </code>
|
251
|
-
#
|
252
|
-
#
|
253
|
-
# Also see the inverse of this method make_readable
|
254
|
-
#
|
255
|
-
#
|
256
|
-
def make_key(readable)
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
237
|
+
# convert a key in human form into trisul key format
|
238
|
+
#
|
239
|
+
# [humanform] the human form of the key
|
240
|
+
#
|
241
|
+
# ==== Typical use
|
242
|
+
#
|
243
|
+
# Used to convert a human form key into a Trisul Key format suitable for use with TRP requests
|
244
|
+
#
|
245
|
+
#
|
246
|
+
# <code>
|
247
|
+
#
|
248
|
+
# make_key("192.168.1.1") => "C0.A8.01.01"
|
249
|
+
#
|
250
|
+
# </code>
|
251
|
+
#
|
252
|
+
#
|
253
|
+
# Also see the inverse of this method make_readable
|
254
|
+
#
|
255
|
+
#
|
256
|
+
def make_key(readable)
|
257
|
+
[ TrisulRP::Keys::Port,
|
258
|
+
TrisulRP::Keys::Host,
|
259
|
+
TrisulRP::Keys::HostInterface,
|
260
|
+
TrisulRP::Keys::Subnet,
|
261
|
+
TrisulRP::Keys::ASNumber
|
262
|
+
].each do |kls|
|
263
|
+
return kls.invert_xform(readable) if kls.is_human_form?(readable)
|
264
|
+
end
|
265
|
+
return readable
|
264
266
|
end
|
265
|
-
|
266
|
-
|
267
|
+
|
268
|
+
|
269
|
+
# convert a set of keys into labels
|
270
|
+
#
|
271
|
+
# This method accepts an array of keys (which are references to counter items in Trisul) and sends
|
272
|
+
# a key lookup request to Trisul. Trisul responds with labels for those keys that had labels. Finally a
|
273
|
+
# ready to use map is constructed and returned to the caller.
|
274
|
+
#
|
275
|
+
# [conn] a TRP connection opened earlier via connect(..)
|
276
|
+
# [cgguid] a counter group id. See TrisulRP::Guids for a list of common guids
|
277
|
+
# [key_arr] an array of keys, possibly obtained as a result of an earlier command
|
278
|
+
#
|
279
|
+
# ==== Returns
|
280
|
+
# a hash of Key => Label. All keys in the incoming array will have a hash entry. If Trisul could not
|
281
|
+
# find a label for a key, it will store the key itself as the hash value.
|
282
|
+
#
|
283
|
+
# ==== Typical usage
|
284
|
+
#
|
285
|
+
# You use this method as a bulk resolving mechanism.
|
286
|
+
# <code>
|
287
|
+
#
|
288
|
+
# host_keys = ["0A.0A.18.E0", "B1.01.8F.01",...]
|
289
|
+
# host_names = TrisulRP::Protocol.get_labels_for_keys(conn,
|
290
|
+
# TrisulRP::Guids::CG_HOSTS, host_keys)
|
291
|
+
#
|
292
|
+
# host_names["0A.0A.18.E0"] = "demo.trisul.org" # ok
|
293
|
+
# host_names["B1.01.8F.01"] = "B1.01.8F.01" # no label for this key
|
294
|
+
#
|
295
|
+
# </code>
|
296
|
+
#
|
297
|
+
def get_labels_for_keys(conn, cgguid, key_arr)
|
298
|
+
req = mk_request(TRP::Message::Command::KEY_LOOKUP_REQUEST,
|
299
|
+
:counter_group => cgguid, :keys => key_arr.uniq )
|
300
|
+
h = key_arr.inject({}) { |m,i| m.store(i,make_readable(i)); m }
|
301
|
+
get_response(conn,req) do |resp|
|
302
|
+
resp.key_lookup_response.key_details.each { |d| h.store(d.key,d.label) }
|
303
|
+
end
|
304
|
+
return h
|
305
|
+
end
|
267
306
|
|
268
307
|
end
|
data/lib/trisulrp/protocol.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# = Trisul Remote Protocol
|
1
|
+
# = Trisul Remote Protocol functions
|
2
2
|
#
|
3
3
|
# dependency = ruby_protobuf
|
4
4
|
#
|
@@ -110,45 +110,6 @@ module TrisulRP::Protocol
|
|
110
110
|
end
|
111
111
|
return [from_tm,to_tm]
|
112
112
|
end
|
113
|
-
|
114
|
-
# convert a set of keys into labels
|
115
|
-
#
|
116
|
-
# This method accepts an array of keys (which are references to counter items in Trisul) and sends
|
117
|
-
# a key lookup request to Trisul. Trisul responds with labels for those keys that had labels. Finally a
|
118
|
-
# ready to use map is constructed and returned to the caller.
|
119
|
-
#
|
120
|
-
# [conn] a TRP connection opened earlier via connect(..)
|
121
|
-
# [cgguid] a counter group id. See TrisulRP::Guids for a list of common guids
|
122
|
-
# [key_arr] an array of keys, possibly obtained as a result of an earlier command
|
123
|
-
#
|
124
|
-
# ==== Returns
|
125
|
-
# a hash of Key => Label. All keys in the incoming array will have a hash entry. If Trisul could not
|
126
|
-
# find a label for a key, it will store the key itself as the hash value.
|
127
|
-
#
|
128
|
-
# ==== Typical usage
|
129
|
-
#
|
130
|
-
# You use this method as a bulk resolving mechanism.
|
131
|
-
# <code>
|
132
|
-
#
|
133
|
-
# host_keys = ["0A.0A.18.E0", "B1.01.8F.01",...]
|
134
|
-
# host_names = TrisulRP::Protocol.get_labels_for_keys(conn,
|
135
|
-
# TrisulRP::Guids::CG_HOSTS, host_keys)
|
136
|
-
#
|
137
|
-
# host_names["0A.0A.18.E0"] = "demo.trisul.org" # ok
|
138
|
-
# host_names["B1.01.8F.01"] = "B1.01.8F.01" # no label for this key
|
139
|
-
#
|
140
|
-
# </code>
|
141
|
-
#
|
142
|
-
def get_labels_for_keys(conn, cgguid, key_arr)
|
143
|
-
req = mk_request(TRP::Message::Command::KEY_LOOKUP_REQUEST,
|
144
|
-
:counter_group => cgguid, :keys => key_arr.uniq )
|
145
|
-
h = key_arr.inject({}) { |m,i| m.store(i,i); m }
|
146
|
-
get_response(conn,req) do |resp|
|
147
|
-
resp.key_lookup_response.key_details.each { |d| h.store(d.key,d.label) }
|
148
|
-
end
|
149
|
-
return h
|
150
|
-
end
|
151
|
-
|
152
113
|
# Helper to create a TRP TimeInterval object
|
153
114
|
#
|
154
115
|
# [tmarr] An array of two Time objects representing a window
|
@@ -198,7 +159,7 @@ module TrisulRP::Protocol
|
|
198
159
|
# </code>
|
199
160
|
#
|
200
161
|
#
|
201
|
-
def mk_request(cmd_id,params)
|
162
|
+
def mk_request(cmd_id,params={})
|
202
163
|
req = TRP::Message.new(:trp_command => cmd_id)
|
203
164
|
case cmd_id
|
204
165
|
when TRP::Message::Command::HELLO_REQUEST
|
@@ -212,7 +173,7 @@ module TrisulRP::Protocol
|
|
212
173
|
when TRP::Message::Command::CONTROLLED_COUNTER_GROUP_REQUEST
|
213
174
|
req.controlled_counter_group_request = TRP::ControlledCounterGroupRequest.new(params)
|
214
175
|
when TRP::Message::Command::FILTERED_DATAGRAMS_REQUEST
|
215
|
-
req.
|
176
|
+
req.filtered_datagram_request = TRP::FilteredDatagramRequest.new(params)
|
216
177
|
when TRP::Message::Command::CONTROLLED_CONTEXT_REQUEST
|
217
178
|
req.controlled_context_request = TRP::ControlledContextRequest.new(params)
|
218
179
|
when TRP::Message::Command::SEARCH_KEYS_REQUEST
|
data/lib/trisulrp/trp.pb.rb
CHANGED
@@ -370,11 +370,48 @@ module TRP
|
|
370
370
|
end
|
371
371
|
|
372
372
|
class FilteredDatagramRequest < ::ProtocolBuffers::Message
|
373
|
+
# forward declarations
|
374
|
+
class ByFilterExpr < ::ProtocolBuffers::Message; end
|
375
|
+
class BySession < ::ProtocolBuffers::Message; end
|
376
|
+
class ByAlert < ::ProtocolBuffers::Message; end
|
377
|
+
class ByResource < ::ProtocolBuffers::Message; end
|
378
|
+
|
379
|
+
# nested messages
|
380
|
+
class ByFilterExpr < ::ProtocolBuffers::Message
|
381
|
+
required ::TRP::TimeInterval, :time_interval, 1
|
382
|
+
required :string, :filter_expression, 2
|
383
|
+
|
384
|
+
gen_methods! # new fields ignored after this point
|
385
|
+
end
|
386
|
+
|
387
|
+
class BySession < ::ProtocolBuffers::Message
|
388
|
+
optional :string, :session_group, 1, :default => "{99A78737-4B41-4387-8F31-8077DB917336}"
|
389
|
+
required ::TRP::SessionID, :session_id, 2
|
390
|
+
|
391
|
+
gen_methods! # new fields ignored after this point
|
392
|
+
end
|
393
|
+
|
394
|
+
class ByAlert < ::ProtocolBuffers::Message
|
395
|
+
optional :string, :alert_group, 1, :default => "{9AFD8C08-07EB-47E0-BF05-28B4A7AE8DC9}"
|
396
|
+
required ::TRP::AlertID, :alert_id, 2
|
397
|
+
|
398
|
+
gen_methods! # new fields ignored after this point
|
399
|
+
end
|
400
|
+
|
401
|
+
class ByResource < ::ProtocolBuffers::Message
|
402
|
+
required :string, :resource_group, 1
|
403
|
+
required ::TRP::ResourceID, :resource_id, 2
|
404
|
+
|
405
|
+
gen_methods! # new fields ignored after this point
|
406
|
+
end
|
407
|
+
|
373
408
|
optional :int64, :max_packets, 1, :default => 0
|
374
409
|
optional :int64, :max_bytes, 2, :default => 0
|
375
410
|
optional ::TRP::CompressionType, :compress_type, 3, :default => ::TRP::CompressionType::UNCOMPRESSED
|
376
|
-
|
377
|
-
|
411
|
+
optional ::TRP::FilteredDatagramRequest::ByFilterExpr, :filter_expression, 4
|
412
|
+
optional ::TRP::FilteredDatagramRequest::BySession, :session, 5
|
413
|
+
optional ::TRP::FilteredDatagramRequest::ByAlert, :alert, 6
|
414
|
+
optional ::TRP::FilteredDatagramRequest::ByResource, :resource, 7
|
378
415
|
|
379
416
|
gen_methods! # new fields ignored after this point
|
380
417
|
end
|
@@ -741,7 +778,7 @@ module TRP
|
|
741
778
|
optional :int64, :context, 1, :default => 0
|
742
779
|
optional :string, :session_group, 2, :default => "{99A78737-4B41-4387-8F31-8077DB917336}"
|
743
780
|
required ::TRP::TimeInterval, :time_interval, 3
|
744
|
-
optional :int64, :maxitems, 4, :default =>
|
781
|
+
optional :int64, :maxitems, 4, :default => 50
|
745
782
|
required :string, :pattern, 5
|
746
783
|
|
747
784
|
gen_methods! # new fields ignored after this point
|
data/lib/trisulrp/trp.proto
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// Trisul Remote Protocol (TRP) definition
|
2
2
|
// Based on Google Protocol Buffers
|
3
|
-
// (c) 2010-11, Unleash Networks
|
4
|
-
// $Rev:
|
3
|
+
// (c) 2010-11, Unleash Networks (http://www.unleashnetworks.com)
|
4
|
+
// $Rev: 3535 $
|
5
5
|
package TRP;
|
6
6
|
|
7
7
|
message Timestamp {
|
@@ -274,8 +274,35 @@ message FilteredDatagramRequest{
|
|
274
274
|
optional int64 max_packets=1[default=0];
|
275
275
|
optional int64 max_bytes=2[default=0];
|
276
276
|
optional CompressionType compress_type=3[default=UNCOMPRESSED];
|
277
|
-
|
278
|
-
|
277
|
+
|
278
|
+
// by trisul filter format expr
|
279
|
+
message ByFilterExpr {
|
280
|
+
required TimeInterval time_interval=1;
|
281
|
+
required string filter_expression=2;
|
282
|
+
}
|
283
|
+
optional ByFilterExpr filter_expression=4;
|
284
|
+
|
285
|
+
// by session
|
286
|
+
message BySession {
|
287
|
+
optional string session_group=1[default="{99A78737-4B41-4387-8F31-8077DB917336}"];
|
288
|
+
required SessionID session_id=2;
|
289
|
+
}
|
290
|
+
optional BySession session=5;
|
291
|
+
|
292
|
+
|
293
|
+
// by alert
|
294
|
+
message ByAlert {
|
295
|
+
optional string alert_group=1[default="{9AFD8C08-07EB-47E0-BF05-28B4A7AE8DC9}"];
|
296
|
+
required AlertID alert_id=2;
|
297
|
+
}
|
298
|
+
optional ByAlert alert=6;
|
299
|
+
|
300
|
+
// by resource
|
301
|
+
message ByResource {
|
302
|
+
required string resource_group=1;
|
303
|
+
required ResourceID resource_id=2;
|
304
|
+
}
|
305
|
+
optional ByResource resource=7;
|
279
306
|
}
|
280
307
|
|
281
308
|
/////////////////////////////////////
|
@@ -627,7 +654,7 @@ message GrepRequest {
|
|
627
654
|
optional int64 context=1[default=0];
|
628
655
|
optional string session_group=2[default="{99A78737-4B41-4387-8F31-8077DB917336}"];
|
629
656
|
required TimeInterval time_interval=3;
|
630
|
-
optional int64 maxitems=4 [default=
|
657
|
+
optional int64 maxitems=4 [default=50];
|
631
658
|
required string pattern=5;
|
632
659
|
}
|
633
660
|
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# = TrisulRP utility methods
|
2
|
+
#
|
3
|
+
# == Contains utility to print objects like flows, alerts
|
4
|
+
# and to resolve keys etc
|
5
|
+
#
|
6
|
+
|
7
|
+
# ==== TrisulRP::Utils
|
8
|
+
#
|
9
|
+
# Utility methods to help with
|
10
|
+
# * retrieving and printing objects
|
11
|
+
# * prints sessions / alerts if given an array of IDs
|
12
|
+
# * helper to resolve a key
|
13
|
+
#
|
14
|
+
#
|
15
|
+
module TrisulRP::Utils
|
16
|
+
|
17
|
+
# Print session (flow) details
|
18
|
+
#
|
19
|
+
# [conn] active TRP connection opened earlier
|
20
|
+
# [sessions] an array of SessionIDs
|
21
|
+
#
|
22
|
+
# ==== Returns
|
23
|
+
# ==== Yields
|
24
|
+
# Nothing
|
25
|
+
#
|
26
|
+
# Prints details about the list of sessions (flows) passed
|
27
|
+
#
|
28
|
+
# ==== On error
|
29
|
+
def print_session_details(conn,sessions)
|
30
|
+
all_sids = sessions.collect{ |ai| TRP::SessionID.new(
|
31
|
+
:slice_id => ai.slice_id,
|
32
|
+
:session_id => ai.session_id ) }
|
33
|
+
|
34
|
+
follow_up = TrisulRP::Protocol.mk_request(TRP::Message::Command::SESSION_ITEM_REQUEST,
|
35
|
+
:session_ids => all_sids)
|
36
|
+
|
37
|
+
TrisulRP::Protocol.get_response(conn,follow_up) do |resp|
|
38
|
+
resp.session_item_response.items.each do |item|
|
39
|
+
print "#{item.session_id.slice_id},#{item.session_id.session_id} "
|
40
|
+
print "#{Time.at(item.time_interval.from.tv_sec)} "
|
41
|
+
print "#{item.time_interval.to.tv_sec-item.time_interval.from.tv_sec} ".rjust(8)
|
42
|
+
print "#{item.key1A.label}".ljust(28)
|
43
|
+
print "#{item.key2A.label}".ljust(11)
|
44
|
+
print "#{item.key1Z.label}".ljust(28)
|
45
|
+
print "#{item.key2Z.label}".ljust(11)
|
46
|
+
print "#{item.az_bytes}".rjust(10)
|
47
|
+
print "#{item.za_bytes}".rjust(10)
|
48
|
+
print "\n"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Make key
|
54
|
+
#
|
55
|
+
# [conn] active TRP connection opened earlier
|
56
|
+
# [guid] counter group id (eg hosts, apps, countries)
|
57
|
+
# [str] eg a resolved name (eg a host like www.blue.net)
|
58
|
+
#
|
59
|
+
# ==== Returns
|
60
|
+
# A string containing the key in Trisul format corresponding to the
|
61
|
+
# label passed in via ''str''
|
62
|
+
#
|
63
|
+
# ==== Yields
|
64
|
+
# Nothing
|
65
|
+
#
|
66
|
+
# ==== On error
|
67
|
+
def mk_trisul_key(conn,guid,str)
|
68
|
+
req = TrisulRP::Protocol.mk_request(TRP::Message::Command::SEARCH_KEYS_REQUEST,
|
69
|
+
:pattern => str,
|
70
|
+
:counter_group => guid,
|
71
|
+
:maxitems => 1)
|
72
|
+
|
73
|
+
resp = TrisulRP::Protocol.get_response(conn,req)
|
74
|
+
|
75
|
+
if resp.search_keys_response.found_keys.size > 0
|
76
|
+
resp.search_keys_response.found_keys[0].key
|
77
|
+
else
|
78
|
+
str
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Print alert details
|
83
|
+
#
|
84
|
+
# [conn] active TRP connection opened earlier
|
85
|
+
# [alerts] an array of AlertIDs
|
86
|
+
#
|
87
|
+
# ==== Returns
|
88
|
+
# ==== Yields
|
89
|
+
# Nothing
|
90
|
+
#
|
91
|
+
# Prints details about the list of alerts passed
|
92
|
+
#
|
93
|
+
# ==== On error
|
94
|
+
def print_alert_details(conn, alerts)
|
95
|
+
|
96
|
+
p "No alerts found " and return if alerts.empty?
|
97
|
+
|
98
|
+
# retrieve details of alerts from server
|
99
|
+
follow_up = TrisulRP::Protocol.mk_request(TRP::Message::Command::ALERT_ITEM_REQUEST,
|
100
|
+
:alert_group => TrisulRP::Guids::AG_IDS,
|
101
|
+
:alert_ids => alerts.collect do |al|
|
102
|
+
TRP::AlertID.new(:slice_id => al.slice_id,
|
103
|
+
:alert_id => al.alert_id)
|
104
|
+
end
|
105
|
+
)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
TrisulRP::Protocol.get_response(conn,follow_up) do | resp2 |
|
110
|
+
resp=resp2.alert_item_response
|
111
|
+
resolv_candidates = resp.items.collect { |item| [item.source_ip, item.source_port, item.destination_ip, item.destination_port,item.sigid] }
|
112
|
+
resolv_arr = resolv_candidates.transpose
|
113
|
+
sip_names = TrisulRP::Keys.get_labels_for_keys(conn,TrisulRP::Guids::CG_HOST, resolv_arr[0])
|
114
|
+
sport_names = TrisulRP::Keys.get_labels_for_keys(conn,TrisulRP::Guids::CG_APP, resolv_arr[1])
|
115
|
+
dip_names = TrisulRP::Keys.get_labels_for_keys(conn,TrisulRP::Guids::CG_HOST, resolv_arr[2])
|
116
|
+
dport_names = TrisulRP::Keys.get_labels_for_keys(conn,TrisulRP::Guids::CG_APP, resolv_arr[3])
|
117
|
+
sigid_names = TrisulRP::Keys.get_labels_for_keys(conn,TrisulRP::Guids::CG_ALERT_SIGNATURES, resolv_arr[4])
|
118
|
+
resp.items.each do |item|
|
119
|
+
print "#{Time.at(item.time.tv_sec)} "
|
120
|
+
print "#{sip_names[item.source_ip]}".ljust(28)
|
121
|
+
print "#{sport_names[item.source_port]}".ljust(11)
|
122
|
+
print "#{dip_names[item.destination_ip]}".ljust(28)
|
123
|
+
print "#{dport_names[item.destination_port]}".ljust(11)
|
124
|
+
print "#{sigid_names[item.sigid]}".rjust(10)
|
125
|
+
print "\n"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/test/helper.rb
CHANGED
@@ -12,49 +12,11 @@ require 'shoulda'
|
|
12
12
|
|
13
13
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
14
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
|
15
16
|
require 'trisulrp'
|
16
17
|
|
17
18
|
class Test::Unit::TestCase
|
18
19
|
|
19
|
-
|
20
|
-
def print_session_details(conn,sessions)
|
21
|
-
all_sids = sessions.collect{ |ai| TRP::SessionID.new(
|
22
|
-
:slice_id => ai.slice_id,
|
23
|
-
:session_id => ai.session_id ) }
|
24
|
-
|
25
|
-
follow_up = TrisulRP::Protocol.mk_request(TRP::Message::Command::SESSION_ITEM_REQUEST,
|
26
|
-
:session_ids => all_sids)
|
27
|
-
|
28
|
-
TrisulRP::Protocol.get_response(conn,follow_up) do |resp|
|
29
|
-
resp.session_item_response.items.each do |item|
|
30
|
-
print "#{item.session_id.slice_id},#{item.session_id.session_id} "
|
31
|
-
print "#{Time.at(item.time_interval.from.tv_sec)} "
|
32
|
-
print "#{item.time_interval.to.tv_sec-item.time_interval.from.tv_sec} ".rjust(8)
|
33
|
-
print "#{item.key1A.label}".ljust(28)
|
34
|
-
print "#{item.key2A.label}".ljust(11)
|
35
|
-
print "#{item.key1Z.label}".ljust(28)
|
36
|
-
print "#{item.key2Z.label}".ljust(11)
|
37
|
-
print "#{item.az_bytes}".rjust(10)
|
38
|
-
print "#{item.za_bytes}".rjust(10)
|
39
|
-
print "\n"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# convert a string to a key
|
45
|
-
def mk_trisul_key(guid,str)
|
46
|
-
req = TrisulRP::Protocol.mk_request(TRP::Message::Command::SEARCH_KEYS_REQUEST,
|
47
|
-
:pattern => str,
|
48
|
-
:counter_group => guid,
|
49
|
-
:maxitems => 1)
|
50
|
-
|
51
|
-
resp = TrisulRP::Protocol.get_response(@conn,req)
|
52
|
-
|
53
|
-
if resp.search_keys_response.found_keys.size > 0
|
54
|
-
resp.search_keys_response.found_keys[0].key
|
55
|
-
else
|
56
|
-
str
|
57
|
-
end
|
58
|
-
end
|
20
|
+
include TrisulRP::Utils
|
59
21
|
|
60
22
|
end
|
data/test/test_alerts.rb
CHANGED
@@ -5,43 +5,26 @@ require 'rubygems'
|
|
5
5
|
|
6
6
|
require './helper'
|
7
7
|
include TrisulRP::Protocol
|
8
|
-
|
8
|
+
include TrisulRP::Keys
|
9
|
+
|
9
10
|
class TestTrisulrp < Test::Unit::TestCase
|
10
11
|
|
11
12
|
def test_query_alerts
|
12
13
|
|
13
|
-
target_ip = "
|
14
|
+
target_ip = "10.1.10.10" # 10.2.199.235"
|
15
|
+
|
14
16
|
TrisulRP::Protocol.connect("127.0.0.1",12001,"Demo_Client.crt","Demo_Client.key") do |conn|
|
17
|
+
|
15
18
|
tm_arr = TrisulRP::Protocol.get_available_time(conn)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
|
20
|
+
req =TrisulRP::Protocol.mk_request(TRP::Message::Command::ALERT_GROUP_REQUEST,
|
21
|
+
:alert_group =>TrisulRP::Guids::AG_IDS,
|
22
|
+
:source_ip => TrisulRP::Keys.make_key(target_ip),
|
23
|
+
:maxitems => 1000,
|
24
|
+
:time_interval => mk_time_interval(tm_arr))
|
19
25
|
|
20
26
|
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
21
|
-
|
22
|
-
resp.alert_group_response.alerts.each do |al|
|
23
|
-
follow_up.alert_item_request.alert_ids << TRP::AlertID.new(:slice_id => al.slice_id, :alert_id => al.alert_id)
|
24
|
-
end
|
25
|
-
|
26
|
-
TrisulRP::Protocol.getresponse(conn,follow_up) do | resp2 |
|
27
|
-
resp=resp2.alert_item_response
|
28
|
-
resolv_candidates = resp.items.collect { |item| [item.source_ip, item.source_port, item.destination_ip, item.destination_port,item.sigid] }
|
29
|
-
resolv_arr = resolv_candidates.transpose
|
30
|
-
sip_names = TrisulRP::Protocol.get_labels_for_keys(conn,TrisulRP::Guids::CG_HOSTS, resolv_arr[0])
|
31
|
-
sport_names = TrisulRP::Protocol.get_labels_for_keys(conn,TrisulRP::Guids::CG_APPS, resolv_arr[1])
|
32
|
-
dip_names = TrisulRP::Protocol.get_labels_for_keys(conn,TrisulRP::Guids::CG_HOSTS, resolv_arr[2])
|
33
|
-
dport_names = TrisulRP::Protocol.get_labels_for_keys(conn,TrisulRP::Guids::CG_APPS, resolv_arr[3])
|
34
|
-
sigid_names = TrisulRP::Protocol.get_labels_for_keys(conn,TrisulRP::Guids::CG_SIGDS, resolv_arr[4])
|
35
|
-
resp.items.each do |item|
|
36
|
-
print "#{Time.at(item.time.tv_sec)} "
|
37
|
-
print "#{sip_names[item.source_ip]}".ljust(28)
|
38
|
-
print "#{sport_names[item.source_port]}".ljust(11)
|
39
|
-
print "#{dip_names[item.destination_ip]}".ljust(28)
|
40
|
-
print "#{dport_names[item.destination_port]}".ljust(11)
|
41
|
-
print "#{sigid_names[item.sigid]}".rjust(10)
|
42
|
-
print "\n"
|
43
|
-
end
|
44
|
-
end
|
27
|
+
print_alert_details(conn,resp.alert_group_response.alerts)
|
45
28
|
end
|
46
29
|
end
|
47
30
|
end
|
data/test/test_cap.rb
CHANGED
@@ -3,21 +3,82 @@
|
|
3
3
|
# Testing change
|
4
4
|
require 'rubygems'
|
5
5
|
require './helper'
|
6
|
-
include TrisulRP::Protocol
|
7
|
-
require 'guidmap'
|
8
6
|
|
7
|
+
include TrisulRP::Protocol
|
9
8
|
|
10
9
|
class TestCap < Test::Unit::TestCase
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
|
11
|
+
|
12
|
+
# get all DNS & SMTP packets in last 1 hour
|
13
|
+
# test setup is xff-test.pcap
|
14
|
+
def test_filter_expr
|
15
|
+
|
16
|
+
conn = TrisulRP::Protocol.connect("127.0.0.1", 12001,"Demo_Client.crt","Demo_Client.key")
|
17
|
+
|
18
|
+
expr = "#{TrisulRP::Guids::CG_APP}=p-0019,p-0035"
|
19
|
+
|
20
|
+
tm_arr = get_available_time(conn)
|
21
|
+
tm_arr[0] = tm_arr[1] - 900
|
22
|
+
|
23
|
+
req = TrisulRP::Protocol.mk_request(TRP::Message::Command::FILTERED_DATAGRAMS_REQUEST,
|
24
|
+
:filter_expression => TRP::FilteredDatagramRequest::ByFilterExpr.new(
|
25
|
+
:time_interval => mk_time_interval(tm_arr),
|
26
|
+
:filter_expression => expr)
|
27
|
+
)
|
28
|
+
|
29
|
+
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
30
|
+
fdr=resp.filtered_datagram_response
|
31
|
+
p "Number of bytes = #{fdr.num_bytes}\n"
|
32
|
+
p "Number of pkts = #{fdr.num_datagrams}\n"
|
33
|
+
p "Hash = #{fdr.sha1}\n"
|
34
|
+
|
35
|
+
File.open("t.pcap","wb") do |f|
|
36
|
+
f.write(fdr.contents)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def wtest_sess
|
44
|
+
|
45
|
+
target_sess = TRP::SessionID.new(:slice_id => 1, :session_id => 45542)
|
46
|
+
|
47
|
+
conn = TrisulRP::Protocol.connect("127.0.0.1", 12001,"Demo_Client.crt","Demo_Client.key")
|
48
|
+
|
49
|
+
|
50
|
+
req = TrisulRP::Protocol.mk_request(TRP::Message::Command::FILTERED_DATAGRAMS_REQUEST,
|
51
|
+
:session => TRP::FilteredDatagramRequest::BySession.new(
|
52
|
+
:session_id => target_sess)
|
53
|
+
)
|
54
|
+
|
55
|
+
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
56
|
+
fdr=resp.filtered_datagram_response
|
57
|
+
p "Number of bytes = #{fdr.num_bytes}\n"
|
58
|
+
p "Number of pkts = #{fdr.num_datagrams}\n"
|
59
|
+
p "Hash = #{fdr.sha1}\n"
|
60
|
+
|
61
|
+
File.open("t.pcap","wb") do |f|
|
62
|
+
f.write(fdr.contents)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
# alert test
|
69
|
+
def test_alert
|
70
|
+
|
71
|
+
target_alert = TRP::AlertID.new(:slice_id => 2, :alert_id => 10133)
|
72
|
+
|
73
|
+
conn = TrisulRP::Protocol.connect("127.0.0.1", 12001,"Demo_Client.crt","Demo_Client.key")
|
74
|
+
|
75
|
+
|
76
|
+
req = TrisulRP::Protocol.mk_request(TRP::Message::Command::FILTERED_DATAGRAMS_REQUEST,
|
77
|
+
:alert => TRP::FilteredDatagramRequest::ByAlert.new(
|
78
|
+
:alert_id => target_alert)
|
79
|
+
)
|
80
|
+
|
81
|
+
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
21
82
|
fdr=resp.filtered_datagram_response
|
22
83
|
p "Number of bytes = #{fdr.num_bytes}\n"
|
23
84
|
p "Number of pkts = #{fdr.num_datagrams}\n"
|
@@ -26,10 +87,38 @@ class TestCap < Test::Unit::TestCase
|
|
26
87
|
File.open("t.pcap","wb") do |f|
|
27
88
|
f.write(fdr.contents)
|
28
89
|
end
|
29
|
-
end
|
30
|
-
end
|
31
90
|
end
|
91
|
+
|
92
|
+
end
|
93
|
+
#
|
94
|
+
# resource test
|
95
|
+
def test_resource
|
96
|
+
|
97
|
+
target = TRP::ResourceID.new(:slice_id => 2, :resource_id => 308)
|
98
|
+
|
99
|
+
conn = TrisulRP::Protocol.connect("127.0.0.1", 12001,"Demo_Client.crt","Demo_Client.key")
|
100
|
+
|
101
|
+
|
102
|
+
req = TrisulRP::Protocol.mk_request(TRP::Message::Command::FILTERED_DATAGRAMS_REQUEST,
|
103
|
+
:resource => TRP::FilteredDatagramRequest::ByResource.new(
|
104
|
+
:resource_group => TrisulRP::Guids::RG_DNS,
|
105
|
+
:resource_id => target)
|
106
|
+
)
|
107
|
+
|
108
|
+
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
109
|
+
fdr=resp.filtered_datagram_response
|
110
|
+
p "Number of bytes = #{fdr.num_bytes}\n"
|
111
|
+
p "Number of pkts = #{fdr.num_datagrams}\n"
|
112
|
+
p "Hash = #{fdr.sha1}\n"
|
113
|
+
|
114
|
+
File.open("t.pcap","wb") do |f|
|
115
|
+
f.write(fdr.contents)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
32
119
|
end
|
33
120
|
end
|
34
121
|
|
35
122
|
|
123
|
+
|
124
|
+
|
data/test/test_key_flows.rb
CHANGED
@@ -15,7 +15,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
15
15
|
def teardown
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def test_flows_for_host
|
19
19
|
|
20
20
|
target_key = "0A.01.3C.BB"
|
21
21
|
|
@@ -36,7 +36,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
36
36
|
def test_flows_for_appname
|
37
37
|
|
38
38
|
target = "ssh"
|
39
|
-
target_key = mk_trisul_key(CG_APP,target)
|
39
|
+
target_key = mk_trisul_key(@conn,CG_APP,target)
|
40
40
|
|
41
41
|
tmarr = TrisulRP::Protocol.get_available_time(@conn)
|
42
42
|
|
data/test/test_resources.rb
CHANGED
@@ -4,23 +4,23 @@
|
|
4
4
|
require 'rubygems'
|
5
5
|
require './helper'
|
6
6
|
include TrisulRP::Protocol
|
7
|
-
require guidmap
|
8
7
|
|
9
8
|
class TestTrisulrp < Test::Unit::TestCase
|
10
9
|
|
11
10
|
|
12
|
-
# demonstrates getting all
|
11
|
+
# demonstrates getting all DNS resources for smtp (string contains smtp)
|
13
12
|
def test_query_resources
|
14
13
|
|
15
14
|
target_ip = "0A.02.C7.EB" # 10.2.199.235"
|
16
15
|
|
17
|
-
TrisulRP::Protocol.
|
16
|
+
TrisulRP::Protocol.connect("127.0.0.1", 12001,"Demo_Client.crt","Demo_Client.key") do |conn|
|
18
17
|
|
19
18
|
tm_arr = TrisulRP::Protocol. get_available_time(conn)
|
19
|
+
|
20
20
|
req = TrisulRP::Protocol.mk_request(TRP::Message::Command::RESOURCE_GROUP_REQUEST,
|
21
21
|
:context => 0,
|
22
|
-
:resource_group => TrisulRP::Guids::
|
23
|
-
:uri_pattern => "
|
22
|
+
:resource_group => TrisulRP::Guids::RG_DNS,
|
23
|
+
:uri_pattern => "smtp",:maxitems => 1000, :time_interval => mk_time_interval(tm_arr))
|
24
24
|
|
25
25
|
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
26
26
|
|
@@ -30,7 +30,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
follow_up = TrisulRP::Protocol.mk_request( TRP::Message::Command::RESOURCE_ITEM_REQUEST,
|
33
|
-
:context => 0, :resource_group => TrisulRP::Guids::
|
33
|
+
:context => 0, :resource_group => TrisulRP::Guids::RG_DNS,
|
34
34
|
:resource_ids => resource_ids)
|
35
35
|
|
36
36
|
TrisulRP::Protocol.get_response(conn,follow_up) do | resp2 |
|
@@ -50,4 +50,4 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
50
50
|
|
51
51
|
end
|
52
52
|
|
53
|
-
end
|
53
|
+
end
|
data/trisulrp.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{trisulrp}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["vivek"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-22}
|
13
13
|
s.description = %q{This gem deals about the trisul remote protocol}
|
14
14
|
s.email = %q{vivek_rajagopal@yahoo.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/trisulrp/protocol.rb",
|
31
31
|
"lib/trisulrp/trp.pb.rb",
|
32
32
|
"lib/trisulrp/trp.proto",
|
33
|
+
"lib/trisulrp/utils.rb",
|
33
34
|
"test/Demo_Client.crt",
|
34
35
|
"test/Demo_Client.key",
|
35
36
|
"test/helper.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
8
|
+
- 8
|
9
|
+
version: 1.2.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- vivek
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-22 00:00:00 +05:30
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/trisulrp/protocol.rb
|
127
127
|
- lib/trisulrp/trp.pb.rb
|
128
128
|
- lib/trisulrp/trp.proto
|
129
|
+
- lib/trisulrp/utils.rb
|
129
130
|
- test/Demo_Client.crt
|
130
131
|
- test/Demo_Client.key
|
131
132
|
- test/helper.rb
|
@@ -151,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
152
|
requirements:
|
152
153
|
- - ">="
|
153
154
|
- !ruby/object:Gem::Version
|
154
|
-
hash: -
|
155
|
+
hash: -371857393
|
155
156
|
segments:
|
156
157
|
- 0
|
157
158
|
version: "0"
|