passivedns-client 2.0.6 → 2.1.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.
@@ -48,7 +48,7 @@ class TestPassiveDnsQuery < Minitest::Test
48
48
 
49
49
  def test_BFK
50
50
  PassiveDNS::Client.new(['bfk'])
51
- d = PassiveDNS::BFK.new(@cp['bfk'] || {})
51
+ d = PassiveDNS::Provider::BFK.new(@cp['bfk'] || {})
52
52
  refute_nil(d)
53
53
  rows = d.lookup("example.org",3)
54
54
  refute_nil(rows)
@@ -67,7 +67,7 @@ class TestPassiveDnsQuery < Minitest::Test
67
67
 
68
68
  def test_DNSDB
69
69
  PassiveDNS::Client.new(['dnsdb'])
70
- d = PassiveDNS::DNSDB.new(@cp['dnsdb'] || {})
70
+ d = PassiveDNS::Provider::DNSDB.new(@cp['dnsdb'] || {})
71
71
  refute_nil(d)
72
72
  rows = d.lookup("example.org",3)
73
73
  refute_nil(rows)
@@ -86,7 +86,7 @@ class TestPassiveDnsQuery < Minitest::Test
86
86
 
87
87
  def test_VirusTotal
88
88
  PassiveDNS::Client.new(['virustotal'])
89
- d = PassiveDNS::VirusTotal.new(@cp['virustotal'] || {})
89
+ d = PassiveDNS::Provider::VirusTotal.new(@cp['virustotal'] || {})
90
90
  refute_nil(d)
91
91
  rows = d.lookup("google.com",3)
92
92
  refute_nil(rows)
@@ -105,7 +105,7 @@ class TestPassiveDnsQuery < Minitest::Test
105
105
 
106
106
  def test_TCPIPUtils
107
107
  PassiveDNS::Client.new(['tcpiputils'])
108
- d = PassiveDNS::TCPIPUtils.new(@cp['tcpiputils'] || {})
108
+ d = PassiveDNS::Provider::TCPIPUtils.new(@cp['tcpiputils'] || {})
109
109
  refute_nil(d)
110
110
  rows = d.lookup("example.org")
111
111
  refute_nil(rows)
@@ -130,7 +130,7 @@ class TestPassiveDnsQuery < Minitest::Test
130
130
 
131
131
  def test_cn360
132
132
  PassiveDNS::Client.new(['cn360'])
133
- d = PassiveDNS::CN360.new(@cp['cn360'] || {})
133
+ d = PassiveDNS::Provider::CN360.new(@cp['cn360'] || {})
134
134
  refute_nil(d)
135
135
  rows = d.lookup("example.org")
136
136
  refute_nil(rows)
@@ -155,7 +155,7 @@ class TestPassiveDnsQuery < Minitest::Test
155
155
 
156
156
  def test_nmemonic
157
157
  PassiveDNS::Client.new(['mnemonic'])
158
- d = PassiveDNS::Mnemonic.new(@cp['mnemonic'] || {})
158
+ d = PassiveDNS::Provider::Mnemonic.new(@cp['mnemonic'] || {})
159
159
  refute_nil(d)
160
160
  rows = d.lookup("example.org")
161
161
  refute_nil(rows)
@@ -180,7 +180,7 @@ class TestPassiveDnsQuery < Minitest::Test
180
180
 
181
181
  def test_passivetotal
182
182
  PassiveDNS::Client.new(['passivetotal'])
183
- d = PassiveDNS::PassiveTotal.new(@cp['passivetotal'] || {})
183
+ d = PassiveDNS::Provider::PassiveTotal.new(@cp['passivetotal'] || {})
184
184
  refute_nil(d)
185
185
  rows = d.lookup("example.org")
186
186
  refute_nil(rows)
@@ -205,7 +205,32 @@ class TestPassiveDnsQuery < Minitest::Test
205
205
 
206
206
  def test_circl
207
207
  PassiveDNS::Client.new(['circl'])
