Skip to content

Commit 8a432fb

Browse files
committed
fix: default is_weak_key is nil; handling of empty key_dec_data
1 parent 80e942b commit 8a432fb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ def valid_transport?(transport)
758758
#
759759
def negotiate_tlv_encryption(timeout: client.comm_timeout)
760760
sym_key = nil
761+
is_weak_key = nil
761762
rsa_key = OpenSSL::PKey::RSA.new(2048)
762763
rsa_pub_key = rsa_key.public_key
763764

@@ -769,10 +770,13 @@ def negotiate_tlv_encryption(timeout: client.comm_timeout)
769770
key_enc = response.get_tlv_value(TLV_TYPE_ENC_SYM_KEY)
770771
key_type = response.get_tlv_value(TLV_TYPE_SYM_KEY_TYPE)
771772
key_length = { Packet::ENC_FLAG_AES128 => 16, Packet::ENC_FLAG_AES256 => 32 }[key_type]
772-
is_weak_key = false
773773
if key_enc
774774
key_dec_data = rsa_key.private_decrypt(key_enc, OpenSSL::PKey::RSA::PKCS1_PADDING)
775+
if !key_dec_data
776+
raise Rex::Post::Meterpreter::RequestError
777+
end
775778
sym_key = key_dec_data[0..key_length - 1]
779+
is_weak_key = false
776780
if key_dec_data.length > key_length
777781
key_dec_data = key_dec_data[key_length...]
778782
if key_dec_data.length > 0

0 commit comments

Comments
 (0)