Proof-of-concept hostile Meterpreter agent and writeup for CVE-2026-87690, a path traversal in Metasploit's ios_image_gather module leading to operator-level RCE.
Path traversal (CWE-22) in Metasploit Framework's post/apple_ios/gather/ios_image_gather
post-exploitation module: a hostile or tampered "iOS device" (any Meterpreter
session whose agent controls its own protocol responses) achieves an arbitrary
file write on the pentester's workstation, which chains to persistent code
execution as the operator on the next msfconsole launch.
| CVE | CVE-2026-87690 |
| Weakness | CWE-22 (Relative Path Traversal) |
| Affected product | Metasploit Framework, module post/apple_ios/gather/ios_image_gather |
| Impact | Arbitrary file write as the operator -> persistent code execution and an interactive shell as the operator (frequently root) on the pentester's workstation |
| Fix | rapid7/metasploit-framework#21880 (merged into master on 2026-09-14; any framework release built after that date contains the fix) |
Metasploit's post/apple_ios/gather/ios_image_gather module interpolates file
names from a Meterpreter directory listing - data fully controlled by a hostile
or tampered "iOS device" - directly into the local destination path passed to
client.fs.file.download_file() with no sanitization, and the underlying stdapi
sink (lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb,
FileUtils.mkdir_p + File.new(dest,'wb')) writes wherever that path points.
A listing entry such as ../../msfconsole.rc therefore escapes the intended
~/.msf4/loot/<random> directory and overwrites ~/.msf4/msfconsole.rc, a
resource file that every msfconsole invocation automatically executes at
startup (lib/msf/ui/console/driver.rb:196).
A device under attacker control that lures an operator into running this gather
module achieves arbitrary file write as the operator, which - because the
written msfconsole.rc loads a second written file (a Ruby plugin whose
top-level code runs on require) - yields persistent code execution and an
interactive shell as the operator (frequently root) on the pentester's
workstation on the next console launch.
The same traversal was already fixed upstream in the recursive downloader
(stdapi/fs/dir.rb:291-296 scrubs separators), confirming this module's
omission was an oversight; the fix is to apply the identical scrub (or
File.basename) to listing entries before building the local path.
Verified end-to-end against an unmodified framework checkout: a hostile
Meterpreter agent serving the crafted listing caused the unmodified module to
write the plugin and rc, and a subsequent msfconsole -q connected a reverse
shell executing commands as the operator.
Fixed upstream in
rapid7/metasploit-framework#21880:
the module was rewritten to use read_file + store_loot instead of
download_file into a local path built from listing entries, and to skip
./.. directory entries. It also adds a MAX_FILE_SIZE cap (10 MB) before
reading. The PR carries the rn-fix release-notes label; check the framework
release notes for the first weekly release containing it.
| File | Purpose |
|---|---|
ios_hostile_agent.py | The exploit: a minimal, dependency-free hostile Meterpreter agent (the "iOS device") that serves a crafted directory listing and file contents, then catches the resulting shell. |
ios_poc_run.rc | msfconsole resource script that drives the unmodified framework through the vulnerable module. |
ios_hostile_agent.py IS the malicious device: a pure-Python speaker of just
enough of the Meterpreter TLV protocol (XOR'd 32-byte header, staged-payload
stage skip) to pass as a session. When the module lists the photo directory,
the agent returns three entries:
IMG_0001.jpg - a benign cover image (24 bytes).../../poc_shell_plugin.rb - a Ruby plugin whose top-level code spawns a reverse-shell thread back to the agent.../../msfconsole.rc - a single line: load ~/.msf4/poc_shell_plugin.rb.The real, unmodified module downloads each "image" into
~/.msf4/loot/<random6>/; the ../ entries escape it, so the plugin lands at
~/.msf4/poc_shell_plugin.rb and the rc at ~/.msf4/msfconsole.rc. The latter
auto-executes at every msfconsole start, so the next console the operator
opens (any console, in any terminal) loads the plugin, its top-level Ruby runs,
and a shell connects back to the agent's catcher (default port 4466).
Notes:
enumextcmd is deliberately answered empty - a non-empty extension list
trips msf's skip_loading guard and stdapi never loads.LHOST 127.0.0.1).Requirements: a metasploit-framework checkout (pre-fix, i.e. built before 2026-09-14), Python 3 (stdlib only), two terminals.
Terminal 1 (attacker - the hostile "iOS device"):
$ python3 ios_hostile_agent.py
Terminal 2 (victim - the metasploit operator, from the framework directory):
$ ./msfconsole -q -r /path/to/ios_poc_run.rc
The rc starts a handler, waits for the agent, runs the gather module, and exits.
Once the agent reports PAYLOAD DEPLOYED, any new msfconsole the operator
starts fires the payload and the shell arrives at the agent's catcher:
$ ./msfconsole -q
The run leaves a live persistence stub on the operator's box
(~/.msf4/msfconsole.rc + ~/.msf4/poc_shell_plugin.rb). Remove it when done
testing:
$ python3 ios_hostile_agent.py --cleanup
Captured 2026-08-27 against an unmodified framework checkout on loopback.
Terminal 1 (attacker):
$ python3 ios_hostile_agent.py
[agent] shell catcher listening on 0.0.0.0:4466 (fires when the operator starts any new msfconsole)