passivedns-client 2.1.9 → 2.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b6b0dc4227f010b9fc53b01f2307f49b405db80
4
- data.tar.gz: 1e3b0abb99ceddee325ee4245f9924500127089d
3
+ metadata.gz: 41bb1d54d9a49eb1995dfdd9c78538dc91ed40d7
4
+ data.tar.gz: c446107f1d435fcc1334b20d62c72ec18c495a3f
5
5
  SHA512:
6
- metadata.gz: d638e8dba5e9af5476c626dca055925c702bd41c3b836ba876d914d8d2e609a9ed042983da8987b0d1ae7af41316c1ad5d3a4f559f5db2bf694a96d2bae06547
7
- data.tar.gz: 22b0c684739e932b646f2bd7a508f9e8a53c4c2ff8ba69c5623f36a51d7d4931f83d317dcc2fbab9df3b8944f84101c854596c32a6c07486adaaad445404c028
6
+ metadata.gz: 4117587bbb9789a381696295a40d88fff86e0284e358ec8feeae64f1436de6f09d17db8f71f3add3d950f8fd6f4ce31b43bd19b7f8a2ff1fabd4e5a4d5e135b9
7
+ data.tar.gz: da94f1292023be6bb0ec75a380ac3fa661e8ecfbe6cb2fc13ad327a9930a28d7cd23b81ab1d6715df817b85760ddaab14f90fd07c4bdb16634fab521de6a8823
data/README.md CHANGED
@@ -115,6 +115,9 @@ Or use the included tool...
115
115
  -r# specifies the levels of recursion to pull. **WARNING** This is quite taxing on the pDNS servers, so use judiciously (never more than 3 or so) or find yourself blocked!
116
116
  -w# specifies the amount of time to wait, in seconds, between queries (Default: 0)
117
117
  -l <count> limits the number of records returned per passive dns database queried.
118
+
119
+ Specifying a Configuration File
120
+ --config <file> specifies a config file. default: #{ENV['HOME']}/.passivedns-client
118
121
 
119
122
  Getting Help
120
123
  -v debugging information
@@ -94,6 +94,12 @@ module PassiveDNS # :nodoc:
94
94
  end
95
95
  end
96
96
 
97
+ def timeout=(t)
98
+ @pdnsdbs.each do |pdnsdb|
99
+ pdnsdb.timeout = t
100
+ end
101
+ end
102
+
97
103
  # perform the query lookup accross all configured PassiveDNS providers
98
104
  def query(item, limit=nil)
99
105
  threads = []
@@ -75,7 +75,8 @@ module PassiveDNS # :nodoc:
75
75
  :debug => false,
76
76
  :sqlitedb => nil,
77
77
  :limit => nil,
78
- :help => false
78
+ :help => false,
79
+ :configfile => "#{ENV['HOME']}/.passivedns-client"
79
80
  }
80
81
 
81
82
  opts.each do |opt, arg|
@@ -186,6 +187,9 @@ module PassiveDNS # :nodoc:
186
187
  help_text << " -w# specifies the amount of time to wait, in seconds, between queries (Default: 0)\n"
187
188
  help_text << " -l <count> limits the number of records returned per passive dns database queried.\n"
188
189
  help_text << "\n"
190
+ help_text << "Specifying a Configuration File\n"
191
+ help_text << " --config <file> specifies a config file. default: #{ENV['HOME']}/.passivedns-client\n"
192
+ help_text << "\n"
189
193
  help_text << "Getting Help\n"
190
194
  help_text << " -h hello there. This option produces this helpful help information on how to access help.\n"
191
195
  help_text << " -v debugging information\n"
@@ -36,6 +36,7 @@ module PassiveDNS #:nodoc: don't document this
36
36
  #
37
37
  def initialize(options={})
38
38
  @debug = options[:debug] || false
39
+ @timeout = options[:timeout] || 20
39
40
  @base = options["URL"] || "http://www.bfk.de/bfk_dnslogger.html?query="
40
41
  raise "Due to the EU GDPR policy, this service has been shut down until further notice."
41
42
  end
@@ -44,7 +45,7 @@ module PassiveDNS #:nodoc: don't document this
44
45
  # an array of PassiveDNS::PDNSResult instances with the answers to the query
45
46
  def lookup(label, limit=nil)
46
47
  $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
