passivedns-client 2.1.13 → 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 +4 -4
- data/CHANGELOG.md +43 -0
- data/LICENSE.txt +0 -0
- data/README.md +51 -43
- data/bin/pdnstool +3 -1
- data/lib/passivedns/client/cli.rb +85 -105
- data/lib/passivedns/client/passivedb.rb +44 -9
- data/lib/passivedns/client/provider/circl.rb +54 -50
- data/lib/passivedns/client/provider/dnsdb.rb +65 -52
- data/lib/passivedns/client/provider/osc.rb +147 -0
- data/lib/passivedns/client/provider/passivetotal.rb +53 -49
- data/lib/passivedns/client/provider/virustotal.rb +68 -62
- data/lib/passivedns/client/state.rb +121 -130
- data/lib/passivedns/client/version.rb +3 -1
- data/lib/passivedns/client.rb +93 -89
- metadata +52 -45
- data/.gitignore +0 -18
- data/Gemfile +0 -4
- data/Rakefile +0 -20
- data/lib/passivedns/client/provider/riskiq.rb +0 -146
- data/passivedns-client.gemspec +0 -31
- data/test/helper.rb +0 -6
- data/test/test_cli.rb +0 -219
- data/test/test_passivedns-client.rb +0 -162
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dadfb4d6f7c00ee3db5748f766859417cfb82186bde8f983d15eefd626935a88
|
|
4
|
+
data.tar.gz: 3e5741e62a00533f68b05114d0846388ddcf4a7bab613f45e8e2749a18edbff6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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/LICENSE.txt
CHANGED
|
File without changes
|
data/README.md
CHANGED
|
@@ -1,11 +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
5
|
* CIRCL
|
|
6
6
|
* DNSDB (FarSight)
|
|
7
|
+
* OpenSource Context (OSC)
|
|
7
8
|
* PassiveTotal
|
|
8
|
-
* RiskIQ
|
|
9
9
|
* VirusTotal
|
|
10
10
|
|
|
11
11
|
Passive DNS is a technique where IP to hostname mappings are made by recording the answers of other people's queries.
|
|
@@ -16,6 +16,10 @@ Please note that use of any passive DNS database is subject to the terms of use
|
|
|
16
16
|
|
|
17
17
|
If you like this library, please buy the Passive DNS operators a round of beers.
|
|
18
18
|
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
Ruby 3.2 or newer.
|
|
22
|
+
|
|
19
23
|
## Installation
|
|
20
24
|
|
|
21
25
|
Add this line to your application's Gemfile:
|
|
@@ -32,7 +36,7 @@ Or install it yourself as:
|
|
|
32
36
|
|
|
33
37
|
## Configuration
|
|
34
38
|
|
|
35
|
-
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
|
|
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:
|
|
36
40
|
|
|
37
41
|
[dnsdb]
|
|
38
42
|
APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
|
@@ -44,9 +48,8 @@ From version 2.0.0 on, all configuration keys for passive DNS providers are in o
|
|
|
44
48
|
[circl]
|
|
45
49
|
USERNAME = circl_user
|
|
46
50
|
PASSWORD = circl_pass
|
|
47
|
-
[
|
|
48
|
-
|
|
49
|
-
API_PRIVATE_KEY = 01234567890abcdefghijklmnopqrstu
|
|
51
|
+
[osc]
|
|
52
|
+
APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
|
50
53
|
|
|
51
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:
|
|
52
55
|
|
|
@@ -56,29 +59,29 @@ CIRCL also can use and authorization token. In that case, you should drop the U
|
|
|
56
59
|
## Getting Access
|
|
57
60
|
* CIRCL : https://www.circl.lu/services/passive-dns/
|
|
58
61
|
* DNSDB (Farsight Security) : https://api.dnsdb.info/
|
|
62
|
+
* OSC: https://oscontext.com/
|
|
59
63
|
* PassiveTotal : https://www.passivetotal.org
|
|
60
|
-
* RiskIQ : https://github.com/RiskIQ/python_api/blob/master/LICENSE
|
|
61
64
|
* VirusTotal : https://www.virustotal.com
|
|
62
65
|
|
|
63
66
|
## Usage
|
|
64
67
|
|
|
65
68
|
require 'passivedns/client'
|
|
66
|
-
|
|
67
|
-
c = PassiveDNS::Client.new(['
|
|
69
|
+
|
|
70
|
+
c = PassiveDNS::Client.new(['virustotal','dnsdb'])
|
|
68
71
|
results = c.query("example.com")
|
|
69
|
-
|
|
72
|
+
|
|
70
73
|
|
|
71
74
|
Or use the included tool...
|
|
72
75
|
|
|
73
|
-
Usage: bin/pdnstool [-d [
|
|
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>
|
|
74
77
|
Passive DNS Providers
|
|
75
|
-
-
|
|
78
|
+
-dcdopv uses all of the available passive dns database
|
|
76
79
|
-dc use CIRCL
|
|
77
80
|
-dd use DNSDB
|
|
81
|
+
-do use OSC
|
|
78
82
|
-dp use PassiveTotal
|
|
79
|
-
-dr use RiskIQ
|
|
80
83
|
-dv use VirusTotal
|
|
81
|
-
-
|
|
84
|
+
-dvp uses VirusTotal and PassiveTotal (for example)
|
|
82
85
|
|
|
83
86
|
Output Formatting
|
|
84
87
|
-g link-nodal GDF visualization definition
|
|
@@ -106,9 +109,12 @@ Or use the included tool...
|
|
|
106
109
|
|
|
107
110
|
## Writing Your Own Database Adaptor
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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"
|
|
112
118
|
def self.name
|
|
113
119
|
"MyPerfectDNS" # short, proper label
|
|
114
120
|
end
|
|
@@ -120,33 +126,35 @@ Or use the included tool...
|
|
|
120
126
|
def self.option_letter
|
|
121
127
|
"p" # single letter to specify the option for the command line tool
|
|
122
128
|
end
|
|
123
|
-
|
|
129
|
+
|
|
124
130
|
attr_accessor :debug
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
150
158
|
end
|
|
151
159
|
end
|
|
152
160
|
|
data/bin/pdnstool
CHANGED
|
@@ -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.
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
42
|
-
ARGV.replace
|
|
33
|
+
orig_argv = ARGV.dup
|
|
34
|
+
ARGV.replace args
|
|
43
35
|
opts = GetoptLong.new(
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
47
|
-
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
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
|
-
:
|
|
70
|
-
:
|
|
71
|
-
:
|
|
72
|
-
:
|
|
73
|
-
:
|
|
74
|
-
:
|
|
75
|
-
:
|
|
76
|
-
:
|
|
77
|
-
:
|
|
78
|
-
:
|
|
79
|
-
:
|
|
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.
|
|
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
|
-
|
|
96
|
-
usage
|
|
81
|
+
warn "ERROR: Unknown passive DNS database identifier: #{c}."
|
|
82
|
+
usage letter_map
|
|
97
83
|
end
|
|
98
84
|
end
|
|
99
85
|
when '--gdf'
|
|
@@ -125,45 +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
|
|
119
|
+
ARGV.replace orig_argv
|
|
134
120
|
|
|
135
|
-
if options[:pdnsdbs].
|
|
136
|
-
options[:pdnsdbs] << "virustotal"
|
|
137
|
-
end
|
|
121
|
+
options[:pdnsdbs] << 'virustotal' if options[:pdnsdbs].empty?
|
|
138
122
|
|
|
139
123
|
if options[:debug]
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if options[:format] ==
|
|
143
|
-
|
|
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]}\")"
|
|
144
128
|
else
|
|
145
|
-
|
|
146
|
-
end
|
|
147
|
-
if ENV['http_proxy']
|
|
148
|
-
$stderr.puts "Using proxy settings: http_proxy=#{ENV['http_proxy']}, https_proxy=#{ENV['https_proxy']}"
|
|
129
|
+
warn "Output format: #{options[:format]}"
|
|
149
130
|
end
|
|
131
|
+
warn "Using proxy settings: http_proxy=#{ENV['http_proxy']}, https_proxy=#{ENV.fetch 'https_proxy', nil}" if ENV['http_proxy']
|
|
150
132
|
end
|
|
151
|
-
|
|
133
|
+
|
|
152
134
|
[options, args]
|
|
153
135
|
end
|
|
154
|
-
|
|
136
|
+
|
|
155
137
|
# returns a string containing the usage information
|
|
156
138
|
# takes in a hash of letter to passive dns providers
|
|
139
|
+
# rubocop:disable-next Layout/LineLength
|
|
157
140
|
def self.usage(letter_map)
|
|
158
|
-
databases = letter_map.keys.sort.join
|
|
159
|
-
help_text =
|
|
160
|
-
help_text << "Usage: #{$
|
|
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"
|
|
161
144
|
help_text << "Passive DNS Providers\n"
|
|
162
145
|
help_text << " -d#{databases} uses all of the available passive dns database\n"
|
|
163
146
|
letter_map.keys.sort.each do |l|
|
|
164
147
|
help_text << " -d#{l} use #{letter_map[l][0]}\n"
|
|
165
148
|
end
|
|
166
|
-
help_text << " -
|
|
149
|
+
help_text << " -dvp uses VirusTotal and PassiveTotal (for example)\n"
|
|
167
150
|
help_text << "\n"
|
|
168
151
|
help_text << "Output Formatting\n"
|
|
169
152
|
help_text << " -g link-nodal GDF visualization definition\n"
|
|
@@ -183,15 +166,15 @@ module PassiveDNS # :nodoc:
|
|
|
183
166
|
help_text << " -l <count> limits the number of records returned per passive dns database queried.\n"
|
|
184
167
|
help_text << "\n"
|
|
185
168
|
help_text << "Specifying a Configuration File\n"
|
|
186
|
-
help_text << " --config <file> specifies a config file. default: #{
|
|
169
|
+
help_text << " --config <file> specifies a config file. default: #{Dir.home}/.passivedns-client\n"
|
|
187
170
|
help_text << "\n"
|
|
188
171
|
help_text << "Getting Help\n"
|
|
189
172
|
help_text << " -h hello there. This option produces this helpful help information on how to access help.\n"
|
|
190
173
|
help_text << " -v debugging information\n"
|
|
191
|
-
|
|
174
|
+
|
|
192
175
|
help_text
|
|
193
176
|
end
|
|
194
|
-
|
|
177
|
+
|
|
195
178
|
# performs a stateful, recursive (if desired) passive DNS lookup against all specified providers
|
|
196
179
|
def self.pdnslookup(state, pdnsclient, options)
|
|
197
180
|
recursedepth = options[:recursedepth]
|
|
@@ -202,17 +185,17 @@ module PassiveDNS # :nodoc:
|
|
|
202
185
|
level = 0
|
|
203
186
|
while level < recursedepth
|
|
204
187
|
puts "pdnslookup: #{level} < #{recursedepth}" if debug
|
|
205
|
-
state.each_query
|
|
206
|
-
rv = pdnsclient.query
|
|
188
|
+
state.each_query recursedepth do |q|
|
|
189
|
+
rv = pdnsclient.query q, limit
|
|
207
190
|
if rv
|
|
208
191
|
rv.each do |r|
|
|
209
|
-
if
|
|
210
|
-
puts "pdnslookup: #{r
|
|
211
|
-
state.add_result
|
|
192
|
+
if PassiveDNS::Client::RRTYPES.include? r.rrtype
|
|
193
|
+
puts "pdnslookup: #{r}" if debug
|
|
194
|
+
state.add_result r
|
|
212
195
|
end
|
|
213
196
|
end
|
|
214
197
|
else
|
|
215
|
-
state.update_query
|
|
198
|
+
state.update_query q, 'failed'
|
|
216
199
|
end
|
|
217
200
|
sleep wait if level < recursedepth
|
|
218
201
|
end
|
|
@@ -220,14 +203,14 @@ module PassiveDNS # :nodoc:
|
|
|
220
203
|
end
|
|
221
204
|
state
|
|
222
205
|
end
|
|
223
|
-
|
|
206
|
+
|
|
224
207
|
# returns a string transforming all the PassiveDNS::PDNSResult stored in the state object into text/xml/json/etc.
|
|
225
|
-
def self.results_to_s(state,options)
|
|
208
|
+
def self.results_to_s(state, options)
|
|
226
209
|
format = options[:format]
|
|
227
210
|
sep = options[:sep]
|
|
228
211
|
case format
|
|
229
212
|
when 'text'
|
|
230
|
-
PassiveDNS::PDNSResult.members.join
|
|
213
|
+
"#{PassiveDNS::PDNSResult.members.join sep}\n#{state.to_s sep}"
|
|
231
214
|
when 'yaml'
|
|
232
215
|
state.to_yaml
|
|
233
216
|
when 'xml'
|
|
@@ -242,48 +225,45 @@ module PassiveDNS # :nodoc:
|
|
|
242
225
|
state.to_graphml
|
|
243
226
|
end
|
|
244
227
|
end
|
|
245
|
-
|
|
228
|
+
|
|
246
229
|
# create a state instance
|
|
247
|
-
def self.create_state(sqlitedb=nil)
|
|
248
|
-
state = nil
|
|
230
|
+
def self.create_state(sqlitedb = nil)
|
|
249
231
|
if sqlitedb
|
|
250
|
-
|
|
232
|
+
PassiveDNS::PDNSToolStateDB.new sqlitedb
|
|
251
233
|
else
|
|
252
|
-
|
|
234
|
+
PassiveDNS::PDNSToolState.new
|
|
253
235
|
end
|
|
254
|
-
state
|
|
255
236
|
end
|
|
256
|
-
|
|
237
|
+
|
|
257
238
|
# main method, takes command-line arguments and performs the desired queries and outputs
|
|
258
239
|
def self.run(args)
|
|
259
|
-
options, items = parse_command_line
|
|
260
|
-
if options[:help]
|
|
261
|
-
|
|
262
|
-
end
|
|
240
|
+
options, items = parse_command_line args
|
|
241
|
+
return usage letter_map if options[:help]
|
|
242
|
+
|
|
263
243
|
if options[:recursedepth] > 3
|
|
264
|
-
|
|
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)'
|
|
265
246
|
sleep 60
|
|
266
247
|
end
|
|
267
|
-
state = create_state
|
|
248
|
+
state = create_state options[:sqlitedb]
|
|
268
249
|
state.debug = options[:debug]
|
|
269
250
|
|
|
270
|
-
pdnsclient = PassiveDNS::Client.new
|
|
251
|
+
pdnsclient = PassiveDNS::Client.new options[:pdnsdbs], options[:configfile]
|
|
271
252
|
pdnsclient.debug = options[:debug]
|
|
272
|
-
|
|
273
|
-
if items.length
|
|
253
|
+
|
|
254
|
+
if items.length.positive?
|
|
274
255
|
items.each do |arg|
|
|
275
|
-
state.add_query
|
|
256
|
+
state.add_query arg, 'pending', 0
|
|
276
257
|
end
|
|
277
258
|
else
|
|
278
259
|
$stdin.each_line do |l|
|
|
279
|
-
state.add_query
|
|
260
|
+
state.add_query l.chomp, 'pending', 0
|
|
280
261
|
end
|
|
281
262
|
end
|
|
282
|
-
pdnslookup
|
|
283
|
-
results_to_s
|
|
263
|
+
pdnslookup state, pdnsclient, options
|
|
264
|
+
results_to_s state, options
|
|
284
265
|
end
|
|
285
266
|
end
|
|
286
267
|
# Alias for the CLInterface class
|
|
287
268
|
CLI = PassiveDNS::CLInterface
|
|
288
269
|
end
|
|
289
|
-
|
|
@@ -1,24 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
|
|
5
|
+
module PassiveDNS # :nodoc: don't document this
|
|
6
|
+
# raised when a passive DNS provider reports a failure, such as a bad API key or a rate limit
|
|
7
|
+
class ProviderError < StandardError; end
|
|
8
|
+
|
|
2
9
|
# abstract class that all PassiveDNS::Provider should subclass
|
|
3
10
|
class PassiveDB
|
|
11
|
+
@providers = []
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
# all of the classes that subclass PassiveDB
|
|
15
|
+
attr_reader :providers
|
|
16
|
+
|
|
17
|
+
# registers each subclass as a provider
|
|
18
|
+
def inherited(subclass)
|
|
19
|
+
super
|
|
20
|
+
PassiveDB.providers << subclass
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# :debug enables verbose logging to standard output
|
|
25
|
+
# :timeout is the number of seconds to wait for a lookup
|
|
26
|
+
attr_accessor :debug, :timeout
|
|
27
|
+
|
|
4
28
|
# raises an exception that this should be implemented by the subclass
|
|
5
29
|
def self.name
|
|
6
|
-
raise
|
|
30
|
+
raise 'You should implement your own version of .name'
|
|
7
31
|
end
|
|
8
|
-
|
|
32
|
+
|
|
9
33
|
# raises an exception that this should be implemented by the subclass
|
|
10
34
|
def self.config_section_name
|
|
11
35
|
name
|
|
12
36
|
end
|
|
13
|
-
|
|
37
|
+
|
|
14
38
|
# raises an exception that this should be implemented by the subclass
|
|
15
39
|
def self.option_letter
|
|
16
|
-
raise
|
|
40
|
+
raise 'You should pick a unique letter to serve as your database option letter for the command line option -d'
|
|
17
41
|
end
|
|
18
|
-
|
|
42
|
+
|
|
19
43
|
# raises an exception that this should be implemented by the subclass
|
|
20
|
-
def lookup(
|
|
21
|
-
raise
|
|
44
|
+
def lookup(_label, _limit = nil)
|
|
45
|
+
raise 'You must implement the lookup function'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
# returns the response when it is a success, otherwise raises a ProviderError that names the provider, the HTTP status
|
|
51
|
+
# and the first line of the body (providers report errors as plain text, HTML or JSON)
|
|
52
|
+
def check_response(response)
|
|
53
|
+
return response if response.is_a? Net::HTTPSuccess
|
|
54
|
+
|
|
55
|
+
detail = response.body.to_s.strip.lines.first.to_s.strip[0, 200]
|
|
56
|
+
raise ProviderError, "#{self.class.name}: HTTP #{response.code}#{": #{detail}" unless detail.empty?}"
|
|
22
57
|
end
|
|
23
58
|
end
|
|
24
|
-
end
|
|
59
|
+
end
|