Skip to content

Commit

Permalink
Currently asktgt ignores /changepw when /certificate is used. Fix thi…
Browse files Browse the repository at this point in the history
…s by adding support for /changepw with /certificates. Can be used to change the ad user password of a user using smartcard / certificate authentication.

Tested with Windows 10 + Windows Server 2019.
  • Loading branch information
michael-dev committed Apr 19, 2023
1 parent f6685f4 commit c13534a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Rubeus/Commands/Asktgt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void Execute(Dictionary<string, string> arguments)
else if (String.IsNullOrEmpty(certificate))
Ask.TGT(user, domain, hash, encType, outfile, ptt, dc, luid, true, opsec, servicekey, changepw, pac, proxyUrl, service);
else
Ask.TGT(user, domain, certificate, password, encType, outfile, ptt, dc, luid, true, verifyCerts, servicekey, getCredentials, proxyUrl, service);
Ask.TGT(user, domain, certificate, password, encType, outfile, ptt, dc, luid, true, verifyCerts, servicekey, getCredentials, proxyUrl, service, changepw);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions Rubeus/lib/Ask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static X509Certificate2 FindCertificate(string certificate, string storeP
}
}

public static byte[] TGT(string userName, string domain, string certFile, string certPass, Interop.KERB_ETYPE etype, string outfile, bool ptt, string domainController = "", LUID luid = new LUID(), bool describe = false, bool verifyCerts = false, string servicekey = "", bool getCredentials = false, string proxyUrl = null, string service = null) {
public static byte[] TGT(string userName, string domain, string certFile, string certPass, Interop.KERB_ETYPE etype, string outfile, bool ptt, string domainController = "", LUID luid = new LUID(), bool describe = false, bool verifyCerts = false, string servicekey = "", bool getCredentials = false, string proxyUrl = null, string service = null, bool changepw = false) {
try {
X509Certificate2 cert = FindCertificate(certFile, certPass);

Expand All @@ -206,7 +206,7 @@ public static X509Certificate2 FindCertificate(string certificate, string storeP
Console.WriteLine("[*] Using PKINIT with etype {0} and subject: {1} ", etype, cert.Subject);
Console.WriteLine("[*] Building AS-REQ (w/ PKINIT preauth) for: '{0}\\{1}'", domain, userName);

AS_REQ pkinitASREQ = AS_REQ.NewASReq(userName, domain, cert, agreement, etype, verifyCerts, service);
AS_REQ pkinitASREQ = AS_REQ.NewASReq(userName, domain, cert, agreement, etype, verifyCerts, service, changepw);
return InnerTGT(pkinitASREQ, etype, outfile, ptt, domainController, luid, describe, true, false, servicekey, getCredentials, proxyUrl);

} catch (KerberosErrorException ex) {
Expand Down
9 changes: 7 additions & 2 deletions Rubeus/lib/krb_structures/AS_REQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static AS_REQ NewASReq(string userName, string domain, string keyString,
}

//TODO: Insert DHKeyPair parameter also.
public static AS_REQ NewASReq(string userName, string domain, X509Certificate2 cert, KDCKeyAgreement agreement, Interop.KERB_ETYPE etype, bool verifyCerts = false, string service = null) {
public static AS_REQ NewASReq(string userName, string domain, X509Certificate2 cert, KDCKeyAgreement agreement, Interop.KERB_ETYPE etype, bool verifyCerts = false, string service = null, bool changepw = false) {

// build a new AS-REQ for the given userName, domain, and etype, w/ PA-ENC-TIMESTAMP
// used for "legit" AS-REQs w/ pre-auth
Expand Down Expand Up @@ -198,11 +198,16 @@ public static AS_REQ NewASReq(string userName, string domain, X509Certificate2 c
req.req_body.sname.name_string.Add(part);
}
}
else
else if (!changepw)
{
req.req_body.sname.name_string.Add("krbtgt");
req.req_body.sname.name_string.Add(domain);
}
else
{
req.req_body.sname.name_string.Add("kadmin");
req.req_body.sname.name_string.Add("changepw");
}

// add in our encryption type
req.req_body.etypes.Add(etype);
Expand Down

0 comments on commit c13534a

Please sign in to comment.