47
- Timeout::timeout(240) {
48
+ Timeout::timeout(@timeout) {
48
49
  t1 = Time.now
49
50
  open(
50
51
  @base+label,
@@ -47,6 +47,7 @@ module PassiveDNS #:nodoc: don't document this
47
47
  #
48
48
  def initialize(options={})
49
49
  @debug = options[:debug] || false
50
+ @timeout = options[:timeout] || 20
50
51
  @username = options["USERNAME"]
51
52
  @password = options["PASSWORD"]
52
53
  @auth_token = options["AUTH_TOKEN"]
@@ -57,10 +58,16 @@ module PassiveDNS #:nodoc: don't document this
57
58
  # an array of PassiveDNS::PDNSResult instances with the answers to the query
58
59
  def lookup(label, limit=nil)
59
60
  $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
60
- Timeout::timeout(240) {
61
+ recs = []
62
+ Timeout::timeout(@timeout) {
61
63
  url = @url+"/"+label
62
64
  $stderr.puts "DEBUG: #{self.class.name} url = #{url}" if @debug
63
- url = URI.parse url
65
+ begin
66
+ url = URI.parse url
67
+ rescue URI::InvalidURIError
68
+ $stderr.puts "ERROR: Invalid address: #{url}"
69
+ return recs
70
+ end
64
71
  http = Net::HTTP.new(url.host, url.port)
65
72
  http.use_ssl = (url.scheme == 'https')
66
73
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -74,9 +81,17 @@ module PassiveDNS #:nodoc: don't document this
74
81
  request.add_field("Authorization", @auth_token)
75
82
  end
76
83
  t1 = Time.now
77
- response = http.request(request)
78
- t2 = Time.now
79
- recs = parse_json(response.body, label, t2-t1)
84
+ 0.upto(9) do
85
+ response = http.request(request)
86
+ body = response.body
87
+ if body == "Rate Limit Exceeded"
88
+ $stderr.puts "DEBUG: Rate Limit Exceeded. Retrying #{label}" if @debug
89
+ else
90
+ t2 = Time.now
91
+ recs = parse_json(response.body, label, t2-t1)
92
+ break
93
+ end
94
+ end
80
95
  if limit
81
96
  recs[0,limit]
82
97
  else
@@ -85,6 +100,7 @@ module PassiveDNS #:nodoc: don't document this
85
100
  }
86
101
  rescue Timeout::Error => e
87
102
  $stderr.puts "#{self.class.name} lookup timed out: #{label}"
103
+ recs
88
104
  end
89
105
 
90
106
  private
@@ -43,6 +43,7 @@ module PassiveDNS #:nodoc: don't document this
43
43
  #
44
44
  def initialize(options={})
45
45
  @debug = options[:debug] || false
46
+ @timeout = options[:timeout] || 20
46
47
  ["API", "API_ID", "API_KEY"].each do |opt|
47
48
  if not options[opt]
48
49
  raise "Field #{opt} is required. See README.md"
@@ -60,28 +61,33 @@ module PassiveDNS #:nodoc: don't document this
60
61
  end
61
62
  limit ||= 10000
62
63
  path = "/api/#{table}/keyword/#{label}/count/#{limit}/"
63
- url = @cp["API"]+path
64
- url = URI.parse url
65
- http = Net::HTTP.new(url.host, url.port)
66
- http.use_ssl = (url.scheme == 'https')
67
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE # I hate doing this
68
- http.verify_depth = 5
69
- request = Net::HTTP::Get.new(url.path)
70
- request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
71
- request.add_field('Accept', 'application/json')
72
- request.add_field("X-BashTokid", @cp["API_ID"])
73
- token = Digest::MD5.hexdigest(path+@cp["API_KEY"])
74
- $stderr.puts "DEBUG: cn360 url = #{url} token = #{token}" if @debug
75
- request.add_field("X-BashToken", token)
76
- t1 = Time.now
77
- response = http.request(request)
78
- t2 = Time.now
79
- recs = parse_json(response.body, label, t2-t1)
80
- if limit
81
- recs[0,limit]
82
- else
83
- recs
84
- end
64
+ Timeout::timeout(@timeout) {
65
+ url = @cp["API"]+path
66
+ url = URI.parse url
67
+ http = Net::HTTP.new(url.host, url.port)
68
+ http.use_ssl = (url.scheme == 'https')
69
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE # I hate doing this
70
+ http.verify_depth = 5
71
+ request = Net::HTTP::Get.new(url.path)
72
+ request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
73
+ request.add_field('Accept', 'application/json')
74
+ request.add_field("X-BashTokid", @cp["API_ID"])
75
+ token = Digest::MD5.hexdigest(path+@cp["API_KEY"])
76
+ $stderr.puts "DEBUG: cn360 url = #{url} token = #{token}" if @debug
77
+ request.add_field("X-BashToken", token)
78
+ t1 = Time.now
79
+ response = http.request(request)
80
+ t2 = Time.now
81
+ recs = parse_json(response.body, label, t2-t1)
82
+ if limit
83
+ recs[0,limit]
84
+ else
85
+ recs
86
+ end
87
+ }
88
+ rescue Timeout::Error => e
89
+ $stderr.puts "#{self.class.name} lookup timed out: #{label}"
90
+ recs
85
91
  end
86
92
 
87
93
  private
@@ -41,6 +41,7 @@ module PassiveDNS #:nodoc: don't document this
41
41
  #
42
42
  def initialize(options={})
43
43
  @debug = options[:debug] || false
44
+ @timeout = options[:timeout] || 20
44
45
  @key = options["APIKEY"] || raise("APIKEY option required for #{self.class}")
45
46
  @base = options["URL"] || "https://api.dnsdb.info/lookup"
46
47
  end
@@ -49,7 +50,7 @@ module PassiveDNS #:nodoc: don't document this
49
50
  # an array of PassiveDNS::PDNSResult instances with the answers to the query
50
51
  def lookup(label, limit=nil)
51
52
  $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
52
- Timeout::timeout(240) {
53
+ Timeout::timeout(@timeout) {
53
54
  url = nil
54
55
  if label =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$/
55
56
  label = label.gsub(/\//,',')
@@ -41,6 +41,7 @@ module PassiveDNS #:nodoc: don't document this
41
41
  #
42
42
  def initialize(options={})
43
43
  @debug = options[:debug] || false
44
+ @timeout = options[:timeout] || 20
44
45
  @apikey = options["APIKEY"]
45
46
  @url = options["URL"] || "https://api.mnemonic.no/pdns/v3/"
46
47
  if @url == "https://passivedns.mnemonic.no/api1/?apikey="
@@ -52,7 +53,7 @@ module PassiveDNS #:nodoc: don't document this
52
53
  # an array of PassiveDNS::PDNSResult instances with the answers to the query
53
54
  def lookup(label, limit=nil)
54
55
  $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
55
- Timeout::timeout(240) {
56
+ Timeout::timeout(@timeout) {
56
57
  url = "#{@url}#{label}"
57
58
  $stderr.puts "DEBUG: #{self.class.name} url = #{url}" if @debug
58
59
  url = URI.parse url
@@ -54,6 +54,7 @@ module PassiveDNS #:nodoc: don't document this
54
54
  #
55
55
  def initialize(options={})
56
56
  @debug = options[:debug] || false
57
+ @timeout = options[:timeout] || 20
57
58
  @username = options["USERNAME"] || raise("#{self.class.name} requires a USERNAME")
58
59
  @apikey = options["APIKEY"] || raise("#{self.class.name} requires an APIKEY")
59
60
  @url = options["URL"] || "https://api.passivetotal.org/v2/dns/passive"
@@ -63,7 +64,7 @@ module PassiveDNS #:nodoc: don't document this
63
64
  # an array of PassiveDNS::PDNSResult instances with the answers to the query
64
65
  def lookup(label, limit=nil)
65
66
  $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
66
- Timeout::timeout(240) {
67
+ Timeout::timeout(@timeout) {
67
68
  url = @url+"?query=#{label}"
68
69
  $stderr.puts "DEBUG: #{self.class.name} url = #{url}" if @debug
69
70
  url = URI.parse url
@@ -46,10 +46,11 @@ module PassiveDNS #:nodoc: don't document this
46
46
  #
47
47
  def initialize(options={})
48
48
  @debug = options[:debug] || false
49
+ @timeout = options[:timeout] || 20
49
50
  @token = options["API_TOKEN"] || raise("#{self.class.name} requires an API_TOKEN")
50
51
  @privkey = options["API_PRIVATE_KEY"] || raise("#{self.class.name} requires an API_PRIVATE_KEY")
51
- @server = options["API_SERVER"] || "ws.riskiq.net"
52
52
  @version = options["API_VERSION"] || "v1"
53
+ @server = options["API_SERVER"] || api_settings[@version][:server]
53
54
  @url = "https://#{@server}/#{@version}"
54
55
  end
55
56
 
@@ -57,7 +58,7 @@ module PassiveDNS #:nodoc: don't document this
57
58
  # an array of PassiveDNS::PDNSResult instances with the answers to the query
58
59
  def lookup(label, limit=nil)
59
60
  $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
60
- Timeout::timeout(240) {
61
+ Timeout::timeout(@timeout) {
61
62
  url = nil
62
63
  params = {"rrType" => "", "maxResults" => limit || 1000}
63
64
 
@@ -65,8 +66,10 @@ module PassiveDNS #:nodoc: don't document this
65
66
  url = @url+"/dns/data"
66
67
  params["ip"] = label
67
68
  else
68
- url = @url+"/dns/name"
69
- params["name"] = label
69
+ resource = api_settings[@version][:resource]
70
+ param = api_settings[@version][:param]
71
+ url = @url+"/dns/#{resource}"
72
+ params[param] = label
70
73
  end
71
74
  url << "?"
72
75
  params.each do |k,v|
@@ -101,10 +104,23 @@ module PassiveDNS #:nodoc: don't document this
101
104
 
102
105
  private
103
106
 
107
+ def api_settings
108
+ @api_settings ||= {
109
+ 'v1' => { server: "ws.riskiq.net", resource: 'name', param: 'name' },
110
+ 'v2' => { server: "api.passivetotal.org", resource: 'passive', param: 'query' }
111
+ }
112
+ end
113
+
104
114
  # parses the response of riskiq's JSON reply to generate an array of PDNSResult
105
115
  def parse_json(page,query,response_time=0)
106
- res = []
116
+ res = []
107
117
  data = JSON.parse(page)
118
+ if data['message']
119
+ if data['message'] =~ /quota_exceeded/
120
+ $stderr.puts "ERROR: quota exceeded."
121
+ return res
122
+ end
123
+ end
108
124
  if data['records']
109
125
  data['records'].each do |record|
110
126
  name = record['name'].gsub!(/\.$/,'')
@@ -42,6 +42,7 @@ module PassiveDNS #:nodoc: don't document this
42
42
  #
43
43
  def initialize(options={})
44
44
  @debug = options[:debug] || false
45
+ @timeout = options[:timeout] || 20
45
46
  @apikey = options["APIKEY"] || raise("#{self.class.name} requires an APIKEY. See README.md")
46
47
  @url = options["URL"] || "https://www.utlsapi.com/api.php?version=1.0&apikey="
47
48
  end
@@ -53,7 +54,7 @@ module PassiveDNS #:nodoc: don't document this
53
54
  type = (label.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) ? "domainneighbors" : "domainipdnshistory"
54
55
  url = "#{@url}#{@apikey}&type=#{type}&q=#{label}"
55
56
  recs = []
56
- Timeout::timeout(240) {
57
+ Timeout::timeout(@timeout) {
57
58
  url = URI.parse url
58
59
  http = Net::HTTP.new(url.host, url.port)
59
60
  http.use_ssl = (url.scheme == 'https')
@@ -41,6 +41,7 @@ module PassiveDNS #:nodoc: don't document this
41
41
  #
42
42
  def initialize(options={})
43
43
  @debug = options[:debug] || false
44
+ @timeout = options[:timeout] || 20
44
45
  @apikey = options["APIKEY"] || raise("#{self.class.name} requires an APIKEY. See README.md")
45
46
  @url = options["URL"] || "https://www.virustotal.com/vtapi/v2/"
46
47
  end
@@ -49,7 +50,7 @@ module PassiveDNS #:nodoc: don't document this
49
50
  # an array of PassiveDNS::PDNSResult instances with the answers to the query
50
51
  def lookup(label, limit=nil)
51
52
  $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
52
- Timeout::timeout(240) {
53
+ Timeout::timeout(@timeout) {
53
54
  url = nil
54
55
  if label =~ /^[\d\.]+$/
55
56
  url = "#{@url}ip-address/report?ip=#{label}&apikey=#{@apikey}"
@@ -57,7 +58,12 @@ module PassiveDNS #:nodoc: don't document this
57
58
  url = "#{@url}domain/report?domain=#{label}&apikey=#{@apikey}"
58
59
  end
59
60
  $stderr.puts "DEBUG: #{self.class.name} url = #{url}" if @debug
60
- url = URI.parse url
61
+ begin
62
+ url = URI.parse url
63
+ rescue URI::InvalidURIError
64
+ $stderr.puts "ERROR: Invalid address: #{url}"
65
+ return
66
+ end
61
67
  http = Net::HTTP.new(url.host, url.port)
62
68
  http.use_ssl = (url.scheme == 'https')
63
69
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -66,6 +72,10 @@ module PassiveDNS #:nodoc: don't document this
66
72
  request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
67
73
  t1 = Time.now
68
74
  response = http.request(request)
75
+ if response.code.to_i == 204
76
+ $stderr.puts "DEBUG: empty response from server" if @debug
77
+ return
78
+ end
69
79
  t2 = Time.now
70
80
  recs = parse_json(response.body, label, t2-t1)
71
81
  if limit
@@ -83,6 +93,7 @@ module PassiveDNS #:nodoc: don't document this
83
93
  # parses the response of virustotal's JSON reply to generate an array of PDNSResult
84
94
  def parse_json(page,query,response_time=0)
85
95
  res = []
96
+ return res if !page
86
97
  data = JSON.parse(page)
87
98
  if data['resolutions']
88
99
  data['resolutions'].each do |row|
@@ -94,6 +105,9 @@ module PassiveDNS #:nodoc: don't document this
94
105
  end
95
106
  end
96
107
  end
108
+ if data['response_code'] == 0
109
+ $stderr.puts "DEBUG: server returned error: #{data['verbose_msg']}" if @debug
110
+ end
97
111
  res
98
112
  rescue Exception => e
99
113
  $stderr.puts "VirusTotal Exception: #{e}"
@@ -2,6 +2,6 @@ module PassiveDNS # :nodoc:
2
2
  # coodinates the lookups accross all configured PassiveDNS providers
3
3
  class Client
4
4
  # version of PassiveDNS::Client
5
- VERSION = "2.1.9"
5
+ VERSION = "2.1.11"
6
6
  end
7
7
  end
@@ -51,6 +51,9 @@ State and Recursion
51
51
  -w# specifies the amount of time to wait, in seconds, between queries (Default: 0)
52
52
  -l <count> limits the number of records returned per passive dns database queried.
53
53
 
54
+ Specifying a Configuration File
55
+ --config <file> specifies a config file. default: #{ENV['HOME']}/.passivedns-client
56
+
54
57
  Getting Help
55
58
  -h hello there. This option produces this helpful help information on how to access help.
56
59
  -v debugging information
@@ -68,7 +71,8 @@ Getting Help
68
71
  :debug => false,
69
72
  :sqlitedb => nil,
70
73
  :limit => nil,
71
- :help => false
74
+ :help => false,
75
+ :configfile => "#{ENV['HOME']}/.passivedns-client"
72
76
  }
73
77
 
74
78
  options, items = PassiveDNS::CLI.parse_command_line([])
@@ -108,7 +112,8 @@ Getting Help
108
112
  :debug => false,
109
113
  :sqlitedb => nil,
110
114
  :limit => nil,
111
- :help => false
115
+ :help => false,
116
+ :configfile => "#{ENV['HOME']}/.passivedns-client"
112
117
  }
113
118
 
114
119
  options_target[:sep] = ","
@@ -171,7 +176,8 @@ Getting Help
171
176
  :debug => false,
172
177
  :sqlitedb => nil,
173
178
  :limit => nil,
174
- :help => true
179
+ :help => true,
180
+ :configfile => "#{ENV['HOME']}/.passivedns-client"
175
181
  }
176
182
 
177
183
  options, items = PassiveDNS::CLI.parse_command_line(["-dptv", "-h", "8.8.8.8"])
@@ -195,7 +201,8 @@ Getting Help
195
201
  :debug => false,
196
202
  :sqlitedb => "test.db",
197
203
  :limit => 10,
198
- :help => false
204
+ :help => false,
205
+ :configfile => "#{ENV['HOME']}/.passivedns-client"
199
206
  }
200
207
 
201
208
  options, items = PassiveDNS::CLI.parse_command_line(["-dptv", "-f", "test.db", "-r", "5", "-w", "30", "-l", "10", "8.8.8.8"])
@@ -215,11 +222,11 @@ Getting Help
215
222
  :sqlitedb => nil,
216
223
  :limit => nil,
217
224
  :help => false,
218
- :configfile => ".passivedns-client"
225
+ :configfile => "#{ENV['HOME']}/.passivedns-client"
219
226
  }
220
227
 
221
228
 
222
- options, items = PassiveDNS::CLI.parse_command_line(["--config", ".passivedns-client"])
229
+ options, items = PassiveDNS::CLI.parse_command_line(["--config", "#{ENV['HOME']}/.passivedns-client"])
223
230
  assert_equal(options_target, options)
224
231
  assert_equal([], items)
225
232
 
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.1.9
4
+ version: 2.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrislee35
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2018-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json