0% found this document useful (0 votes)
29 views23 pages

Jarvis HTB Penetration Test Report

The penetration test of the Jarvis machine involved: 1) Discovering an SQL injection vulnerability in the website that allowed dumping credentials and gaining remote code execution as the www-data user. 2) Using command injection in the simpler.py script to gain a shell as the pepper user. 3) Exploiting the systemctl binary having the SUID bit enabled to escalate privileges to the root user.

Uploaded by

rowen prather
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views23 pages

Jarvis HTB Penetration Test Report

The penetration test of the Jarvis machine involved: 1) Discovering an SQL injection vulnerability in the website that allowed dumping credentials and gaining remote code execution as the www-data user. 2) Using command injection in the simpler.py script to gain a shell as the pepper user. 3) Exploiting the systemctl binary having the SUID bit enabled to escalate privileges to the root user.

Uploaded by

rowen prather
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

Penetration Test Report


Target: Jarvis (HTB)

Report by

3/25/2022
2

Table of Contents

1.0 Introduction and Objective 3

1.1 Introduction

1.2 Objective

2.0 Report – High-Level Summary 4

2.1 High-Level Summary

2.2 Recommendations

3.0 Report – Methodologies 6

3.1 Enumeration 6

3.2 RCE via Website SQLi 11

3.3 Lateral Movement via [Link] 15

3.4 Privilege Escalation via systemctl SUID 19


3

1.0 Introduction and Objective

1.1 Introduction

This report contains complete and detailed documentation of all steps necessary to compromise
the target machine. This machine is identified by IP address [Link], known under the simple
name of “Jarvis.” Any associated vulnerabilities, proof of concept scripts, CVEs, etc. will be
sourced and linked for further background information. Screenshots of the exploitation process
will be included for demonstration of specific commands used.

1.2 Objective

The objective of this black-box penetration test was to discover and exploit vulnerabilities in the
aforementioned machine, with the ultimate target being unrestricted root-level access. The scope
was not to exceed this specific box, nor were denial of service attacks permitted in the test. This
report’s objective is to demonstrate the process used in a clear, concise and easily reproducible
manner as well as explain any steps necessary to patch associated vulnerabilities and properly
secure the machine.
4

2.0 Report – High-Level Summary

2.1 High-Level Summary

I was tasked with performing a penetration test against the Jarvis box on the HTB network. This
penetration test served as a simulated attack against this specific machine.

The focus of this test was to perform attacks, similar to those of a malicious entity, in order to
exploit the Jarvis box to obtain unrestricted root-level access on its domain. My overall objective
was to evaluate the network, identify active systems and exploit any discovered flaws in such
systems as necessary, all while remaining within the agreed-upon scope and reporting all findings.

While conducting this test, multiple vulnerabilities were discovered. An SQLi vulnerability was
discovered for the website, and various sqlmap tools were used to bypass the WAF and get a shell
as www-data. From there, [Link] was found to have insufficient input sanitization and abused
for a shell as pepper. systemctl had the SUID bit enabled, and this was abused for root-level access.

2.2 Recommendations

It is my firm recommendation that all vulnerabilities found are thoroughly patched as follows:

• Input sanitization should be implemented on the website to prevent SQLi. Unexpected


and/or potentially malicious characters such as ‘ should not be accepted in the cod
parameter’s input, nor should inputs undergo any kind of processing until validated.
o SQLi vulnerabilities are extremely dangerous and very easily exploitable; therefore
this patch should be given high priority.
• [Link] should have its input sanitization adjusted to prevent command injection. The
characters used in this test, $(), should obviously be blacklisted; additionally, consider
using Python’s ping module instead of an [Link] call so as to further prevent command
injection. Otherwise, www-data’s sudo permissions might be adjusted to prevent priv esc
via the script.
o Any of the options here might be implemented. Overall, patching this script should
be treated with medium priority.
• The systemctl SUID bit should be turned off, as enabling it allows for an easy and
commonly-known privilege escalation vulnerability.
5

o Disabling the systemctl SUID bit should be treated with medium priority as well.
Securing the point with which most users will be interacting (here, the web app) is
of the highest priority.
6

3.0 Report – Methodologies

3.1 Enumeration

nmap finds ports 22, 80, and 64999 open; the latter is an HTTP server.

The website is for Stark Hotel.


7

There are both “rooms” and “dining & bar” pages; hyperlinks don’t seem to work on the latter.
8

On the former page, room rental pages can be accessed. I’ll look at this more in a moment.
9

Enumerating the rest of the site, a phpMyAdmin directory can be found.

Visiting it returns a login page, and default/common credentials don’t work.


10

The [Link] found in dirb is empty.

Quickly looking at port 64999, it returns a ban message. Nothing else can be found on this port.

Revisiting the room rental page, I noted a parameter in the URL. Adjusting this parameter and
adding an apostrophe causes the page to break, indicating a potential SQLi vulnerability.
11

3.2 RCE via Website SQLi

I run sqlmap against the page, and it quickly detects some form of WAF or IPS.

Returning to the website gives the same message as on port 64999. If I want to use sqlmap to
enumerate, I’ll have to use some tricks.

These tricks are some extra flags, including –random-agent to mess with the User Agent string.
12

This new command works, and an SQLi vulnerability is found.

With this, I can dump usernames and passwords from the database.

I find credentials for a single user: DBadmin.


13

These credentials let me log into phpMyAdmin. I note the version as 4.8.0, which is vulnerable to
CVE-2018-12613. With an NVD risk score of 8.8/10, it allows for LFI as well as RCE, the former
of which can be seen here:

