passivedns-client 2.1.12 → 3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8ea3feed82ed9f049ef8d7cd6ac78c087b94a630449cdbb3560fc28364ffe41
4
- data.tar.gz: 37056ad39c2d721a3b5e6ee9f0347c5f1f79686f75eb15da99e2f155fc7b22d0
3
+ metadata.gz: dadfb4d6f7c00ee3db5748f766859417cfb82186bde8f983d15eefd626935a88
4
+ data.tar.gz: 3e5741e62a00533f68b05114d0846388ddcf4a7bab613f45e8e2749a18edbff6
5
5
  SHA512:
6
- metadata.gz: 61ca76c52991e1a9e131d51412f0a855301b9555cbd0d1d6e5fe9c0071c1bc2d0b1539926148c090ad31c7db1aaff544565537c4db2f59bfd449e6747786d655
7
- data.tar.gz: 4bae5d3265ca1723c9170dc3e1ec726a6d855ff2324b4744692f0a9a486444751723fa907ce50ef9960900fa4236b53fdfb1484f04fc4a91c7dc1e6d61889756
6
+ metadata.gz: e4a3ce693df012d03a225e899d6e1c0b4a68346b90ccac54a9df897e255999bc4bbb998bedab7246804c56994d8e528d6d520ed9475e30e708886f5e6c20c61d
7
+ data.tar.gz: 288cc7cc1999d381410bd8422579f5cc2199ff8f5054ca3506140b496cc5dae20c7c806feb25a8657f82ee668f9a5a3c88cdf7de8ddbca3224b9f4c3e67dfcb0
data/CHANGELOG.md ADDED
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ ## 3.0.0 - 2026-11-23
4
+
5
+ ### Breaking changes
6
+
7
+ - Requires Ruby 3.2 or newer.
8
+ - The RiskIQ provider (`riskiq`, `-dr`) was removed. Its default endpoint, `ws.riskiq.net`, no longer answers, and RiskIQ is now part of
9
+ Microsoft Defender Threat Intelligence. PassiveTotal's `v2` mode was already the same service. Remove any `[riskiq]` section from your config.
10
+ - The VirusTotal provider now uses VirusTotal's v3 API (`/api/v3/{domains,ip_addresses}/<item>/resolutions`) instead of v2, and returns at
11
+ most 40 resolutions per query. A `URL` setting that points at the v2 API must be removed or updated. The provider is untested against the
12
+ live service.
13
+ - The configuration file is now read with [iniparse](https://rubygems.org/gems/iniparse) instead of `configparser`. The file format and
14
+ location (`~/.passivedns-client`) are unchanged. A file that cannot be parsed now raises an error that names the file.
15
+ - TLS certificates are now verified. Every provider used to disable verification (`OpenSSL::SSL::VERIFY_NONE`).
16
+ - `PassiveDNS::CLInterface.get_letter_map` was renamed to `letter_map`, and the `$passivedns_providers` global was replaced by
17
+ `PassiveDNS::Client.provider_names`. Providers register themselves by subclassing `PassiveDNS::PassiveDB`.
18
+ - The constructor argument of every provider is now named `config` (it is still a positional hash).
19
+ - The gem no longer ships the `test/` directory.
20
+ - `getoptlong` is now an explicit dependency (it is no longer a default gem in Ruby 3.4), and the `json` and `bundler` dependencies were dropped.
21
+
22
+ ### Fixed
23
+
24
+ - The SQLite state database (`-f`) built its SQL by interpolating strings, so a `'` in a query or answer broke it and it could be injected.
25
+ It now uses bound parameters.
26
+ - Results read back from the SQLite state database had their columns shifted (the query was reported as the source).
27
+ - A failed query was marked as failed using the wrong value, so it was never actually marked.
28
+ - A non-2xx response from a provider (a bad API key, a rate limit) crashed the query with a JSON parse error and a backtrace. It now
29
+ raises `PassiveDNS::ProviderError` (`DNSDB: HTTP 403: Error: Bad API key`), and `Client#query` prints it and still returns the answers from
30
+ the other providers.
31
+ - `Client#timeout=` raised `NoMethodError`, because providers had no `timeout=`.
32
+ - DNSDB lost the name of a record that had no trailing dot (`gsub!` returned `nil`).
33
+ - OSC, VirusTotal and PassiveTotal put the `security` marking in the `count` field of a result.
34
+ - OSC asked for gzip responses and then did not decompress them.
35
+ - The PassiveTotal provider no longer prints every response to standard output.
36
+ - `TLPSecurityControl#allow` reported `nil` instead of the offending level in its error message.
37
+
38
+ ### Changed
39
+
40
+ - Linting with RuboCop, CI for Ruby 3.2 to 3.4 and head, and API documentation published to GitHub Pages:
41
+ <https://chrislee35.github.io/passivedns-client/>.
42
+ - The tests no longer need a `~/.passivedns-client` file or network access. They use a local fake HTTP server.
43
+ - Modernized the gemspec, Rakefile and `.gitignore`, and added `CHANGELOG.md` and `.mailmap`.
data/README.md CHANGED
@@ -1,15 +1,11 @@
1
1
  # PassiveDNS::Client
2
2
 
3
- This rubygem queries the following Passive DNS databases:
3
+ This rubygem queries the following Passive DNS databases:
4
4
 
5
- * BFK.de
6
5
  * CIRCL
7
6
  * DNSDB (FarSight)
8
- * Mnemonic
9
- * PassiveDNS.cn (Qihoo 360 Technology Co.,Ltd)
7
+ * OpenSource Context (OSC)
10
8
  * PassiveTotal
11
- * RiskIQ
12
- * TCPIPUtils
13
9
  * VirusTotal
14
10
 
15
11
  Passive DNS is a technique where IP to hostname mappings are made by recording the answers of other people's queries.
@@ -20,6 +16,10 @@ Please note that use of any passive DNS database is subject to the terms of use
20
16
 
21
17
  If you like this library, please buy the Passive DNS operators a round of beers.
22
18
 
19
+ ## Requirements
20
+
21
+ Ruby 3.2 or newer.
22
+
23
23
  ## Installation
24
24
 
25
25
  Add this line to your application's Gemfile:
@@ -36,29 +36,20 @@ Or install it yourself as:
36
36
 
37
37
  ## Configuration
38
38
 
39
- From version 2.0.0 on, all configuration keys for passive DNS providers are in one configuration file. By default the location of the file is $HOME/.passivedns-client . The syntax of this file is as follows:
39
+ From version 2.0.0 on, all configuration keys for passive DNS providers are in one configuration file. By default the location of the file is $HOME/.passivedns-client . The file is a standard INI file (it is read with the [iniparse](https://rubygems.org/gems/iniparse) gem). The syntax is as follows:
40
40
 
41
41
  [dnsdb]
42
42
  APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
43
- [cn360]
44
- API = http://some.web.address.for.their.api
45
- API_ID = a username that is given when you register
46
- API_KEY = a long and random password of sorts that is used along with the page request to generate a per page API key
47
- [tcpiputils]
48
- APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
49
43
  [virustotal]
50
44
  APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
51
- [mnemonic]
52
- APIKEY = 01234567890abcdef01234567890abcdef012345
53
45
  [passivetotal]
54
46
  USERNAME = tom@example.com
55
47
  APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
56
48
  [circl]
57
49
  USERNAME = circl_user
58
50
  PASSWORD = circl_pass
59
- [riskiq]
60
- API_TOKEN = 0123456789abcdef
61
- API_PRIVATE_KEY = 01234567890abcdefghijklmnopqrstu
51
+ [osc]
52
+ APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
62
53
 
63
54
  CIRCL also can use and authorization token. In that case, you should drop the USERNAME and PASSWORD options and change the section to something like the following:
64
55
 
@@ -66,67 +57,64 @@ CIRCL also can use and authorization token. In that case, you should drop the U
66
57
  AUTH_TOKEN = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
67
58
 
68
59
  ## Getting Access
69
- * 360.cn : http://www.passivedns.cn
70
- * BFK.de : No registration required, but please, please ready their usage policy at http://www.bfk.de/bfk_dnslogger.html
71
60
  * CIRCL : https://www.circl.lu/services/passive-dns/
72
61
  * DNSDB (Farsight Security) : https://api.dnsdb.info/
73
- * Mnemonic : mss .at. mnemonic.no
62
+ * OSC: https://oscontext.com/
74
63
  * PassiveTotal : https://www.passivetotal.org
75
- * RiskIQ : https://github.com/RiskIQ/python_api/blob/master/LICENSE
76
- * TCPIPUtils : http://www.tcpiputils.com/premium-access
77
64
  * VirusTotal : https://www.virustotal.com
78
65
 
79
66
  ## Usage
80
67
 
81
68
  require 'passivedns/client'
82
-
83
- c = PassiveDNS::Client.new(['bfk','dnsdb']) # providers: bfk, tcpiputils, certee, dnsdb, virustotal, passivedns.cn, mnemonic
69
+
70
+ c = PassiveDNS::Client.new(['virustotal','dnsdb'])
84
71
  results = c.query("example.com")
85
-
72
+
86
73
 
87
74
  Or use the included tool...
88
75
 
89
- Usage: bin/pdnstool [-d [3bcdmptv]] [-g|-v|-m|-c|-x|-y|-j|-t] [-os <sep>] [-f <file>] [-r#|-w#|-v] [-l <count>] <ip|domain|cidr>
90
- Passive DNS Providers -d3bcdmptv uses all of the available passive dns database
91
- -d3 use 360.cn
92
- -db use BFK.de
93
- -dc use CIRCL
94
- -dd use DNSDB
95
- -dm use Mnemonic
96
- -dp use PassiveTotal
97
- -dr use RiskIQ
98
- -dt use TCPIPUtils
99
- -dv use VirusTotal
100
- -dvt uses VirusTotal and TCPIPUtils (for example)
101
-
102
- Output Formatting
103
- -g link-nodal GDF visualization definition
104
- -z link-nodal graphviz visualization definition
105
- -m link-nodal graphml visualization definition
106
- -c CSV
107
- -x XML
108
- -y YAML
109
- -j JSON
110
- -t ASCII text (default)
111
- -s <sep> specifies a field separator for text output, default is tab
112
-
113
- State and Recusion
114
- -f[file] specifies a sqlite3 database used to read the current state - useful for large result sets and generating graphs of previous runs.
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
- -w# specifies the amount of time to wait, in seconds, between queries (Default: 0)
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
121
-
122
- Getting Help
123
- -v debugging information
76
+ Usage: bin/pdnstool [-d [cdopv]] [-g|-v|-m|-c|-x|-y|-j|-t] [-os <sep>] [-f <file>] [-r#|-w#|-v] [-l <count>] [--config <file>] <ip|domain|cidr>
77
+ Passive DNS Providers
78
+ -dcdopv uses all of the available passive dns database
79
+ -dc use CIRCL
80
+ -dd use DNSDB
81
+ -do use OSC
82
+ -dp use PassiveTotal
83
+ -dv use VirusTotal
84
+ -dvp uses VirusTotal and PassiveTotal (for example)
85
+
86
+ Output Formatting
87
+ -g link-nodal GDF visualization definition
88
+ -z link-nodal graphviz visualization definition
89
+ -m link-nodal graphml visualization definition
90
+ -c CSV
91
+ -x XML
92
+ -y YAML
93
+ -j JSON
94
+ -t ASCII text (default)
95
+ -s <sep> specifies a field separator for text output, default is tab
96
+
97
+ State and Recursion
98
+ -f[file] specifies a sqlite3 database used to read the current state - useful for large result sets and generating graphs of previous runs.
99
+ -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!
100
+ -w# specifies the amount of time to wait, in seconds, between queries (Default: 0)
101
+ -l <count> limits the number of records returned per passive dns database queried.
102
+
103
+ Specifying a Configuration File
104
+ --config <file> specifies a config file. default: /home/chris/.passivedns-client
105
+
106
+ Getting Help
107
+ -h hello there. This option produces this helpful help information on how to access help.
108
+ -v debugging information
124
109
 
125
110
  ## Writing Your Own Database Adaptor
126
111
 
127
- module PassiveDNS
128
- class MyDatabaseAdaptor < PassiveDB
129
- # override
112
+ module PassiveDNS #:nodoc: don't document this
113
+ # The Provider module contains all the Passive DNS provider client code
114
+ module Provider
115
+ # Queries OSContext's passive DNS database
116
+ class MyDatabaseAdaptor < PassiveDB
117
+ # Sets the modules self-reported name to "OSC"
130
118
  def self.name
131
119
  "MyPerfectDNS" # short, proper label
132
120
  end
@@ -138,33 +126,35 @@ Or use the included tool...
138
126
  def self.option_letter
139
127
  "p" # single letter to specify the option for the command line tool
140
128
  end
141
-
129
+
142
130
  attr_accessor :debug
143
- def initialize(options={})
144
- @debug = options[:debug] || false
145
- # please include a way to change the base URL, HOST, etc., so that people can test
146
- # against a test/alternate version of your service
147
- @base = options["URL"] || "http://myperfectdns.example.com/pdns.cgi?query="
148
- @apikey = options["APIKEY"] || raise("APIKEY option required for #{self.class}")
149
- end
150
-
151
- # override
152
- def lookup(label, limit=nil)
153
- $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
154
- recs = []
155
- Timeout::timeout(240) {
156
- t1 = Time.now
157
- # TODO: your code goes here to fetch the data from your service
158
- # TODO: don't forget to impose the limit either during the fetch or during the parse phase
159
- response_time = Time.now - t1
160
- # TODO: parse your data and add PDNSResult objects to recs array
161
- recs << PDNSResult.new(self.class.name, response_time, rrname ,
162
- rdata, rrtype, ttl, first_seen, last_seen, count )
163
- }
164
- recs
165
- rescue Timeout::Error => e # using the implied "begin/try" from the beginning of the function
166
- $stderr.puts "#{self.class.name} lookup timed out: #{label}"
167
- end
131
+
132
+ def initialize(options={})
133
+ @debug = options[:debug] || false
134
+ # please include a way to change the base URL, HOST, etc., so that people can test
135
+ # against a test/alternate version of your service
136
+ @base = options["URL"] || "http://myperfectdns.example.com/pdns.cgi?query="
137
+ @apikey = options["APIKEY"] || raise("APIKEY option required for #{self.class}")
138
+ end
139
+
140
+ # override
141
+ def lookup(label, limit=nil)
142
+ $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
143
+ recs = []
144
+ Timeout::timeout(240) {
145
+ t1 = Time.now
146
+ # TODO: your code goes here to fetch the data from your service
147
+ # TODO: don't forget to impose the limit either during the fetch or during the parse phase
148
+ response_time = Time.now - t1
149
+ # TODO: parse your data and add PDNSResult objects to recs array
150
+ recs << PDNSResult.new(self.class.name, response_time, rrname ,
151
+ rdata, rrtype, ttl, first_seen, last_seen, count )
152
+ }
153
+ recs
154
+ rescue Timeout::Error => e # using the implied "begin/try" from the beginning of the function
155
+ $stderr.puts "#{self.class.name} lookup timed out: #{label}"
156
+ end
157
+ end
168
158
  end
169
159
  end
170
160
 
data/bin/pdnstool CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'passivedns/client'
3
5
  require 'passivedns/client/cli'
4
6
 
5
- puts PassiveDNS::CLI.run(ARGV)
7
+ puts PassiveDNS::CLI.run(ARGV)
@@ -1,28 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'getoptlong'
2
4
  require 'structformatter'
3
- require 'getoptlong'
4
5
  require 'yaml'
5
- require 'pp'
6
6
 
7
7
  module PassiveDNS # :nodoc:
8
8
  # Handles all the command-line parsing, state tracking, and dispatching queries to the PassiveDNS::Client instance
9
9
  # CLInterface is aliased by CLI
10
10
  class CLInterface
11
11
  # generates a mapping between the option letter for each PassiveDNS provider and the class
12
- def self.get_letter_map
13
- letter_map = {}
14
- mod = PassiveDNS::Provider
15
- mod.constants.each do |const|
16
- if mod.const_get(const).is_a?(Class) and mod.const_get(const).superclass == PassiveDNS::PassiveDB
17
- letter = mod.const_get(const).option_letter
18
- name = mod.const_get(const).name
19
- config_section_name = mod.const_get(const).config_section_name
20
- letter_map[letter] = [name, config_section_name]
21
- end
12
+ def self.letter_map
13
+ PassiveDB.providers.to_h do |provider|
14
+ [provider.option_letter, [provider.name, provider.config_section_name]]
22
15
  end
23
- letter_map
24
16
  end
25
-
17
+
26
18
  # parses the command line and yields an options hash
27
19
  # === Default Options
28
20
  # options = {
@@ -38,62 +30,56 @@ module PassiveDNS # :nodoc:
38
30
  # :help => false # display the usage text
39
31
  # }
40
32
  def self.parse_command_line(args)
41
- origARGV = ARGV.dup
42
- ARGV.replace(args)
33
+ orig_argv = ARGV.dup
34
+ ARGV.replace args
43
35
  opts = GetoptLong.new(
44
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
45
- [ '--debug', '-v', GetoptLong::NO_ARGUMENT ],
46
- [ '--database', '-d', GetoptLong::REQUIRED_ARGUMENT ],
47
-
48
- [ '--gdf', '-g', GetoptLong::NO_ARGUMENT ],
49
- [ '--graphviz', '-z', GetoptLong::NO_ARGUMENT ],
50
- [ '--graphml', '-m', GetoptLong::NO_ARGUMENT ],
51
- [ '--csv', '-c', GetoptLong::NO_ARGUMENT ],
52
- [ '--xml', '-x', GetoptLong::NO_ARGUMENT ],
53
- [ '--yaml', '-y', GetoptLong::NO_ARGUMENT ],
54
- [ '--json', '-j', GetoptLong::NO_ARGUMENT ],
55
- [ '--text', '-t', GetoptLong::NO_ARGUMENT ],
56
- [ '--sep', '-s', GetoptLong::REQUIRED_ARGUMENT ],
57
-
58
- [ '--sqlite3', '-f', GetoptLong::REQUIRED_ARGUMENT ],
59
- [ '--recurse', '-r', GetoptLong::REQUIRED_ARGUMENT ],
60
- [ '--wait', '-w', GetoptLong::REQUIRED_ARGUMENT ],
61
- [ '--limit', '-l', GetoptLong::REQUIRED_ARGUMENT ],
62
- [ '--config', GetoptLong::REQUIRED_ARGUMENT ]
36
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
37
+ ['--debug', '-v', GetoptLong::NO_ARGUMENT],
38
+ ['--database', '-d', GetoptLong::REQUIRED_ARGUMENT],
39
+ ['--gdf', '-g', GetoptLong::NO_ARGUMENT],
40
+ ['--graphviz', '-z', GetoptLong::NO_ARGUMENT],
41
+ ['--graphml', '-m', GetoptLong::NO_ARGUMENT],
42
+ ['--csv', '-c', GetoptLong::NO_ARGUMENT],
43
+ ['--xml', '-x', GetoptLong::NO_ARGUMENT],
44
+ ['--yaml', '-y', GetoptLong::NO_ARGUMENT],
45
+ ['--json', '-j', GetoptLong::NO_ARGUMENT],
46
+ ['--text', '-t', GetoptLong::NO_ARGUMENT],
47
+ ['--sep', '-s', GetoptLong::REQUIRED_ARGUMENT],
48
+ ['--sqlite3', '-f', GetoptLong::REQUIRED_ARGUMENT],
49
+ ['--recurse', '-r', GetoptLong::REQUIRED_ARGUMENT],
50
+ ['--wait', '-w', GetoptLong::REQUIRED_ARGUMENT],
51
+ ['--limit', '-l', GetoptLong::REQUIRED_ARGUMENT],
52
+ ['--config', GetoptLong::REQUIRED_ARGUMENT]
63
53
  )
64
54
 
65
- letter_map = get_letter_map
66
-
67
55
  # sets the default search methods
68
56
  options = {
69
- :pdnsdbs => [],
70
- :format => "text",
71
- :sep => "\t",
72
- :recursedepth => 1,
73
- :wait => 0,
74
- :res => nil,
75
- :debug => false,
76
- :sqlitedb => nil,
77
- :limit => nil,
78
- :help => false,
79
- :configfile => "#{ENV['HOME']}/.passivedns-client"
57
+ pdnsdbs: [],
58
+ format: 'text',
59
+ sep: "\t",
60
+ recursedepth: 1,
61
+ wait: 0,
62
+ res: nil,
63
+ debug: false,
64
+ sqlitedb: nil,
65
+ limit: nil,
66
+ help: false,
67
+ configfile: "#{Dir.home}/.passivedns-client"
80
68
  }
81
69
 
82
70
  opts.each do |opt, arg|
83
71
  case opt
84
- when '--help'
85
- options[:help] = true
86
72
  when '--debug'
87
73
  options[:debug] = true
88
74
  when '--database'
89
- arg.split(//).each do |c|
75
+ arg.chars.each do |c|
90
76
  if c == ','
91
77
  next
92
78
  elsif letter_map[c]
93
79
  options[:pdnsdbs] << letter_map[c][1]
94
80
  else
95
- $stderr.puts "ERROR: Unknown passive DNS database identifier: #{c}."
96
- usage(letter_map)
81
+ warn "ERROR: Unknown passive DNS database identifier: #{c}."
82
+ usage letter_map
97
83
  end
98
84
  end
99
85
  when '--gdf'
@@ -125,50 +111,42 @@ module PassiveDNS # :nodoc:
125
111
  options[:limit] = arg.to_i
126
112
  when '--config'
127
113
  options[:configfile] = arg
128
- else
114
+ else # --help and anything unrecognized
129
115
  options[:help] = true
130
116
  end
131
117
  end
132
118
  args = ARGV.dup
133
- ARGV.replace(origARGV)
134
-
135
- if options[:pdnsdbs].length == 0
136
- options[:pdnsdbs] << "bfk"
137
- end
119
+ ARGV.replace orig_argv
138
120
 
139
- if options[:pdnsdbs].index("bfk") and options[:recursedepth] > 1 and options[:wait] < 60
140
- options[:wait] = 60
141
- $stderr.puts "Enforcing a minimal 60 second wait when using BFK for recursive crawling"
142
- end
121
+ options[:pdnsdbs] << 'virustotal' if options[:pdnsdbs].empty?
143
122
 
144
123
  if options[:debug]
145
- $stderr.puts "Using the following databases: #{options[:pdnsdbs].join(", ")}"
146
- $stderr.puts "Recursions: #{options[:recursedepth]}, Wait time: #{options[:wait]}, Limit: #{options[:limit] or 'none'}"
147
- if options[:format] == "text" or options[:format] == "csv"
148
- $stderr.puts "Output format: #{options[:format]} (sep=\"#{options[:sep]}\")"
124
+ warn "Using the following databases: #{options[:pdnsdbs].join ', '}"
125
+ warn "Recursions: #{options[:recursedepth]}, Wait time: #{options[:wait]}, Limit: #{options[:limit] or 'none'}"
126
+ if (options[:format] == 'text') || (options[:format] == 'csv')
127
+ warn "Output format: #{options[:format]} (sep=\"#{options[:sep]}\")"
149
128
  else
150
- $stderr.puts "Output format: #{options[:format]}"
151
- end
152
- if ENV['http_proxy']
153
- $stderr.puts "Using proxy settings: http_proxy=#{ENV['http_proxy']}, https_proxy=#{ENV['https_proxy']}"
129
+ warn "Output format: #{options[:format]}"
154
130
  end
131
+ warn "Using proxy settings: http_proxy=#{ENV['http_proxy']}, https_proxy=#{ENV.fetch 'https_proxy', nil}" if ENV['http_proxy']
155
132
  end
156
-
133
+
157
134
  [options, args]
158
135
  end
159
-
136
+
160
137
  # returns a string containing the usage information
161
138
  # takes in a hash of letter to passive dns providers
139
+ # rubocop:disable-next Layout/LineLength
162
140
  def self.usage(letter_map)
163
- databases = letter_map.keys.sort.join("")
164
- help_text = ""
165
- help_text << "Usage: #{$0} [-d [#{databases}]] [-g|-v|-m|-c|-x|-y|-j|-t] [-os <sep>] [-f <file>] [-r#|-w#|-v] [-l <count>] [--config <file>] <ip|domain|cidr>\n"
141
+ databases = letter_map.keys.sort.join
142
+ help_text = +''
143
+ help_text << "Usage: #{$PROGRAM_NAME} [-d [#{databases}]] [-g|-v|-m|-c|-x|-y|-j|-t] [-os <sep>] [-f <file>] [-r#|-w#|-v] [-l <count>] [--config <file>] <ip|domain|cidr>\n"
166
144
  help_text << "Passive DNS Providers\n"
167
145
  help_text << " -d#{databases} uses all of the available passive dns database\n"
168
146
  letter_map.keys.sort.each do |l|
169
147
  help_text << " -d#{l} use #{letter_map[l][0]}\n"
170
148
  end
171
- help_text << " -dvt uses VirusTotal and TCPIPUtils (for example)\n"
149
+ help_text << " -dvp uses VirusTotal and PassiveTotal (for example)\n"
172
150
  help_text << "\n"
173
151
  help_text << "Output Formatting\n"
174
152
  help_text << " -g link-nodal GDF visualization definition\n"
@@ -188,15 +166,15 @@ module PassiveDNS # :nodoc:
188
166
  help_text << " -l <count> limits the number of records returned per passive dns database queried.\n"
189
167
  help_text << "\n"
190
168
  help_text << "Specifying a Configuration File\n"
191
- help_text << " --config <file> specifies a config file. default: #{ENV['HOME']}/.passivedns-client\n"
169
+ help_text << " --config <file> specifies a config file. default: #{Dir.home}/.passivedns-client\n"
192
170
  help_text << "\n"
193
171
  help_text << "Getting Help\n"
194
172
  help_text << " -h hello there. This option produces this helpful help information on how to access help.\n"
195
173
  help_text << " -v debugging information\n"
196
-
174
+
197
175
  help_text
198
176
  end
199
-
177
+
200
178
  # performs a stateful, recursive (if desired) passive DNS lookup against all specified providers
201
179
  def self.pdnslookup(state, pdnsclient, options)
202
180
  recursedepth = options[:recursedepth]
@@ -207,17 +185,17 @@ module PassiveDNS # :nodoc:
207
185
  level = 0
208
186
  while level < recursedepth
209
187
  puts "pdnslookup: #{level} < #{recursedepth}" if debug
210
- state.each_query(recursedepth) do |q|
211
- rv = pdnsclient.query(q,limit)
188
+ state.each_query recursedepth do |q|
189
+ rv = pdnsclient.query q, limit
212
190
  if rv
213
191
  rv.each do |r|
214
- if ["A","AAAA","NS","CNAME","PTR"].index(r.rrtype)
215
- puts "pdnslookup: #{r.to_s}" if debug
216
- state.add_result(r)
192
+ if PassiveDNS::Client::RRTYPES.include? r.rrtype
193
+ puts "pdnslookup: #{r}" if debug
194
+ state.add_result r
217
195
  end
218
196
  end
219
197
  else
220
- state.update_query(rv,'failed')
198
+ state.update_query q, 'failed'
221
199
  end
222
200
  sleep wait if level < recursedepth
223
201
  end
@@ -225,14 +203,14 @@ module PassiveDNS # :nodoc:
225
203
  end
226
204
  state
227
205
  end
228
-
206
+
229
207
  # returns a string transforming all the PassiveDNS::PDNSResult stored in the state object into text/xml/json/etc.
230
- def self.results_to_s(state,options)
208
+ def self.results_to_s(state, options)
231
209
  format = options[:format]
232
210
  sep = options[:sep]
233
211
  case format
234
212
  when 'text'
235
- PassiveDNS::PDNSResult.members.join(sep)+"\n"+state.to_s(sep)
213
+ "#{PassiveDNS::PDNSResult.members.join sep}\n#{state.to_s sep}"
236
214
  when 'yaml'
237
215
  state.to_yaml
238
216
  when 'xml'
@@ -247,48 +225,45 @@ module PassiveDNS # :nodoc:
247
225
  state.to_graphml
248
226
  end
249
227
  end
250
-
228
+
251
229
  # create a state instance
252
- def self.create_state(sqlitedb=nil)
253
- state = nil
230
+ def self.create_state(sqlitedb = nil)
254
231
  if sqlitedb
255
- state = PassiveDNS::PDNSToolStateDB.new(sqlitedb)
232
+ PassiveDNS::PDNSToolStateDB.new sqlitedb
256
233
  else
257
- state = PassiveDNS::PDNSToolState.new
234
+ PassiveDNS::PDNSToolState.new
258
235
  end
259
- state
260
236
  end
261
-
237
+
262
238
  # main method, takes command-line arguments and performs the desired queries and outputs
263
239
  def self.run(args)
264
- options, items = parse_command_line(args)
265
- if options[:help]
266
- return usage(get_letter_map)
267
- end
240
+ options, items = parse_command_line args
241
+ return usage letter_map if options[:help]
242
+
268
243
  if options[:recursedepth] > 3
269
- $stderr.puts "WARNING: a recursedepth of > 3 can be abusive, please reconsider: sleeping 60 seconds for sense to come to you (hint: hit CTRL-C)"
244
+ warn 'WARNING: a recursedepth of > 3 can be abusive, please reconsider: ' \
245
+ 'sleeping 60 seconds for sense to come to you (hint: hit CTRL-C)'
270
246
  sleep 60
271
247
  end
272
- state = create_state(options[:sqlitedb])
248
+ state = create_state options[:sqlitedb]
273
249
  state.debug = options[:debug]
274
250
 
275
- pdnsclient = PassiveDNS::Client.new(options[:pdnsdbs], options[:configfile])
251
+ pdnsclient = PassiveDNS::Client.new options[:pdnsdbs], options[:configfile]
276
252
  pdnsclient.debug = options[:debug]
277
-
278
- if items.length > 0
253
+
254
+ if items.length.positive?
279
255
  items.each do |arg|
280
- state.add_query(arg,'pending',0)
256
+ state.add_query arg, 'pending', 0
281
257
  end
282
258
  else
283
259
  $stdin.each_line do |l|
284
- state.add_query(l.chomp,'pending',0)
260
+ state.add_query l.chomp, 'pending', 0
285
261
  end
286
262
  end
287
- pdnslookup(state,pdnsclient,options)
288
- results_to_s(state,options)
263
+ pdnslookup state, pdnsclient, options
264
+ results_to_s state, options
289
265
  end
290
266
  end
291
267
  # Alias for the CLInterface class
292
268
  CLI = PassiveDNS::CLInterface
293
269
  end
294
-