securitytrails 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a98a7e435666d8e24c6fc43e321f0c830666b5bad72624a889aa9127ed05002
4
- data.tar.gz: 208fa1488c86ad91b7a8985c44bb5bf0641c0052612b2e0af112590981025f5b
3
+ metadata.gz: a7357b61e8302a39f839c4cbc3447cf23569bd60ff26f51171e135fd87519936
4
+ data.tar.gz: 0ec95a9dce876ad1c16ab72b79e232476ab9510e2b5ec9df8fb6afa5a5aff401
5
5
  SHA512:
6
- metadata.gz: 5d0716e4993ce48071046aa9fb0758a9e7dde0a5863926f71d39e637ffc960625a099946fcb87f76c8f8d3f3d0b0f1a7d63943ad3a7f94b4ef7be9b9ceb42784
7
- data.tar.gz: 6825a21d343225b5d07f88d084de0d62afad3e5d78c2c1d9721406c02723eac9d11a975048125ad9f68ce91ffd7bce11651963d841311e35d5d0b1db31371b7a
6
+ metadata.gz: 0ac1a84b08a3e2c2a5288295e40f019af446d96306f8b86dc9076381f4c3acdd8d4d7459d46b65df38ce862442d69da1576454b2b6850f11658972dcc9cfce91
7
+ data.tar.gz: 80dd0c1733bbc6fc7f93b134468a226cecad5ac6d03fbffb090fd9aecc404fdb4b9e11e9131efed7dfef27053ad7a8445cb287bb061aa67fc0bcd2824b79b0e5
data/README.md CHANGED
@@ -33,6 +33,11 @@ api = SecurityTrails::API.new
33
33
  # or you can pass your API key as an argument
34
34
  api = SecurityTrails::API.new(YOUR_API_KEY)
35
35
 
36
+ # General
37
+ # https://docs.securitytrails.com/reference#general
38
+ api.ping
39
+ api.usage
40
+
36
41
  # Domain details
37
42
  # https://docs.securitytrails.com/v1.0/reference#domains
38
43
  api.domain.get_by_hostname("github.com")
