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
data/test/test_cli.rb
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
unless Kernel.respond_to?(:require_relative)
|
|
2
|
-
module Kernel
|
|
3
|
-
def require_relative(path)
|
|
4
|
-
require File.join(File.dirname(caller[0]), path.to_str)
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
require_relative 'helper'
|
|
10
|
-
require 'configparser'
|
|
11
|
-
require_relative '../lib/passivedns/client/cli.rb'
|
|
12
|
-
|
|
13
|
-
class TestCLI < Minitest::Test
|
|
14
|
-
def test_letter_map
|
|
15
|
-
letter_map = PassiveDNS::CLI.get_letter_map
|
|
16
|
-
assert_equal("cdprv", letter_map.keys.sort.join(""))
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_help_text
|
|
20
|
-
helptext = PassiveDNS::CLI.run(["--help"])
|
|
21
|
-
helptext.gsub!(/Usage: .*?\[/, "Usage: [")
|
|
22
|
-
assert_equal(
|
|
23
|
-
"Usage: [-d [cdprv]] [-g|-v|-m|-c|-x|-y|-j|-t] [-os <sep>] [-f <file>] [-r#|-w#|-v] [-l <count>] [--config <file>] <ip|domain|cidr>
|
|
24
|
-
Passive DNS Providers
|
|
25
|
-
-dcdprv uses all of the available passive dns database
|
|
26
|
-
-dc use CIRCL
|
|
27
|
-
-dd use DNSDB
|
|
28
|
-
-dp use PassiveTotal
|
|
29
|
-
-dr use RiskIQ
|
|
30
|
-
-dv use VirusTotal
|
|
31
|
-
-dvr uses VirusTotal and RiskIQ (for example)
|
|
32
|
-
|
|
33
|
-
Output Formatting
|
|
34
|
-
-g link-nodal GDF visualization definition
|
|
35
|
-
-z link-nodal graphviz visualization definition
|
|
36
|
-
-m link-nodal graphml visualization definition
|
|
37
|
-
-c CSV
|
|
38
|
-
-x XML
|
|
39
|
-
-y YAML
|
|
40
|
-
-j JSON
|
|
41
|
-
-t ASCII text (default)
|
|
42
|
-
-s <sep> specifies a field separator for text output, default is tab
|
|
43
|
-
|
|
44
|
-
State and Recursion
|
|
45
|
-
-f[file] specifies a sqlite3 database used to read the current state - useful for large result sets and generating graphs of previous runs.
|
|
46
|
-
-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!
|
|
47
|
-
-w# specifies the amount of time to wait, in seconds, between queries (Default: 0)
|
|
48
|
-
-l <count> limits the number of records returned per passive dns database queried.
|
|
49
|
-
|
|
50
|
-
Specifying a Configuration File
|
|
51
|
-
--config <file> specifies a config file. default: #{ENV['HOME']}/.passivedns-client
|
|
52
|
-
|
|
53
|
-
Getting Help
|
|
54
|
-
-h hello there. This option produces this helpful help information on how to access help.
|
|
55
|
-
-v debugging information
|
|
56
|
-
", helptext)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_provider_parsing
|
|
60
|
-
options_target = {
|
|
61
|
-
:pdnsdbs => ["virustotal"],
|
|
62
|
-
:format => "text",
|
|
63
|
-
:sep => "\t",
|
|
64
|
-
:recursedepth => 1,
|
|
65
|
-
:wait => 0,
|
|
66
|
-
:res => nil,
|
|
67
|
-
:debug => false,
|
|
68
|
-
:sqlitedb => nil,
|
|
69
|
-
:limit => nil,
|
|
70
|
-
:help => false,
|
|
71
|
-
:configfile => "#{ENV['HOME']}/.passivedns-client"
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
options, items = PassiveDNS::CLI.parse_command_line([])
|
|
75
|
-
assert_equal(options_target, options)
|
|
76
|
-
assert_equal([], items)
|
|
77
|
-
|
|
78
|
-
options_target[:pdnsdbs] = ["circl", "dnsdb", "riskiq"]
|
|
79
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dcdr"])
|
|
80
|
-
assert_equal(options_target, options)
|
|
81
|
-
assert_equal([], items)
|
|
82
|
-
|
|
83
|
-
options_target[:pdnsdbs] = ["passivetotal", "virustotal"]
|
|
84
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv"])
|
|
85
|
-
assert_equal(options_target, options)
|
|
86
|
-
assert_equal([], items)
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def test_output_parsing
|
|
91
|
-
options_target = {
|
|
92
|
-
:pdnsdbs => ["passivetotal", "virustotal"],
|
|
93
|
-
:format => "text",
|
|
94
|
-
:sep => "\t",
|
|
95
|
-
:recursedepth => 1,
|
|
96
|
-
:wait => 0,
|
|
97
|
-
:res => nil,
|
|
98
|
-
:debug => false,
|
|
99
|
-
:sqlitedb => nil,
|
|
100
|
-
:limit => nil,
|
|
101
|
-
:help => false,
|
|
102
|
-
:configfile => "#{ENV['HOME']}/.passivedns-client"
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
options_target[:sep] = ","
|
|
106
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-c", "8.8.8.8"])
|
|
107
|
-
assert_equal(options_target, options)
|
|
108
|
-
assert_equal(["8.8.8.8"], items)
|
|
109
|
-
|
|
110
|
-
options_target[:sep] = "|"
|
|
111
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-s", "|", "8.8.8.8"])
|
|
112
|
-
assert_equal(options_target, options)
|
|
113
|
-
assert_equal(["8.8.8.8"], items)
|
|
114
|
-
|
|
115
|
-
options_target[:sep] = "\t"
|
|
116
|
-
|
|
117
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-t", "8.8.8.8"])
|
|
118
|
-
assert_equal(options_target, options)
|
|
119
|
-
assert_equal(["8.8.8.8"], items)
|
|
120
|
-
|
|
121
|
-
options_target[:format] = "json"
|
|
122
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-j", "8.8.8.8"])
|
|
123
|
-
assert_equal(options_target, options)
|
|
124
|
-
assert_equal(["8.8.8.8"], items)
|
|
125
|
-
|
|
126
|
-
options_target[:format] = "xml"
|
|
127
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-x", "8.8.8.8"])
|
|
128
|
-
assert_equal(options_target, options)
|
|
129
|
-
assert_equal(["8.8.8.8"], items)
|
|
130
|
-
|
|
131
|
-
options_target[:format] = "yaml"
|
|
132
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-y", "8.8.8.8"])
|
|
133
|
-
assert_equal(options_target, options)
|
|
134
|
-
assert_equal(["8.8.8.8"], items)
|
|
135
|
-
|
|
136
|
-
options_target[:format] = "gdf"
|
|
137
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-g", "8.8.8.8"])
|
|
138
|
-
assert_equal(options_target, options)
|
|
139
|
-
assert_equal(["8.8.8.8"], items)
|
|
140
|
-
|
|
141
|
-
options_target[:format] = "graphviz"
|
|
142
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-z", "8.8.8.8"])
|
|
143
|
-
assert_equal(options_target, options)
|
|
144
|
-
assert_equal(["8.8.8.8"], items)
|
|
145
|
-
|
|
146
|
-
options_target[:format] = "graphml"
|
|
147
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-m", "8.8.8.8"])
|
|
148
|
-
assert_equal(options_target, options)
|
|
149
|
-
assert_equal(["8.8.8.8"], items)
|
|
150
|
-
|
|
151
|
-
options_target[:format] = "text"
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def test_help_debug_parsing
|
|
155
|
-
options_target = {
|
|
156
|
-
:pdnsdbs => ["passivetotal", "virustotal"],
|
|
157
|
-
:format => "text",
|
|
158
|
-
:sep => "\t",
|
|
159
|
-
:recursedepth => 1,
|
|
160
|
-
:wait => 0,
|
|
161
|
-
:res => nil,
|
|
162
|
-
:debug => false,
|
|
163
|
-
:sqlitedb => nil,
|
|
164
|
-
:limit => nil,
|
|
165
|
-
:help => true,
|
|
166
|
-
:configfile => "#{ENV['HOME']}/.passivedns-client"
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-h", "8.8.8.8"])
|
|
170
|
-
assert_equal(options_target, options)
|
|
171
|
-
assert_equal(["8.8.8.8"], items)
|
|
172
|
-
|
|
173
|
-
options_target[:debug] = true
|
|
174
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-h", "-v", "8.8.8.8"])
|
|
175
|
-
assert_equal(options_target, options)
|
|
176
|
-
assert_equal(["8.8.8.8"], items)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_state_recursion_parsing
|
|
180
|
-
options_target = {
|
|
181
|
-
:pdnsdbs => ["passivetotal", "virustotal"],
|
|
182
|
-
:format => "text",
|
|
183
|
-
:sep => "\t",
|
|
184
|
-
:recursedepth => 5,
|
|
185
|
-
:wait => 30,
|
|
186
|
-
:res => nil,
|
|
187
|
-
:debug => false,
|
|
188
|
-
:sqlitedb => "test.db",
|
|
189
|
-
:limit => 10,
|
|
190
|
-
:help => false,
|
|
191
|
-
:configfile => "#{ENV['HOME']}/.passivedns-client"
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
options, items = PassiveDNS::CLI.parse_command_line(["-dpv", "-f", "test.db", "-r", "5", "-w", "30", "-l", "10", "8.8.8.8"])
|
|
195
|
-
assert_equal(options_target, options)
|
|
196
|
-
assert_equal(["8.8.8.8"], items)
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def test_configuration_file
|
|
200
|
-
options_target = {
|
|
201
|
-
:pdnsdbs => ["virustotal"],
|
|
202
|
-
:format => "text",
|
|
203
|
-
:sep => "\t",
|
|
204
|
-
:recursedepth => 1,
|
|
205
|
-
:wait => 0,
|
|
206
|
-
:res => nil,
|
|
207
|
-
:debug => false,
|
|
208
|
-
:sqlitedb => nil,
|
|
209
|
-
:limit => nil,
|
|
210
|
-
:help => false,
|
|
211
|
-
:configfile => "#{ENV['HOME']}/.passivedns-client"
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
options, items = PassiveDNS::CLI.parse_command_line(["--config", "#{ENV['HOME']}/.passivedns-client"])
|
|
215
|
-
assert_equal(options_target, options)
|
|
216
|
-
assert_equal([], items)
|
|
217
|
-
|
|
218
|
-
end
|
|
219
|
-
end
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
unless Kernel.respond_to?(:require_relative)
|
|
2
|
-
module Kernel
|
|
3
|
-
def require_relative(path)
|
|
4
|
-
require File.join(File.dirname(caller[0]), path.to_str)
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
require_relative 'helper'
|
|
10
|
-
require 'configparser'
|
|
11
|
-
|
|
12
|
-
class TestPassiveDnsQuery < Minitest::Test
|
|
13
|
-
|
|
14
|
-
def setup
|
|
15
|
-
configfile="#{ENV['HOME']}/.passivedns-client"
|
|
16
|
-
@cp = ConfigParser.new(configfile)
|
|
17
|
-
@class_map = {}
|
|
18
|
-
PassiveDNS.constants.each do |const|
|
|
19
|
-
if PassiveDNS.const_get(const).is_a?(Class) and PassiveDNS.const_get(const).superclass == PassiveDNS::PassiveDB
|
|
20
|
-
@class_map[PassiveDNS.const_get(const).config_section_name] = PassiveDNS.const_get(const)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_instantiate_Nonexisting_Client
|
|
26
|
-
assert_raises RuntimeError do
|
|
27
|
-
PassiveDNS::Client.new(['doesnotexist'])
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_instantiate_All_Clients
|
|
32
|
-
PassiveDNS::Client.new()
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_instantiate_Passive_DNS_State
|
|
36
|
-
refute_nil(PassiveDNS::PDNSToolState.new)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_instantiate_Passive_DNS_State_database
|
|
40
|
-
if File.exist?("test/test.sqlite3")
|
|
41
|
-
File.unlink("test/test.sqlite3")
|
|
42
|
-
end
|
|
43
|
-
refute_nil(PassiveDNS::PDNSToolStateDB.new("test/test.sqlite3"))
|
|
44
|
-
if File.exist?("test/test.sqlite3")
|
|
45
|
-
File.unlink("test/test.sqlite3")
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_DNSDB
|
|
50
|
-
PassiveDNS::Client.new(['dnsdb'])
|
|
51
|
-
d = PassiveDNS::Provider::DNSDB.new(@cp['dnsdb'] || {})
|
|
52
|
-
refute_nil(d)
|
|
53
|
-
rows = d.lookup("example.org",3)
|
|
54
|
-
refute_nil(rows)
|
|
55
|
-
refute_nil(rows.to_s)
|
|
56
|
-
refute_nil(rows.to_xml)
|
|
57
|
-
refute_nil(rows.to_json)
|
|
58
|
-
refute_nil(rows.to_yaml)
|
|
59
|
-
assert_equal(3, rows.length) # this will fail since DNSDB has an off by one error
|
|
60
|
-
rows = d.lookup("8.8.8.8")
|
|
61
|
-
refute_nil(rows)
|
|
62
|
-
refute_nil(rows.to_s)
|
|
63
|
-
refute_nil(rows.to_xml)
|
|
64
|
-
refute_nil(rows.to_json)
|
|
65
|
-
refute_nil(rows.to_yaml)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_VirusTotal
|
|
69
|
-
PassiveDNS::Client.new(['virustotal'])
|
|
70
|
-
d = PassiveDNS::Provider::VirusTotal.new(@cp['virustotal'] || {})
|
|
71
|
-
refute_nil(d)
|
|
72
|
-
rows = d.lookup("google.com",3)
|
|
73
|
-
refute_nil(rows)
|
|
74
|
-
refute_nil(rows.to_s)
|
|
75
|
-
refute_nil(rows.to_xml)
|
|
76
|
-
refute_nil(rows.to_json)
|
|
77
|
-
refute_nil(rows.to_yaml)
|
|
78
|
-
assert_equal(3, rows.length)
|
|
79
|
-
rows = d.lookup("8.8.8.8")
|
|
80
|
-
refute_nil(rows)
|
|
81
|
-
refute_nil(rows.to_s)
|
|
82
|
-
refute_nil(rows.to_xml)
|
|
83
|
-
refute_nil(rows.to_json)
|
|
84
|
-
refute_nil(rows.to_yaml)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def test_passivetotal
|
|
88
|
-
PassiveDNS::Client.new(['passivetotal'])
|
|
89
|
-
d = PassiveDNS::Provider::PassiveTotal.new(@cp['passivetotal'] || {})
|
|
90
|
-
refute_nil(d)
|
|
91
|
-
rows = d.lookup("example.org")
|
|
92
|
-
refute_nil(rows)
|
|
93
|
-
refute_nil(rows.to_s)
|
|
94
|
-
refute_nil(rows.to_xml)
|
|
95
|
-
refute_nil(rows.to_json)
|
|
96
|
-
refute_nil(rows.to_yaml)
|
|
97
|
-
rows = d.lookup("example.org", 3)
|
|
98
|
-
refute_nil(rows)
|
|
99
|
-
refute_nil(rows.to_s)
|
|
100
|
-
refute_nil(rows.to_xml)
|
|
101
|
-
refute_nil(rows.to_json)
|
|
102
|
-
refute_nil(rows.to_yaml)
|
|
103
|
-
puts(rows)
|
|
104
|
-
assert_equal(3, rows.length)
|
|
105
|
-
rows = d.lookup("8.8.8.8")
|
|
106
|
-
refute_nil(rows)
|
|
107
|
-
refute_nil(rows.to_s)
|
|
108
|
-
refute_nil(rows.to_xml)
|
|
109
|
-
refute_nil(rows.to_json)
|
|
110
|
-
refute_nil(rows.to_yaml)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def test_circl
|
|
114
|
-
PassiveDNS::Client.new(['circl'])
|
|
115
|
-
d = PassiveDNS::Provider::CIRCL.new(@cp['circl'] || {})
|
|
116
|
-
refute_nil(d)
|
|
117
|
-
rows = d.lookup("example.org")
|
|
118
|
-
refute_nil(rows)
|
|
119
|
-
refute_nil(rows.to_s)
|
|
120
|
-
refute_nil(rows.to_xml)
|
|
121
|
-
refute_nil(rows.to_json)
|
|
122
|
-
refute_nil(rows.to_yaml)
|
|
123
|
-
rows = d.lookup("example.org",3)
|
|
124
|
-
refute_nil(rows)
|
|
125
|
-
refute_nil(rows.to_s)
|
|
126
|
-
refute_nil(rows.to_xml)
|
|
127
|
-
refute_nil(rows.to_json)
|
|
128
|
-
refute_nil(rows.to_yaml)
|
|
129
|
-
assert_equal(3, rows.length)
|
|
130
|
-
rows = d.lookup("8.8.8.8")
|
|
131
|
-
refute_nil(rows)
|
|
132
|
-
refute_nil(rows.to_s)
|
|
133
|
-
refute_nil(rows.to_xml)
|
|
134
|
-
refute_nil(rows.to_json)
|
|
135
|
-
refute_nil(rows.to_yaml)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def test_riskiq
|
|
139
|
-
PassiveDNS::Client.new(['riskiq'])
|
|
140
|
-
d = PassiveDNS::Provider::RiskIQ.new(@cp['riskiq'] || {})
|
|
141
|
-
refute_nil(d)
|
|
142
|
-
rows = d.lookup("example.org")
|
|
143
|
-
refute_nil(rows)
|
|
144
|
-
refute_nil(rows.to_s)
|
|
145
|
-
refute_nil(rows.to_xml)
|
|
146
|
-
refute_nil(rows.to_json)
|
|
147
|
-
refute_nil(rows.to_yaml)
|
|
148
|
-
rows = d.lookup("example.org",3)
|
|
149
|
-
refute_nil(rows)
|
|
150
|
-
refute_nil(rows.to_s)
|
|
151
|
-
refute_nil(rows.to_xml)
|
|
152
|
-
refute_nil(rows.to_json)
|
|
153
|
-
refute_nil(rows.to_yaml)
|
|
154
|
-
assert_equal(3, rows.length)
|
|
155
|
-
rows = d.lookup("8.8.8.8")
|
|
156
|
-
refute_nil(rows)
|
|
157
|
-
refute_nil(rows.to_s)
|
|
158
|
-
refute_nil(rows.to_xml)
|
|
159
|
-
refute_nil(rows.to_json)
|
|
160
|
-
refute_nil(rows.to_yaml)
|
|
161
|
-
end
|
|
162
|
-
end
|