Penetration Testing with Kali Linux
PWK - Copyright © 2023 OffSec Services Limited. All rights reserved.
252
Figure 121: Mountain Desserts Single Page Application
Figure 121 shows the page after we open it in a browser. The navigation bar displays a file named
index.php
, so we can conclude that the web application uses PHP. To gather more information
about the page’s
structure, we should hover over all buttons and links,
collecting information
about parameters and the different pages we come across.
Figure 122: Hovering over a Button
Scrolling down and hovering over all buttons and links, we’ll notice most of them only link to the
page itself, as shown in Figure 122.
At the bottom of the page, we’ll find a link labeled “Admin”.
Figure 123: Hovering over the “Admin” Link
Figure 123 shows the link preview when we hover over the Admin link with our cursor, displaying
the URL http://mountaindesserts.com/meteor/index.php?page=admin.php.
We know the web application uses PHP and a parameter called “page”, so let’s assume this
parameter is used to display different pages. PHP uses
$_GET
386
to manage variables via a GET
request.
When we click on the link, we receive an error message stating the page is currently
under maintenance.
386
(PHP Manual, 2022), https://www.php.net/manual/en/reserved.variables.get.php
Penetration Testing with Kali Linux
PWK - Copyright © 2023 OffSec Services Limited. All rights reserved.
253
Figure 124: Error Message of Admin Link
This is an important detail for us, since it reveals that information is shown on the same page. In
this case, we’ll make a few assumptions about how the web application could be developed to
behave in such a way. For example, when we open mountaindesserts.com/meteor/admin.php in
our browser, we’ll notice the same message that was shown on the index.php page after clicking
the “Admin” link.
Figure 125: Maintenance of Admin Page
This message indicates the web application includes the content
of this page via the
page
parameter and displays it under the “Admin” link. We can now try to use ../ to traverse directories
in the potentially-vulnerable parameter. We’ll specify a relative path to /etc/passwd to test the
page
parameter for directory traversal.
http://mountaindesserts.com/meteor/index.php?page=../../../../../../../../../etc/passw
d
Listing 134 - Entire URL of our Directory Traversal attack
Let’s copy the shown URL from listing 134 into the address bar of our browser.
Figure 126: Web Application shows contents of Passwd File
Figure 126 shows the contents of /etc/passwd. We successfully leveraged the directory traversal
vulnerability by using a relative path.
Penetration Testing with Kali Linux
PWK - Copyright © 2023 OffSec Services Limited. All rights reserved.
254
Directory traversal vulnerabilities are mostly used for gathering information. As mentioned before,
if we can access certain files containing sensitive information, like passwords or keys, it may lead
to system access.
In most cases, the web server is run in the context of a dedicated user such as
www-data
. These
users usually have limited access permissions on the system. However, users and administrators
often intentionally set file access permissions to be very permissive or even world-readable.
Sometimes this occurs due to time constraints in deployment or less-mature security programs.
This means we should always check for the existence of SSH keys and their access permissions.
SSH keys are usually located in the home directory of a user in the .ssh folder. Fortunately for us,
/etc/passwd
also contains the home
directory paths of all users, as shown in Figure 126. The
output of /etc/passwd shows a user called
offsec
. Let’s specify a relative path for the vulnerable
“page” parameter to try and display the contents of the user’s private key.
http://mountaindesserts.com/meteor/index.php?page=../../../../../../../../../home/offs
ec/.ssh/id_rsa
Listing 135 - Entire URL of our Directory Traversal attack
Let’s copy the shown URL from listing 135 into the address bar of our browser.
Figure 127: Content of SSH Private Key
Figure 127 shows that we successfully retrieved the private key for the
offsec
user. Reviewing the
output, we’ll notice that its formatting is a bit messy.
During web application assessments, we should understand that as soon as we’ve
identified a
possible vulnerability, such as with the “page”
parameter in this case, we should not rely on a
browser for testing. Browsers often try to parse or optimize elements for user friendliness. When
performing
web application testing, we should mainly use tools such as
Burp
,
387
cURL
,
388
or a
programming language of our choice.
387
(PortSwigger, 2022), https://portswigger.net/burp
388
(Curl, 2022), https://curl.se/
Penetration Testing with Kali Linux
PWK - Copyright © 2023 OffSec Services Limited. All rights reserved.
255
Let’s use curl to retrieve the SSH private key as we did with the browser.
kali@kali:~$
Yüklə
Dostları ilə paylaş: