๐งงEnvironment
https://app.hackthebox.com/machines/Environment

Used htbscan script for Recon and checking result of dir/dns/vhost
Recon
Website

Login-Page
Our recon script shows us a login page

User
Laravel
Our feroxbuster-scan shows us a upload page:

Laravel Version Identified:
Laravel 11.30.0PHP Version:
8.2.28APP_DEBUG=Truesince we can see the stracktrace

detecting environment=preprod
We can bypass the Login-Page by adding /login?--env=preprod to the url while intercepting the login POST-Request. https://github.com/laravel/framework/security/advisories/GHSA-gv7v-rgg6-548h
Reverse-Shell
We are getting redirected to the dashboad:

Now we gonna upload a webshell as userpicture but we need to bypass some detection.


Starting a listener and getting a reverse shell:
And we get our userflag:
Root
Continuing in our shell we download the gpg file
Ctrl-C on Attacker-Side if you think the file has been transfered, it is quite small should only be some seconds.
Same for the keys
move you gnupg-folder back afterwards:
Login in using that credentials
Checking what we can do and checking the scripts
The script /usr/bin/systeminfo is a bash script run as root, and it uses unsanitized system commands like dmesg, ss, mount, and column.
This means you can do a PATH hijack attack, because sudo will preserve env_keep+="ENV BASH_ENV"

Hijacking Path with BASH_ENV
Hereโs how:
/tmp/root.shHijack: Theecho 'echo "BASH_ENV sourced as root!"; id; /bin/bash -p' > /tmp/root.shcommand creates a new script at/tmp/root.sh. The contents of this file:
The first line will print a message indicating that
BASH_ENVhas been sourced.The second line (
id) will show the user ID, which should showrootwhen executed with elevated privileges.The third line (
/bin/bash -p) will start a new interactive root shell with the-pflag, which preserves the environment and avoids resetting some environment variables that may give you additional access.
Exploiting with
env -iandsudo:
The command:
env -iruns a command with a clean environment (i.e., clears all environment variables except those explicitly passed).BASH_ENV=/tmp/root.shsets theBASH_ENVvariable to point to the malicious script/tmp/root.sh.The
PATHvariable is set to the default systemPATH, which is fine for running standard commands, includingsudoand/usr/bin/systeminfo.sudoruns thesysteminfoscript with root privileges, but now theBASH_ENVis set to/tmp/root.sh, so the malicious script is sourced, and the root shell is spawned.
Why This Works
sudodoes not resetBASH_ENV: When you runsudo, it typically does not reset theBASH_ENVvariable unless explicitly configured to do so in the sudoers file. This allows you to control the environment in whichsysteminfois executed, giving you the ability to inject your own commands as root.Bypass Restrictions: The use of
env -ito clear the environment variables except forBASH_ENVandPATHis crucial here. It prevents any other environment variables that might be present from interfering with your exploit.
Last updated