class Miteru::Website
Constants
- VALID_EXTENSIONS
Attributes
source[R]
@return [String]
url[R]
@return [String]
Public Class Methods
new(url, source)
click to toggle source
# File lib/miteru/website.rb, line 15 def initialize(url, source) @url = url @source = source end
Public Instance Methods
has_kits?()
click to toggle source
# File lib/miteru/website.rb, line 43 def has_kits? kits? rescue Addressable::URI::InvalidURIError, ArgumentError, Encoding::CompatibilityError, HTTP::Error, LL::ParserError, OpenSSL::SSL::SSLError => _e false end
index?()
click to toggle source
# File lib/miteru/website.rb, line 35 def index? title.to_s.start_with? "Index of" end
kits()
click to toggle source
# File lib/miteru/website.rb, line 24 def kits @kits ||= links.filter_map do |link| kit = Kit.new(link, source) kit.valid? ? kit : nil end end
kits?()
click to toggle source
# File lib/miteru/website.rb, line 39 def kits? !kits.empty? end
links()
click to toggle source
# File lib/miteru/website.rb, line 57 def links (href_links + possible_file_links).compact.uniq end
message()
click to toggle source
# File lib/miteru/website.rb, line 49 def message return "it doesn't contain a phishing kit." unless kits? filename_with_sizes = kits.map(&:filename_with_size).join(", ") noun = kits.length == 1 ? "a phishing kit" : "phishing kits" "it might contain #{noun}: #{filename_with_sizes}." end
ok?()
click to toggle source
# File lib/miteru/website.rb, line 31 def ok? response.code == 200 end
title()
click to toggle source
# File lib/miteru/website.rb, line 20 def title doc&.at_css("title")&.text end
Private Instance Methods
doc()
click to toggle source
# File lib/miteru/website.rb, line 71 def doc @doc ||= parse_html(response.body.to_s) end
get()
click to toggle source
# File lib/miteru/website.rb, line 67 def get HTTPClient.get url end
href_links()
click to toggle source
# File lib/miteru/website.rb, line 81 def href_links if doc && ok? && index? doc.css("a").filter_map { |a| a.get("href") }.map do |href| href = href.start_with?("/") ? href : "/#{href}" url + href end else [] end rescue Addressable::URI::InvalidURIError, ArgumentError, Encoding::CompatibilityError, HTTP::Error, LL::ParserError, OpenSSL::SSL::SSLError => _e [] end
parse_html(html)
click to toggle source
# File lib/miteru/website.rb, line 75 def parse_html(html) Oga.parse_html(html) rescue ArgumentError, Encoding::CompatibilityError, LL::ParserError => _e nil end
possible_file_links()
click to toggle source
# File lib/miteru/website.rb, line 94 def possible_file_links uri = URI.parse(url) segments = uri.path.split("/") return [] if segments.length.zero? last = segments.last VALID_EXTENSIONS.map do |ext| new_segments = segments[0..-2] + ["#{last}#{ext}"] uri.path = new_segments.join("/") uri.to_s end end
response()
click to toggle source
# File lib/miteru/website.rb, line 63 def response @response ||= get end