Skip to content

Commit

Permalink
Show session/rhost options separate from each other
Browse files Browse the repository at this point in the history
Add ability to group options for display
  • Loading branch information
dwelch-r7 committed Feb 20, 2024
1 parent 175d584 commit c45ae5d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/msf/core/opt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def self.RHOSTS(default= nil, required=true, desc="The target host(s), see https
Msf::OptRhosts.new('RHOSTS', [ required, desc, default ], aliases: [ 'RHOST' ])
end

def self.RHOST(default=nil, required=true, desc="The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html")
Msf::OptRhosts.new('RHOSTS', [ required, desc, default ], aliases: [ 'RHOST' ])
def self.RHOST(default=nil, required=true, desc="The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html", **kwargs)
Msf::OptRhosts.new('RHOSTS', [ required, desc, default ], aliases: [ 'RHOST' ], **kwargs)
end

# @return [OptPort]
Expand Down
6 changes: 5 additions & 1 deletion lib/msf/core/opt_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ class OptBase
#
def initialize(in_name, attrs = [],
required: false, desc: nil, default: nil, conditions: [], enums: [], regex: nil, aliases: [], max_length: nil,
fallbacks: [])
fallbacks: [], group: nil)
self.name = in_name
self.advanced = false
self.evasion = false
self.aliases = aliases
self.max_length = max_length
self.conditions = conditions
self.fallbacks = fallbacks
self.group = group

if attrs.is_a?(String) || attrs.length == 0
self.required = required
Expand Down Expand Up @@ -230,6 +231,9 @@ def invalid_value_length?(value)
#
attr_accessor :max_length

# @return [Msf::OptionGroup, nil] The option group that this option belongs to if any
attr_accessor :group

protected

attr_writer :required, :desc, :default # :nodoc:
Expand Down
9 changes: 6 additions & 3 deletions lib/msf/core/opt_condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
module Msf
module OptCondition
# Check a condition's result
# @param [Msf::Module] mod The module module
# @param [Msf::OptBase] opt the option which has conditions present
# @return [String]
# @param [String] left_value The left hand side of the condition
# @param [String] operator The conditions comparison operator
# @param [String] right_value The right hand side of the condition
# @return [Boolean]
def self.eval_condition(left_value, operator, right_value)
case operator.to_sym
when :==
Expand All @@ -16,6 +17,8 @@ def self.eval_condition(left_value, operator, right_value)
right_value.include?(left_value)
when :nin
!right_value.include?(left_value)
else
raise ArgumentError("Operator: #{operator} is invalid")
end
end

Expand Down
13 changes: 13 additions & 0 deletions lib/msf/core/option_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: binary -*-

module Msf
class OptionGroup

attr_accessor :name, :description

def initialize(name:, description:)
self.name = name
self.description = description
end
end
end
4 changes: 4 additions & 0 deletions lib/msf/core/optional_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
module Msf
module OptionalSession
include Msf::SessionCompatibility

def session_enabled?(session_feature_name)
framework.features.enabled?(session_feature_name)
end
end
end
25 changes: 20 additions & 5 deletions lib/msf/core/optional_session/smb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module OptionalSession
module SMB
include Msf::OptionalSession

FEATURE_NAME = Msf::FeatureManager::SMB_SESSION_TYPE
RHOST_GROUP_OPTIONS = %w[RHOSTS RPORT SMBDomain SMBUser SMBPass THREADS]

def initialize(info = {})
super(
update_info(
Expand All @@ -13,24 +16,36 @@ def initialize(info = {})
)
)


if framework.features.enabled?(Msf::FeatureManager::SMB_SESSION_TYPE)
if session_enabled?
session_group = Msf::OptionGroup.new(name: 'SESSION', description: 'Used when connecting via an existing SESSION')
rhost_group = Msf::OptionGroup.new(name: 'RHOST', description: 'Used when making a new connection via RHOSTS')
register_options(
[
Msf::OptInt.new('SESSION', [ false, 'The session to run this module on' ]),
Msf::OptInt.new('SESSION', [ false, 'The session to run this module on' ], group: session_group),
Msf::Opt::RHOST(nil, false),
Msf::Opt::RPORT(443, false)
Msf::Opt::RPORT(445, false),
]
)

RHOST_GROUP_OPTIONS.each do |option_name|
if options[option_name]
options[option_name].group = rhost_group
end
end

add_info('New in Metasploit 6.4 - This module can target a %grnSESSION%clr or an %grnRHOST%clr')
end
end

def session
return nil unless framework.features.enabled?(Msf::FeatureManager::SMB_SESSION_TYPE)
return nil unless session_enabled?

super
end

def session_enabled?
super(FEATURE_NAME)
end
end
end
end

0 comments on commit c45ae5d

Please sign in to comment.