Class: Ronin::Vulns::SSTI::TestExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/vulns/ssti/test_expression.rb

Overview

Represents a expression to test SSTI with (ex: 7*7).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, result) ⇒ TestExpression

Initializes the test expression.

Parameters:

  • string (String)

    The expression string.

  • result (String)

    The expected result of the expression.



53
54
55
56
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 53

def initialize(string,result)
  @string = string
  @result = result
end

Instance Attribute Details

#resultString (readonly)

The expected result of the string.

Returns:

  • (String)


42
43
44
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 42

def result
  @result
end

#stringString (readonly)

The expression string.

Returns:

  • (String)


37
38
39
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 37

def string
  @string
end

Class Method Details

.parse(string) ⇒ TestExpression

Parses an expression string and calculates the result.

Parameters:

  • string (String)

    The expression string to parse.

Returns:

Raises:

  • (ArgumentError)

    Could not parse the test expression.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 70

def self.parse(string)
  unless (match = string.match(%r{\A(\d+)\s*([\*/\+\-])\s*(\d+)\z}))
    raise(ArgumentError,"could not parse the expression: #{string.inspect}")
  end

  lvalue = match[1].to_i
  op     = match[2]
  rvalue = match[3].to_i

  result = case op
           when '*' then lvalue * rvalue
           when '/' then lvalue / rvalue
           when '+' then lvalue + rvalue
           when '-' then lvalue - rvalue
           else
             raise(NotImplementedError,"unsupported expression operator: #{op.inspect}")
           end

  return new(string,result.to_s)
end

Instance Method Details

#to_sString

The test expression as a String.

Returns:



97
98
99
# File 'lib/ronin/vulns/ssti/test_expression.rb', line 97

def to_s
  @string
end