I won’t be exploiting this for RCE, as I obtain it by a different means, but I still very highly
recommend updating phpMyAdmin to version 4.8.2 or later (preferably the latest secure patch to
prevent against other potential vulnerabilities).

For my method of RCE, I simply write a PHP backdoor file onto the website.
14

From there, curl can be used to execute commands on the box.

nc can be used to obtain a full shell.


15

3.3 Lateral Movement via [Link]

There is one user on the box: pepper. I can access their folder, but I don’t have permission to read
the user flag.

Running sudo -l, one of the best commands to start with for box enumeration, quickly gives me a
potential priv esc vector: I have permission to run a Python script as pepper.
16

The script is in /var/www/Admin-Utilities and has a couple IP-related capabilities.

The ping function is done via an [Link] call, which opens a door for command injection. There
is some level of input sanitization, wherein a number of special characters typically used in
commands are forbidden.
17

These characters, however, do not include $(), which can be abused to execute bash commands,
as seen here. whoami returns “pepper,” which then causes the system to run ping pepper. This
obviously returns a name resolution failure, but it proves that command injection is possible.

I can’t execute a bash nc command on its own, but I can write the command into a script and then
call that.
18

Executing the malicious script gives me a reverse shell as pepper.


19

3.4 Privilege Escalation via systemctl SUID

I’ll run LinPEAS to find potential priv esc vectors.


20

Interestingly, systemctl’s SUID bit is set, giving me a perfect priv esc path.
21

I configure a malicious service file, which will execute a nc command.

Since systemctl is set to be an SUID, it runs as root. Linking the service and starting it will execute
the nc command at a root level.

Just as you’d expect, this gives me a root shell.


22

I note an interesting Python script in the root folder.


23

This script seems to function as the WAF. It checks the logs regularly, and if in the course of eight
seconds, five or more requests containing [Link]?cod are made from the same IP address, it
adds the IP to the ban list for 90 seconds, which causes all requests from that IP to be redirected to
port 64999.

Common questions

Powered by AI

The main vulnerabilities identified in the Jarvis penetration test included a website SQL injection (SQLi) vulnerability, insufficient input sanitization in the simpler.py script, and a systemctl SUID bit misconfiguration. The SQLi vulnerability was exploited using sqlmap, bypassing the WAF to gain a shell as www-data. Input sanitization flaws in simpler.py allowed command injection via the $() operator, enabling lateral movement to the user 'pepper'. The systemctl SUID bit was exploited to escalate privileges to root by running a malicious service at a root level .

According to the report, the highest priority should be given to securing the web application against SQL injection due to its immediate risk and exploitability. Input sanitization should be promptly applied to mitigate this vulnerability. The input sanitization adjustment in simpler.py is assigned a medium priority because, while it allows command injection, there are conditions and restrictions that somewhat limit the attack. Disabling the systemctl SUID bit is also given medium priority as it poses a known privilege escalation threat but might not be directly exploited without additional vulnerabilities .

The reverse shell execution as user 'pepper' involved exploiting the simpler.py script, which had inadequate input sanitization. The tester used command injection by writing a script that executed a bash command within the $() operator. They then triggered this command using the script’s functionality, leading to a reverse shell as the 'pepper' user. This method showcased the impact of omitted input checks and how they can be leveraged in scripted environments .

Disabling the systemctl SUID bit is significant as it addresses a known privilege escalation vulnerability. With the SUID bit enabled, systemctl can be executed with root privileges, allowing attackers to execute arbitrary services as root. This vulnerability provides a straightforward path to gaining root-level access, which is why the report recommends disabling it as a medium priority security measure .

The simpler.py script played a crucial role in lateral movement during the penetration test on Jarvis by allowing command injection due to insufficient input sanitization. The script used an os.system call for its ping function, enabling the penetration tester to inject commands using the $() operator. This facilitated obtaining a shell on the box as the user 'pepper', demonstrating the critical impact of improper input validation in facilitating unauthorized access .

The PHP backdoor file was utilized on Jarvis to achieve remote command execution by writing it to the website via SQLi exploitation. Once deployed, the attacker used curl to send HTTP requests to the backdoor file, which executed system commands on the box. By using nc through the PHP backdoor, a full shell on the target system was achieved, enabling further exploitation and control .

During the enumeration phase, indicators of vulnerability included the ability to break the page by adjusting a parameter in the URL and adding an apostrophe, suggesting a potential SQL injection vulnerability. Additionally, ports 22, 80, and 64999 were found open with an HTTP server running on 64999, and an accessible phpMyAdmin login page was identified, further indicating potential places for deeper probes .

The report suggests mitigating the SQLi vulnerability by implementing input sanitization on the website. This includes rejecting unexpected or potentially malicious characters, such as apostrophes, in input parameters like 'cod'. Inputs should not undergo processing until they are validated to prevent SQLi, which is considered extremely dangerous and easily exploitable .

The primary limitation encountered when using sqlmap was interference from a Web Application Firewall (WAF) or Intrusion Prevention System (IPS), which blocked standard enumeration attempts. This limitation was overcome by using additional sqlmap flags, such as --random-agent, to alter the User Agent string and bypass the WAF, enabling the discovery of the SQLi vulnerability and subsequent data dump of credentials .

The WAF deployed against SQLmap employed a mechanism that detected multiple requests in a short time span targeting the same vulnerable URL and temporarily banned the originating IP. This forced the penetration tester to incorporate strategies, such as using the --random-agent option, to alter the client fingerprint, thereby evading the WAF's pattern recognition and allowing further exploit attempts. This defensive mechanism highlights the importance of employing dynamic response measures in security configurations .

You might also like