Skip to content

Commit a495394

Browse files
Add debug output for CCache DCERPC authentication
1 parent ee0d8ca commit a495394

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

dcerpcauth/dcerpcauth.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net"
99
"strings"
10+
"time"
1011

1112
"github.com/RedTeamPentesting/adauth"
1213
"github.com/RedTeamPentesting/adauth/pkinit"
@@ -192,15 +193,58 @@ func DCERPCCredentials(ctx context.Context, creds *adauth.Credential, options *O
192193

193194
return credential.NewFromCCache(creds.LogonNameWithUpperCaseDomain(), ccache), nil
194195
case creds.CCache != "":
195-
options.debug("Authenticating with ccache")
196+
options.debug("Authenticating with CCache")
196197

197198
ccache, err := credentials.LoadCCache(creds.CCache)
198199
if err != nil {
199200
return nil, fmt.Errorf("load CCache: %w", err)
200201
}
201202

203+
describeCCache(ccache, options.debug)
204+
202205
return credential.NewFromCCache(creds.LogonNameWithUpperCaseDomain(), ccache), nil
203206
default:
204207
return nil, fmt.Errorf("no credentials available")
205208
}
206209
}
210+
211+
func describeCCache(cchache *credentials.CCache, log func(string, ...any)) {
212+
tickets := cchache.GetEntries()
213+
214+
log("CCache contains %d tickets:", len(tickets))
215+
216+
now := time.Now()
217+
218+
for _, ticket := range tickets {
219+
ticketType := "Service Ticket"
220+
if len(ticket.Server.PrincipalName.NameString) > 0 &&
221+
strings.EqualFold(ticket.Server.PrincipalName.NameString[0], "krbtgt") {
222+
ticketType = "Ticket Granting Ticket"
223+
}
224+
225+
log(
226+
" * %s: User=%s (%s), Target=%s (%s), Start=%s, End=%s, Renew=%s, Auth=%s, KeyType=%d",
227+
ticketType,
228+
strings.Join(ticket.Client.PrincipalName.NameString, "/"),
229+
ticket.Client.Realm,
230+
strings.Join(ticket.Server.PrincipalName.NameString, "/"),
231+
ticket.Server.Realm,
232+
formatTime(ticket.StartTime, now),
233+
formatTime(ticket.EndTime, now),
234+
formatTime(ticket.RenewTill, now),
235+
formatTime(ticket.AuthTime, now),
236+
ticket.Key.KeyType,
237+
)
238+
}
239+
}
240+
241+
func formatTime(t time.Time, now time.Time) string {
242+
ty, tm, td := t.Date()
243+
ny, nm, nd := now.Date()
244+
245+
if ty == ny && tm == nm && td == nd {
246+
return t.Format(time.TimeOnly)
247+
}
248+
249+
return t.Format(time.DateTime)
250+
}

0 commit comments

Comments
 (0)