Class: Ronin::Recon::Values::OpenPort

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

Overview

Represents a discovered open port.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ronin::Recon::Value

#==, parse, #to_csv, #to_json

Constructor Details

#initialize(address, number, host: nil, protocol: :tcp, service: nil, ssl: false) ⇒ OpenPort

Initializes the open port.

Parameters:

  • address (String)

    The IP address for the open port.

  • number (Integer)

    The port number.

  • host (String, nil) (defaults to: nil)

    The optional hostname associated with the address.

  • protocol (:tcp, :udp) (defaults to: :tcp)

    The protocol of the port.

  • service (String, nil) (defaults to: nil)

    The optional service information.

  • ssl (Boolean) (defaults to: false)

    Indicates that the open port uses SSL/TLS.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ronin/recon/values/open_port.rb', line 84

def initialize(address,number, host:     nil,
                               protocol: :tcp,
                               service:  nil,
                               ssl:      false)
  @address  = address
  @number   = number
  @host     = host
  @protocol = protocol
  @service  = service
  @ssl      = ssl
end

Instance Attribute Details

#addressString (readonly)

The IP address that the open port listens on.

Returns:

  • (String)


36
37
38
# File 'lib/ronin/recon/values/open_port.rb', line 36

def address
  @address
end

#hostString? (readonly)

The optional hostname associated with the address.

Returns:

  • (String, nil)


46
47
48
# File 'lib/ronin/recon/values/open_port.rb', line 46

def host
  @host
end

#numberInteger (readonly)

The port number.

Returns:

  • (Integer)


41
42
43
# File 'lib/ronin/recon/values/open_port.rb', line 41

def number
  @number
end

#protocol:tcp, :udp (readonly)

The protocol of the port.

Returns:

  • (:tcp, :udp)

    protocol



51
52
53
# File 'lib/ronin/recon/values/open_port.rb', line 51

def protocol
  @protocol
end

#serviceString? (readonly)

The optional service information.

Returns:

  • (String, nil)

    service



56
57
58
# File 'lib/ronin/recon/values/open_port.rb', line 56

def service
  @service
end

#sslBoolean (readonly)

Indiciates whether the open port uses SSL.

Returns:

  • (Boolean)


61
62
63
# File 'lib/ronin/recon/values/open_port.rb', line 61

def ssl
  @ssl
end

Class Method Details

.value_type:open_port

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:

  • (:open_port)


183
184
185
# File 'lib/ronin/recon/values/open_port.rb', line 183

def self.value_type
  :open_port
end

Instance Method Details

#as_jsonHash{Symbol => Object}

Coerces the open port value into JSON.

Returns:

  • (Hash{Symbol => Object})

    The Ruby Hash that will be converted into JSON.



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/ronin/recon/values/open_port.rb', line 158

def as_json
  hash = {
    type:     :open_port,
    address:  @address,
    protocol: @protocol,
    number:   @number
  }

  hash[:service] = @service if @service
  hash[:ssl]     = @ssl     if @ssl

  return hash
end

#eql?(other) ⇒ Boolean

Compares the value to another value.

Parameters:

Returns:

  • (Boolean)


112
113
114
115
116
117
118
119
# File 'lib/ronin/recon/values/open_port.rb', line 112

def eql?(other)
  other.kind_of?(self.class) &&
    @address  == other.address &&
    @number   == other.number &&
    @protocol == other.protocol &&
    @service  == other.service &&
    @ssl      == other.ssl
end

#hashInteger

The "hash" value of the open port.

Returns:

  • (Integer)


126
127
128
# File 'lib/ronin/recon/values/open_port.rb', line 126

def hash
  [self.class, @address, @number, @protocol, @service, @ssl].hash
end

#ssl?Boolean

Determines whether the open port uses SSL/TLS.

Returns:

  • (Boolean)


101
102
103
# File 'lib/ronin/recon/values/open_port.rb', line 101

def ssl?
  @ssl
end

#to_iInteger Also known as: to_int

Converts the open port into an Integer.

Returns:



146
147
148
# File 'lib/ronin/recon/values/open_port.rb', line 146

def to_i
  @number.to_i
end

#to_sString

Converts the open port into a String.

Returns:

  • (String)

    The hot-name/IP and port number.



136
137
138
# File 'lib/ronin/recon/values/open_port.rb', line 136

def to_s
  "#{@address}:#{@number}"
end