Class: Ronin::Vulns::ReflectedXSS::TestString Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/vulns/reflected_xss/test_string.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A test string of characters to determine which special characters are escaped/filtered and which are passed through.

Constant Summary collapse

ESCAPED_CHARS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Special characters and their common escaped equivalents.

{
  "'" => ['%27', ''', "\\'"],
  '"' => ['%22', '"', "\\\""],
  ' ' => ['+', '%20', ' '],
  '=' => ['%3D'],
  '/' => ['%2F'],
  '<' => ['%3C', '&lt;'],
  '>' => ['%3E', '&gt;'],
  '&' => ['%26', '&amp;']
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, regexp) ⇒ TestString

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.

Initializes the test string.

Parameters:

  • string (String)

    The test string.

  • regexp (Regexp)

    The test regexp to determine which special characters were escaped/filtered and which were passed through unescaped.



55
56
57
58
# File 'lib/ronin/vulns/reflected_xss/test_string.rb', line 55

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

Instance Attribute Details

#regexpRegexp (readonly)

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.

The test regexp to determine which special characters were escaped/filtered and which were passed through unescaped.

Returns:

  • (Regexp)


43
44
45
# File 'lib/ronin/vulns/reflected_xss/test_string.rb', line 43

def regexp
  @regexp
end

#stringString (readonly)

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.

The test string.

Returns:

  • (String)


37
38
39
# File 'lib/ronin/vulns/reflected_xss/test_string.rb', line 37

def string
  @string
end

Class Method Details

.build(chars) ⇒ TestString

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.

Builds a test string from a mapping of characters and their HTML escaped equivalents.

Parameters:

  • chars (String)

    The characters for the test string.

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ronin/vulns/reflected_xss/test_string.rb', line 82

def self.build(chars)
  string = String.new
  regexp = String.new

  chars.each_char do |char|
    string << char

    regexp << "(?:(#{Regexp.escape(char)})"

    if (escaped_chars = ESCAPED_CHARS[char])
      escaped_chars.each do |string|
        regexp << "|#{Regexp.escape(string)}"
      end
    end

    regexp << ')?'
  end

  return new(string,Regexp.new(regexp))
end

Instance Method Details

#match(body) ⇒ MatchData?

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.

Matches the response body against #regexp.

Parameters:

  • body (String)

    The response body to try matching.

Returns:

  • (MatchData, nil)

    The match data or nil if the body did not match #regexp.



131
132
133
# File 'lib/ronin/vulns/reflected_xss/test_string.rb', line 131

def match(body)
  body.match(@regexp)
end

#to_sString

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.

Converts the test string to a String.

Returns:



141
142
143
# File 'lib/ronin/vulns/reflected_xss/test_string.rb', line 141

def to_s
  @string
end

#wrap(prefix, suffix) ⇒ TestString

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.

Wraps the test string with a prefix and suffix.

Parameters:

  • prefix (String)

    The prefix string to prepend to the test string.

  • suffix (String)

    The suffix string to append to the test string.

Returns:

  • (TestString)

    The new test string with the prefix and suffix.



115
116
117
118
119
120
# File 'lib/ronin/vulns/reflected_xss/test_string.rb', line 115

def wrap(prefix,suffix)
  self.class.new(
    "#{prefix}#{@string}#{suffix}",
    /#{Regexp.escape(prefix)}#{@regexp}#{Regexp.escape(suffix)}/
  )
end