-
Notifications
You must be signed in to change notification settings - Fork 0
/
pac_xml_dump.c
770 lines (672 loc) · 20.4 KB
/
pac_xml_dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/*
* Copyright (C) 2014 Sven Fabricius <sven.fabricius{at}livediesel[dot]de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <stdint.h>
#include <sys/stat.h>
#include <time.h>
#include <stdlib.h>
#include "pac_xml_dump.h"
#include "pac_collected.h"
#ifdef _MSC_VER
#define STIN static __inline
#else
#define STIN static inline
#endif
STIN uint16_t load_16_le (const unsigned char *p)
{
return (p[0] | (p[1] << 8));
}
STIN uint32_t load_32_le (const unsigned char *p)
{
return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
}
STIN uint64_t load_64_le (const unsigned char *p)
{
return ((uint64_t)load_32_le(p+4) << 32) | load_32_le(p);
}
STIN uint64_t load_48_be (const unsigned char *p)
{
return (uint64_t)(p[5] | (p[4] << 8) | (p[3] << 16) | (p[2] << 24) | ((uint64_t)p[1] << 32) | ((uint64_t)p[0] << 40));
}
/* parse PAC Header, alignment of the info buffers */
PACTYPE * parse_pac_header(const void *ptr, size_t len)
{
PACTYPE *ppac_header;
const unsigned char *p = (const unsigned char *)ptr;
uint32_t cbuffers, version;
size_t header_len;
size_t i;
if (len < PACTYPE_LENGTH)
return NULL;
cbuffers = load_32_le(p);
p += 4;
version = load_32_le(p);
p += 4;
if (version != 0)
return NULL;
header_len = PACTYPE_LENGTH + (cbuffers * PAC_INFO_BUFFER_LENGTH);
if (len < header_len)
return NULL;
ppac_header = (PACTYPE *)malloc(sizeof(PACTYPE) + ((cbuffers - 1) * sizeof(PAC_INFO_BUFFER)));
if (ppac_header == NULL)
return NULL;
ppac_header->cBuffers = cbuffers;
ppac_header->Version = version;
for (i = 0; i < ppac_header->cBuffers; i++)
{
PAC_INFO_BUFFER *buffer = &ppac_header->Buffers[i];
buffer->ulType = load_32_le(p);
p += 4;
buffer->cbBufferSize = load_32_le(p);
p += 4;
buffer->Offset = load_64_le(p);
p += 8;
if (buffer->Offset % PAC_ALIGNMENT)
{
free(ppac_header);
return NULL;
}
if (buffer->Offset < header_len || buffer->Offset + buffer->cbBufferSize > len)
{
free(ppac_header);
return NULL;
}
}
return ppac_header;
}
/* parse and output a checksum info buffer */
void parse_checksum(FILE *fp, const void *ptr, PAC_INFO_BUFFER * infoBuffer, const char *name)
{
const unsigned char *p = (const unsigned char *)ptr;
int32_t cksumType;
size_t i;
p += infoBuffer->Offset;
if (infoBuffer->cbBufferSize < CKSUM_LENGTH)
return;
cksumType = load_32_le(p);
p += 4;
fprintf(fp, "<%s CheckSumType=\"", name);
switch (cksumType)
{
case CKSUMTYPE_NONE:
fprintf(fp, "NONE");
break;
case CKSUMTYPE_CRC32:
fprintf(fp, "CRC32");
break;
case CKSUMTYPE_RSA_MD4:
fprintf(fp, "RSA_MD4");
break;
case CKSUMTYPE_RSA_MD4_DES:
fprintf(fp, "RSA_MD4_DES");
break;
case CKSUMTYPE_DES_MAC:
fprintf(fp, "DES_MAC");
break;
case CKSUMTYPE_DES_MAC_K:
fprintf(fp, "DES_MAC_K");
break;
case CKSUMTYPE_RSA_MD4_DES_K:
fprintf(fp, "RSA_MD4_DES_K");
break;
case CKSUMTYPE_RSA_MD5:
fprintf(fp, "RSA_MD5");
break;
case CKSUMTYPE_RSA_MD5_DES:
fprintf(fp, "RSA_MD5_DES");
break;
case CKSUMTYPE_RSA_MD5_DES3:
fprintf(fp, "RSA_MD5_DES3");
break;
case CKSUMTYPE_SHA1_OTHER:
fprintf(fp, "SHA1_OTHER");
break;
case CKSUMTYPE_HMAC_SHA1_DES3:
fprintf(fp, "HMAC_SHA1_DES3");
break;
case CKSUMTYPE_SHA1:
fprintf(fp, "SHA1");
break;
case CKSUMTYPE_HMAC_SHA1_96_AES_128:
fprintf(fp, "HMAC_SHA1_96_AES_128");
break;
case CKSUMTYPE_HMAC_SHA1_96_AES_256:
fprintf(fp, "HMAC_SHA1_96_AES_256");
break;
case CKSUMTYPE_GSSAPI:
fprintf(fp, "GSSAPI");
break;
case CKSUMTYPE_HMAC_MD5:
fprintf(fp, "HMAC_MD5");
break;
case CKSUMTYPE_HMAC_MD5_ENC:
fprintf(fp, "HMAC_MD5_ENC");
break;
}
fprintf(fp, "\">");
for (i = 4; i < infoBuffer->cbBufferSize; i++)
{
fprintf(fp, "%02X", *p++);
}
fprintf(fp, "</%s>\n", name);
}
/* parse and output the UPN DNS info buffer */
void parse_upn_dns_info(FILE *fp, const void *ptr, PAC_INFO_BUFFER * infoBuffer)
{
const unsigned char *p = (const unsigned char *)ptr;
const unsigned char *p1;
const unsigned char *p2;
uint16_t len;
uint16_t pos;
size_t i;
p += infoBuffer->Offset;
p1 = p;
fprintf(fp, "<UPN_DNS_Info>\n");
do {
len = load_16_le(p);
p += 2;
pos = load_16_le(p);
p += 2;
if (len == 0)
{
fprintf(fp, "</UPN_DNS_Info>\n");
return;
}
p2 = p1 + pos;
for (i = 0; i < len; i+=2)
{
fprintf(fp, "%c", *p2++);
p2++;
}
fprintf(fp, "\n");
} while(1);
}
/* convert kerberos timestamp to seconds since 1970 */
int32_t k5_time_to_seconds_since_1970(int64_t ntTime)
{
uint64_t abstime;
ntTime /= 10000000;
abstime = ntTime > 0 ? ntTime - NT_TIME_EPOCH : -ntTime;
if (abstime > KRB5_INT32_MAX)
return 0;
return abstime;
}
/* parse and output the client info buffer */
void parse_client_info(FILE *fp, const void *ptr, PAC_INFO_BUFFER * infoBuffer)
{
const unsigned char *p = (const unsigned char *)ptr;
int64_t nt_authtime;
uint16_t princname_length;
size_t i;
p += infoBuffer->Offset;
if (infoBuffer->cbBufferSize < CLIENT_INFO_LENGTH)
return;
nt_authtime = load_64_le(p);
p += 8;
princname_length = load_16_le(p);
p += 2;
nt_authtime = k5_time_to_seconds_since_1970(nt_authtime);
fprintf(fp, "<ClientInfo NTAuthTime=\"%lu\">", nt_authtime);
for (i = 0; i < princname_length; i+=2)
{
fprintf(fp, "%c", *p++);
p++;
}
fprintf(fp, "</ClientInfo>\n");
}
/* parse and output a kerberos timestamp */
void parse_k5_time(FILE *fp, const char * format, const unsigned char **p)
{
int64_t nt_time = load_64_le(*p);
*p += 8;
fprintf(fp, format, k5_time_to_seconds_since_1970(nt_time));
}
/* parse and output a uint16 value */
void parse_uint16(FILE *fp, const char * format, const unsigned char **p)
{
uint16_t res = load_16_le(*p);
*p += 2;
fprintf(fp, format, res);
}
/* parse and output a uint32 value */
void parse_uint32(FILE *fp, const char * format, const unsigned char **p)
{
uint32_t res = load_32_le(*p);
*p += 4;
fprintf(fp, format, res);
}
/* parse and the user flags */
void parse_user_flgs(FILE *fp, const uint32_t user_flgs)
{
uint8_t listFlag = 0;
if (user_flgs & NETLOGON_GUEST)
{
fprintf(fp, "GUEST");
listFlag = 1;
}
if (user_flgs & NETLOGON_NOENCRYPTION)
{
fprintf(fp, "%sNOENCRYPTION", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_CACHED_ACCOUNT)
{
fprintf(fp, "%sCACHED_ACCOUNT", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_USED_LM_PASSWORD)
{
fprintf(fp, "%sUSED_LM_PASSWORD", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_EXTRA_SIDS)
{
fprintf(fp, "%sEXTRA_SIDS", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_SUBAUTH_SESSION_KEY)
{
fprintf(fp, "%sSUBAUTH_SESSION_KEY", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_SERVER_TRUST_ACCOUNT)
{
fprintf(fp, "%sSERVER_TRUST_ACCOUNT", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_NTLMV2_ENABLED)
{
fprintf(fp, "%sNTLMV2_ENABLED", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_RESOURCE_GROUPS)
{
fprintf(fp, "%sRESOURCE_GROUPS", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_PROFILE_PATH_RETURNED)
{
fprintf(fp, "%sPROFILE_PATH_RETURNED", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (user_flgs & NETLOGON_GRACE_LOGON)
{
fprintf(fp, "%sGRACE_LOGON", listFlag == 1 ? "," : "");
}
}
/* parse and output a UNISTR2 value */
void parse_UNISTR2(FILE *fp, const unsigned char **p)
{
uint32_t uni_max_len;
uint32_t offset;
uint32_t uni_str_len;
size_t i;
uni_max_len = load_32_le(*p); *p += 4;
offset = load_32_le(*p); *p += 4;
uni_str_len = load_32_le(*p); *p += 4;
for (i = 0; i < uni_str_len; i++)
{
fprintf(fp, "%c", **p);
*p += 2;
}
if (i % 2 == 1)
{
*p += 2;
}
}
/* parse and output a DOM_SID2 value */
void parse_DOM_SID2(FILE *fp, const unsigned char **p)
{
uint32_t num_auths;
uint8_t sid_no;
uint8_t num_auths2;
uint64_t id_auth;
uint32_t auth;
size_t i;
num_auths = load_32_le(*p); *p += 4;
sid_no = (uint8_t)(**p); *p += 1;
num_auths2 = (uint8_t)**p; *p += 1;
id_auth = load_48_be(*p); *p += 6;
fprintf(fp, "S-%u-%lu", sid_no, id_auth);
for (i = 0; i < num_auths2; i++)
{
auth = load_32_le(*p); *p += 4;
fprintf(fp, "-%u", auth);
}
}
/* parse and output SID or RID attributes */
void parse_dom_attribute(FILE *fp, uint32_t attr)
{
uint8_t listFlag = 0;
if (attr & SE_GROUP_MANDATORY)
{
fprintf(fp, "MANDATORY");
listFlag = 1;
}
if (attr & SE_GROUP_ENABLED_BY_DEFAULT)
{
fprintf(fp, "%sENABLED_BY_DEFAULT", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (attr & SE_GROUP_ENABLED)
{
fprintf(fp, "%sENABLED", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (attr & SE_GROUP_OWNER)
{
fprintf(fp, "%sOWNER", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (attr & SE_GROUP_USE_FOR_DENY_ONLY)
{
fprintf(fp, "%sUSE_FOR_DENY_ONLY", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (attr & SE_GROUP_INTEGRITY)
{
fprintf(fp, "%sINTEGRITY", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (attr & SE_GROUP_INTEGRITY_ENABLED)
{
fprintf(fp, "%sINTEGRITY_ENABLED", listFlag == 1 ? "," : "");
listFlag = 1;
}
if (attr & SE_GROUP_RESOURCE)
{
fprintf(fp, "%sRESOURCE", listFlag == 1 ? "," : "");
listFlag = 1;
}
fprintf(fp, "%s%u", listFlag == 1 ? "," : "", ((attr & SE_GROUP_LOGON_ID) >> 30));
}
/* parse and output a RID with attributes */
void parse_rid_with_attribute(FILE *fp, DOM_GID * rid)
{
fprintf(fp,"<RID attributes=\"");
parse_dom_attribute(fp, rid->attr);
fprintf(fp,"\">%u</RID>\n", rid->g_rid);
}
/* parse and output a SID with attributes */
void parse_sid_with_attribute(FILE *fp, const unsigned char **p, DOM_GID * rid)
{
fprintf(fp,"<SID attributes=\"");
parse_dom_attribute(fp, rid->attr);
fprintf(fp,"\">");
parse_DOM_SID2(fp, p);
fprintf(fp,"</SID>\n", rid->g_rid);
}
/* parse and output the NET_USER_INFO_3 info buffer */
int parse_logon_info(FILE *fp, const void *ptr, PAC_INFO_BUFFER * infoBuffer)
{
const unsigned char *p = (const unsigned char *)ptr;
int64_t nt_time;
UNIHDR* hdr_user_name;
UNIHDR* hdr_full_name;
UNIHDR* hdr_logon_script;
UNIHDR* hdr_profile_path;
UNIHDR* hdr_home_dir;
UNIHDR* hdr_dir_drive;
UNIHDR* hdr_logon_srv;
UNIHDR* hdr_logon_dom;
uint32_t ptr_user_info;
uint32_t num_groups;
uint32_t buffer_groups;
uint32_t user_flgs;
uint8_t listFlag = 0;
uint32_t buffer_dom_id;
uint32_t num_other_sids;
uint32_t buffer_other_sids;
uint32_t num_groups2;
uint32_t num_sids;
DOM_GID *gids;
size_t i;
p += infoBuffer->Offset;
/* Common Type Header for the Serialization Stream
* http://msdn.microsoft.com/en-us/library/cc243890.aspx
*/
if (*p != 0x01) /* Version */
{
return PAC_DUMP_USER_INFO_VERSION_MISMATCH;
}
p++;
if (*p != 0x10) /* Endianness */
{
return PAC_DUMP_USER_INFO_ENDIANESS_MISMATCH;
}
p++;
if (load_16_le(p) != 0x0008) /* CommonHeaderLength */
{
return PAC_DUMP_USER_INFO_COMMON_HEADER_LENGTH_MISMATCH;
}
p += 2;
if (load_32_le(p) != 0xCCCCCCCC) /* Filler */
{
return PAC_DUMP_USER_INFO_FILLER_MISMATCH;
}
p += 4;
p += 4; /* length of the info buffer */
p += 4; /* is zero */
fprintf(fp,"<LogonInfo>\n");
ptr_user_info = load_32_le(p); p += 4;
fprintf(fp,"<UserInfo3 ");
parse_k5_time(fp, "LogonTime=\"%lu\" ", &p);
parse_k5_time(fp, "LogoffTime=\"%lu\" ", &p);
parse_k5_time(fp, "KickoffTime=\"%lu\" ", &p);
parse_k5_time(fp, "PasswordLastSetTime=\"%lu\" ", &p);
parse_k5_time(fp, "PasswordCanChangeTime=\"%lu\" ", &p);
parse_k5_time(fp, "PasswordMustChangeTime=\"%lu\" ", &p);
hdr_user_name = (UNIHDR *)p; p += sizeof(UNIHDR);
hdr_full_name = (UNIHDR *)p; p += sizeof(UNIHDR);
hdr_logon_script = (UNIHDR *)p; p += sizeof(UNIHDR);
hdr_profile_path = (UNIHDR *)p; p += sizeof(UNIHDR);
hdr_home_dir = (UNIHDR *)p; p += sizeof(UNIHDR);
hdr_dir_drive = (UNIHDR *)p; p += sizeof(UNIHDR);
parse_uint16(fp, "LogonCount=\"%u\" ", &p);
parse_uint16(fp, "BadPasswordCount=\"%u\" ", &p);
parse_uint32(fp, "UserRID=\"%u\" ", &p);
parse_uint32(fp, "GroupRID=\"%u\" ", &p);
num_groups = load_32_le(p); p += 4;
buffer_groups = load_32_le(p); p += 4;
user_flgs = load_32_le(p); p += 4;
fprintf(fp,"UserFlags=\"");
parse_user_flgs(fp, user_flgs);
fprintf(fp,"\" ");
fprintf(fp,"UserSessionKey=\"");
for (i = 0; i < 16; i++)
{
fprintf(fp,"%02X", *p++);
}
fprintf(fp,"\" ");
hdr_logon_srv = (UNIHDR *)p; p += sizeof(UNIHDR);
hdr_logon_dom = (UNIHDR *)p; p += sizeof(UNIHDR);
buffer_dom_id = load_32_le(p); p += 4;
/* Padding is type of LMSessKey
* currently I don't know for what this is.
* If you need it, implement it!
LMSessKey: struct netr_LMSessionKey
key : 0000000000000000
acct_flags : 0x00000014 (20)
0: ACB_DISABLED
0: ACB_HOMDIRREQ
1: ACB_PWNOTREQ
0: ACB_TEMPDUP
1: ACB_NORMAL
0: ACB_MNS
0: ACB_DOMTRUST
0: ACB_WSTRUST
0: ACB_SVRTRUST
0: ACB_PWNOEXP
0: ACB_AUTOLOCK
0: ACB_ENC_TXT_PWD_ALLOWED
0: ACB_SMARTCARD_REQUIRED
0: ACB_TRUSTED_FOR_DELEGATION
0: ACB_NOT_DELEGATED
0: ACB_USE_DES_KEY_ONLY
0: ACB_DONT_REQUIRE_PREAUTH
0: ACB_PW_EXPIRED
0: ACB_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION
0: ACB_NO_AUTH_DATA_REQD
0: ACB_PARTIAL_SECRETS_ACCOUNT
0: ACB_USE_AES_KEYS
unknown: ARRAY(7)
unknown : 0x00000000 (0)
unknown : 0x00000000 (0)
unknown : 0x00000000 (0)
unknown : 0x00000000 (0)
unknown : 0x00000000 (0)
unknown : 0x00000000 (0)
unknown : 0x00000000 (0)
*/
fprintf(fp,"Padding=\"");
for (i = 0; i < 40; i++)
{
fprintf(fp,"%02X", *p++);
}
fprintf(fp,"\" ");
num_other_sids = load_32_le(p); p += 4;
buffer_other_sids = load_32_le(p); p += 4;
/* Step Over next UNISTR2 element.
* This element is referenced by the ptr_user_info, it should be empty.
*/
parse_UNISTR2(fp, &p);
fprintf(fp,"UserName=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" UserFullName=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" LogonScript=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" ProfilePath=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" HomeDir=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" DirDrive=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" ");
num_groups2 = load_32_le(p); p += 4;
gids = (DOM_GID *)p;
p += sizeof(DOM_GID) * num_groups2;
fprintf(fp,"LogonServer=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" LogonDomain=\"");
parse_UNISTR2(fp, &p);
fprintf(fp,"\" DomainSID=\"");
parse_DOM_SID2(fp, &p);
fprintf(fp,"\">\n");
fprintf(fp,"<GroupRID>\n");
for (i = 0; i < num_groups2; i++)
{
parse_rid_with_attribute(fp, &gids[i]);
}
num_sids = load_32_le(p); p += 4;
fprintf(fp,"</GroupRID>\n");
gids = (DOM_GID *)p;
p += sizeof(DOM_GID) * num_sids;
fprintf(fp,"<ExtraSID>\n");
for (i = 0; i < num_sids; i++)
{
parse_sid_with_attribute(fp, &p, &gids[i]);
}
fprintf(fp,"</ExtraSID>\n");
fprintf(fp, "</UserInfo3>\n");
/* Not implemented Resource Group, because I don't have that.
* PSID ResourceGroupDomainSid;
* ULONG ResourceGroupCount;
* [size_is(ResourceGroupCount)] PGROUP_MEMBERSHIP ResourceGroupIds;
*/
fprintf(fp, "</LogonInfo>\n");
return PAC_DUMP_OK;
}
/* check the file modified time and the existance of the output xml */
int check_file(const char* filename, int32_t cache_time)
{
struct stat buffer;
int exist = stat(filename, &buffer);
time_t now;
time(&now);
if(exist == 0)
{
if (buffer.st_mtime + cache_time < time(NULL))
{
return 0;
}
return 1;
}
else // -1
return 0;
}
int pac_to_xml_file(size_t length, void *buffer, const char *filename, int32_t cache_time)
{
PACTYPE *ppac_header;
FILE *outFile;
size_t i;
if(check_file(filename, cache_time))
{
return PAC_DUMP_OK;
}
outFile = fopen(filename, "w");
if (!outFile)
{
return PAC_DUMP_UNABLE_TO_OPEN_FILE;
}
fprintf(outFile, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
fprintf(outFile, "<PAC>\n");
ppac_header = parse_pac_header(buffer, length);
if (ppac_header != NULL)
{
for (i = 0; i < ppac_header->cBuffers; i++)
{
switch (ppac_header->Buffers[i].ulType)
{
case KRB5_PAC_LOGON_INFO:
parse_logon_info(outFile, buffer, &ppac_header->Buffers[i]);
break;
case KRB5_PAC_CREDENTIALS_INFO:
break;
case KRB5_PAC_SERVER_CHECKSUM:
parse_checksum(outFile, buffer, &ppac_header->Buffers[i], "ServerCheckSum");
break;
case KRB5_PAC_PRIVSVR_CHECKSUM:
parse_checksum(outFile, buffer, &ppac_header->Buffers[i], "PrivateServerCheckSum");
break;
case KRB5_PAC_CLIENT_INFO:
parse_client_info(outFile, buffer, &ppac_header->Buffers[i]);
break;
case KRB5_PAC_DELEGATION_INFO:
break;
case KRB5_PAC_UPN_DNS_INFO:
parse_upn_dns_info(outFile, buffer, &ppac_header->Buffers[i]);
break;
default:
break;
}
}
free(ppac_header);
}
fprintf(outFile, "</PAC>\n");
fclose(outFile);
return PAC_DUMP_OK;
}