From 9f2be21eb750ba228c1b35abfbd060632947f550 Mon Sep 17 00:00:00 2001 From: OJ Date: Mon, 26 Jun 2017 15:22:56 +1000 Subject: [PATCH] Ignore missing method error when doing aes negotiation This means that meterpreter instances that don't support will continue to work. --- lib/rex/post/meterpreter/client_core.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/rex/post/meterpreter/client_core.rb b/lib/rex/post/meterpreter/client_core.rb index fb784701be..6b860898ab 100644 --- a/lib/rex/post/meterpreter/client_core.rb +++ b/lib/rex/post/meterpreter/client_core.rb @@ -693,18 +693,18 @@ class ClientCore < Extension request = Packet.create_request('core_negotiate_aes') request.add_tlv(TLV_TYPE_RSA_PUB_KEY, rsa_pub_key.to_pem) - response = client.send_request(request) - aes_key_enc = response.get_tlv_value(TLV_TYPE_ENC_AES_KEY) + begin + response = client.send_request(request) + aes_key_enc = response.get_tlv_value(TLV_TYPE_ENC_AES_KEY) - if aes_key_enc - begin + if aes_key_enc aes_key = rsa_key.private_decrypt(aes_key_enc, OpenSSL::PKey::RSA::PKCS1_PADDING) - rescue OpenSSL::PKey::RSAError - # probably failed due to padding, everything else can be bubbled up, but - # we'll stick with a blank key + else + aes_key = response.get_tlv_value(TLV_TYPE_AES_KEY) end - else - aes_key = response.get_tlv_value(TLV_TYPE_AES_KEY) + rescue OpenSSL::PKey::RSAError, Rex::Post::Meterpreter::RequestError + # 1) OpenSSL error may be due to padding issues (or something else) + # 2) Request error probably means the request isn't supported, so fallback to plain end aes_key