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 +4 -4
- data/CHANGELOG.md +43 -0
- data/README.md +80 -90
- data/bin/pdnstool +3 -1
- data/lib/passivedns/client/cli.rb +85 -110
- 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 -91
- metadata +52 -49
- data/.gitignore +0 -18
- data/Gemfile +0 -4
- data/Rakefile +0 -20
- data/lib/passivedns/client/provider/bfk.rb +0 -109
- data/lib/passivedns/client/provider/cn360.rb +0 -122
- data/lib/passivedns/client/provider/mnemonic.rb +0 -112
- data/lib/passivedns/client/provider/riskiq.rb +0 -146
- data/lib/passivedns/client/provider/tcpiputils.rb +0 -129
- data/passivedns-client.gemspec +0 -31
- data/test/helper.rb +0 -6
- data/test/test_cli.rb +0 -234
- data/test/test_passivedns-client.rb +0 -262
metadata
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: passivedns-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- chrislee35
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: getoptlong
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
@@ -25,35 +24,35 @@ dependencies:
|
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
27
|
+
name: iniparse
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
32
|
+
version: '1.5'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
39
|
+
version: '1.5'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
41
|
+
name: sqlite3
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
44
43
|
requirements:
|
|
45
44
|
- - ">="
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
46
|
+
version: '1.4'
|
|
48
47
|
type: :runtime
|
|
49
48
|
prerelease: false
|
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
50
|
requirements:
|
|
52
51
|
- - ">="
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
53
|
+
version: '1.4'
|
|
55
54
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
55
|
+
name: structformatter
|
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
|
58
57
|
requirements:
|
|
59
58
|
- - ">="
|
|
@@ -70,46 +69,60 @@ dependencies:
|
|
|
70
69
|
name: minitest
|
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
|
-
- - "
|
|
72
|
+
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
74
|
+
version: '6.0'
|
|
76
75
|
type: :development
|
|
77
76
|
prerelease: false
|
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
|
80
|
-
- - "
|
|
79
|
+
- - "~>"
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
81
|
+
version: '6.0'
|
|
83
82
|
- !ruby/object:Gem::Dependency
|
|
84
|
-
name:
|
|
83
|
+
name: rake
|
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
|
86
85
|
requirements:
|
|
87
|
-
- - "
|
|
86
|
+
- - "~>"
|
|
88
87
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
88
|
+
version: '13.0'
|
|
90
89
|
type: :development
|
|
91
90
|
prerelease: false
|
|
92
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
92
|
requirements:
|
|
94
|
-
- - "
|
|
93
|
+
- - "~>"
|
|
95
94
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
95
|
+
version: '13.0'
|
|
97
96
|
- !ruby/object:Gem::Dependency
|
|
98
|
-
name:
|
|
97
|
+
name: rubocop
|
|
99
98
|
requirement: !ruby/object:Gem::Requirement
|
|
100
99
|
requirements:
|
|
101
|
-
- - "
|
|
100
|
+
- - "~>"
|
|
102
101
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0'
|
|
102
|
+
version: '1.0'
|
|
104
103
|
type: :development
|
|
105
104
|
prerelease: false
|
|
106
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
106
|
requirements:
|
|
108
|
-
- - "
|
|
107
|
+
- - "~>"
|
|
109
108
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0'
|
|
109
|
+
version: '1.0'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rubocop-performance
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '1.0'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '1.0'
|
|
111
124
|
description: This provides interfaces to various passive DNS databases to do the query
|
|
112
|
-
and to normalize the responses.
|
|
125
|
+
and to normalize the responses. The query tool also allows for recursive queries,
|
|
113
126
|
using an SQLite3 database to keep state.
|
|
114
127
|
email:
|
|
115
128
|
- rubygems@chrislee.dhs.org
|
|
@@ -118,35 +131,29 @@ executables:
|
|
|
118
131
|
extensions: []
|
|
119
132
|
extra_rdoc_files: []
|
|
120
133
|
files:
|
|
121
|
-
-
|
|
122
|
-
- Gemfile
|
|
134
|
+
- CHANGELOG.md
|
|
123
135
|
- LICENSE.txt
|
|
124
136
|
- README.md
|
|
125
|
-
- Rakefile
|
|
126
137
|
- bin/pdnstool
|
|
127
138
|
- lib/passivedns/client.rb
|
|
128
139
|
- lib/passivedns/client/cli.rb
|
|
129
140
|
- lib/passivedns/client/passivedb.rb
|
|
130
|
-
- lib/passivedns/client/provider/bfk.rb
|
|
131
141
|
- lib/passivedns/client/provider/circl.rb
|
|
132
|
-
- lib/passivedns/client/provider/cn360.rb
|
|
133
142
|
- lib/passivedns/client/provider/dnsdb.rb
|
|
134
|
-
- lib/passivedns/client/provider/
|
|
143
|
+
- lib/passivedns/client/provider/osc.rb
|
|
135
144
|
- lib/passivedns/client/provider/passivetotal.rb
|
|
136
|
-
- lib/passivedns/client/provider/riskiq.rb
|
|
137
|
-
- lib/passivedns/client/provider/tcpiputils.rb
|
|
138
145
|
- lib/passivedns/client/provider/virustotal.rb
|
|
139
146
|
- lib/passivedns/client/state.rb
|
|
140
147
|
- lib/passivedns/client/version.rb
|
|
141
|
-
- passivedns-client.gemspec
|
|
142
|
-
- test/helper.rb
|
|
143
|
-
- test/test_cli.rb
|
|
144
|
-
- test/test_passivedns-client.rb
|
|
145
148
|
homepage: https://github.com/chrislee35/passivedns-client
|
|
146
149
|
licenses:
|
|
147
150
|
- MIT
|
|
148
|
-
metadata:
|
|
149
|
-
|
|
151
|
+
metadata:
|
|
152
|
+
source_code_uri: https://github.com/chrislee35/passivedns-client
|
|
153
|
+
bug_tracker_uri: https://github.com/chrislee35/passivedns-client/issues
|
|
154
|
+
changelog_uri: https://github.com/chrislee35/passivedns-client/blob/master/CHANGELOG.md
|
|
155
|
+
documentation_uri: https://chrislee35.github.io/passivedns-client/
|
|
156
|
+
rubygems_mfa_required: 'true'
|
|
150
157
|
rdoc_options: []
|
|
151
158
|
require_paths:
|
|
152
159
|
- lib
|
|
@@ -154,18 +161,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
154
161
|
requirements:
|
|
155
162
|
- - ">="
|
|
156
163
|
- !ruby/object:Gem::Version
|
|
157
|
-
version: '
|
|
164
|
+
version: '3.2'
|
|
158
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
166
|
requirements:
|
|
160
167
|
- - ">="
|
|
161
168
|
- !ruby/object:Gem::Version
|
|
162
169
|
version: '0'
|
|
163
170
|
requirements: []
|
|
164
|
-
rubygems_version: 3.
|
|
165
|
-
signing_key:
|
|
171
|
+
rubygems_version: 3.7.2
|
|
166
172
|
specification_version: 4
|
|
167
173
|
summary: Query passive DNS databases
|
|
168
|
-
test_files:
|
|
169
|
-
- test/helper.rb
|
|
170
|
-
- test/test_cli.rb
|
|
171
|
-
- test/test_passivedns-client.rb
|
|
174
|
+
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env rake
|
|
2
|
-
require "bundler/gem_tasks"
|
|
3
|
-
|
|
4
|
-
require 'rake/testtask'
|
|
5
|
-
require 'rdoc/task'
|
|
6
|
-
|
|
7
|
-
Rake::TestTask.new do |t|
|
|
8
|
-
t.libs << 'lib'
|
|
9
|
-
t.test_files = FileList['test/test_*.rb']
|
|
10
|
-
t.verbose = true
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
RDoc::Task.new do |rd|
|
|
14
|
-
rd.main = "README.doc"
|
|
15
|
-
rd.rdoc_files.include("README.md", "lib/**/*.rb")
|
|
16
|
-
rd.options << "--all"
|
|
17
|
-
rd.options << "--verbose"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
task :default => :test
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
require 'open-uri'
|
|
2
|
-
|
|
3
|
-
module PassiveDNS #:nodoc: don't document this
|
|
4
|
-
# The Provider module contains all the Passive DNS provider client code
|
|
5
|
-
module Provider
|
|
6
|
-
|
|
7
|
-
# Queries BFK.de's passive DNS database
|
|
8
|
-
class BFK < PassiveDB
|
|
9
|
-
# Sets the modules self-reported name to "BFK.de"
|
|
10
|
-
def self.name
|
|
11
|
-
"BFK.de"
|
|
12
|
-
end
|
|
13
|
-
# Sets the configuration section name to "bfk"
|
|
14
|
-
def self.config_section_name
|
|
15
|
-
"bfk"
|
|
16
|
-
end
|
|
17
|
-
# Sets the command line database argument to "b"
|
|
18
|
-
def self.option_letter
|
|
19
|
-
"b"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# :debug enables verbose logging to standard output
|
|
23
|
-
attr_accessor :debug
|
|
24
|
-
# === Options
|
|
25
|
-
# * :debug Sets the debug flag for the module
|
|
26
|
-
# * "URL" Alternate url for testing. Defaults to "http://www.bfk.de/bfk_dnslogger.html?query="
|
|
27
|
-
#
|
|
28
|
-
# === Example Instantiation
|
|
29
|
-
#
|
|
30
|
-
# options = {
|
|
31
|
-
# :debug => true,
|
|
32
|
-
# "URL" => "http://www.bfk.de/bfk_dnslogger.html?query="
|
|
33
|
-
# }
|
|
34
|
-
#
|
|
35
|
-
# PassiveDNS::Provider::BFK.new(options)
|
|
36
|
-
#
|
|
37
|
-
def initialize(options={})
|
|
38
|
-
@debug = options[:debug] || false
|
|
39
|
-
@timeout = options[:timeout] || 20
|
|
40
|
-
@base = options["URL"] || "http://www.bfk.de/bfk_dnslogger.html?query="
|
|
41
|
-
raise "Due to the EU GDPR policy, this service has been shut down until further notice."
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Takes a label (either a domain or an IP address) and returns
|
|
45
|
-
# an array of PassiveDNS::PDNSResult instances with the answers to the query
|
|
46
|
-
def lookup(label, limit=nil)
|
|
47
|
-
$stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
|
|
48
|
-
Timeout::timeout(@timeout) {
|
|
49
|
-
t1 = Time.now
|
|
50
|
-
open(
|
|
51
|
-
@base+label,
|
|
52
|
-
"User-Agent" => "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}"
|
|
53
|
-
) do |f|
|
|
54
|
-
t2 = Time.now
|
|
55
|
-
recs = parse(f.read,t2-t1)
|
|
56
|
-
if limit
|
|
57
|
-
recs[0,limit]
|
|
58
|
-
else
|
|
59
|
-
recs
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
}
|
|
63
|
-
rescue Timeout::Error
|
|
64
|
-
$stderr.puts "#{self.class.name} lookup timed out: #{label}"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
private
|
|
68
|
-
|
|
69
|
-
# parses the webpage returned by BFK to generate an array of PDNSResult
|
|
70
|
-
def parse(page,response_time)
|
|
71
|
-
line = page.unpack('C*').pack('U*').split(/<table/).grep(/ id=\"logger\"/)
|
|
72
|
-
return [] unless line.length > 0
|
|
73
|
-
line = line[0].gsub(/[\t\n]/,'').gsub(/<\/table.*/,'')
|
|
74
|
-
rows = line.split(/<tr.*?>/)
|
|
75
|
-
res = []
|
|
76
|
-
rows.collect do |row|
|
|
77
|
-
r = row.split(/<td>/).map{|x| x.gsub(/<.*?>/,'').gsub(/\&.*?;/,'')}[1,1000]
|
|
78
|
-
if r and r[0] =~ /\w/
|
|
79
|
-
# BFK includes the MX weight in the answer response. First, find the MX records,
|
|
80
|
-
# then dump the weight to present a consistent record name to the collecting
|
|
81
|
-
# array. Otherwise the other repositories will present the same answer and
|
|
82
|
-
# your results will become cluttered with duplicates.
|
|
83
|
-
if r[1] == "MX" then
|
|
84
|
-
# MX lines look like "5 mx.domain.tld", so split on the space and assign r[2] (:answer) to the latter part.
|
|
85
|
-
#s = r[2].split(/\w/).map{|x| x}[1,1000]
|
|
86
|
-
# r[2] = s[1]
|
|
87
|
-
r[2] =~ /[0-9]+?\s(.+)/
|
|
88
|
-
s=$1
|
|
89
|
-
#puts "DEBUG: == BFK: MX Parsing Strip: Answer: " + r[2] + " : mod: " + s if @debug
|
|
90
|
-
r[2] = s
|
|
91
|
-
|
|
92
|
-
######### FIX BLANKS FOR MX
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
query = r[0]
|
|
96
|
-
answer = r[2]
|
|
97
|
-
rrtype = r[1]
|
|
98
|
-
res << PDNSResult.new(self.class.name,response_time,query,answer,rrtype,'white')
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
res
|
|
102
|
-
rescue Exception => e
|
|
103
|
-
$stderr.puts "#{self.class.name} Exception: #{e}"
|
|
104
|
-
raise e
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
require 'net/http'
|
|
2
|
-
require 'net/https'
|
|
3
|
-
require 'openssl'
|
|
4
|
-
require 'json'
|
|
5
|
-
require 'digest/md5'
|
|
6
|
-
require 'pp'
|
|
7
|
-
|
|
8
|
-
module PassiveDNS #:nodoc: don't document this
|
|
9
|
-
# The Provider module contains all the Passive DNS provider client code
|
|
10
|
-
module Provider
|
|
11
|
-
# Queries 360.cn's passive DNS database
|
|
12
|
-
class CN360 < PassiveDB
|
|
13
|
-
# Sets the modules self-reported name to "360.cn"
|
|
14
|
-
def self.name
|
|
15
|
-
"360.cn"
|
|
16
|
-
end
|
|
17
|
-
# Sets the configuration section name to "cn360"
|
|
18
|
-
def self.config_section_name
|
|
19
|
-
"cn360"
|
|
20
|
-
end
|
|
21
|
-
# Sets the command line database argument to "3"
|
|
22
|
-
def self.option_letter
|
|
23
|
-
"3"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# :debug enables verbose logging to standard output
|
|
27
|
-
attr_accessor :debug
|
|
28
|
-
# === Options
|
|
29
|
-
# * :debug Sets the debug flag for the module
|
|
30
|
-
# * "API" REQUIRED: http://some.web.address.for.their.api
|
|
31
|
-
# * "API_ID" REQUIRED: a username that is given when you register
|
|
32
|
-
# * "API_KEY" REQUIRED: a long and random password of sorts that is used along with the page request to generate a per page API key
|
|
33
|
-
#
|
|
34
|
-
# === Example Instantiation
|
|
35
|
-
#
|
|
36
|
-
# options = {
|
|
37
|
-
# :debug => true,
|
|
38
|
-
# "API" => "http://some.web.address.for.their.api",
|
|
39
|
-
# "API_ID" => "360user",
|
|
40
|
-
# "API_KEY" => "360apikey"
|
|
41
|
-
# }
|
|
42
|
-
#
|
|
43
|
-
# PassiveDNS::Provider::CN360.new(options)
|
|
44
|
-
#
|
|
45
|
-
def initialize(options={})
|
|
46
|
-
@debug = options[:debug] || false
|
|
47
|
-
@timeout = options[:timeout] || 20
|
|
48
|
-
["API", "API_ID", "API_KEY"].each do |opt|
|
|
49
|
-
if not options[opt]
|
|
50
|
-
raise "Field #{opt} is required. See README.md"
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
@cp = options
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Takes a label (either a domain or an IP address) and returns
|
|
57
|
-
# an array of PassiveDNS::PDNSResult instances with the answers to the query
|
|
58
|
-
def lookup(label, limit=10000)
|
|
59
|
-
table = "rrset"
|
|
60
|
-
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]$/
|
|
61
|
-
table = "rdata"
|
|
62
|
-
end
|
|
63
|
-
limit ||= 10000
|
|
64
|
-
path = "/api/#{table}/keyword/#{label}/count/#{limit}/"
|
|
65
|
-
Timeout::timeout(@timeout) {
|
|
66
|
-
url = @cp["API"]+path
|
|
67
|
-
url = URI.parse url
|
|
68
|
-
http = Net::HTTP.new(url.host, url.port)
|
|
69
|
-
http.use_ssl = (url.scheme == 'https')
|
|
70
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # I hate doing this
|
|
71
|
-
http.verify_depth = 5
|
|
72
|
-
request = Net::HTTP::Get.new(url.path)
|
|
73
|
-
request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
|
|
74
|
-
request.add_field('Accept', 'application/json')
|
|
75
|
-
request.add_field("X-BashTokid", @cp["API_ID"])
|
|
76
|
-
token = Digest::MD5.hexdigest(path+@cp["API_KEY"])
|
|
77
|
-
$stderr.puts "DEBUG: cn360 url = #{url} token = #{token}" if @debug
|
|
78
|
-
request.add_field("X-BashToken", token)
|
|
79
|
-
t1 = Time.now
|
|
80
|
-
response = http.request(request)
|
|
81
|
-
t2 = Time.now
|
|
82
|
-
recs = parse_json(response.body, label, t2-t1)
|
|
83
|
-
if limit
|
|
84
|
-
recs[0,limit]
|
|
85
|
-
else
|
|
86
|
-
recs
|
|
87
|
-
end
|
|
88
|
-
}
|
|
89
|
-
rescue Timeout::Error
|
|
90
|
-
$stderr.puts "#{self.class.name} lookup timed out: #{label}"
|
|
91
|
-
recs
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
private
|
|
95
|
-
|
|
96
|
-
# parses the response of 360.cn's JSON reply to generate an array of PDNSResult
|
|
97
|
-
def parse_json(page,query,response_time=0)
|
|
98
|
-
res = []
|
|
99
|
-
data = JSON.parse(page)
|
|
100
|
-
if data.class == Hash and data['err']
|
|
101
|
-
raise "#{self.class.name} Error: #{data['err']}"
|
|
102
|
-
end
|
|
103
|
-
data.each do |row|
|
|
104
|
-
time_first = (row["time_first"]) ? Time.at(row["time_first"]) : nil
|
|
105
|
-
time_last = (row["time_last"]) ? Time.at(row["time_last"]) : nil
|
|
106
|
-
count = row["count"] || 0
|
|
107
|
-
query = row["rrname"]
|
|
108
|
-
answers = row["rdata"].gsub(/;$/,'').split(/;/)
|
|
109
|
-
rrtype = row["rrtype"]
|
|
110
|
-
answers.each do |answer|
|
|
111
|
-
res << PDNSResult.new(self.class.name, response_time, query, answer, rrtype, nil, time_first, time_last, count, TLPSecurityControl.new('yellow'))
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
res
|
|
115
|
-
rescue Exception => e
|
|
116
|
-
$stderr.puts "#{self.class.name} Exception: #{e}"
|
|
117
|
-
puts e.backtrace
|
|
118
|
-
raise e
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
end
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# DESCRIPTION: Module to query Mnemonic's passive DNS repository
|
|
2
|
-
# CONTRIBUTOR: Drew Hunt (pinowudi@yahoo.com)
|
|
3
|
-
require 'net/http'
|
|
4
|
-
require 'net/https'
|
|
5
|
-
require 'openssl'
|
|
6
|
-
|
|
7
|
-
module PassiveDNS #:nodoc: don't document this
|
|
8
|
-
# The Provider module contains all the Passive DNS provider client code
|
|
9
|
-
module Provider
|
|
10
|
-
# Queries Mnemonic's passive DNS database
|
|
11
|
-
class Mnemonic < PassiveDB
|
|
12
|
-
# Sets the modules self-reported name to "Mnemonic"
|
|
13
|
-
def self.name
|
|
14
|
-
"Mnemonic"
|
|
15
|
-
end
|
|
16
|
-
# Sets the configuration section name to "mnemonic"
|
|
17
|
-
def self.config_section_name
|
|
18
|
-
"mnemonic"
|
|
19
|
-
end
|
|
20
|
-
# Sets the command line database argument to "m"
|
|
21
|
-
def self.option_letter
|
|
22
|
-
"m"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# :debug enables verbose logging to standard output
|
|
26
|
-
attr_accessor :debug
|
|
27
|
-
# === Options
|
|
28
|
-
# * :debug Sets the debug flag for the module
|
|
29
|
-
# * "APIKEY" The API key associated with Mnemonic for doing automated queries
|
|
30
|
-
# * "URL" Alternate url for testing. Defaults to "https://api.mnemonic.no/pdns/v3/"
|
|
31
|
-
#
|
|
32
|
-
# === Example Instantiation
|
|
33
|
-
#
|
|
34
|
-
# options = {
|
|
35
|
-
# :debug => true,
|
|
36
|
-
# "APIKEY" => "01234567890abcdef01234567890abcdef012345",
|
|
37
|
-
# "URL" => "https://api.mnemonic.no/pdns/v3/"
|
|
38
|
-
# }
|
|
39
|
-
#
|
|
40
|
-
# PassiveDNS::Provider::Mnemonic.new(options)
|
|
41
|
-
#
|
|
42
|
-
def initialize(options={})
|
|
43
|
-
@debug = options[:debug] || false
|
|
44
|
-
@timeout = options[:timeout] || 20
|
|
45
|
-
@apikey = options["APIKEY"]
|
|
46
|
-
@url = options["URL"] || "https://api.mnemonic.no/pdns/v3/"
|
|
47
|
-
if @url == "https://passivedns.mnemonic.no/api1/?apikey="
|
|
48
|
-
@url = "https://api.mnemonic.no/pdns/v3/"
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Takes a label (either a domain or an IP address) and returns
|
|
53
|
-
# an array of PassiveDNS::PDNSResult instances with the answers to the query
|
|
54
|
-
def lookup(label, limit=nil)
|
|
55
|
-
$stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
|
|
56
|
-
Timeout::timeout(@timeout) {
|
|
57
|
-
url = "#{@url}#{label}"
|
|
58
|
-
$stderr.puts "DEBUG: #{self.class.name} url = #{url}" if @debug
|
|
59
|
-
url = URI.parse url
|
|
60
|
-
http = Net::HTTP.new(url.host, url.port)
|
|
61
|
-
http.use_ssl = (url.scheme == 'https')
|
|
62
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
63
|
-
http.verify_depth = 5
|
|
64
|
-
request = Net::HTTP::Get.new(url.path)
|
|
65
|
-
request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}")
|
|
66
|
-
if @apikey
|
|
67
|
-
request.add_field("Argus-API-Key", @apikey)
|
|
68
|
-
end
|
|
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
|
-
}
|
|
79
|
-
rescue Timeout::Error
|
|
80
|
-
$stderr.puts "#{self.class.name} lookup timed out: #{label}"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
private
|
|
84
|
-
|
|
85
|
-
# parses the response of mnemonic's JSON reply to generate an array of PDNSResult
|
|
86
|
-
def parse_json(page,query,response_time=0)
|
|
87
|
-
res = []
|
|
88
|
-
data = JSON.parse(page)
|
|
89
|
-
if data['data']
|
|
90
|
-
data['data'].each do |row|
|
|
91
|
-
if row['query']
|
|
92
|
-
query = row['query']
|
|
93
|
-
answer = row['answer']
|
|
94
|
-
rrtype = row['rrtype'].upcase
|
|
95
|
-
ttl = row['maxTtl'].to_i
|
|
96
|
-
firstseen = Time.at(row['firstSeenTimestamp'].to_i / 1000)
|
|
97
|
-
lastseen = Time.at(row['lastSeenTimestamp'].to_i / 1000)
|
|
98
|
-
tlp = row['tlp']
|
|
99
|
-
r = PDNSResult.new(self.class.name,response_time, query, answer, rrtype, ttl, firstseen, lastseen, tlp)
|
|
100
|
-
res << r
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
res
|
|
105
|
-
rescue Exception => e
|
|
106
|
-
$stderr.puts "#{self.class.name} Exception: #{e}"
|
|
107
|
-
raise e
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|