@@ -55,8 +60,8 @@ api.domains.stats(
55
60
 
56
61
  # History
57
62
  # https://docs.securitytrails.com/v1.0/reference#history
58
- api.history.get_dns_history("github.com", "a")
59
- api.history.get_all_dns_history("github.com", "a")
63
+ api.history.get_dns_history("github.com", type: "a")
64
+ api.history.get_all_dns_history("github.com", type: "a")
60
65
  api.history.get_whois_history("github.com")
61
66
 
62
67
  # IPs
@@ -67,18 +72,8 @@ api.ips.stats("ptr_part = 'amazon.com'")
67
72
 
68
73
  # Feeds
69
74
  # https://docs.securitytrails.com/v1.0/reference#feeds
70
- api.feeds.domain("new")
71
- api.feeds.domain("new", tld: "jp")
72
- ```
73
-
74
- All the API response (JSON / Hash) is wrapped by [OpenStruct](https://github.com/ruby/ostruct).
75
-
76
- It means you can access to a response through a property-like syntax.
77
-
78
- ```ruby
79
- res = api.domain.get_by_hostname("github.com")
80
- puts res.hostname # => "github.com"
81
- puts res.current_dns.a.first_seen # => "2018-09-12"
75
+ api.feeds.domains("new")
76
+ api.feeds.domains("new", tld: "jp")
82
77
  ```
83
78
 
84
79
  ## Contributing
@@ -5,9 +5,10 @@ require "securitytrails/version"
5
5
  require "securitytrails/utility"
6
6
 
7
7
  require "securitytrails/api"
8
- require "securitytrails/response"
9
8
  require "securitytrails/client"
10
9
 
10
+ require "securitytrails/clients/general"
11
+
11
12
  require "securitytrails/clients/domain"
12
13
  require "securitytrails/clients/domains"
13
14
  require "securitytrails/clients/feeds"
@@ -1,21 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "forwardable"
4
+
3
5
  module SecurityTrails
4
6
  class API
5
- attr_reader :domain
6
- attr_reader :domains
7
- attr_reader :history
8
- attr_reader :ips
9
- attr_reader :feeds
7
+ extend Forwardable
8
+
9
+ attr_reader :api_key
10
10
 
11
11
  def initialize(api_key = ENV["SECURITYTRAILS_API_KEY"])
12
- raise(ArgumentError, "'api_key' argument is required") unless api_key
12
+ @api_key = api_key
13
+ raise ArgumentError, "'api_key' argument is required" unless api_key
14
+ end
15
+
16
+ #
17
+ # General API client
18
+ #
19
+ # @return [SecurityTrails::Clients::General]
20
+ #
21
+ def general
22
+ @general ||= Clients::General.new(api_key)
23
+ end
24
+
25
+ %w(ping usage scroll).each do |delegate_method|
26
+ sym = delegate_method.to_sym
27
+ def_delegator :general, sym, sym
28
+ end
29
+
30
+ #
31
+ # Domain API client
32
+ #
33
+ # @return [SecurityTrails::Clients::Domain]
34
+ #
35
+ def domain
36
+ @domain ||= Clients::Domain.new(api_key)
37
+ end
38
+
39
+ #
40
+ # Domains API client
41
+ #
42
+ # @return [SecurityTrails::Clients::Domains]
43
+ #
44
+ def domains
45
+ @domains ||= Clients::Domains.new(api_key)
46
+ end
47
+
48
+ #
49
+ # History API client
50
+ #
51
+ # @return [SecurityTrails::Clients::History]
52
+ #
53
+ def history
54
+ @history ||= Clients::History.new(api_key)
55
+ end
56
+
57
+ #
58
+ # IPs API client
59
+ #
60
+ # @return [SecurityTrails::Clients::IPs]
61
+ #
62
+ def ips
63
+ @ips ||= Clients::IPs.new(api_key)
64
+ end
13
65
 
14
- @domain = Clients::Domain.new(api_key)
15
- @domains = Clients::Domains.new(api_key)
16
- @history = Clients::History.new(api_key)
17
- @ips = Clients::IPs.new(api_key)
18
- @feeds = Clients::Feeds.new(api_key)
66
+ #
67
+ # Feed API client
68
+ #
69
+ # @return [SecurityTrails::Clients::Feeds]
70
+ #
71
+ def feeds
72
+ @feeds ||= Clients::Feeds.new(api_key)
19
73
  end
20
74
  end
21
75
  end
@@ -42,7 +42,7 @@ module SecurityTrails
42
42
  raise(Error, "unsupported response code returned: #{response.code}") unless response.code == "200"
43
43
 
44
44
  if response["Content-Type"].to_s.include? "application/json"
45
- yield JSON.parse(response.body, object_class: Response)
45
+ yield JSON.parse(response.body)
46
46
  else
47
47
  yield response.body
48
48
  end
@@ -3,22 +3,67 @@
3
3
  module SecurityTrails
4
4
  module Clients
5
5
  class Domain < Client
6
+ #
7
+ # Returns the current data about the given domain. In addition to the current data, you also get the current statistics associated with a particular record. For example, for a records you'll get how many other domains have the same IP.
8
+ #
9
+ # @see https://docs.securitytrails.com/reference#get-domain
10
+ #
11
+ # @param [String] hostname
12
+ #
13
+ # @return [Hash]
14
+ #
6
15
  def get_by_hostname(hostname)
7
16
  get("/domain/#{hostname}") { |json| json }
8
17
  end
9
18
 
19
+ #
20
+ # Returns subdomains for a given hostname
21
+ #
22
+ # @see https://docs.securitytrails.com/reference#list-subdomains
23
+ #
24
+ # @param [String] hostname
25
+ #
26
+ # @return [Hash]
27
+ #
10
28
  def get_subdomains(hostname)
11
29
  get("/domain/#{hostname}/subdomains") { |json| json }
12
30
  end
13
31
 
32
+ #
33
+ # Returns tags for a given hostname
34
+ #
35
+ # @see https://docs.securitytrails.com/reference#list-tags
36
+ #
37
+ # @param [String] hostname
38
+ #
39
+ # @return [Hash]
40
+ #
14
41
  def get_tags(hostname)
15
42
  get("/domain/#{hostname}/tags") { |json| json }
16
43
  end
17
44
 
45
+ #
46
+ # Find all domains that are related to a domain you input
47
+ #
48
+ # @see https://docs.securitytrails.com/reference#find-associated-domains
49
+ #
50
+ # @param [String] hostname
51
+ #
52
+ # @return [Hash]
53
+ #
18
54
  def get_associated_domains(hostname)
19
55
  get("/domain/#{hostname}/associated") { |json| json }
20
56
  end
21
57
 
58
+ #
59
+ # Returns the current WHOIS data about a given domain with the stats merged together
60
+ #
61
+ # @see https://docs.securitytrails.com/reference#get-whois
62
+ #
63
+ # @param [String] hostname
64
+ #
65
+ # @return [Hash]
66
+ #
22
67
  def get_whois(hostname)
23
68
  get("/domain/#{hostname}/whois") { |json| json }
24
69
  end
@@ -3,11 +3,29 @@
3
3
  module SecurityTrails
4
4
  module Clients
5
5
  class Domains < Client
6
- def search(params)
6
+ #
7
+ # Filter and search specific records using this endpoint.
8
+ #
9
+ # @see https://docs.securitytrails.com/reference#domain-search
10
+ #
11
+ # @param [Hash] **params
12
+ #
13
+ # @return [Hash]
14
+ #
15
+ def search(**params)
7
16
  post("/domains/list", params) { |json| json }
8
17
  end
9
18
 
10
- def stats(params)
19
+ #
20
+ # Search statistics
21
+ #
22
+ # @see https://docs.securitytrails.com/reference#search-count
23
+ #
24
+ # @param [Hash] **params
25
+ #
26
+ # @return [Hash]
27
+ #
28
+ def stats(**params)
11
29
  post("/domains/stats", params) { |json| json }
12
30
  end
13
31
  end
@@ -3,6 +3,19 @@
3
3
  module SecurityTrails
4
4
  module Clients
5
5
  class Feeds < Client
6
+ #
7
+ # Fetch zone files including authoritative nameservers with ease
8
+ #
9
+ # @see https://docs.securitytrails.com/reference#domains-1
10
+ #
11
+ # @param [String] type valid values are "all", "dropped", "new" or "registered"
12
+ # @param [String, nil] filter valid values are "cctld" and "gtld"
13
+ # @param [String, nil] tld Can be used to only return domains of a specific tld, such as "com"
14
+ # @param [Boolean, nil] ns show nameservers in the list
15
+ # @param [String, nil] date Date to fetch data for, format YYYY-MM-DD,
16
+ #
17
+ # @return [<Type>] <description>
18
+ #
6
19
  def domains(type, filter: nil, tld: nil, ns: nil, date: nil)
7
20
  params = { filter: filter, tld: tld, ns: ns, date: date }.compact
8
21
 
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SecurityTrails
4
+ module Clients
5
+ class General < Client
6
+ #
7
+ # You can use this simple endpoint to test your authentication and access to the SecurityTrails API.
8
+ #
9
+ # @see https://docs.securitytrails.com/reference#ping
10
+ #
11
+ # @return [Hash]
12
+ #
13
+ def ping
14
+ get("/ping") { |json| json }
15
+ end
16
+
17
+ #
18
+ # Usage
19
+ #
20
+ # @see https://docs.securitytrails.com/reference#usage
21
+ #
22
+ # @return [Hash]
23
+ #
24
+ def usage
25
+ get("/account/usage") { |json| json }
26
+ end
27
+
28
+ #
29
+ # A fast and easy way to fetch many results. Currently only available for the DSL API endpoints.
30
+ #
31
+ # @see https://docs.securitytrails.com/reference#scroll
32
+ #
33
+ # @param [String] The scroll_id returned in the scroll request.
34
+ #
35
+ # @return [Hash]
36
+ #
37
+ def scroll(scroll_id)
38
+ get("/scroll/#{scroll_id}") { |json| json }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -3,21 +3,42 @@
3
3
  module SecurityTrails
4
4
  module Clients
5
5
  class History < Client
6
- def get_dns_history(hostname, type, page = 1)
6
+ #
7
+ # Lists out specific historical information about the given hostname parameter
8
+ #
9
+ # @see https://docs.securitytrails.com/reference#dns-history-by-record-type
10
+ #
11
+ # @param [String] hostname
12
+ # @param [String] type allowed values: a, aaaa, mx, ns, soa or txt
13
+ # @param [Integer] page The page of the returned results
14
+ #
15
+ # @return [Hash]
16
+ #
17
+ def get_dns_history(hostname, type:, page: 1)
7
18
  raise ArgumentError, "The API currently supports a, aaaa, mx, ns, soa and txt records." unless valid_type?(type)
8
19
 
9
20
  get("/history/#{hostname}/dns/#{type.downcase}", page: page) { |json| json }
10
21
  end
11
22
 
12
- def get_all_dns_history(hostname, type)
13
- first_page = get_dns_history(hostname, type, 1)
23
+ #
24
+ # Lists out specific historical information about the given hostname parameter with auto paging
25
+ #
26
+ # @see https://docs.securitytrails.com/reference#dns-history-by-record-type
27
+ #
28
+ # @param [String] hostname
29
+ # @param [String] type allowed values: a, aaaa, mx, ns, soa or txt
30
+ #
31
+ # @return [Hash]
32
+ #
33
+ def get_all_dns_history(hostname, type:)
34
+ first_page = get_dns_history(hostname, type: type, page: 1)
14
35
  pages = first_page["pages"].to_i
15
36
 
16
37
  records = []
17
38
  records << first_page["records"]
18
39
 
19
40
  (2..pages).each do |page_idx|
20
- next_page = get_dns_history(hostname, type, page_idx)
41
+ next_page = get_dns_history(hostname, type: type, page: page_idx)
21
42
  records << next_page["records"]
22
43
  end
23
44
 
@@ -25,6 +46,15 @@ module SecurityTrails
25
46
  first_page
26
47
  end
27
48
 
49
+ #
50
+ # Returns historical WHOIS information about the given domain
51
+ #
52
+ # @see https://docs.securitytrails.com/reference#whois-history-by-domain
53
+ #
54
+ # @param [String] hostname
55
+ #
56
+ # @return [Hash]
57
+ #
28
58
  def get_whois_history(hostname)
29
59
  get("/history/#{hostname}/whois/") { |json| json }
30
60
  end
@@ -3,14 +3,41 @@
3
3
  module SecurityTrails
4
4
  module Clients
5
5
  class IPs < Client
6
+ #
7
+ # Returns the neighbors in any given IP level range and essentially allows you to explore closeby IP addresses.
8
+ #
9
+ # @see https://docs.securitytrails.com/reference#explore-ips
10
+ #
11
+ # @param [String] ipaddress Starting IP address (optionally with CIDR subnet mask)
12
+ #
13
+ # @return [Hash]
14
+ #
6
15
  def explore(ipaddress)
7
16
  get("/ips/nearby/#{ipaddress}") { |json| json }
8
17
  end
9
18
 
19
+ #
20
+ # Search IPs (DSL)
21
+ #
22
+ # @see https://docs.securitytrails.com/reference#search-ips-dsl
23
+ #
24
+ # @param [String] query The DSL query you want to run against the IPs database.
25
+ #
26
+ # @return [Hash]
27
+ #
10
28
  def search(query)
11
29
  post("/ips/list", query: query) { |json| json }
12
30
  end
13
31
 
32
+ #
33
+ # IP Search statistics
34
+ #
35
+ # @see https://docs.securitytrails.com/reference#ip-search-statistics
36
+ #
37
+ # @param [String] query
38
+ #
39
+ # @return [Hash]
40
+ #
14
41
  def stats(query)
15
42
  post("/ips/stats", query: query) { |json| json }
16
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecurityTrails
4
- VERSION = "0.2.0"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -26,9 +26,8 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 2.0"
28
28
  spec.add_development_dependency "coveralls", "~> 0.8"
29
- spec.add_development_dependency "dotenv", "~> 2.7"
30
- spec.add_development_dependency "rake", "~> 12.3"
31
- spec.add_development_dependency "rspec", "~> 3.8"
29
+ spec.add_development_dependency "rake", "~> 13.0"
30
+ spec.add_development_dependency "rspec", "~> 3.9"
32
31
  spec.add_development_dependency "vcr", "~> 5.0"
33
- spec.add_development_dependency "webmock", "~> 3.6"
32
+ spec.add_development_dependency "webmock", "~> 3.7"
34
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securitytrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-21 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,48 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.8'
41
- - !ruby/object:Gem::Dependency
42
- name: dotenv
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.7'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.7'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '12.3'
47
+ version: '13.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '12.3'
54
+ version: '13.0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '3.8'
61
+ version: '3.9'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '3.8'
68
+ version: '3.9'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: vcr
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +86,14 @@ dependencies:
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: '3.6'
89
+ version: '3.7'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: '3.6'
96
+ version: '3.7'
111
97
  description: SecurityTrails API wrapper for Ruby
112
98
  email:
113
99
  - manabu.niseki@gmail.com
@@ -119,7 +105,6 @@ files:
119
105
  - ".rspec"
120
106
  - ".travis.yml"
121
107
  - Gemfile
122
- - LICENSE
123
108
  - LICENSE.txt
124
109
  - README.md
125
110
  - Rakefile
@@ -131,9 +116,9 @@ files:
131
116
  - lib/securitytrails/clients/domain.rb
132
117
  - lib/securitytrails/clients/domains.rb
133
118
  - lib/securitytrails/clients/feeds.rb
119
+ - lib/securitytrails/clients/general.rb
134
120
  - lib/securitytrails/clients/history.rb
135
121
  - lib/securitytrails/clients/ips.rb
136
- - lib/securitytrails/response.rb
137
122
  - lib/securitytrails/utility.rb
138
123
  - lib/securitytrails/version.rb
139
124
  - securitytrails.gemspec
@@ -156,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
141
  - !ruby/object:Gem::Version
157
142
  version: '0'
158
143
  requirements: []
159
- rubygems_version: 3.0.2
144
+ rubygems_version: 3.0.3
160
145
  signing_key:
161
146
  specification_version: 4
162
147
  summary: SecurityTrails API wrapper for Ruby
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Manabu Niseki
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "ostruct"
4
-
5
- module SecurityTrails
6
- class Response < OpenStruct
7
- def openstruct_to_hash(object, hash = {})
8
- return object unless object.respond_to?(:each_pair)
9
-
10
- object.each_pair do |key, value|
11
- hash[key] = case value
12
- when OpenStruct then openstruct_to_hash(value)
13
- when Array then value.map { |v| openstruct_to_hash(v) }
14
- else value
15
- end
16
- end
17
- hash
18
- end
19
-
20
- def to_h
21
- openstruct_to_hash(self)
22
- end
23
- end
24
- end