Skip to content

Fix SNMP MIB eval/shell injection, ZIP path traversal, and RPC pre-auth resource exhaustion - #21869

Open
prithvee07 wants to merge 3 commits into
rapid7:masterfrom
prithvee07:fix/security-scan-findings
Open

Fix SNMP MIB eval/shell injection, ZIP path traversal, and RPC pre-auth resource exhaustion#21869
prithvee07 wants to merge 3 commits into
rapid7:masterfrom
prithvee07:fix/security-scan-findings

Conversation

@prithvee07

Copy link
Copy Markdown

Summary

Fixes three medium-severity findings from an internal security scan of this repo:

  • SNMP MIB import (CWE-78, CWE-95): SNMP::MIB.import_module interpolated a caller-controlled filename into a shell command and eval'd the smidump converter output. Now runs smidump via Open3.popen3 with an argv array and parses the output with a new SNMP::PythonLiteralParser instead of eval.
  • ZIP extraction path traversal (CWE-22): is_child_of? used a raw start_with? string check, so a sibling directory like <tmp>_evil/ passed containment. Now compares expanded paths for exact equality or requires the extraction root followed by a path separator.
  • RPC pre-auth resource exhaustion (CWE-400): msfrpcd decoded the full unauthenticated request body with MessagePack.unpack before any size limit or auth check. Added a 10MB ceiling enforced in the HTTP packet parser (before the body is buffered) and re-checked in Msf::RPC::Service#process before unpacking.

Each fix has an accompanying test (spec/lib/snmp/mib_spec.rb, spec/support/shared/examples/msf/db_manager/import/metasploit_framework/zip.rb, spec/lib/rex/proto/http/packet_spec.rb, spec/lib/msf/core/rpc/v10/service_spec.rb).

Test plan

  • Verified SNMP::PythonLiteralParser directly against real MIB-shaped input and injected backtick/method-call payloads that the previous eval would have executed
  • Verified is_child_of? directly: accepts root/descendants, rejects sibling-prefix paths
  • Verified by code inspection that the RPC/HTTP size guard runs before MessagePack.unpack
  • Full bundle exec rspec run (blocked in dev environment: no network, vendored gems incomplete — CI should run the added specs)

🤖 Generated with Claude Code

https://claude.ai/code/session_01YABLbiZQ77C8DtgjjfmR3R

prithvee07 and others added 3 commits September 3, 2026 18:55
SNMP::MIB.import_module interpolated a caller-controlled MIB filename
into a shell command and then eval'd the smidump converter output as
Ruby, letting an attacker-influenced MIB file execute arbitrary shell
and Ruby code. Run smidump via Open3.popen3 with an argv array instead
of a shell string, and replace the eval with a schema-validating
parser (SNMP::PythonLiteralParser) for the primitive Python-literal
subset smidump emits.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YABLbiZQ77C8DtgjjfmR3R
is_child_of? authorized extraction destinations with a raw
target.start_with?(target_dir) string check, so a sibling directory
whose name merely starts with the extraction root's name (e.g.
"<tmp>_evil/file") passed containment even though it isn't a
descendant. Compare expanded paths for exact equality or require the
extraction root followed by a path separator.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YABLbiZQ77C8DtgjjfmR3R
msfrpcd passed the full unauthenticated HTTP request body to
MessagePack.unpack before any size limit or token authentication was
applied, letting an unauthenticated client force large
allocation/parsing work on the default 0.0.0.0 listener. Enforce a
10MB ceiling in the HTTP packet parser (checked against Content-Length
before the body is buffered, and against the decoded chunked body
size) and re-check body size in Msf::RPC::Service#process before
handing it to MessagePack.unpack as defense in depth.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YABLbiZQ77C8DtgjjfmR3R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant