dnstwister 0.1.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 +7 -0
- data/.gitignore +58 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +37 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/dnstwister.gemspec +32 -0
- data/lib/dnstwister.rb +10 -0
- data/lib/dnstwister/api.rb +73 -0
- data/lib/dnstwister/base.rb +67 -0
- data/lib/dnstwister/version.rb +5 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ac91ca3ea81c0ec360b524cc74b6db69e45a3641916b266a2bb562c213e452a4
|
4
|
+
data.tar.gz: a4f9b6079e9117c69ebbcf6606a393f349e24dd6af8111e7b65eb4f9d1c2fd66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20c7ceb669157c2b998d053d31365a2d75a924bca30d5fb0c0ee55602be74afe331957c9c7e97ab65534c56adefa72defe0a3898ddff0de67106ccdb9a46b065
|
7
|
+
data.tar.gz: 6636fe06803425f569bbcd477ff950ef025941517509546da6744b77231a6e8a83d11ebdba3659fed339f89cbdc7350dffdff28eaa6c026d435229519e961fea
|
data/.gitignore
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
.env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
Gemfile.lock
|
49
|
+
.ruby-version
|
50
|
+
.ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
.rubocop-https?--*
|
57
|
+
|
58
|
+
.rspec_status
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 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.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# dnstwister
|
2
|
+
|
3
|
+
[](https://travis-ci.com/ninoseki/dnstwister)
|
4
|
+
[](https://coveralls.io/github/ninoseki/dnstwister?branch=master)
|
5
|
+
[](https://www.codefactor.io/repository/github/ninoseki/dnstwister)
|
6
|
+
|
7
|
+
[dnstwister](https://dnstwister.report/) API wrapper for Ruby.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install dnstwister
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require "dnstwister"
|
19
|
+
|
20
|
+
api = DNSTwister::API.new
|
21
|
+
|
22
|
+
domain = "example.com"
|
23
|
+
|
24
|
+
res = api.fuzz(domain)
|
25
|
+
fuzzy_doamins = res.dig("fuzzy_domains") || []
|
26
|
+
p fuzzy_domains.map { |domain| domain.dig "domain" }
|
27
|
+
# => ["example.com", "examplea.com", "exampleb.com", "examplec.com", "exampled.com", ...]
|
28
|
+
|
29
|
+
api.safebrowsing domain
|
30
|
+
api.ip domain
|
31
|
+
api.parked domain
|
32
|
+
api.whois domain
|
33
|
+
```
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "DNSTwister"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dnstwister.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "dnstwister/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "dnstwister"
|
9
|
+
spec.version = DNSTwister::VERSION
|
10
|
+
spec.authors = ["Manabu Niseki"]
|
11
|
+
spec.email = ["manabu.niseki@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "dnstwister API wrapper for Ruby"
|
14
|
+
spec.description = "dnstwister API wrapper for Ruby"
|
15
|
+
spec.homepage = "https://github.com/ninoseki/dnstwister"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.9"
|
30
|
+
spec.add_development_dependency "vcr", "~> 5.0"
|
31
|
+
spec.add_development_dependency "webmock", "~> 3.7"
|
32
|
+
end
|
data/lib/dnstwister.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DNSTwister
|
4
|
+
class API < Base
|
5
|
+
#
|
6
|
+
# Calculates the dnstwist "fuzzy domains" for a domain
|
7
|
+
#
|
8
|
+
# @param [String] domain
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
#
|
12
|
+
def fuzz(domain)
|
13
|
+
_get("/api/fuzz/#{to_hex(domain)}") { |json| json }
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Returns number of hits in Google Safe Browsing
|
18
|
+
#
|
19
|
+
# @param [String] domain
|
20
|
+
#
|
21
|
+
# @return [Hash]
|
22
|
+
#
|
23
|
+
def safebrowsing(domain)
|
24
|
+
_get("/api/safebrowsing/#{to_hex(domain)}") { |json| json }
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Resolves Domains to IPs
|
29
|
+
#
|
30
|
+
# @param [String] domain
|
31
|
+
#
|
32
|
+
# @return [Hash]
|
33
|
+
#
|
34
|
+
def ip(domain)
|
35
|
+
_get("/api/ip/#{to_hex(domain)}") { |json| json }
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Calculates "parked" scores from 0-1
|
40
|
+
#
|
41
|
+
# @param [String] domain
|
42
|
+
#
|
43
|
+
# @return [Hash]
|
44
|
+
#
|
45
|
+
def parked(domain)
|
46
|
+
_get("/api/parked/#{to_hex(domain)}") { |json| json }
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Calculates the dnstwist "fuzzy domains" for a domain.
|
51
|
+
#
|
52
|
+
# @param [String] domain
|
53
|
+
#
|
54
|
+
# @return [Hash]
|
55
|
+
#
|
56
|
+
def whois(domain)
|
57
|
+
_get("/api/whois/#{to_hex(domain)}") { |json| json }
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
#
|
63
|
+
# Converts string to hex
|
64
|
+
#
|
65
|
+
# @param [String] str String
|
66
|
+
#
|
67
|
+
# @return [String] Hex
|
68
|
+
#
|
69
|
+
def to_hex(str)
|
70
|
+
str.each_byte.map { |b| b.to_s(16) }.join
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "net/https"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
module DNSTwister
|
8
|
+
class Base
|
9
|
+
HOST = "dnstwister.report"
|
10
|
+
BASE_URL = "https://#{HOST}"
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def url_for(path)
|
15
|
+
URI(BASE_URL + path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def https_options
|
19
|
+
if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
|
20
|
+
uri = URI(proxy)
|
21
|
+
{
|
22
|
+
proxy_address: uri.hostname,
|
23
|
+
proxy_port: uri.port,
|
24
|
+
proxy_from_env: false,
|
25
|
+
use_ssl: true
|
26
|
+
}
|
27
|
+
else
|
28
|
+
{ use_ssl: true }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def make_request(req)
|
33
|
+
Net::HTTP.start(HOST, 443, https_options) do |http|
|
34
|
+
response = http.request(req)
|
35
|
+
|
36
|
+
code = response.code.to_i
|
37
|
+
body = response.body
|
38
|
+
json = JSON.parse(body)
|
39
|
+
|
40
|
+
case code
|
41
|
+
when 200
|
42
|
+
yield json
|
43
|
+
else
|
44
|
+
raise Error, "Unsupported response code returned: #{code}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_request(type: "GET", path:, params: {})
|
50
|
+
uri = url_for(path)
|
51
|
+
uri.query = URI.encode_www_form(params) if type == "GET"
|
52
|
+
|
53
|
+
request = case type
|
54
|
+
when "GET"
|
55
|
+
Net::HTTP::Get.new(uri)
|
56
|
+
else
|
57
|
+
raise ArgumentError, "#{type} HTTP method is not supported"
|
58
|
+
end
|
59
|
+
request
|
60
|
+
end
|
61
|
+
|
62
|
+
def _get(path, params = {}, &block)
|
63
|
+
request = build_request(type: "GET", path: path, params: params)
|
64
|
+
make_request(request, &block)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dnstwister
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manabu Niseki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.7'
|
83
|
+
description: dnstwister API wrapper for Ruby
|
84
|
+
email:
|
85
|
+
- manabu.niseki@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- dnstwister.gemspec
|
100
|
+
- lib/dnstwister.rb
|
101
|
+
- lib/dnstwister/api.rb
|
102
|
+
- lib/dnstwister/base.rb
|
103
|
+
- lib/dnstwister/version.rb
|
104
|
+
homepage: https://github.com/ninoseki/dnstwister
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubygems_version: 3.0.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: dnstwister API wrapper for Ruby
|
127
|
+
test_files: []
|