-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
tags: | ||
- Artifact:IP | ||
- Artifact:Domain | ||
- Passive DNS | ||
- Reverse Whois | ||
--- | ||
|
||
# Validin | ||
|
||
- https://www.validin.com/ | ||
|
||
This analyzer uses [Validin API](https://app.validin.com/docs). | ||
|
||
An API endpoint to use is changed based on a type of a query. | ||
|
||
| Query type | API endpoint | Artifact | | ||
| ---------- | ---------------------------------------- | ---------- | | ||
| IP address | `/api/axon/domain/dns/history/:domain/A` | Domain | | ||
| Domain | `/api/axon/ip/dns/history/:ip` | IP address | | ||
|
||
```yaml | ||
analyzer: validin | ||
query: ... | ||
api_key: ... | ||
``` | ||
## Components | ||
### Query | ||
`query` (`string`) is a domain or an IP address. | ||
|
||
### API Key | ||
|
||
`api_key` (`string`) is an API key. Optional. Configurable via `VALIDIN_API_KEY` environment variable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
require "mihari/clients/validin" | ||
|
||
module Mihari | ||
module Analyzers | ||
# | ||
# Validin analyzer | ||
# | ||
class Validin < Base | ||
include Concerns::Refangable | ||
|
||
# @return [String, nil] | ||
attr_reader :type | ||
|
||
# @return [String, nil] | ||
attr_reader :username | ||
|
||
# @return [String, nil] | ||
attr_reader :api_key | ||
|
||
# | ||
# @param [String] query | ||
# @param [Hash, nil] options | ||
# @param [String, nil] api_key | ||
# | ||
def initialize(query, options: nil, api_key: nil) | ||
super(refang(query), options:) | ||
|
||
@type = DataType.type(query) | ||
|
||
@api_key = api_key || Mihari.config.validin_api_key | ||
end | ||
|
||
def artifacts | ||
case type | ||
when "domain" | ||
dns_history_search | ||
when "ip" | ||
reverse_ip_search | ||
else | ||
raise ValueError, "#{query}(type: #{type || "unknown"}) is not supported." unless valid_type? | ||
end | ||
end | ||
|
||
private | ||
|
||
def dns_history_search | ||
res = client.dns_history_search(query) | ||
(res.dig("records", "A") || []).filter_map do |r| | ||
r["value"] | ||
end | ||
end | ||
|
||
def reverse_ip_search | ||
res = client.dns_history_search(query) | ||
(res.dig("records", "A") || []).filter_map do |r| | ||
r["value"] | ||
end | ||
end | ||
|
||
def client | ||
Clients::Validin.new(api_key:, timeout:) | ||
end | ||
|
||
# | ||
# Check whether a type is valid or not | ||
# | ||
# @return [Boolean] | ||
# | ||
def valid_type? | ||
%w[ip domain].include? type | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mihari | ||
module Clients | ||
# | ||
# Validin API client | ||
# | ||
class Validin < Base | ||
# | ||
# @param [String] base_url | ||
# @param [String, nil] api_key | ||
# @param [Hash] headers | ||
# @param [Integer, nil] timeout | ||
# | ||
def initialize( | ||
base_url = "https://app.validin.com", | ||
api_key:, | ||
headers: {}, | ||
timeout: nil | ||
) | ||
raise(ArgumentError, "api_key is required") if api_key.nil? | ||
|
||
headers["Authorization"] = "Bearer #{api_key}" | ||
|
||
super(base_url, headers:, timeout:) | ||
end | ||
|
||
# | ||
# @param [String] domain | ||
# | ||
# @return [Hash] | ||
# | ||
def dns_history_search(domain) | ||
get_json "/api/axon/domain/dns/history/#{domain}/A" | ||
end | ||
|
||
# | ||
# @param [String] ip | ||
# | ||
# @return [Hash] | ||
# | ||
def search_reverse_ip(ip) | ||
get_json "/api/axon/ip/dns/history/#{ip}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Mihari::Analyzers::Validin, :vcr do | ||
subject(:analyzer) { described_class.new(query) } | ||
|
||
context "with ip" do | ||
let(:query) { "1.1.1.1" } | ||
|
||
describe "#artifacts" do | ||
it do | ||
expect(analyzer.artifacts).to be_an(Array) | ||
end | ||
end | ||
end | ||
|
||
context "with domain" do | ||
let(:query) { "example.com" } | ||
|
||
describe "#artifacts" do | ||
it do | ||
expect(analyzer.artifacts).to be_an(Array) | ||
end | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
spec/fixtures/vcr_cassettes/Mihari_Analyzers_Validin/with_domain/_artifacts/1_2_1_1.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
spec/fixtures/vcr_cassettes/Mihari_Analyzers_Validin/with_ip/_artifacts/1_1_1_1.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.