-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
Python Meterpreter Transport #5654
Conversation
* Delete unused method
* Use cmd_exec
* Use cmd_exec
* Use cmd_exec
* Use cmd_exec
* Use cmd_exec
* Use cmd_exec
This reverts commit 76c2198.
We also have a small issue with using
|
The transport resiliency feature doesn't appear to function either. If I have a |
The rest of the stuff works nicely... including
Nice job @zeroSteiner ! Thanks so much for the effort you put into this. |
@OJ yup I'll take a look at fixing all of those things. Thanks for testing. |
@OJ the resiliency should be working but for TCP transports, I know it has to time out first which by default takes over 5 minutes (from the communication timeout). I'm assuming this is incorrect behavior. Can you confirm that resiliency is working for the HTTP transports though as it should be working for them as well? |
@zeroSteiner when the connection dies, the "next" transport should take over. If that transport is the only transport, then that's the one that attempts to reconnect. In that case, it should attempt to connect every The |
@OJ I guess my question was more when the connection dies or is closed it sounds like the next transport should be tried immediately instead of continuing to try and read a packet until the communication timeout expires. I'll rework it to try the next transport immediately when the socket is closed. |
Communication timeout doesn't get used until after a new session is established. Until that happens, only the retry wait/total are used. If a connection is successful, then retry total/wait are abandoned and that's when the comms timeout kicks in. It's a bit confusing and makes more sense in the HTTP/S world too. So the retries are all about |
@OJ all three of the issues should be resolved now. |
Thanks @zeroSteiner ! I'll take another look today. Awesome work. |
We still have an issue with addition of transports:
So the implementation inside the other meterpreters is a circular linked list of transports, and the new transport is always added to the end of the circular list. If this was implemented as a typical python list, then the transport should be inserted into the list immediately before the current index, except when the transport is the first element in the list, at which point it is inserted at the end of the list. In the above example, that HTTP transport should still have appeared at the end of the list. Does that make sense? I don't think I explained it very well. |
Removal and transport switching work really nicely now. It's just the addition left to go! |
Yup that makes sense and it's an easy enough fix, I'll get on it now. Thanks @OJ! |
Transport resiliency works nicely with HTTP, but the TCP stuff still doesn't reconnect as expected. When TCP is disconnected, it should begin polling immediately but that doesn't seem to happen. |
Thanks @zeroSteiner ! Sorry for the churn here mate. We're so close! |
And |
Nice @zeroSteiner, the transport addition stuff works perfectly now. |
@OJ Alright so the http transports now use an incremental back off when receiving empty packets modeled after the logic here. Additionally the transports can now request that they be changed which allows the specific implementations to detect their unique error conditions. This is used to allow the TCP transport to request that a new transport be used when it's read-ready and returns an empty string (which is the case when the remote socket has been closed from msfconsole using Hopefully the behavior should now be identical to the other meterpreters 🙏. Thanks for your patience on this. |
@zeroSteiner thanks mate, will look again today! |
Great work, thanks @zeroSteiner ! Works like a charm now. @bcook-r7 can you please work your magic with merging this into |
Oh sure, I can do the magic. I'll also remove the python / php exception that prevents these from loading from the gem. |
Overview
This adds support to the Python meterpreter for the new transport features.
The main transport features include:
sleep
command supportDemonstrations:
Verification Steps:
transport
command is availabletransport list
shows the available transports (always at least one)transport add
can add a new transport to the listtransport remove
can remove an existing transport (but never the current one)transport next
andtransport prev
change to new transports (only if more than one is set)transport change
will add and then immediately change to the new transportsleep
works as expectedget_timeouts
andset_timeouts
can be used to read and change the timeoutsexit -y
CC and my thanks to @OJ for all the help on this.
Tested with Python 2.5-2-7 and 3.1-3.4.