Class: Ronin::Vulns::CommandInjection
- Defined in:
- lib/ronin/vulns/command_injection.rb
Overview
Represents a Command Injection vulnerability.
Features
- Supports using
;
,|
,&
, and\n
escape characters. - Supports escaping single and double-quoted strings.
- Supports using
;
,#
, and\n
terminator characters.
Constant Summary collapse
- ID_OUTPUT_REGEX =
Regular expression to match the output of the
id
command. /uid=\d+\([^\)]+\) gid=\d+\([^\)]+\) groups=\d+\([^\)]+\)/
Instance Attribute Summary collapse
-
#escape_operator ⇒ String
readonly
The escape character or string to use to escape the command and execute another.
-
#escape_quote ⇒ String?
readonly
The character to use to escape a quoted string.
-
#terminator ⇒ String?
readonly
The terminator charactor to terminate the injected command with.
Attributes inherited from WebVuln
#cookie, #cookie_param, #form_data, #form_param, #header_name, #headers, #http, #password, #query_param, #query_params, #referer, #request_method, #url, #user, #user_agent
Class Method Summary collapse
-
.test_param(url, escape_quote: [nil, "'", '"', '`'], escape_operator: [';', '|', '&', "\n"], terminator: [nil, ';', '#', "\n"], http:, **kwargs) ⇒ CommandInjection?
private
Scans the URL for command injections.
-
.vuln_type ⇒ Symbol
abstract
private
Returns the type or kind of vulnerability.
Instance Method Summary collapse
-
#encode_payload(sql) ⇒ Object
Encodes the command injection payload.
-
#escape(command) ⇒ String
Escapes the given SQL and turns it into a SQL injection.
-
#initialize(url, escape_quote: nil, escape_operator: nil, terminator: nil, **kwargs) ⇒ CommandInjection
constructor
Initializes the command injection vulnerability.
-
#test_command_output ⇒ Boolean
private
Tests whether the URL is vulnerable to command injection, by executing the
id
command and the output is included in the response body. -
#test_sleep ⇒ Boolean
private
Tests whether the URL is vulnerable to command injection, by calling the sleep command to see if it takes longer for the response to be returned.
-
#vulnerable? ⇒ Boolean
Tests whether the URL is vulnerable to command injection.
Methods inherited from WebVuln
#exploit, #exploit_cookie, #exploit_form_data, #exploit_headers, #exploit_query_params, #original_value, #random_value, #request, scan, scan_cookie_params, scan_form_params, scan_headers, scan_query_params, test, #to_curl, #to_http, #to_s
Constructor Details
#initialize(url, escape_quote: nil, escape_operator: nil, terminator: nil, **kwargs) ⇒ CommandInjection
Initializes the command injection vulnerability.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ronin/vulns/command_injection.rb', line 73 def initialize(url, escape_quote: nil, escape_operator: nil, terminator: nil, **kwargs) super(url,**kwargs) @escape_quote = escape_quote @escape_operator = escape_operator @terminator = terminator @escape_string = build_escape_string end |
Instance Attribute Details
#escape_operator ⇒ String (readonly)
The escape character or string to use to escape the command and execute another.
49 50 51 |
# File 'lib/ronin/vulns/command_injection.rb', line 49 def escape_operator @escape_operator end |
#escape_quote ⇒ String? (readonly)
The character to use to escape a quoted string.
43 44 45 |
# File 'lib/ronin/vulns/command_injection.rb', line 43 def escape_quote @escape_quote end |
#terminator ⇒ String? (readonly)
The terminator charactor to terminate the injected command with.
54 55 56 |
# File 'lib/ronin/vulns/command_injection.rb', line 54 def terminator @terminator end |
Class Method Details
.test_param(url, escape_quote: [nil, "'", '"', '`'], escape_operator: [';', '|', '&', "\n"], terminator: [nil, ';', '#', "\n"], http:, **kwargs) ⇒ CommandInjection?
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.
Scans the URL for command injections.
Tests the URL and a specific query param, header name, cookie param, or form param for Command Injection by enumerating over various Command Injection escape syntaxes.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ronin/vulns/command_injection.rb', line 146 def self.test_param(url, escape_quote: [nil, "'", '"', '`'], escape_operator: [';', '|', '&', "\n"], terminator: [nil, ';', '#', "\n"], # keyword arguments for initialize http: , **kwargs) Array(escape_quote).each do |escape_quote_char| Array(escape_operator).each do |escape_operator_char| Array(terminator).each do |terminator_char| vuln = new(url, escape_quote: escape_quote_char, escape_operator: escape_operator_char, terminator: terminator_char, http: http, **kwargs) return vuln if vuln.vulnerable? end end end return nil end |
.vuln_type ⇒ Symbol
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.
This is used internally to map an vulnerability class to a printable type.
Returns the type or kind of vulnerability.
261 262 263 |
# File 'lib/ronin/vulns/command_injection.rb', line 261 def self.vuln_type :command_injection end |
Instance Method Details
#encode_payload(sql) ⇒ Object
Encodes the command injection payload.
194 195 196 |
# File 'lib/ronin/vulns/command_injection.rb', line 194 def encode_payload(sql) escape(sql) end |
#escape(command) ⇒ String
Escapes the given SQL and turns it into a SQL injection.
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ronin/vulns/command_injection.rb', line 177 def escape(command) cmdi = "#{@escape_string}#{command}" if @terminator cmdi << @terminator elsif (@escape_quote && cmdi.end_with?(@escape_quote)) cmdi.chop! end return cmdi end |
#test_command_output ⇒ 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.
Tests whether the URL is vulnerable to command injection, by executing
the id
command and the output is included in the response body.
218 219 220 221 222 223 224 |
# File 'lib/ronin/vulns/command_injection.rb', line 218 def test_command_output response = exploit('id') if response.body =~ ID_OUTPUT_REGEX return true end end |
#test_sleep ⇒ 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.
Tests whether the URL is vulnerable to command injection, by calling the sleep command to see if it takes longer for the response to be returned.
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/ronin/vulns/command_injection.rb', line 235 def test_sleep start_time = Time.now exploit("sleep 5") stop_time = Time.now delta = (stop_time - start_time) # if the response took more than 5 seconds, our SQL sleep function # probably worked. return delta > 5.0 end |
#vulnerable? ⇒ Boolean
Tests whether the URL is vulnerable to command injection.
203 204 205 |
# File 'lib/ronin/vulns/command_injection.rb', line 203 def vulnerable? test_command_output || test_sleep end |