Merge branch 'master' of https://github.com/PowerShellEmpire/Empire
commit
40fda2dd04
|
@ -523,7 +523,8 @@ function Invoke-Empire {
|
||||||
$AES.Key = $encoding.GetBytes($SessionKey);
|
$AES.Key = $encoding.GetBytes($SessionKey);
|
||||||
$AES.IV = $IV;
|
$AES.IV = $IV;
|
||||||
$ciphertext = $IV + ($AES.CreateEncryptor()).TransformFinalBlock($bytes, 0, $bytes.Length);
|
$ciphertext = $IV + ($AES.CreateEncryptor()).TransformFinalBlock($bytes, 0, $bytes.Length);
|
||||||
$hmac = New-Object System.Security.Cryptography.HMACMD5;
|
# append the MAC
|
||||||
|
$hmac = New-Object System.Security.Cryptography.HMACSHA1;
|
||||||
$hmac.Key = $encoding.GetBytes($SessionKey);
|
$hmac.Key = $encoding.GetBytes($SessionKey);
|
||||||
$ciphertext + $hmac.ComputeHash($ciphertext);
|
$ciphertext + $hmac.ComputeHash($ciphertext);
|
||||||
}
|
}
|
||||||
|
@ -532,9 +533,9 @@ function Invoke-Empire {
|
||||||
param ($inBytes)
|
param ($inBytes)
|
||||||
if($inBytes.Length -gt 32){
|
if($inBytes.Length -gt 32){
|
||||||
# Verify the MAC
|
# Verify the MAC
|
||||||
$mac = $inBytes[-16..-1];
|
$mac = $inBytes[-20..-1];
|
||||||
$inBytes = $inBytes[0..($inBytes.length - 17)];
|
$inBytes = $inBytes[0..($inBytes.length - 21)];
|
||||||
$hmac = New-Object System.Security.Cryptography.HMACMD5;
|
$hmac = New-Object System.Security.Cryptography.HMACSHA1;
|
||||||
$hmac.Key = $encoding.GetBytes($SessionKey);
|
$hmac.Key = $encoding.GetBytes($SessionKey);
|
||||||
$expected = $hmac.ComputeHash($inBytes);
|
$expected = $hmac.ComputeHash($inBytes);
|
||||||
if (@(Compare-Object $mac $expected -sync 0).Length -ne 0){
|
if (@(Compare-Object $mac $expected -sync 0).Length -ne 0){
|
||||||
|
|
|
@ -76,7 +76,7 @@ def aes_encrypt_then_mac(key, data):
|
||||||
Encrypt the data then calculate HMAC over the ciphertext.
|
Encrypt the data then calculate HMAC over the ciphertext.
|
||||||
"""
|
"""
|
||||||
data = aes_encrypt(key, data)
|
data = aes_encrypt(key, data)
|
||||||
mac = hmac.new(str(key), data, hashlib.md5).digest()
|
mac = hmac.new(str(key), data, hashlib.sha1).digest()
|
||||||
return data + mac
|
return data + mac
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,10 +95,10 @@ def verify_hmac(key, data):
|
||||||
"""
|
"""
|
||||||
Verify the HMAC supplied in the data with the given key.
|
Verify the HMAC supplied in the data with the given key.
|
||||||
"""
|
"""
|
||||||
if len(data) > 16:
|
if len(data) > 20:
|
||||||
mac = data[-16:]
|
mac = data[-20:]
|
||||||
data = data[:-16]
|
data = data[:-20]
|
||||||
expected = hmac.new(str(key), data, hashlib.md5).digest()
|
expected = hmac.new(str(key), data, hashlib.sha1).digest()
|
||||||
# Double HMAC to prevent timing attacks. hmac.compare_digest() is
|
# Double HMAC to prevent timing attacks. hmac.compare_digest() is
|
||||||
# preferable, but only available since Python 2.7.7.
|
# preferable, but only available since Python 2.7.7.
|
||||||
return hmac.new(str(key), expected).digest() == hmac.new(str(key), mac).digest()
|
return hmac.new(str(key), expected).digest() == hmac.new(str(key), mac).digest()
|
||||||
|
@ -111,7 +111,7 @@ def aes_decrypt_and_verify(key, data):
|
||||||
Decrypt the data, but only if it has a valid MAC.
|
Decrypt the data, but only if it has a valid MAC.
|
||||||
"""
|
"""
|
||||||
if len(data) > 32 and verify_hmac(key, data):
|
if len(data) > 32 and verify_hmac(key, data):
|
||||||
return aes_decrypt(key, data[:-16])
|
return aes_decrypt(key, data[:-20])
|
||||||
|
|
||||||
raise Exception("Invalid ciphertext received.")
|
raise Exception("Invalid ciphertext received.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue