|
7 | 7 | "fmt" |
8 | 8 | "net" |
9 | 9 | "strings" |
| 10 | + "time" |
10 | 11 |
|
11 | 12 | "github.com/RedTeamPentesting/adauth" |
12 | 13 | "github.com/RedTeamPentesting/adauth/pkinit" |
@@ -192,15 +193,58 @@ func DCERPCCredentials(ctx context.Context, creds *adauth.Credential, options *O |
192 | 193 |
|
193 | 194 | return credential.NewFromCCache(creds.LogonNameWithUpperCaseDomain(), ccache), nil |
194 | 195 | case creds.CCache != "": |
195 | | - options.debug("Authenticating with ccache") |
| 196 | + options.debug("Authenticating with CCache") |
196 | 197 |
|
197 | 198 | ccache, err := credentials.LoadCCache(creds.CCache) |
198 | 199 | if err != nil { |
199 | 200 | return nil, fmt.Errorf("load CCache: %w", err) |
200 | 201 | } |
201 | 202 |
|
| 203 | + describeCCache(ccache, options.debug) |
| 204 | + |
202 | 205 | return credential.NewFromCCache(creds.LogonNameWithUpperCaseDomain(), ccache), nil |
203 | 206 | default: |
204 | 207 | return nil, fmt.Errorf("no credentials available") |
205 | 208 | } |
206 | 209 | } |
| 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