Class: OTX::Domain

Inherits:
Base
  • Object
show all
Defined in:
lib/otx_ruby/domain.rb

Instance Method Summary collapse

Methods inherited from Base

#get, #initialize, #patch, #post

Constructor Details

This class inherits a constructor from OTX::Base

Instance Method Details

#count_nids_list(domain, pda) ⇒ Integer

Tallies total NIDS rules linked to a domain

Parameters:

  • domain (String)

    Domain to check for NIDS rules

  • pda (Array)

    Passive DNS objects to check for linked NIDS rules

Returns:

  • (Integer)

    Total number of NIDS rules



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/otx_ruby/domain.rb', line 97

def count_nids_list(domain, pda)
  grant_access = self.instance_variable_get('@key')
  ip_object = OTX::IP.new(grant_access)

  total = 0
  pda.each do |pdr|
    nids_list = ip_object.get_nids_list(pdr.address)
    total += nids_list.count
  end

  return total
end

#get_general(domain) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/otx_ruby/domain.rb', line 3

def get_general(domain)
  uri = "/api/v1/indicators/domain/#{domain}/general"

  json_data = get(uri)

  general = OTX::Indicator::IP::General.new(json_data)

  return general
end

#get_geo(domain) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/otx_ruby/domain.rb', line 13

def get_geo(domain)
  uri = "/api/v1/indicators/domain/#{domain}/geo"

  json_data = get(uri)

  geo = OTX::Indicator::IP::Geo.new(json_data)

  return geo
end

#get_malware(domain) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/otx_ruby/domain.rb', line 23

def get_malware(domain)
  uri = "/api/v1/indicators/domain/#{domain}/malware"
  malwares = []
  params = {}

  begin
    json_data = get(uri, params)
    page = json_data['next']

    params = URI::decode_www_form(URI(page).query).to_h unless page.nil?

    malwares += json_data['data']
  end while page && !json_data['data'].empty?

  results = []
  malwares.each do |malware|
    results << OTX::Indicator::IP::Malware.new(malware)
  end

  return results
end

#get_passive_dns(domain) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/otx_ruby/domain.rb', line 67

def get_passive_dns(domain)
  uri = "/api/v1/indicators/domain/#{domain}/passive_dns"

  json_data = get(uri)

  results = []
  json_data['passive_dns'].each do |dns|
    results << OTX::Indicator::IP::DNS.new(dns)
  end

  return results
end

#get_url_list(domain) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/otx_ruby/domain.rb', line 45

def get_url_list(domain)
  uri = "/api/v1/indicators/domain/#{domain}/url_list"

  page = 0
  url_list = []
  begin
    page += 1
    params = {limit: 20, page: page}
    json_data = get(uri, params)
    has_next = json_data['has_next']

    url_list += json_data['url_list']
  end while has_next

  results = []
  url_list.each do |url|
    results << OTX::Indicator::IP::URL.new(url)
  end

  return results
end

#whois(domain) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/otx_ruby/domain.rb', line 80

def whois(domain)
  uri = "/api/v1/indicators/domain/#{domain}/whois"

  json_data = get(uri)

  whois = OTX::Indicator::IP::Whois.new(json_data)

  return whois
end