Skip to content

Add TLV encryption support to Python Meterpreter #13432

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

Merged
merged 12 commits into from
Jun 16, 2020

Conversation

OJ
Copy link
Contributor

@OJ OJ commented May 11, 2020

Dependencies

Details

This PR aims to bring us another step closer to having TLV encryption support in all versions of Meterpreter. After this, Java/Android is the only beast that's left.

This PR contains supporting code that allows Python Meterpreter to function with TLV encryption. This was not a simple, pleasant nor easy thing. The approach that I have gone with here is up for discussion, and so I hope to get some interesting feedback and constructive criticism (imma lookin' at you @smcintyre-r7!).

The Pain of Python

I will keep my opinions of Python out of this because it's not relevant and it'd be totally indiscrete and unprofessional let people know that I think Python is a steaming pile of dynamic horse manure. So I won't say that, and instead I'll focus on the issues at hand.

When Python Meterp runs it doesn't know anything at all about the environment it's spinning up in. It could be 2.4, 2.7, 3.1, 3.7 ... who knows! It also doesn't know which operating system it's on, nor does it know which libraries are installed and available. This poses all kinds of issues in general, but when it comes to crypto, things are worse.

Python has a stack of crypto libraries available that can be installed out of bad. Some libs might even exist by default in more recent intallations. Unfortunately, we are not in a position to assume that any of them area installed and available for us to use. As a result, we need to write code that provides an implementation that will work no matter what.

This means that there's not point in even trying to use them if they're present, because our own code has to work anyway.

So what do we do? Well, we have to bring our own to the party! This code includes the following:

  • A very simple DER parser that contains a few assumptions. This parser is able to parse PEM and DER files that come from Metasploit. The code will parse the public key into its modulus and exponent components.
  • An implementation of RSA encryption. When we've generated an AES key, we have to encrypt that to send it back to MSF, but we never need to decrypt anything with a private key. This means we can get away with implementing encryption only. The mod/esp from the DER parser can be passed in to this. Right now, we only encrypt a single "block", which is more than enough for the 256 bit key we've generated. This isn't intended to be used for anything more than key exchange.
  • A very specific implementation of AES in CBC mode (both encryption and decryption). No other modes are included, because they're not used.

I've split these changes up into separate chunks for a few reasons. The code for handling the packets and whatnot lives in meterpreter.py with the rest of the stuff. That's where it belongs. I didn't want to include the AES/DER/RSA stuff directly in the same file because:

  • They're obnoxious and will get in the way.
  • I wanted to have each of them put in their own namespaces/modules so that they wouldn't interfere with anything that might appear in the main/global module/namespace.

In order to support this, I modified the Meterpreter loader to patch this stuff in on the fly when the payload is generated. This means Meterpreter remains clean as a module, but MSF is responsible for inserting it. Meterpreter will call met_aes_encrypt, met_aes_decrypt and met_rsa_encrypt functions when required. MSF inserts those functions and abstracts how they're implemented. There are advantages and disadvantages to this approach, and I'm happy to hear some views as to how this might be improved. I favoured this because:

  • The python encryption code can be stored in Ruby, meaning that the meterpreter libs don't have to be updated if the encryption implementation changes.
  • Ruby can change the way the files are loaded and managed outside of Meterp.
  • The generated code is base64 encoded, and then inserted into the script. This stuff is hot-loaded into custom namespaces (met_rsa and met_aes) so that they're functionally separate.

This means we can still modify raw python code in MSF, and all the wiring handles the process of getting it inserted cleanly into a separate namespace. We couldn't do this very easily directly in meterpreter.py

EDIT -- 12th May 2020

I changed a couple of things:

  • The encryption libs are compressed.
  • After compressing, i thought "why does this not happen with the stagers?" So they're compressed now too. This reduced the size of the stages quite a bit. The stagers now use zlib and base64 to pull the stage apart before executing it. Assuming that these libs are in all the pythons, this should be good to go!

Full disclosure

Yes, I wrote this code. I used a bunch of other resources as references, and there was some copy/pasta. I minimized the code manually to reduce the size on the wire, clearly at the cost of readability. I know you should never write your own crypto. Technically I didn't, I just wrote my own implementation of existing crypto. Yes, this is probably as bad.

Verification

  • Pull in the changes from the Payloads repo.
  • Generate payloads.
  • Set up handlers.
  • Kick off payloads.
  • Validate that the sessions are now encrypted.
  • Validate that the messages that are sent include encrypted AES keys rather than plain text (this can be a bit painful, but wireshark is your friend).
  • Validate that python 3 and 2 both work.
  • Validate that it works on Windows.
  • Validate that it works on Linux.
  • Validate that it works on OSX.

Note that I have seen issues with Python3 and resilient transports. I will log a bug about this, but at the moment it's not a result of the code changes in this PR.

Sample Run

Sample Run

Things to do

When the PEM to DER PR is landed, this stuff needs to be updated so that Meterp just reads the DER off the wire instead of converting from PEM to DER first.

Copy link
Contributor

@smcintyre-r7 smcintyre-r7 left a comment

Choose a reason for hiding this comment

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

The use of var b overwrites the base64 module from the outer namespace in a couple of functions. It's also a little confusing in general due to it's use as a string prefix. Also, I don't think the b string prefix to define byte-literals works on Python 2.5.

This forces python to use zlib and base64 when transferring the stages
around. In my testing this dropped the stage for reverse_tcp from 111801
bytes to 36200 bytes (while still including the encryption libs).
@OJ
Copy link
Contributor Author

OJ commented May 12, 2020

Update from the last commit. From:

[*] Sending stage (111801 bytes) ...

To:

[*] Sending stage (36200 bytes) ...

@OJ
Copy link
Contributor Author

OJ commented May 12, 2020

The use of var b overwrites the base64 module from the outer namespace in a couple of functions. It's also a little confusing in general due to it's use as a string prefix. Also, I don't think the b string prefix to define byte-literals works on Python 2.5.

  1. Aye I did see that, misread at first. I shall fix that up.
  2. Didn't know that :) Thanks. What should I be doing instead? using bytes() ?

@OJ
Copy link
Contributor Author

OJ commented May 19, 2020

I'll update the payload cache sizes when the Metasploit Payloads PR lands.

@smcintyre-r7 smcintyre-r7 self-assigned this Jun 4, 2020
@smcintyre-r7
Copy link
Contributor

I submitted OJ#23 to you for some changes around Python version compatibility. There were some issues with older 2.x versions and the b prefix.

@OJ
Copy link
Contributor Author

OJ commented Jun 6, 2020

Thank you @smcintyre-r7 I'll get it this soon!

@bwatters-r7 bwatters-r7 added the msf6 PRs that need to be landed into the msf 6 branch label Jun 8, 2020
@smcintyre-r7 smcintyre-r7 changed the base branch from master to 6.x June 11, 2020 14:39
@smcintyre-r7
Copy link
Contributor

Tested this once more with the current 6.x changes at this time. Everything still looks good so I'm going to look at updating the payload sizes and then landing this assuming I'm successful.

To test all the versions I used a simple harness around pyenv.

Test results

The one failure you'll see in here is from Python 2.4 which isn't supported so that failure is expected.

Meterpreter output:

msf5 payload(python/meterpreter/reverse_tcp) > to_handler 
[*] Payload Handler Started as Job 1
msf5 payload(python/meterpreter/reverse_tcp) > 
[*] Started reverse TCP handler on 192.168.159.128:4444 
WARNING: Local file /home/smcintyre/.msf4/payloads/meterpreter/meterpreter.py is being used
WARNING: Local files may be incompatible with the Metasploit Framework
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] 192.168.159.128 - Meterpreter session 1 closed.  Reason: Died
[*] Meterpreter session 1 opened (192.168.159.128:4444 -> 192.168.159.128:58762) at 2020-06-11 10:36:43 -0400
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 2 opened (192.168.159.128:4444 -> 192.168.159.128:58768) at 2020-06-11 10:36:48 -0400
WARNING: Local file /home/smcintyre/.msf4/payloads/meterpreter/ext_server_stdapi.py is being used
[*] Session ID 2 (192.168.159.128:4444 -> 192.168.159.128:58768) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 2
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 2
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 3 opened (192.168.159.128:4444 -> 192.168.159.128:58770) at 2020-06-11 10:36:53 -0400
[*] Session ID 3 (192.168.159.128:4444 -> 192.168.159.128:58770) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 3
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 3
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 4 opened (192.168.159.128:4444 -> 192.168.159.128:58774) at 2020-06-11 10:36:58 -0400
[*] Session ID 4 (192.168.159.128:4444 -> 192.168.159.128:58774) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 4
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 4
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 5 opened (192.168.159.128:4444 -> 192.168.159.128:58778) at 2020-06-11 10:37:03 -0400
[*] Session ID 5 (192.168.159.128:4444 -> 192.168.159.128:58778) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 5
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 5
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 6 opened (192.168.159.128:4444 -> 192.168.159.128:58782) at 2020-06-11 10:37:08 -0400
[*] Session ID 6 (192.168.159.128:4444 -> 192.168.159.128:58782) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 6
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 6
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 7 opened (192.168.159.128:4444 -> 192.168.159.128:58786) at 2020-06-11 10:37:13 -0400
[*] Session ID 7 (192.168.159.128:4444 -> 192.168.159.128:58786) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 7
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 7
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 8 opened (192.168.159.128:4444 -> 192.168.159.128:58788) at 2020-06-11 10:37:18 -0400
[*] Session ID 8 (192.168.159.128:4444 -> 192.168.159.128:58788) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 8
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 8
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 9 opened (192.168.159.128:4444 -> 192.168.159.128:58790) at 2020-06-11 10:37:24 -0400
[*] Session ID 9 (192.168.159.128:4444 -> 192.168.159.128:58790) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 9
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 9
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39204 bytes) to 192.168.159.128
[*] Meterpreter session 10 opened (192.168.159.128:4444 -> 192.168.159.128:58792) at 2020-06-11 10:37:29 -0400
[*] Session ID 10 (192.168.159.128:4444 -> 192.168.159.128:58792) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 10
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 10
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
[*] Sending stage (39200 bytes) to 192.168.159.128
[*] Meterpreter session 11 opened (192.168.159.128:4444 -> 192.168.159.128:58794) at 2020-06-11 10:37:34 -0400
[*] Session ID 11 (192.168.159.128:4444 -> 192.168.159.128:58794) processing AutoRunScript '/tmp/meterpreter.rc'
[*] Processing /tmp/meterpreter.rc for ERB directives.
resource (/tmp/meterpreter.rc)> getuid
Server username: smcintyre
resource (/tmp/meterpreter.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 5.6.15-300.fc32.x86_64 #1 SMP Fri May 29 14:23:59 UTC 2020
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
resource (/tmp/meterpreter.rc)> run post/test/meterpreter
[*] Running against session 11
[*] Session type is meterpreter and platform is linux
[+] should return its own process id
[+] should return a list of processes
[+] should return a user id
[+] should return a sysinfo Hash
[+] should return network interfaces
[+] should have an interface that matches session_host
[-] FAILED: should return network routes
[-] Exception: Rex::Post::Meterpreter::RequestError : 1022: Operation failed: Unknown error
[+] should return the proper directory separator
[+] should return the current working directory
[+] should list files in the current directory
[+] should stat a directory
[+] should create and remove a dir
[+] should change directories
[+] should create and remove files
[+] should upload a file
[+] should move files
[+] should copy files
[+] should do md5 and sha1 of files
[*] Passed: 18; Failed: 0
resource (/tmp/meterpreter.rc)> run post/test/file
[*] Running against session 11
[*] Session type is meterpreter and platform is linux
[+] should write binary data
[+] should read the binary data we just wrote
[+] should delete binary files
[+] should append binary data
[+] should test for file existence
[+] should test for directory existence
[+] should create text files
[+] should read the text we just wrote
[+] should append text files
[+] should delete text files
[+] should move files
[*] Passed: 11; Failed: 0
sessions -V

Active sessions
===============

  Id  Name  Type                      Information                        Connection
  --  ----  ----                      -----------                        ----------
  2         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58768 (192.168.159.128)
  3         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58770 (192.168.159.128)
  4         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58774 (192.168.159.128)
  5         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58778 (192.168.159.128)
  6         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58782 (192.168.159.128)
  7         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58786 (192.168.159.128)
  8         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58788 (192.168.159.128)
  9         meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58790 (192.168.159.128)
  10        meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58792 (192.168.159.128)
  11        meterpreter python/linux  smcintyre @ localhost.localdomain  192.168.159.128:4444 -> 192.168.159.128:58794 (192.168.159.128)

msf5 payload(python/meterpreter/reverse_tcp) > sessions -v

Active sessions
===============

  Session ID: 2
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58768 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: d08f019398d6bf01/python=20/linux=6/2020-06-11T14:36:48Z
     CheckIn: 6s ago @ 2020-06-11 10:37:51 -0400
  Registered: No

  Session ID: 3
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58770 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: 48e181f8a8ed6b81/python=20/linux=6/2020-06-11T14:36:53Z
     CheckIn: 1s ago @ 2020-06-11 10:37:56 -0400
  Registered: No

  Session ID: 4
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58774 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: f5c0bfbc8c1aac46/python=20/linux=6/2020-06-11T14:36:58Z
     CheckIn: 57s ago @ 2020-06-11 10:37:00 -0400
  Registered: No

  Session ID: 5
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58778 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: 3ee49598da164ed9/python=20/linux=6/2020-06-11T14:37:03Z
     CheckIn: 51s ago @ 2020-06-11 10:37:06 -0400
  Registered: No

  Session ID: 6
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58782 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: 635eb5ab8e070731/python=20/linux=6/2020-06-11T14:37:08Z
     CheckIn: 46s ago @ 2020-06-11 10:37:11 -0400
  Registered: No

  Session ID: 7
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58786 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: 8303e3360eb5dbf6/python=20/linux=6/2020-06-11T14:37:13Z
     CheckIn: 41s ago @ 2020-06-11 10:37:16 -0400
  Registered: No

  Session ID: 8
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58788 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: cef4c3a9fb7ec6e6/python=20/linux=6/2020-06-11T14:37:18Z
     CheckIn: 35s ago @ 2020-06-11 10:37:22 -0400
  Registered: No

  Session ID: 9
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58790 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: 7318b5426644ea50/python=20/linux=6/2020-06-11T14:37:24Z
     CheckIn: 30s ago @ 2020-06-11 10:37:27 -0400
  Registered: No

  Session ID: 10
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58792 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: 0fb162d6e41f0808/python=20/linux=6/2020-06-11T14:37:29Z
     CheckIn: 25s ago @ 2020-06-11 10:37:32 -0400
  Registered: No

  Session ID: 11
        Name: 
        Type: meterpreter linux
        Info: smcintyre @ localhost.localdomain
      Tunnel: 192.168.159.128:4444 -> 192.168.159.128:58794 (192.168.159.128)
         Via: exploit/multi/handler
   Encrypted: true
        UUID: ad5347993f3f693f/python=20/linux=6/2020-06-11T14:37:34Z
     CheckIn: 20s ago @ 2020-06-11 10:37:37 -0400
  Registered: No



msf5 payload(python/meterpreter/reverse_tcp) >

Test harness output:

[*] [2.4.6  ] Running...
[-] [2.4.6  ] Status: FAILED WITH STATUS 1
[*] [2.5.6  ] Running...
[+] [2.5.6  ] Status: SUCCESSFUL
[*] [2.6.9  ] Running...
[+] [2.6.9  ] Status: SUCCESSFUL
[*] [2.7.17 ] Running...
[+] [2.7.17 ] Status: SUCCESSFUL
[*] [3.1.5  ] Running...
[+] [3.1.5  ] Status: SUCCESSFUL
[*] [3.2.6  ] Running...
[+] [3.2.6  ] Status: SUCCESSFUL
[*] [3.4.10 ] Running...
[+] [3.4.10 ] Status: SUCCESSFUL
[*] [3.5.9  ] Running...
[+] [3.5.9  ] Status: SUCCESSFUL
[*] [3.6.10 ] Running...
[+] [3.6.10 ] Status: SUCCESSFUL
[*] [3.7.7  ] Running...
[+] [3.7.7  ] Status: SUCCESSFUL
[*] [3.8.2  ] Running...
[+] [3.8.2  ] Status: SUCCESSFUL

@smcintyre-r7
Copy link
Contributor

I missed a bug on my first pass that surfaced as I was doing a last minute check before landing this. The issue was the stage being double encoded which broke the unstaged payloads. Fix proposed in OJ#24. With that sorted out I should be able to land this. Luckily it's framework side so the payloads build is just fine.

@smcintyre-r7 smcintyre-r7 merged commit 012e152 into rapid7:6.x Jun 16, 2020
@smcintyre-r7
Copy link
Contributor

Landed after one more quick test in the 6.x branch. Checked both a staged and an unstaged payload to ensure they were both functioning and encrypted.

Bumped the payloads gem and updated the cached sizes in 4ce610e. Thanks @OJ !

@smcintyre-r7
Copy link
Contributor

smcintyre-r7 commented Jun 16, 2020

Release Notes

Added TLV encryption support to the Python Meterpreter, allowing it to securely communicate with Metasploit Framework.

@OJ
Copy link
Contributor Author

OJ commented Jun 16, 2020 via email

@pbarry-r7 pbarry-r7 added the rn-enhancement release notes enhancement label Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement library meterpreter msf6 PRs that need to be landed into the msf 6 branch rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants