Module: Msf::OptCondition

Defined in:
lib/msf/core/opt_condition.rb

Class Method Summary collapse

Class Method Details

.eval_condition(left_value, operator, right_value) ⇒ Boolean

Check a condition’s result

Parameters:

  • left_value (String)

    The left hand side of the condition

  • operator (String)

    The conditions comparison operator

  • right_value (String)

    The right hand side of the condition

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/msf/core/opt_condition.rb', line 10

def self.eval_condition(left_value, operator, right_value)
  case operator.to_sym
  when :==
    right_value == left_value
  when :!=
    right_value != left_value
  when :in
    right_value.include?(left_value)
  when :nin
    !right_value.include?(left_value)
  else
    raise ArgumentError("Operator: #{operator} is invalid")
  end
end

.format_conditions(_mod, opt) ⇒ String

Format an option’s conditions as a human readable string

Parameters:

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/msf/core/opt_condition.rb', line 29

def self.format_conditions(_mod, opt)
  left_source = opt.conditions[0]
  operator = opt.conditions[1]
  right_value = opt.conditions[2]
  expects_blank_values = Array(right_value).all?(&:blank?)

  case operator.to_sym
  when :==
    "#{left_source} is #{right_value}"
  when :!=
    "#{left_source} is not #{right_value}"
  when :in
    if expects_blank_values
      return "#{left_source} is blank"
    end

    "#{left_source} is one of #{right_value.join(',')}"
  when :nin
    if expects_blank_values
      return "#{left_source} is not blank"
    end

    "#{left_source} not in #{right_value.join(',')}"
  else
    "#{left_source} #{operator} #{right_value}"
  end
end

.show_option(mod, opt) ⇒ Object

Check an OPTION conditions. This function supports dump_options()



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/msf/core/opt_condition.rb', line 59

def self.show_option(mod, opt)
  return true if opt.conditions.empty?

  left_source = opt.conditions[0]
  operator = opt.conditions[1]
  right_value = opt.conditions[2]
  if left_source == 'ACTION'
    left_value = mod.action ? mod.action.name.to_s : nil
  elsif left_source == 'TARGET'
    left_value = mod.target.name.to_s
  else
    left_value = mod.datastore[left_source] || opt.default
  end

  show = eval_condition(left_value, operator, right_value)
  show ||= eval_condition(left_value.to_s, operator, right_value) if left_value.is_a?(Symbol)
  show
end