Skip to content

Fix analyze_db size bypass for dynamic payloads - #21743

Open
keyanskv wants to merge 1 commit into
rapid7:masterfrom
keyanskv:fix-analyze-db-dynamic-payload-size
Open

Fix analyze_db size bypass for dynamic payloads#21743
keyanskv wants to merge 1 commit into
rapid7:masterfrom
keyanskv:fix-analyze-db-dynamic-payload-size

Conversation

@keyanskv

@keyanskv keyanskv commented Aug 2, 2026

Copy link
Copy Markdown

Adds payload_cached_size to module metadata cache to allow is_payload_compatible? to correctly reject large payloads with dynamic sizes.

Description

This change adds payload_cached_size to the module metadata cache so that is_payload_compatible? can make payload size decisions without loading the payload module.

Previously, payloads with dynamic sizes could not always be evaluated correctly from cached metadata alone. As a result, oversized payloads could pass compatibility checks because the cached metadata did not include the information needed to determine their effective size.

With this change:

  • payload_cached_size is stored in the module metadata cache.

  • is_payload_compatible? uses the cached size information when performing compatibility checks.

  • Dynamic payloads with cached size metadata are correctly rejected when they exceed the exploit's available payload space.

  • Existing behavior for static payloads remains unchanged.

Related Issue: None


Breaking Changes

None.


Reviewer Notes

The primary implementation is the addition of payload_cached_size to the module metadata cache and updating payload compatibility checks to consume the cached value.

The accompanying RSpec tests verify:

  • Msf::Payload.cached_size behavior.

  • Payload cached size metadata generation and validation.

  • Handling of static and dynamic payloads.

  • Cached size override generation for staged payloads.


Verification Steps

  1. Build the project and install dependencies.

  2. Apply this patch.

  3. Run:

bundle exec rspec spec/lib/msf/core/payload_spec.rb

Expected result:

  • 12 examples

  • 0 failures

  1. Run:

bundle exec rspec spec/lib/msf/util/payload_cached_size_spec.rb

Expected result:

  • 16 examples

  • 0 failures

  1. Verify that payload metadata now includes payload_cached_size.

  2. Verify that is_payload_compatible? correctly rejects payloads whose cached size exceeds the available payload space, including dynamically-sized payloads.


Test Evidence

Test 1

bundle exec rspec spec/lib/msf/core/payload_spec.rb

Finished in 0.64117 seconds (files took 6.53 seconds to load)
12 examples, 0 failures

Coverage report generated for RSpec to coverage.
Line Coverage: 18.54% (2683 / 14471)

Test 2

bundle exec rspec spec/lib/msf/util/payload_cached_size_spec.rb

Finished in 0.468 seconds (files took 5.94 seconds to load)
16 examples, 0 failures

Coverage report generated for RSpec to coverage.
Line Coverage: 16.86% (2238 / 13275)


Environment

Field Details
Operating System Ubuntu 24.04.4 LTS
Ruby Version Ruby 3.2.x
PostgreSQL PostgreSQL 16
Target Software/Hardware Metasploit Framework (master branch)
Docker Image / Vagrant Setup Not used

AI Usage Disclosure

ChatGPT was used to assist with drafting the pull request description and improving documentation. The implementation, testing, debugging, and validation of the code were completed by the contributor.


Pre-Submission Checklist

  • No sensitive information (credentials, API keys, IP addresses, or secrets) included

  • Tested on the target environment specified above

  • Included RSpec tests for library changes

  • Read the CONTRIBUTING.md and module acceptance guidelines

  • Included a corresponding documentation markdown file (Not applicable — library change only)

Screenshot from 2026-08-02 19-05-55 Screenshot from 2026-08-02 19-06-15

Adds payload_cached_size to module metadata cache to allow is_payload_compatible? to correctly reject large payloads with dynamic sizes.

@keyanskv keyanskv left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Maintainers,

I have reviewed the proposed changes in this pull request and believe they are ready for GitHub Actions to run. Could a maintainer please review the changes and approve the pending workflow execution?

Thank you for your time and assistance.

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