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

Patches UA and Proxy Settings in metsrv when running migrate #3632

Merged
merged 11 commits into from
Dec 17, 2014

Conversation

veritysr
Copy link
Contributor

@veritysr veritysr commented Aug 8, 2014

Earlier today, I saw that my User-Agent was changing to "METERPRETER_UA" after running "migrate" with windows/meterpreter/reverse_http. It appeared that metsrv was not getting patched with MeterpreterUserAgent so I pulled the pertinent code (added the proxy stuff for completeness) from msf/core/handler/reverse_http.rb and dumped it here.

@Meatballs1
Copy link
Contributor

Get the same behaviour here, but we should refactor the code to a common class in lib/rex/somewhere to prevent the code deviating in future.

lib/rex/post/meterpreter isn't appropriate as the code is for payloads and post, but not sure where to put it at the moment. Poke @jlee-r7 ?

@Meatballs1
Copy link
Contributor

Maybe something like lib/rex/payloads/meterpreter/patch.rb or something?

@veritysr
Copy link
Contributor Author

@Meatballs1 - For sure. Does it make sense to build something that would handle all of the original payload's advanced options? For example, I don't believe that EnableStageEncoding or StageEncoder get applied during migrate.

@Meatballs1
Copy link
Contributor

Yes, if stage encoding etc dont get applied on migrate that's not good!

@jlee-r7
Copy link
Contributor

jlee-r7 commented Aug 15, 2014

UA and Proxy are definitely oversights.

The stage used for migration should be compressed and encrypted anyway, so stage encoding doesn't matter.

@jlee-r7
Copy link
Contributor

jlee-r7 commented Aug 15, 2014

After a bit of a look, I think this belongs in a method on the payload objects. Similar code (though not identical! copy-pasta for the lose) is in lib/msf/core/handler/reverse_http.rb, lib/msf/core/handler/reverse_hop_http.rb, and lib/rex/post/meterpreter/client_core.rb.

@veritysr
Copy link
Contributor Author

I'll start working on a proper solution. Will probably be a little while before I have something ready though.

@veritysr
Copy link
Contributor Author

Does this seem reasonable? Want to make sure this passes the sniff test before moving forward with applying these methods to reverse_http and reverse_hop_http.

@Meatballs1
Copy link
Contributor

Looks reasonable to me, the code isn't quite correct (patch_transport isn't in a method). Not sure if @jlee-r7 wanted it to sit on lib/msf/core/handler/reverse_http.rb but shouldn't require 'msf' from 'rex' etc.

@veritysr
Copy link
Contributor Author

Doh! Thanks, Meatballs1.

@mubix
Copy link
Contributor

mubix commented Sep 2, 2014

bump

@hdm
Copy link
Contributor

hdm commented Sep 13, 2014

