Class: PhisherPhinder::LinkExplorer

Inherits:
Object
  • Object
show all
Defined in:
lib/phisher_phinder/link_explorer.rb

Instance Method Summary collapse

Constructor Details

#initialize(host_information_finder:, host_response_policy:) ⇒ LinkExplorer

Returns a new instance of LinkExplorer.



6
7
8
9
# File 'lib/phisher_phinder/link_explorer.rb', line 6

def initialize(host_information_finder:, host_response_policy:)
  @host_information_finder = host_information_finder
  @host_response_policy = host_response_policy
end

Instance Method Details

#explore(hyperlink) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/phisher_phinder/link_explorer.rb', line 11

def explore(hyperlink)
  if hyperlink.type == :url
    chain_terminated = false
    url = hyperlink.href
    output = []

    until chain_terminated do
      result = Excon.get(url.to_s)

      output << LinkHost.new(
        url: url,
        body: result.body,
        headers: result.headers,
        status_code: result.status,
        host_information: @host_information_finder.information_for("#{url.scheme}://#{url.host}"),
      )

      unless url = @host_response_policy.next_url(url, result)
        chain_terminated = true
      end
    end

    output
  else
    hyperlink.href =~ /mailto:(.+)/
    ($1.split(';').map { |address| address.strip }).uniq
  end
end