Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add at rest encryption to Meterpreter payloads #18441

Merged
merged 5 commits into from
Oct 27, 2023

Conversation

sjanusz-r7
Copy link
Contributor

@sjanusz-r7 sjanusz-r7 commented Oct 10, 2023

This PR is requires rapid7/metasploit-payloads#679
The change to client_core.rb is necessary to support encrypted stdapi libraries.
Other changes were made to support encrypted file contents being added to zip/jar/archive files by using ::MetasploitPayloads.read which will handle encrypted/plain-text payloads as #add_files cannot take in a buffer, and we have to resort to calling #add_file for each file with the contents instead.

Verification

  • Start msfconsole
  • Use a payload, for example use payload/python/meterpreter/reverse_tcp
  • Ensure you can get get a session as usual
  • When in irb, check that the payload being read is stored as an encrypted file on disk
    • path = ::MetasploitPayloads.path('meterpreter', 'meterpreter.py')
    • raw_contents = ::File.binread(path); nil
    • raw_contents[0..5] == "msf\x01\x01\x01"
    • decrypted_contents = ::MetasploitPayloads.read('meterpreter', 'meterpreter.py')

@sempervictus
Copy link
Contributor

Is there some place where we can find a bit of conext for the intended use of this functionality

@adfoster-r7 adfoster-r7 changed the title Add encrypted payloads support Add at rest encryption to Meterpreter payloads Oct 13, 2023
@adfoster-r7
Copy link
Contributor

The title was a bit of a misnomer. We're just adding at rest encryption for the Meterpreter payloads on disk, the changes should be transparent for the average user

@sjanusz-r7 sjanusz-r7 force-pushed the add-encrypted-payloads-support branch from 2e6bea0 to b08eca6 Compare October 13, 2023 13:45
@sjanusz-r7 sjanusz-r7 marked this pull request as ready for review October 13, 2023 13:56
@sempervictus
Copy link
Contributor

Pesky AVs not appreciating users having the files on their machines?
Might be interesting to have runtime decryption on the other side for conditional loading/clearing of extensions when not in use to an encrypted read-only "inert code cave" (or just from remote again) for reloading on-demand. Might help reduce our runtime fingerprints in-memory.

@sempervictus
Copy link
Contributor

Is there a facility for dumping the raw DLLs? Other tools might want access to them...

@sjanusz-r7 sjanusz-r7 force-pushed the add-encrypted-payloads-support branch 2 times, most recently from c43e9bb to 63e9a29 Compare October 16, 2023 12:33
@sjanusz-r7 sjanusz-r7 force-pushed the add-encrypted-payloads-support branch from 63e9a29 to c73e815 Compare October 24, 2023 14:46
Comment on lines +387 to +388
encrypted_dll = ::File.binread(library_path)
dll = ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_dll)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
encrypted_dll = ::File.binread(library_path)
dll = ::MetasploitPayloads::Crypto.decrypt(ciphertext: encrypted_dll)
dll = ::File.binread(library_path)

@adfoster-r7 adfoster-r7 merged commit 3b4302d into rapid7:master Oct 27, 2023
55 checks passed
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Oct 27, 2023

Release Notes

Add at rest encryption to Meterpreter payloads on the Metasploit host machine's file system

@dwelch-r7 dwelch-r7 added the rn-enhancement release notes enhancement label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants