# frozen_string_literal: true
#
# ronin-exploits - A Ruby library for ronin-rb that provides exploitation and
# payload crafting functionality.
#
# Copyright (c) 2007-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# ronin-exploits is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-exploits is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-exploits. If not, see .
#
module Ronin
module Exploits
module Metadata
#
# Metadata mixin that allows an exploit to define a default port number.
#
module DefaultPort
#
# Adds an {ClassMethods#default_port default_port} metadata attribute
# to the exploit.
#
# @param [Class] exploit
# The exploit class that is including {Metadata::DefaultPort}.
#
# @api private
#
def self.included(exploit)
exploit.extend ClassMethods
end
#
# Class-methods.
#
module ClassMethods
#
# Gets or sets the exploit's default port.
#
# @param [Integer, nil] new_default_port
# The optional new default port number to set.
#
# @return [Integer, nil]
# The exploit's default port number.
#
# @example
# default_port 143
#
# @api public
#
def default_port(new_default_port=nil)
if new_default_port
@default_port = new_default_port
else
@default_port ||= if superclass.kind_of?(ClassMethods)
superclass.default_port
end
end
end
end
end
end
end
end