Skip to content

Fix exec payload size crash - #21424

Merged
adfoster-r7 merged 3 commits into
rapid7:masterfrom
sjanusz-r7:fix-exec-payload-size-crash
May 8, 2026
Merged

adfoster-r7 merged 3 commits into
rapid7:masterfrom
sjanusz-r7:fix-exec-payload-size-crash

Conversation

@sjanusz-r7

@sjanusz-r7 sjanusz-r7 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

This PR re-enables the recently-migrated CI payload cache size specs.

Follow on from #21411

This PR uses a custom rex-text branch from this PR: rapid7/rex-text#76

This PR fixes issues in modules that use custom copy-pasted logic for converting a string to hex.
This logic was causing issues when the string was empty. It was resulting in broken assembly:

db #{server_uri}, 0x00

can result in

db , 0x00

Verification

  • bundle exec rspec spec/modules/payloads_spec.rb

@sjanusz-r7 sjanusz-r7 changed the title Re-enabled payload cache size CI specs Fix exec payload size crash May 8, 2026
@sjanusz-r7
sjanusz-r7 force-pushed the fix-exec-payload-size-crash branch 2 times, most recently from 15d30c7 to 6afe625 Compare May 8, 2026 15:39
@sjanusz-r7
sjanusz-r7 force-pushed the fix-exec-payload-size-crash branch from 6afe625 to 79b0fd6 Compare May 8, 2026 15:41
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Metasploit Kanban May 8, 2026
@adfoster-r7
adfoster-r7 merged commit 33754fd into rapid7:master May 8, 2026
59 of 60 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metasploit Kanban May 8, 2026
sjanusz-r7 pushed a commit that referenced this pull request May 20, 2026
Replaces all `Rex::Text.to_hex_cstring` calls in payload modules with
the new `Metasm::Shellcode.define_data` and `Metasm::Shellcode.define_cstring`
class methods, which emit full `db` directives (string-literal form
for printable runs, hex tokens otherwise) and are a better home for
assembly-source generation than rex-text.

The 9 affected modules are:
  - modules/payloads/singles/linux/x64/exec.rb
  - modules/payloads/singles/linux/x64/set_hostname.rb
  - modules/payloads/singles/linux/x86/exec.rb
  - modules/payloads/singles/linux/x86/read_file.rb
  - modules/payloads/singles/osx/x64/shell_reverse_tcp.rb
  - modules/payloads/singles/windows/download_exec.rb
  - modules/payloads/singles/windows/messagebox.rb
  - modules/payloads/singles/windows/x64/download_exec.rb
  - modules/payloads/singles/windows/x64/messagebox.rb

Surrounding heredoc templates have the `db ` prefix removed since the
new methods include it. Where a `db` directive previously combined an
interpolated byte list with an additional literal (e.g. a trailing
sentinel byte or `"cmd /c "`), the directive is split into adjacent
`db` lines, which assemble to the same contiguous bytes.

Verified by re-running the `payload_cached_size_is_consistent` shared
examples for each affected payload (30 examples, 0 failures), which
were the tests originally fixed by #21424.
h00die pushed a commit to h00die/metasploit-framework that referenced this pull request May 27, 2026
Replaces all `Rex::Text.to_hex_cstring` calls in payload modules with
the new `Metasm::Shellcode.define_data` and `Metasm::Shellcode.define_cstring`
class methods, which emit full `db` directives (string-literal form
for printable runs, hex tokens otherwise) and are a better home for
assembly-source generation than rex-text.

The 9 affected modules are:
  - modules/payloads/singles/linux/x64/exec.rb
  - modules/payloads/singles/linux/x64/set_hostname.rb
  - modules/payloads/singles/linux/x86/exec.rb
  - modules/payloads/singles/linux/x86/read_file.rb
  - modules/payloads/singles/osx/x64/shell_reverse_tcp.rb
  - modules/payloads/singles/windows/download_exec.rb
  - modules/payloads/singles/windows/messagebox.rb
  - modules/payloads/singles/windows/x64/download_exec.rb
  - modules/payloads/singles/windows/x64/messagebox.rb

Surrounding heredoc templates have the `db ` prefix removed since the
new methods include it. Where a `db` directive previously combined an
interpolated byte list with an additional literal (e.g. a trailing
sentinel byte or `"cmd /c "`), the directive is split into adjacent
`db` lines, which assemble to the same contiguous bytes.

Verified by re-running the `payload_cached_size_is_consistent` shared
examples for each affected payload (30 examples, 0 failures), which
were the tests originally fixed by rapid7#21424.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rn-no-release-notes no release notes

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants