dronebl.rb 0.0.10 → 0.0.11
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 +4 -4
- data/bin/dronebl-add +5 -2
- data/bin/dronebl-query +6 -2
- data/lib/dronebl-client.rb +6 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45bc94d05aa14f311e9506834de8bdbe13578842
|
4
|
+
data.tar.gz: fcbe4cead5705d0e89b7d1b8882a386f7dc629d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8bf384847ec9f3cb386be428eb50e1a6eadabee121badf655fb8e034dd0c877e4d896754d4158f973d9c459bc03d60e60dd0023f1f4d3b6b3be8204a4b650aa
|
7
|
+
data.tar.gz: 5e96f22bf7cd87d7acce9d0f48dfd39078a9a9fb415689f8a96c62989d8e3e7bd731f595000208cc22497c3d20a645e6784e15100751c75b083ae22de47b4cef
|
data/bin/dronebl-add
CHANGED
@@ -6,7 +6,7 @@ require 'resolv'
|
|
6
6
|
require 'optparse'
|
7
7
|
class Options
|
8
8
|
attr_reader :read_from_stdin, :key_str, :key_file, :type, :comment, :dry_run,
|
9
|
-
:use_key_file, :no_check, :max_ips_per_chunk
|
9
|
+
:use_key_file, :no_check, :max_ips_per_chunk, :show_raw_xml
|
10
10
|
attr_accessor :ips
|
11
11
|
def initialize
|
12
12
|
@key_file = File.expand_path "~/.droneblkey"
|
@@ -45,6 +45,9 @@ class Options
|
|
45
45
|
opts.on('-u', '--use-key-file', 'Use the default key file located at ~/.droneblkey') do
|
46
46
|
@use_key_file = true
|
47
47
|
end
|
48
|
+
opts.on('-r', '--show-raw-xml', 'Print the raw response received from the DroneBL server') do
|
49
|
+
@show_raw_xml = true
|
50
|
+
end
|
48
51
|
opts.on('-d', '--dry-run', 'Prints the query to be run to STDOUT instead of sending it as a query to the DroneBL RPC service.') do
|
49
52
|
@dry_run = true
|
50
53
|
end
|
@@ -101,7 +104,7 @@ if opts.dry_run
|
|
101
104
|
valid.each_slice(opts.max_ips_per_chunk) { |submit| puts DroneBL::gen_add_query(submit, opts.type, opts.comment) }
|
102
105
|
puts "#{valid.count} IPs will be added as type #{opts.type}#{" with comment '#{opts.comment if opts.comment}'"}."
|
103
106
|
else
|
104
|
-
valid.each_slice(opts.max_ips_per_chunk) { |submit| DroneBL::add(submit, opts.type, opts.comment) }
|
107
|
+
valid.each_slice(opts.max_ips_per_chunk) { |submit| DroneBL::add(submit, opts.type, opts.comment, show_raw=opts.show_raw_xml) }
|
105
108
|
puts "#{valid.count} IPs added as type #{opts.type}#{" with comment '#{opts.comment}'" if opts.comment}"
|
106
109
|
end
|
107
110
|
unless invalid.empty?
|
data/bin/dronebl-query
CHANGED
@@ -6,11 +6,12 @@ require 'resolv'
|
|
6
6
|
require 'optparse'
|
7
7
|
class Options
|
8
8
|
attr_reader :read_from_stdin, :key_str, :key_file, :get_archived, :long_types,
|
9
|
-
:dry_run, :time_format, :use_key_file
|
9
|
+
:dry_run, :time_format, :use_key_file, :show_raw_xml
|
10
10
|
attr_accessor :ips
|
11
11
|
def initialize
|
12
12
|
@key_file = File.expand_path "~/.droneblkey"
|
13
13
|
@ips = []
|
14
|
+
@show_raw_xml = false
|
14
15
|
@opt_parser = OptionParser.new do |opts|
|
15
16
|
opts.banner = "Usage: #{$0} [options]"
|
16
17
|
opts.separator ""
|
@@ -40,6 +41,9 @@ class Options
|
|
40
41
|
opts.on('-L', '--long-types', 'Print type definitions instead of numeric types for record matches.') do
|
41
42
|
@long_types = true
|
42
43
|
end
|
44
|
+
opts.on('-r', '--show-raw-xml', 'Print the raw response received from the DroneBL server') do
|
45
|
+
@show_raw_xml = true
|
46
|
+
end
|
43
47
|
opts.on('-d', '--dry-run', 'Prints the query to be run to STDOUT instead of sending it as a query to the DroneBL RPC service.') do
|
44
48
|
@dry_run = true
|
45
49
|
end
|
@@ -114,7 +118,7 @@ if @dry_run
|
|
114
118
|
puts DroneBL::gen_lookup_query query, opts.get_archived
|
115
119
|
puts "#{query.count} IPs will be looked up."
|
116
120
|
else
|
117
|
-
response = DroneBL::lookup(query, opts.get_archived)
|
121
|
+
response = DroneBL::lookup(query, opts.get_archived, show_raw=opts.show_raw_xml)
|
118
122
|
print_table response, opts.long_types
|
119
123
|
puts "#{query.count} IPs looked up. #{response.map { |r| r['ip'] }.uniq.length} unique IPs found in response."
|
120
124
|
end
|
data/lib/dronebl-client.rb
CHANGED
@@ -26,10 +26,11 @@ module DroneBL
|
|
26
26
|
"255"=>"Uncategorized threat class"}
|
27
27
|
class << self
|
28
28
|
attr_accessor :key
|
29
|
-
def parse_response xml
|
29
|
+
def parse_response xml, show_raw=false
|
30
30
|
# This giant mess of hax is needed because the DroneBL response to queries
|
31
31
|
# is encased in CDATA for whatever reason.
|
32
32
|
begin
|
33
|
+
puts xml if show_raw
|
33
34
|
resp = Nokogiri.parse(xml).at("response")
|
34
35
|
if resp['type'].downcase == 'error'
|
35
36
|
abort "call failed: '#{resp.css('message').text}' data: '#{resp.css('data').text}'"
|
@@ -58,14 +59,14 @@ EOF
|
|
58
59
|
</request>"
|
59
60
|
end
|
60
61
|
|
61
|
-
def lookup ips, archived=false
|
62
|
+
def lookup ips, archived=false, show_raw=false
|
62
63
|
query = gen_lookup_query ips, archived
|
63
|
-
parse_response post('/RPC2', {:body => query }).
|
64
|
+
parse_response post('/RPC2', {:body => query }).bodya, show_raw=show_raw
|
64
65
|
end
|
65
66
|
|
66
|
-
def add ips, type, comment=''
|
67
|
+
def add ips, type, comment='', show_raw=false
|
67
68
|
query = gen_add_query ips, type, comment
|
68
|
-
parse_response post('/RPC2', {:body => query }).body
|
69
|
+
parse_response post('/RPC2', {:body => query }).body, show_raw=show_raw
|
69
70
|
end
|
70
71
|
|
71
72
|
end
|