Class: Ronin::Recon::Values::Website

Inherits:
Ronin::Recon::Value show all
Defined in:
lib/ronin/recon/values/website.rb

Overview

Represents a discovered website (ex: https://example.com).

Constant Summary collapse

URI_CLASSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mapping of #scheme values to URI classes.

{
  'https' => URI::HTTPS,
  'http'  => URI::HTTP
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ronin::Recon::Value

#==, #to_csv, #to_json

Constructor Details

#initialize(scheme, host, port) ⇒ Website

Initializes the website.

Parameters:

  • scheme ('http', 'https')

    Indicates whether the website uses http:// or https://.

  • host (String)

    The website's host name.

  • port (Integer)

    The website's port number.



64
65
66
67
68
# File 'lib/ronin/recon/values/website.rb', line 64

def initialize(scheme,host,port)
  @scheme = scheme
  @host   = host
  @port   = port
end

Instance Attribute Details

#hostString (readonly)

The website's host name.

Returns:

  • (String)


45
46
47
# File 'lib/ronin/recon/values/website.rb', line 45

def host
  @host
end

#portInteger (readonly)

The website's port number.

Returns:

  • (Integer)


50
51
52
# File 'lib/ronin/recon/values/website.rb', line 50

def port
  @port
end

#scheme'http', 'https' (readonly)

Indicates whether the website uses http:// or https://.

Returns:



40
41
42
# File 'lib/ronin/recon/values/website.rb', line 40

def scheme
  @scheme
end

Class Method Details

.http(host, port = 80) ⇒ Website

Initializes a new http:// website.

Parameters:

  • host (String)

    The website's host name.

  • port (Integer) (defaults to: 80)

    The website's port number.

Returns:

  • (Website)

    The new website value.



82
83
84
# File 'lib/ronin/recon/values/website.rb', line 82

def self.http(host,port=80)
  new('http',host,port)
end

.https(host, port = 443) ⇒ Website

Initializes a new https:// website.

Parameters:

  • host (String)

    The website's host name.

  • port (Integer) (defaults to: 443)

    The website's port number.

Returns:

  • (Website)

    The new website value.



98
99
100
# File 'lib/ronin/recon/values/website.rb', line 98

def self.https(host,port=443)
  new('https',host,port)
end

.parse(url) ⇒ Website

Parses a URL.

Parameters:

  • url (String)

    The URL string to parse.

Returns:

  • (Website)

    The parsed website object.



111
112
113
114
115
# File 'lib/ronin/recon/values/website.rb', line 111

def self.parse(url)
  uri = URI.parse(url)

  Values::Website.new(uri.scheme,uri.host,uri.port)
end

.value_type:website

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This is used internally to map a recon value class to a printable type.

Returns the type or kind of recon value.

Returns:

  • (:website)


221
222
223
# File 'lib/ronin/recon/values/website.rb', line 221

def self.value_type
  :website
end

Instance Method Details

#===(other) ⇒ Boolean

Case equality method used for fuzzy matching.

Parameters:

  • other (Value)

    The other value to compare.

Returns:



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ronin/recon/values/website.rb', line 142

def ===(other)
  case other
  when Website
    self == other
  when URL
    @scheme == other.scheme &&
      @host == other.host &&
      @port == other.port
  when EmailAddress
    other.address.end_with?("@#{@host}")
  else
    false
  end
end

#as_jsonHash{Symbol => Object}

Coerces the website value into JSON.

Returns:

  • (Hash{Symbol => Object})

    The Ruby Hash that will be converted into JSON.



206
207
208
# File 'lib/ronin/recon/values/website.rb', line 206

def as_json
  {type: :website, scheme: @scheme, host: @host, port: @port}
end

#eql?(other) ⇒ Boolean

Compares the value to another value.

Parameters:

Returns:

  • (Boolean)


124
125
126
127
128
129
# File 'lib/ronin/recon/values/website.rb', line 124

def eql?(other)
  self.class == other.class &&
    @scheme == other.scheme &&
    @host   == other.host &&
    @port   == other.port
end

#hashInteger

The "hash" value of the wildcard host name.

Returns:

  • (Integer)

    The hash value of #host and #port.



163
164
165
# File 'lib/ronin/recon/values/website.rb', line 163

def hash
  [self.class, @scheme, @host, @port].hash
end

#to_sString

Converts the website to a String.

Returns:

  • (String)

    The base URL value for the website.



191
192
193
194
195
196
197
198
# File 'lib/ronin/recon/values/website.rb', line 191

def to_s
  if ((@scheme == 'https') && (@port != 443)) ||
     ((@scheme == 'http')  && (@port != 80))
    "#{@scheme}://#{@host}:#{@port}"
  else
    "#{@scheme}://#{@host}"
  end
end

#to_uriURI::HTTP, URI::HTTPS

Converts the website into a URI.

Returns:

  • (URI::HTTP, URI::HTTPS)

    The URI object for the website.



181
182
183
# File 'lib/ronin/recon/values/website.rb', line 181

def to_uri
  URI_CLASSES.fetch(@scheme).build(host: @host, port: @port, path: '/')
end