Skip to content

Commit

Permalink
add method GetServiceTicket to the kerberos module
Browse files Browse the repository at this point in the history
  • Loading branch information
5amu committed Nov 26, 2023
1 parent 8056072 commit cacfccc
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkg/js/libs/kerberos/kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,49 @@ func asRepToHashcat(asrep messages.ASRep) (string, error) {
hex.EncodeToString(asrep.EncPart.Cipher[:16]),
hex.EncodeToString(asrep.EncPart.Cipher[16:])), nil
}

type TGS struct {
Ticket messages.Ticket
Hash string
}

func (c *KerberosClient) GetServiceTicket(domain, controller string, username, password string, target, spn string) (TGS, error) {
var tgs TGS

if !protocolstate.IsHostAllowed(domain) {
// host is not valid according to network policy
return tgs, protocolstate.ErrHostDenied.Msgf(domain)
}

opts, err := newKerbrosEnumUserOpts(domain, controller)
if err != nil {
return tgs, err
}
cl := kclient.NewWithPassword(username, opts.realm, password, opts.config, kclient.DisablePAFXFAST(true))

ticket, _, err := cl.GetServiceTicket(spn)
if err != nil {
return tgs, err
}

hashcat, err := tgsToHashcat(ticket)
if err != nil {
return tgs, err
}

return TGS{
Ticket: ticket,
Hash: hashcat,
}, nil
}

func tgsToHashcat(tgs messages.Ticket) (string, error) {
return fmt.Sprintf("$krb5tgs$%d$*%s$%s$%s*$%s$%s",
tgs.EncPart.EType,
"",
tgs.Realm,
strings.Join(tgs.SName.NameString[:], "/"),
hex.EncodeToString(tgs.EncPart.Cipher[:16]),
hex.EncodeToString(tgs.EncPart.Cipher[16:]),
), nil
}

0 comments on commit cacfccc

Please sign in to comment.