Class: Ronin::Vulns::ReflectedXSS::Context
- Inherits:
-
Object
- Object
- Ronin::Vulns::ReflectedXSS::Context
- Defined in:
- lib/ronin/vulns/reflected_xss/context.rb
Overview
Represents information about the context which the XSS occurs within.
Constant Summary collapse
- IDENTIFIER =
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.
HTML identifier regexp
/[A-Za-z0-9_-]+/
- ATTR_NAME =
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.
HTML attribute name regexp.
IDENTIFIER
- ATTR =
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.
HTML attribute regexp.
/#{ATTR_NAME}(?:\s*=\s*"[^"]+"|\s*=\s*'[^']+'|=[^"'\s]+)?/
- ATTR_LIST =
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.
HTML attribute list regexp.
/(?:\s+#{ATTR})*/
- COMMENT =
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.
HTML comment regexp.
/<![^>]*>/
- TAG_NAME =
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.
HTML tag name regexp.
IDENTIFIER
- IN_TAG_BODY =
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.
Regexp matching when an XSS occurs within a tag's inner HTML.
%r{<(#{TAG_NAME})#{ATTR_LIST}\s*(?:>|/>)([^<>]|#{COMMENT})*\z}
- IN_DOUBLE_QUOTED_ATTR_VALUE =
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.
Regexp matching when an XSS occurs within a double-quoted attribute value.
/<(#{TAG_NAME})#{ATTR_LIST}\s+(#{ATTR_NAME})\s*=\s*"[^"]+\z/
- IN_SINGLE_QUOTED_ATTR_VALUE =
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.
Regexp matching when an XSS occurs within a single-quoted attribute value.
/<(#{TAG_NAME})#{ATTR_LIST}\s+(#{ATTR_NAME})\s*=\s*'[^']+\z/
- IN_UNQUOTED_ATTR_VALUE =
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.
Regexp matching when an XSS occurs within an unquoted attribute value.
/<(#{TAG_NAME})#{ATTR_LIST}\s+(#{ATTR_NAME})=[^"'\s]+\z/
- IN_ATTR_NAME =
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.
Regexp matching when an XSS occurs within an attribute's name.
/<(#{TAG_NAME})#{ATTR_LIST}\s+(#{ATTR_NAME})\z/
- IN_ATTR_LIST =
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.
Regexp matching when an XSS occurs within a tag's attribute list.
/<(#{TAG_NAME})#{ATTR_LIST}\s+\z/
- IN_TAG_NAME =
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.
Regexp matching when an XSS occurs within a tag's name.
/<(#{TAG_NAME})\z/
- IN_COMMENT =
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.
Regexp matching when an XSS occurs within a comment.
/<![^>]*\z/
- MINIMAL_REQUIRED_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.
The minimum set of required characters needed for an XSS.
Set['>', ' ', '/', '<']
- REQUIRED_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.
The mapping of contexts and their required characters.
{ double_quoted_attr_value: MINIMAL_REQUIRED_CHARS + ['"'], single_quoted_attr_value: MINIMAL_REQUIRED_CHARS + ["'"], unquoted_attr_value: MINIMAL_REQUIRED_CHARS, attr_name: MINIMAL_REQUIRED_CHARS, attr_list: MINIMAL_REQUIRED_CHARS, tag_name: MINIMAL_REQUIRED_CHARS, tag_body: MINIMAL_REQUIRED_CHARS, comment: MINIMAL_REQUIRED_CHARS }
Instance Attribute Summary collapse
-
#attr ⇒ String?
readonly
The attribute name that the XSS occurs in.
-
#location ⇒ :double_quoted_attr_value, ...
readonly
Where in the HTML the XSS occurs.
-
#tag ⇒ String?
readonly
The name of the parent tag which the XSS occurs in.
Class Method Summary collapse
-
.identify(body, index) ⇒ Context
private
Determine the context of the XSS by checking the characters that come before the given index.
Instance Method Summary collapse
-
#initialize(location, tag: nil, attr: nil) ⇒ Context
constructor
private
Initializes the context.
-
#viable?(allowed_chars) ⇒ Boolean
private
Determines if the XSS is viable, given the context and the allowed characters.
Constructor Details
#initialize(location, tag: nil, attr: nil) ⇒ Context
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 context.
77 78 79 80 81 82 |
# File 'lib/ronin/vulns/reflected_xss/context.rb', line 77 def initialize(location, tag: nil, attr: nil) @location = location @tag = tag @attr = attr end |
Instance Attribute Details
#attr ⇒ String? (readonly)
The attribute name that the XSS occurs in.
64 65 66 |
# File 'lib/ronin/vulns/reflected_xss/context.rb', line 64 def attr @attr end |
#location ⇒ :double_quoted_attr_value, ... (readonly)
Where in the HTML the XSS occurs.
50 51 52 |
# File 'lib/ronin/vulns/reflected_xss/context.rb', line 50 def location @location end |
#tag ⇒ String? (readonly)
The name of the parent tag which the XSS occurs in.
57 58 59 |
# File 'lib/ronin/vulns/reflected_xss/context.rb', line 57 def tag @tag end |
Class Method Details
.identify(body, index) ⇒ Context
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.
Determine the context of the XSS by checking the characters that come before the given index.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ronin/vulns/reflected_xss/context.rb', line 171 def self.identify(body,index) prefix = body[0,index] if (match = prefix.match(IN_TAG_BODY)) new(:tag_body, tag: match[1]) elsif (match = prefix.match(IN_DOUBLE_QUOTED_ATTR_VALUE)) new(:double_quoted_attr_value, tag: match[1], attr: match[2]) elsif (match = prefix.match(IN_SINGLE_QUOTED_ATTR_VALUE)) new(:single_quoted_attr_value, tag: match[1], attr: match[2]) elsif (match = prefix.match(IN_UNQUOTED_ATTR_VALUE)) new(:unquoted_attr_value, tag: match[1], attr: match[2]) elsif (match = prefix.match(IN_ATTR_NAME)) new(:attr_name, tag: match[1], attr: match[2]) elsif (match = prefix.match(IN_ATTR_LIST)) new(:attr_list, tag: match[1]) elsif (match = prefix.match(IN_TAG_NAME)) new(:tag_name, tag: match[1]) elsif prefix.match?(IN_COMMENT) new(:comment) end end |
Instance Method Details
#viable?(allowed_chars) ⇒ Boolean
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.
Determines if the XSS is viable, given the context and the allowed characters.
226 227 228 229 230 231 232 |
# File 'lib/ronin/vulns/reflected_xss/context.rb', line 226 def viable?(allowed_chars) required_chars = REQUIRED_CHARS.fetch(@location) do raise(NotImplementedError,"cannot determine viability for unknown XSS location type: #{@location.inspect}") end allowed_chars.superset?(required_chars) end |