Skip to content

Fix flakey macho test failures#296

Merged
smcintyre-r7 merged 1 commit into
rapid7:6.5from
adfoster-r7:fix-flakey-macho-test-failures
Jul 8, 2026
Merged

Fix flakey macho test failures#296
smcintyre-r7 merged 1 commit into
rapid7:6.5from
adfoster-r7:fix-flakey-macho-test-failures

Conversation

@adfoster-r7

@adfoster-r7 adfoster-r7 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The CI tests showed a ~6% chance of OSX payloads breaking:

bundle exec rspec ./spec/modules/payloads_spec.rb

Overriding user environment variable 'OPENSSL_CONF' to enable legacy functions.
Run options:
  include {:focus=>true}
  exclude {:acceptance=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 63326
Acceptance::DatastoreFormatting .......
modules/payloads ..............................................................................................................................................................................................................................................................................................................................................................................F.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

  1) modules/payloads osx/aarch64/meterpreter_reverse_https it should behave like payload cached size is consistent osx/aarch64/meterpreter_reverse_https can be instantiated and generated
     Failure/Error: raise "Invalid kSecCodeMagicEmbeddedSignature magic for macho" if s_magic != 0xfade0cc0

     RuntimeError:
       Invalid kSecCodeMagicEmbeddedSignature magic for macho
     Shared Example Group: "payload cached size is consistent" called from ./spec/modules/payloads_spec.rb:2536
     # ./lib/msf/core/payload/macho.rb:66:in `sign'
     # ./modules/payloads/singles/osx/aarch64/meterpreter_reverse_https.rb:41:in `generate'
     # ./lib/msf/core/payload.rb:309:in `generate_complete'
     # ./lib/msf/core/encoded_payload.rb:118:in `generate_raw'
     # ./lib/msf/core/encoded_payload.rb:74:in `generate'
     # ./lib/msf/core/encoded_payload.rb:24:in `create'
     # ./lib/msf/base/simple/payload.rb:52:in `generate_simple'
     # ./lib/msf/base/simple/payload.rb:139:in `generate_simple'
     # ./lib/msf/util/payload_cached_size.rb:174:in `compute_cached_size'

The TL:DR being:

Before: mettle embedded the config block with String#sub(pattern, replacement), and Ruby interprets backslash sequences (\0, \1, etc.) in the string replacement — so random config bytes containing \+char got expanded or dropped, changing the binary's size and shifting the Mach-O code signature out of place, which broke signing.

The fix uses the block form sub(pattern) { replacement }, which inserts the bytes verbatim without interpreting backreferences, so the binary keeps its exact size and the signature stays valid.

@smcintyre-r7

Copy link
Copy Markdown
Contributor

The changes make sense and the tests pretty clearly illustrate what the issue is. Verified they pass with the changes and the tests fail without the changes to spec/metasploit_payloads/mettle/config_embedding_spec.rb.

@smcintyre-r7
smcintyre-r7 merged commit 93fd230 into rapid7:6.5 Jul 8, 2026
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants