Penetration Testing with Kali Linux
PWK - Copyright © 2023 OffSec Services Limited. All rights reserved.
235
Once the blank page is loaded, we’ll click on the
Web Console
from the Web Developer sub-menu
in the Firefox Menu or
use the shortcut
C
+
B
+
k
.
Figure 111: Testing the JavaScript Function in the Browser Console
From within the Console, we can execute our test function and retrieve the output.
Printing values to the browser’s console is another technique we can add to our debugging toolkit
that will be extremely useful when analyzing more complex JavaScript code.
8.4.3
Identifying XSS Vulnerabilities
We can find potential entry points for XSS by examining a web application and identifying input
fields (such as search fields) that accept unsanitized input, which is then displayed as output in
subsequent pages.
Once we identify an entry point, we can input special characters and observe the output to
determine if any of the special characters return unfiltered.
The most common special characters used for this purpose include:
< > ' " { } ;
Listing 120 - Special characters for HTML and JavaScript
Let’s describe the purpose of these special characters. HTML uses “<” and “>”
to denote
elements
,
366
the various components that make up an HTML document. JavaScript uses “{” and
“}” in function declarations. Single (’) and double (") quotes are used to denote strings, and
semicolons (;) are used to mark the end of a statement.
If the application does not remove or encode these characters,
it may be vulnerable to XSS
because the app
interprets
the characters as code, which in turn, enables additional code.
366
(Wikipedia, 2022), https://en.wikipedia.org/wiki/HTML_element
Penetration Testing with Kali Linux
PWK - Copyright © 2023 OffSec Services Limited. All rights reserved.
236
While there are multiple types of
encoding, the most common we’ll encounter in web applications
are
HTML encoding
367
and
URL encoding
.
368
URL encoding, sometimes referred to as
percent
encoding
, is used to convert non-ASCII and reserved characters in URLs,
such as converting a
space to “%20”.
HTML encoding (or
character references
) can be used to display characters that normally have
special meanings, like tag elements. For example, “<” is the character reference for “<”. When
encountering this type of encoding, the browser will not interpret the character as the start of an
element, but will display the actual character as-is.
If we can inject these special
characters into the page, the browser will treat them as code
elements. We can then begin to build code that will be executed in the victim’s browser once it
loads the maliciously-injected JavaScript code.
We may need to use different sets of characters, depending on where our input is being included.
For example, if our input is being added between
div
tags, we’ll
need to include our own
script
tags
369
and need to be able to inject “<” and “>” as part of the payload. If our input is being added
within an existing JavaScript tag, we might only need quotes and semicolons to add our own
code.
8.4.4
Basic XSS
Let’s demonstrate basic XSS with a simple attack against the OffSec WordPress instance. The
WordPress installation is running a plugin named
Visitors
that is vulnerable to stored XSS.
370
The
plugin’s main feature is to log the website’s visitor data, including the IP, source, and User-Agent
fields.
The source code for the plugin can be downloaded from its website.
371
If
we inspect the
database.php
file, we can verify how the data is stored inside the WordPress database:
function VST_save_record() {
global $wpdb;
$table_name = $wpdb->prefix . 'VST_registros';
VST_create_table_records();
return $wpdb->insert(
$table_name,
array(
'patch' => $_SERVER["REQUEST_URI"],
'datetime' => current_time( 'mysql' ),
Yüklə
Dostları ilə paylaş: