Skip to content

Apex -- Proving Grounds (write-up)

Difficulty: Hard Box: Apex (Proving Grounds) Author: dsec Date: 2024-06-24


TL;DR

Exploited OpenEMR via an authenticated file read vulnerability to extract MySQL credentials from sqlconf.php, cracked the admin password hash from the database, and escalated via password reuse to root.


Enumeration

Nmap results

Web enum

Found OpenEMR:

OpenEMR Features PDF

Searched GitHub for password handling:

repo:openemr/openemr "$pass"

GitHub search

feroxbuster -u http://192.168.145.145/openemr -w /usr/share/wordlists/dirb/common.txt -n -x php

Feroxbuster

Directory listing

Admin panel

  • Requires auth.

Auth required


Exploitation

Exploit search

Exploit details

Running exploit

  • Unedited script works but fails to get sqlconf.

sqlconf fail

PHPSESSID needed

  • Need PHPSESSID.

Session cookie

  • otgra9kr3eo0gcteikasu3ji00

Script still fails:

Script fail

Had to edit the clipboard and read functions in the exploit:

Original functions

Changed to:

Modified functions

  • Changed data variable in paste_clipboard function to "path=Documents" because this is the folder we have access to within filemanager.
  • Changed url_path variable in read_file function to %s/filemanager/Documents/%s.
  • The path for OpenEMR is under /var/www instead of /var/www/html.
  • The copied sqlconf.php can only be viewed via the SMB share since PHP files get processed server-side.

SMB share view

sqlconf.php contents

MySQL creds

  • openemr:C78maEQUIEuQ

SSL error

  • SSL error, had to use --ssl=0.
mysql --ssl=0 -u openemr -p -h 192.168.145.145

MySQL access

Database dump

Hash found

  • Cracked without salt.

Cracked password


Privilege escalation

Root via password reuse

  • Password reuse to root.

Lessons & takeaways

  • OpenEMR exploits often need tweaking -- the file paths and session handling vary between installations
  • When PHP files are copied via exploits, view them through SMB or other non-PHP-processing means
  • Always try --ssl=0 if MySQL connections fail with SSL errors
  • Password reuse between application databases and system accounts is common