@Meatballs1 stage encoding is not needed, because the stage is transferred over the existing Meterpreter SSL channel (it isn't clear-text on the wire unless you use http).

@veritysr
Copy link
Contributor Author

Thank you for the feedback, everyone!

@Meatballs1 - Didn't see what you meant about the missing patch_transport method until I looked at the file on github, patch_transport was unclear because of indents; hence the "fixed indents" commit. Please let me know if there's something else I'm missing. Understood on not crossing the streams (including 'rex' on 'msf') so I'll hold off on that. Though I'm not sure how else metsrv patching could get refactored to accomodate client_core, reverse_http, and reverse_hop_http without crossing the streams. ...which gets me to thinking, does it make sense to refactor patching methods (as opposed to copy-paste) when they're only going to be included in a single file (client_core)?

@hmoore-r7 - I was thinking of a decrypting web gateway which would still be in the middle of Meterpreter's SSL channel. As jlee-r7 pointed out, since stage is encrypted and compressed, no worries there. User-Agent with METERPRETER _UA would still be low hanging fruit for web traffic inspection though.

@hdm
Copy link
Contributor

hdm commented Sep 13, 2014

@veritysr Absolutely, any other options we need to patch in should be preserved as well (timeouts, expiration, etc). There is a secondary effort to encode the contents of http stagers, beyond the transport level, and emulate actual web applications.

@veritysr
Copy link
Contributor Author

As far as I can tell, all of the metsrv patching for rex/post/meterpreter/client_core.rb is refactored into rex/payloads/meterpreter/patch.rb with e55dab3.

Can line 238 in rex/post/meterpreter/client_core.rb be removed? I see "conn_id" getting initialized but I don't see where "conn_id" is used.

@hdm
Copy link
Contributor

hdm commented Dec 14, 2014

FYI, this may end up colliding with the proxy setting PR (#4295). Not a problem, but something to take into account.

@veritysr
Copy link
Contributor Author

I think I ended up using extend on blob because I couldn't get include to work...tried including Rex::Payloads::Meterpreter::Patch on blob, migrate_stager, and c. I'll take another look at it and figure out what I was doing wrong.

I took a look at #4295 - will also try to keep an eye out for when it gets landed to make sure this is compatible.

@hdm
Copy link
Contributor

hdm commented Dec 15, 2014

Looks good! We might want to rename this to something other than Patch at some point depending on what else gets added (proxy host brackets for ipv6, etc), but this should be good to test/merge here.

@hdm hdm self-assigned this Dec 15, 2014
@hdm
Copy link
Contributor

hdm commented Dec 15, 2014

Looks like the following two stagers need to be updated to use this method as well:

  • lib/msf/core/handler/reverse_hop_http.rb
  • lib/msf/core/handler/reverse_http.rb

Can you update these two stagers to require this mixin and use the patch methods? This should centralize all of the logic around metsrv patching once and for all.

@hdm
Copy link
Contributor

hdm commented Dec 15, 2014

In the case of IPv6 addresses, the following logic would need to get implemented somewhere (both for the LHOST and the PROXY_HOST):
hdm@ed47e0a

@veritysr
Copy link
Contributor Author

Will do. Thanks
On Dec 15, 2014 4:04 PM, "HD Moore" notifications@github.com wrote:

Looks like the following two stagers need to be updated to use this method
as well:

  • lib/msf/core/handler/reverse_hop_http.rb
  • lib/msf/core/handler/reverse_http.rb

Can you update these two stagers to require this mixin and use the patch
methods? This should centralize all of the logic around metsrv patching
once and for all.


Reply to this email directly or view it on GitHub
#3632 (comment)
.

@veritysr
Copy link
Contributor Author

In the case of reverse_http.rb, Rex::Payloads_Meterpreter::Patch.patch_passive_service relies on the caller to send a properly formatted IPv6 host (payload_uri method in reverse_http.rb):
https://github.com/hmoore-r7/metasploit-framework/blob/c78685269f06d5d70dbb08b1092a84cc07ffc30c/lib/msf/core/handler/reverse_http.rb#L94-101

Is this reasonable?

And for reverse_hop_http.rb and IPv6, is it reasonable to expect that the user is specifying HOPURL with a correctly formatted host when using IPv6?

@hdm
Copy link
Contributor

hdm commented Dec 17, 2014

The expectation is that the input is a IPv6 address, but since some applications and interfaces require brackets, we have to manually add them when appropriate (in this case, WinInet requires it for IPv6 addresses). The LHOST code you mentioned is an example of what we need to handle for PROXY_HOST as well within the patching code.

@hdm
Copy link
Contributor

hdm commented Dec 17, 2014

@veritysr In retrospect, don't worry about IPv6, I can take a pass once this is landed and normalize it all then.

@hdm hdm merged commit 370f600 into rapid7:master Dec 17, 2014
hdm pushed a commit that referenced this pull request Dec 17, 2014
@hdm
Copy link
Contributor

hdm commented Dec 17, 2014

@veritysr Thank you very much for this patch and working with us on the feedback and merge process!

@veritysr
Copy link
Contributor Author

Always a pleasure working with the msf-dev community! :) Thanks!
On Dec 16, 2014 11:31 PM, "HD Moore" notifications@github.com wrote:

@veritysr https://github.com/veritysr Thank you very much for this
patch and working with us on the feedback and merge process!


Reply to this email directly or view it on GitHub
#3632 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants