Skip to content

Commit

Permalink
Fix for KerberosDecrypt problem where additional garbage added to the…
Browse files Browse the repository at this point in the history
… end of the buffer
  • Loading branch information
CCob committed Jun 4, 2021
1 parent 0099aeb commit a85f413
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions Rubeus/lib/Ask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public class Ask
}

// decode the supplied bytes to an AsnElt object
// false == ignore trailing garbage
AsnElt responseAsn = AsnElt.Decode(response, false);
AsnElt responseAsn = AsnElt.Decode(response);

// check the response value
int responseTag = responseAsn.TagValue;
Expand Down Expand Up @@ -204,11 +203,10 @@ public static int GetKeySize(Interop.KERB_ETYPE etype) {
}

// decode the supplied bytes to an AsnElt object
// false == ignore trailing garbage
AsnElt responseAsn;
try
{
responseAsn = AsnElt.Decode(response, false);
responseAsn = AsnElt.Decode(response);
}
catch(Exception e)
{
Expand Down Expand Up @@ -297,7 +295,7 @@ public static byte[] TGS(string userName, string domain, Ticket providedTicket,

// decode the supplied bytes to an AsnElt object
// false == ignore trailing garbage
AsnElt responseAsn = AsnElt.Decode(response, false);
AsnElt responseAsn = AsnElt.Decode(response);

// check the response value
int responseTag = responseAsn.TagValue;
Expand All @@ -314,7 +312,7 @@ public static byte[] TGS(string userName, string domain, Ticket providedTicket,

// KRB_KEY_USAGE_TGS_REP_EP_SESSION_KEY = 8
byte[] outBytes = Crypto.KerberosDecrypt(paEType, Interop.KRB_KEY_USAGE_TGS_REP_EP_SESSION_KEY, clientKey, rep.enc_part.cipher);
AsnElt ae = AsnElt.Decode(outBytes, false);
AsnElt ae = AsnElt.Decode(outBytes);
EncKDCRepPart encRepPart = new EncKDCRepPart(ae.Sub[0]);

// if using /opsec and the ticket is for a server configuration for unconstrained delegation, request a forwardable TGT
Expand Down Expand Up @@ -475,8 +473,7 @@ public static byte[] TGS(string userName, string domain, Ticket providedTicket,
throw new RubeusException("[X] Encryption type \"" + etype + "\" not currently supported");
}


AsnElt ae = AsnElt.Decode(outBytes, false);
AsnElt ae = AsnElt.Decode(outBytes);

EncKDCRepPart encRepPart = new EncKDCRepPart(ae.Sub[0]);

Expand Down
2 changes: 1 addition & 1 deletion Rubeus/lib/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static byte[] KerberosDecrypt(Interop.KERB_ETYPE eType, int keyUsage, byt
status = pCSystemDecrypt(pContext, data, data.Length, output, ref outputSize);
pCSystemFinish(ref pContext);

return output;
return output.Take(outputSize).ToArray();
}

// Adapted from Vincent LE TOUX' "MakeMeEnterpriseAdmin"
Expand Down

0 comments on commit a85f413

Please sign in to comment.