208
- d = PassiveDNS::CIRCL.new(@cp['circl'] || {})
208
+ d = PassiveDNS::Provider::CIRCL.new(@cp['circl'] || {})
209
+ refute_nil(d)
210
+ rows = d.lookup("example.org")
211
+ refute_nil(rows)
212
+ refute_nil(rows.to_s)
213
+ refute_nil(rows.to_xml)
214
+ refute_nil(rows.to_json)
215
+ refute_nil(rows.to_yaml)
216
+ rows = d.lookup("example.org",3)
217
+ refute_nil(rows)
218
+ refute_nil(rows.to_s)
219
+ refute_nil(rows.to_xml)
220
+ refute_nil(rows.to_json)
221
+ refute_nil(rows.to_yaml)
222
+ assert_equal(3, rows.length)
223
+ rows = d.lookup("8.8.8.8")
224
+ refute_nil(rows)
225
+ refute_nil(rows.to_s)
226
+ refute_nil(rows.to_xml)
227
+ refute_nil(rows.to_json)
228
+ refute_nil(rows.to_yaml)
229
+ end
230
+
231
+ def test_riskiq
232
+ PassiveDNS::Client.new(['riskiq'])
233
+ d = PassiveDNS::Provider::RiskIQ.new(@cp['riskiq'] || {})
209
234
  refute_nil(d)
210
235
  rows = d.lookup("example.org")
211
236
  refute_nil(rows)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passivedns-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrislee35
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -127,14 +127,15 @@ files:
127
127
  - lib/passivedns/client.rb
128
128
  - lib/passivedns/client/cli.rb
129
129
  - lib/passivedns/client/passivedb.rb
130
- - lib/passivedns/client/providers/bfk.rb
131
- - lib/passivedns/client/providers/circl.rb
132
- - lib/passivedns/client/providers/cn360.rb
133
- - lib/passivedns/client/providers/dnsdb.rb
134
- - lib/passivedns/client/providers/mnemonic.rb
135
- - lib/passivedns/client/providers/passivetotal.rb
136
- - lib/passivedns/client/providers/tcpiputils.rb
137
- - lib/passivedns/client/providers/virustotal.rb
130
+ - lib/passivedns/client/provider/bfk.rb
131
+ - lib/passivedns/client/provider/circl.rb
132
+ - lib/passivedns/client/provider/cn360.rb
133
+ - lib/passivedns/client/provider/dnsdb.rb
134
+ - lib/passivedns/client/provider/mnemonic.rb
135
+ - lib/passivedns/client/provider/passivetotal.rb
136
+ - lib/passivedns/client/provider/riskiq.rb
137
+ - lib/passivedns/client/provider/tcpiputils.rb
138
+ - lib/passivedns/client/provider/virustotal.rb
138
139
  - lib/passivedns/client/state.rb
139
140
  - lib/passivedns/client/version.rb
140
141
  - passivedns-client.gemspec
@@ -1,77 +0,0 @@
1
- require 'open-uri'
2
-
3
- module PassiveDNS
4
- class BFK < PassiveDB
5
- # override
6
- def self.name
7
- "BFK.de"
8
- end
9
- #override
10
- def self.config_section_name
11
- "bfk"
12
- end
13
- #override
14
- def self.option_letter
15
- "b"
16
- end
17
-
18
- attr_accessor :debug
19
- def initialize(options={})
20
- @debug = options[:debug] || false
21
- @base = options["URL"] || "http://www.bfk.de/bfk_dnslogger.html?query="
22
- end
23
-
24
- def parse(page,response_time)
25
- line = page.unpack('C*').pack('U*').split(/<table/).grep(/ id=\"logger\"/)
26
- return [] unless line.length > 0
27
- line = line[0].gsub(/[\t\n]/,'').gsub(/<\/table.*/,'')
28
- rows = line.split(/<tr.*?>/)
29
- res = []
30
- rows.collect do |row|
31
- r = row.split(/<td>/).map{|x| x.gsub(/<.*?>/,'').gsub(/\&.*?;/,'')}[1,1000]
32
- if r and r[0] =~ /\w/
33
- # BFK includes the MX weight in the answer response. First, find the MX records, then dump the weight to present a consistent record name to the collecting array. Otherwise the other repositories will present the same answer and your results will become cluttered with duplicates.
34
- if r[1] == "MX" then
35
- # MX lines look like "5 mx.domain.tld", so split on the space and assign r[2] (:answer) to the latter part.
36
- #s = r[2].split(/\w/).map{|x| x}[1,1000]
37
- # r[2] = s[1]
38
- r[2] =~ /[0-9]+?\s(.+)/
39
- s=$1
40
- puts "DEBUG: == BFK: MX Parsing Strip: Answer: " + r[2] + " : mod: " + s if @debug
41
- r[2] = s
42
-
43
- ######### FIX BLANKS FOR MX
44
-
45
- end
46
- res << PDNSResult.new(self.class.name,response_time,r[0],r[2],r[1])
47
- end
48
- end
49
- res
50
- rescue Exception => e
51
- $stderr.puts "#{self.class.name} Exception: #{e}"
52
- raise e
53
- end
54
-
55
- # override
56
- def lookup(label, limit=nil)
57
- $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
58
- Timeout::timeout(240) {
59
- t1 = Time.now
60
- open(
61
- @base+label,
62
- "User-Agent" => "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}"
63
- ) do |f|
64
- t2 = Time.now
65
- recs = parse(f.read,t2-t1)
66
- if limit
67
- recs[0,limit]
68
- else
69
- recs
70
- end
71
- end
72
- }
73
- rescue Timeout::Error => e
74
- $stderr.puts "#{self.class.name} lookup timed out: #{label}"
75
- end
76
- end
77
- end
@@ -1,79 +0,0 @@
1
- # DESCRIPTION: Module to query PassiveTotal's passive DNS repository
2
-
3
- require 'net/http'
4
- require 'net/https'
5
- require 'openssl'
6
-
7
- module PassiveDNS
8
- class Circl < PassiveDB
9
- # override
10
- def self.name
11
- "CIRCL"
12
- end
13
- #override
14
- def self.config_section_name
15
- "circl"
16
- end
17
- #override
18
- def self.option_letter
19
- "c"
20
- end
21
-
22
- attr_accessor :debug
23
- def initialize(options={})
24
- @debug = options[:debug] || false
25
- @username = options["USERNAME"]
26
- @password = options["PASSWORD"]
27
- @auth_token = options["AUTH_TOKEN"]
28
- @url = options["URL"] || "https://www.circl.lu/pdns/query"
29
- end
30
-
31
- def parse_json(page,query,response_time=0)
32
- res = []
33
- # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to
34
- page.split(/\n/).each do |line|
35
- row = JSON.parse(line)
36
- res << PDNSResult.new(self.class.name,response_time,
37
- row['rrname'], row['rdata'], row['rrtype'], 0,
38
- row['time_first'], row['time_last'], row['count'])
39
- end
40
- res
41
- rescue Exception => e
42
- $stderr.puts "#{self.class.name} Exception: #{e}"
43
- raise e
44
- end
45
-
46
- def lookup(label, limit=nil)
47
- $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
48
- Timeout::timeout(240) {
49
- url = @url+"/"+label
50
- $stderr.puts "DEBUG: #{self.class.name} url = #{url}" if @debug
51
- url = URI.parse url
52
- http = Net::HTTP.new(url.host, url.port)
53
- http.use_ssl = (url.scheme == 'https')
54
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
55
- http.verify_depth = 5
56
- request = Net::HTTP::Get.new(url.request_uri)
57
- request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
58
- if @username
59
- request.basic_auth(@username, @password)
60
- end
61
- if @auth_token
62
- request.add_field("Authorization", @auth_token)
63
- end
64
- t1 = Time.now
65
- response = http.request(request)
66
- t2 = Time.now
67
- recs = parse_json(response.body, label, t2-t1)
68
- if limit
69
- recs[0,limit]
70
- else
71
- recs
72
- end
73
- }
74
- rescue Timeout::Error => e
75
- $stderr.puts "#{self.class.name} lookup timed out: #{label}"
76
- end
77
- end
78
- CIRCL = PassiveDNS::Circl
79
- end
@@ -1,80 +0,0 @@
1
- require 'net/http'
2
- require 'net/https'
3
- require 'openssl'
4
- require 'json'
5
- require 'digest/md5'
6
-
7
- module PassiveDNS
8
- class CN360 < PassiveDB
9
- # override
10
- def self.name
11
- "360.cn"
12
- end
13
- #override
14
- def self.config_section_name
15
- "cn360"
16
- end
17
- #override
18
- def self.option_letter
19
- "3"
20
- end
21
-
22
- attr_accessor :debug
23
- def initialize(options={})
24
- @debug = options[:debug] || false
25
- ["API", "API_ID", "API_KEY"].each do |opt|
26
- if not options[opt]
27
- raise "Field #{opt} is required. See README.md"
28
- end
29
- end
30
- @cp = options
31
- end
32
-
33
- def parse_json(page,query,response_time=0)
34
- res = []
35
- # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to
36
- data = JSON.parse(page)
37
- data.each do |row|
38
- time_first = (row["time_first"]) ? Time.at(row["time_first"].to_i) : nil
39
- time_last = (row["time_last"]) ? Time.at(row["time_last"].to_i) : nil
40
- count = row["count"] || 0
41
- res << PDNSResult.new(self.class.name, response_time, row["rrname"], row["rdata"], row["rrtype"], time_first, time_last, count)
42
- end
43
- res
44
- rescue Exception => e
45
- $stderr.puts "#{self.class.name} Exception: #{e}"
46
- raise e
47
- end
48
-
49
- def lookup(label, limit=10000)
50
- table = "rrset"
51
- if label =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ or label =~ /^[0-9a-fA-F]+:[0-9a-fA-F:]+[0-9a-fA-F]$/
52
- table = "rdata"
53
- end
54
- limit ||= 10000
55
- path = "/api/#{table}/keyword/#{label}/count/#{limit}/"
56
- url = @cp["API"]+path
57
- url = URI.parse url
58
- http = Net::HTTP.new(url.host, url.port)
59
- http.use_ssl = (url.scheme == 'https')
60
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE # I hate doing this
61
- http.verify_depth = 5
62
- request = Net::HTTP::Get.new(url.path)
63
- request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
64
- request.add_field('Accept', 'application/json')
65
- request.add_field("X-BashTokid", @cp["API_ID"])
66
- token = Digest::MD5.hexdigest(path+@cp["API_KEY"])
67
- $stderr.puts "DEBUG: cn360 url = #{url} token = #{token}" if @debug
68
- request.add_field("X-BashToken", token)
69
- t1 = Time.now
70
- response = http.request(request)
71
- t2 = Time.now
72
- recs = parse_json(response.body, label, t2-t1)
73
- if limit
74
- recs[0,limit]
75
- else
76
- recs
77
- end
78
- end
79
- end
80
- end
@@ -1,85 +0,0 @@
1
- # DESCRIPTION: this is a module for pdns.rb, primarily used by pdnstool.rb, to query the Farsight Security passive DNS database
2
- # details on the API are at https://api.dnsdb.info/
3
- # to request an API key, please email dnsdb-api at farsightsecurity dot com.
4
- require 'net/http'
5
- require 'net/https'
6
-
7
- module PassiveDNS
8
- class DNSDB < PassiveDB
9
- # override
10
- def self.name
11
- "DNSDB"
12
- end
13
- #override
14
- def self.config_section_name
15
- "dnsdb"
16
- end
17
- #override
18
- def self.option_letter
19
- "d"
20
- end
21
-
22
- attr_accessor :debug
23
- def initialize(options={})
24
- @debug = options[:debug] || false
25
- @key = options["APIKEY"] || raise("APIKEY option required for #{self.class}")
26
- @base = options["URL"] || "https://api.dnsdb.info/lookup"
27
- end
28
-
29
- def parse_json(page,response_time)
30
- res = []
31
- raise "Error: unable to parse request" if page =~ /Error: unable to parse request/
32
- # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to
33
- rows = page.split(/\n/)
34
- rows.each do |row|
35
- record = JSON.parse(row)
36
- record['rdata'] = [record['rdata']] if record['rdata'].class == String
37
- record['rdata'].each do |rdata|
38
- if record['time_first']
39
- res << PDNSResult.new(self.class.name,response_time,record['rrname'],rdata,record['rrtype'],0,Time.at(record['time_first'].to_i).utc.strftime("%Y-%m-%dT%H:%M:%SZ"),Time.at(record['time_last'].to_i).utc.strftime("%Y-%m-%dT%H:%M:%SZ"),record['count'])
40
- else
41
- res << PDNSResult.new(self.class.name,response_time,record['rrname'],rdata,record['rrtype'])
42
- end
43
- end
44
- end
45
- res
46
- rescue Exception => e
47
- $stderr.puts "#{self.class.name} Exception: #{e}"
48
- $stderr.puts page
49
- raise e
50
- end
51
-
52
- def lookup(label, limit=nil)
53
- $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
54
- Timeout::timeout(240) {
55
- url = nil
56
- if label =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$/
57
- label = label.gsub(/\//,',')
58
- url = "#{@base}/rdata/ip/#{label}"
59
- else
60
- url = "#{@base}/rrset/name/#{label}"
61
- end
62
- url = URI.parse url
63
- http = Net::HTTP.new(url.host, url.port)
64
- http.use_ssl = (url.scheme == 'https')
65
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
66
- http.verify_depth = 5
67
- path = url.path
68
- if limit
69
- path << "?limit=#{limit}"
70
- end
71
- request = Net::HTTP::Get.new(path)
72
- request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
73
- request.add_field("X-API-Key", @key)
74
- request.add_field("Accept", "application/json")
75
- t1 = Time.now
76
- response = http.request(request)
77
- t2 = Time.now
78
- $stderr.puts response.body if @debug
79
- parse_json(response.body,t2-t1)
80
- }
81
- rescue Timeout::Error => e
82
- $stderr.puts "#{self.class.name} lookup timed out: #{label}"
83
- end
84
- end
85
- end