Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

860 lines
24 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File:
  8. //
  9. // Contents:
  10. //
  11. //
  12. // History:
  13. //
  14. //------------------------------------------------------------------------
  15. extern "C"
  16. {
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. }
  22. #include <stdio.h>
  23. #include <wincred.h>
  24. #include <ntsdexts.h>
  25. #include <dsysdbg.h>
  26. #define SECURITY_PACKAGE
  27. #define SECURITY_WIN32
  28. #include <security.h>
  29. #include <secint.h>
  30. #include <cryptdll.h>
  31. #include <kerberos.h>
  32. #include <..\client2\kerb.hxx>
  33. #include <..\client2\kerbp.h>
  34. typedef struct _KDC_DOMAIN_INFO {
  35. LIST_ENTRY Next;
  36. UNICODE_STRING DnsName;
  37. UNICODE_STRING NetbiosName;
  38. struct _KDC_DOMAIN_INFO * ClosestRoute; // Points to referral target
  39. ULONG Flags;
  40. ULONG Attributes;
  41. ULONG Type;
  42. LONG References;
  43. //
  44. // Types used during building the tree
  45. //
  46. struct _KDC_DOMAIN_INFO * Parent;
  47. ULONG Touched;
  48. } KDC_DOMAIN_INFO, *PKDC_DOMAIN_INFO;
  49. #define AllocHeap(x) RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, x)
  50. #define FreeHeap(x) RtlFreeHeap(RtlProcessHeap(), 0, x)
  51. PNTSD_EXTENSION_APIS pExtApis;
  52. HANDLE hDbgThread;
  53. HANDLE hDbgProcess;
  54. #define DebuggerOut (pExtApis->lpOutputRoutine)
  55. #define GetExpr (PVOID) (pExtApis->lpGetExpressionRoutine)
  56. #define InitDebugHelp(hProc,hThd,pApis) {hDbgProcess = hProc; hDbgThread = hThd; pExtApis = pApis;}
  57. char * ContextState[] = {
  58. "IdleState",
  59. "TgtRequestSentState",
  60. "TgtReplySentState",
  61. "ApRequestSentState",
  62. "ApReplySentState",
  63. "AuthenticatedState",
  64. "ErrorMessageSentState",
  65. "InvalidState"};
  66. void PrintContextAttributes( ULONG Attributes)
  67. {
  68. DebuggerOut(" ContextAttributes\t0x%lx:", Attributes);
  69. if (Attributes & KERB_CONTEXT_MAPPED)
  70. {
  71. DebuggerOut(" KERB_CONTEXT_MAPPED");
  72. }
  73. if (Attributes & KERB_CONTEXT_OUTBOUND)
  74. {
  75. DebuggerOut(" KERB_CONTEXT_OUTBOUND");
  76. }
  77. if (Attributes & KERB_CONTEXT_INBOUND)
  78. {
  79. DebuggerOut(" KERB_CONTEXT_INBOUND");
  80. }
  81. if (Attributes & KERB_CONTEXT_USED_SUPPLIED_CREDS)
  82. {
  83. DebuggerOut(" KERB_CONTEXT_USED_SUPPLIED_CREDS");
  84. }
  85. if (Attributes & KERB_CONTEXT_USER_TO_USER)
  86. {
  87. DebuggerOut(" KERB_CONTEXT_USER_TO_USER");
  88. }
  89. if (Attributes & KERB_CONTEXT_REQ_SERVER_NAME)
  90. {
  91. DebuggerOut(" KERB_CONTEXT_REQ_SERVER_NAME");
  92. }
  93. if (Attributes & KERB_CONTEXT_REQ_SERVER_REALM)
  94. {
  95. DebuggerOut(" KERB_CONTEXT_REQ_SERVER_REALM");
  96. }
  97. if (Attributes & KERB_CONTEXT_IMPORTED)
  98. {
  99. DebuggerOut(" KERB_CONTEXT_IMPORTED");
  100. }
  101. if (Attributes & KERB_CONTEXT_EXPORTED)
  102. {
  103. DebuggerOut(" KERB_CONTEXT_EXPORTED");
  104. }
  105. DebuggerOut("\n");
  106. }
  107. void PrintContextFlags ( ULONG Flags)
  108. {
  109. DebuggerOut(" ContextFlags for 0x%lx are:\n", Flags);
  110. if (Flags & 0x00000001)
  111. {
  112. DebuggerOut("\tISC(ASC)_REQ(RET)_DELEGATE\n");
  113. }
  114. if (Flags & 0x00000002)
  115. {
  116. DebuggerOut("\tISC(ASC)_REQ(RET)_MUTUAL_AUTH\n");
  117. }
  118. if (Flags & 0x00000004)
  119. {
  120. DebuggerOut("\tISC(ASC)_REQ(RET)_REPLAY_DETECT\n");
  121. }
  122. if (Flags & 0x00000008)
  123. {
  124. DebuggerOut("\tISC(ASC)_REQ(RET)_SEQUENCE_DETECT\n");
  125. }
  126. if (Flags & 0x00000010)
  127. {
  128. DebuggerOut("\tISC(ASC)_REQ(RET)_CONFIDENTIALITY\n");
  129. }
  130. if (Flags & 0x00000020)
  131. {
  132. DebuggerOut("\tISC(ASC)_REQ(RET)_USE_SESSION_KEY\n");
  133. }
  134. if (Flags & 0x00000040)
  135. {
  136. DebuggerOut("\tISC_REQ_PROMPT_FOR_CREDS or ISC_RET_USED_COLLECTED_CREDS\n");
  137. }
  138. if (Flags & 0x00000080)
  139. {
  140. DebuggerOut("\tISC_REQ_USE_SUPPLIED_CREDS or ISC_RET_USED_SUPPLIED_CREDS\n");
  141. }
  142. if (Flags & 0x00000100)
  143. {
  144. DebuggerOut("\tISC(ASC)_REQ_ALLOCATE_MEMORY or ISC(ASC)_RET_ALLOCATED_MEMORY\n");
  145. }
  146. if (Flags & 0x00000200)
  147. {
  148. DebuggerOut("\tISC(ASC)_REQ_USE_DCE_STYLE or ISC(ASC)_RET_USED_DCE_STYLE\n");
  149. }
  150. if (Flags & 0x00000400)
  151. {
  152. DebuggerOut("\tISC(ASC)_REQ(RET)_DATAGRAM\n");
  153. }
  154. if (Flags & 0x00000800)
  155. {
  156. DebuggerOut("\tISC(ASC)_REQ(RET)_CONNECTION\n");
  157. }
  158. if (Flags & 0x00001000)
  159. {
  160. DebuggerOut("\tISC(ASC)_REQ_CALL_LEVEL or ISC_RET_INTERMEDIATE_RETURN\n");
  161. }
  162. if (Flags & 0x00002000)
  163. {
  164. DebuggerOut("\tISC(ASC)_RET_CALL_LEVEL\n");
  165. }
  166. if (Flags & 0x00004000)
  167. {
  168. DebuggerOut("\tISC_REQ(RET)_EXTENDED_ERROR or ASC_RET_THIRD_LEG_FAILED\n");
  169. }
  170. if (Flags & 0x00008000)
  171. {
  172. DebuggerOut("\tISC_REQ(RET)_STREAM or ASC_REQ(RET)_EXTENDED_ERROR\n");
  173. }
  174. if (Flags & 0x00010000)
  175. {
  176. DebuggerOut("\tISC_REQ(RET)_INTEGRITY or ASC_REQ(RET)_STREAM\n");
  177. }
  178. if (Flags & 0x00020000)
  179. {
  180. DebuggerOut("\tISC_REQ(RET)_IDENTIFY or ASC_REQ(RET)_INTEGRITY\n");
  181. }
  182. if (Flags & 0x00040000)
  183. {
  184. DebuggerOut("\tISC_REQ(RET)_NULL_SESSION or ASC_REQ(RET)_LICENSING\n");
  185. }
  186. if (Flags & 0x00080000)
  187. {
  188. DebuggerOut("\tISC_REQ(RET)_MANUAL_CRED_VALIDATION or ASC_REQ(RET)_IDENTIFY\n");
  189. }
  190. if (Flags & 0x00100000)
  191. {
  192. DebuggerOut("\tISC_REQ(RET)_DELEGATE_IF_SAFE or ASC_REQ_ALLOW_NULL_SESSION or ASC_RET_NULL_SESSION\n");
  193. }
  194. if (Flags & 0x00200000)
  195. {
  196. DebuggerOut("\tASC_REQ(RET)_ALLOW_NON_USER_LOGONS\n");
  197. }
  198. if (Flags & 0x00400000)
  199. {
  200. DebuggerOut("\tASC_REQ(RET)_ALLOW_CONTEXT_REPLAY\n");
  201. }
  202. }
  203. SECURITY_STATUS
  204. ReadMemory( PVOID pvAddress,
  205. ULONG cbMemory,
  206. PVOID pvLocalMemory)
  207. {
  208. SIZE_T cbActual = cbMemory;
  209. if (ReadProcessMemory(hDbgProcess, pvAddress, pvLocalMemory, cbMemory, &cbActual))
  210. {
  211. if (cbActual != cbMemory)
  212. {
  213. DebuggerOut(" counts don't match\n");
  214. return(-1);
  215. }
  216. return(0);
  217. }
  218. DebuggerOut(" GetLastError from readMemory is %d\n", GetLastError());
  219. return(GetLastError());
  220. }
  221. SECURITY_STATUS
  222. WriteMemory(PVOID pvLocalMemory,
  223. ULONG cbMemory,
  224. PVOID pvAddress)
  225. {
  226. SIZE_T cbActual = cbMemory;
  227. if (WriteProcessMemory(hDbgProcess, pvAddress, pvLocalMemory, cbMemory, &cbActual))
  228. {
  229. if (cbActual != cbMemory)
  230. {
  231. return(-1);
  232. }
  233. return(0);
  234. }
  235. return(GetLastError());
  236. }
  237. DWORD
  238. GetDword(PVOID pvMemory)
  239. {
  240. DWORD dwVal;
  241. SIZE_T cbActual = sizeof(DWORD);
  242. if (ReadProcessMemory(hDbgProcess, pvMemory, &dwVal, sizeof(DWORD), &cbActual))
  243. {
  244. if (cbActual != sizeof(DWORD))
  245. {
  246. return((DWORD) -1);
  247. }
  248. return(dwVal);
  249. }
  250. return((DWORD) -1);
  251. }
  252. #define TIMEBUF_SZ 64
  253. char *Months[] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
  254. "Aug", "Sep", "Oct", "Nov", "Dec" };
  255. void CTimeStamp(PTimeStamp ptsTime,
  256. LPSTR pszTimeBuf)
  257. {
  258. SYSTEMTIME stTime;
  259. FILETIME tLocal;
  260. SYSTEMTIME stLocal;
  261. if (ptsTime->HighPart == 0)
  262. {
  263. strcpy(pszTimeBuf, "<Zero>");
  264. }
  265. else if (ptsTime->HighPart >= 0x7FFFFFFF)
  266. {
  267. strcpy(pszTimeBuf, "<Never>");
  268. }
  269. FileTimeToLocalFileTime((LPFILETIME) ptsTime, &tLocal);
  270. FileTimeToSystemTime((LPFILETIME) ptsTime, &stTime);
  271. FileTimeToSystemTime(&tLocal, &stLocal);
  272. sprintf(pszTimeBuf, "%02d:%02d:%02d.%03d, %s %02d, %d UTC (%02d:%02d:%02d.%03d, %s %02d, %d Local)", stTime.wHour,
  273. stTime.wMinute, stTime.wSecond, stTime.wMilliseconds,
  274. Months[stTime.wMonth], stTime.wDay, stTime.wYear,
  275. stLocal.wHour, stLocal.wMinute, stLocal.wSecond, stLocal.wMilliseconds, Months[stLocal.wMonth], stLocal.wDay, stLocal.wYear);
  276. }
  277. void ContextTimeStamp(PTimeStamp ptsTime,
  278. LPSTR pszTimeBuf)
  279. {
  280. // We set local times in sspi
  281. SYSTEMTIME stTime;
  282. FILETIME tutc;
  283. SYSTEMTIME stLocal;
  284. TimeStamp Time;
  285. if (ReadMemory( ptsTime, sizeof( TimeStamp), &Time))
  286. {
  287. DebuggerOut(" Could not read context\n");
  288. return;
  289. }
  290. if (Time.HighPart == 0)
  291. {
  292. strcpy(pszTimeBuf, "<Zero>");
  293. }
  294. else if (Time.HighPart >= 0x7FFFFFFF)
  295. {
  296. strcpy(pszTimeBuf, "<Never>");
  297. }
  298. FileTimeToSystemTime((LPFILETIME) &Time, &stLocal);
  299. LocalFileTimeToFileTime((LPFILETIME) &Time, &tutc);
  300. FileTimeToSystemTime(&tutc, &stTime);
  301. sprintf(pszTimeBuf, "%02d:%02d:%02d.%03d, %s %02d, %d UTC (%02d:%02d:%02d.%03d, %s %02d, %d Local)", stTime.wHour,
  302. stTime.wMinute, stTime.wSecond, stTime.wMilliseconds,
  303. Months[stTime.wMonth], stTime.wDay, stTime.wYear,
  304. stLocal.wHour, stLocal.wMinute, stLocal.wSecond, stLocal.wMilliseconds, Months[stLocal.wMonth], stLocal.wDay, stLocal.wYear);
  305. }
  306. void
  307. MapString(PSECURITY_STRING pClientString,
  308. PSECURITY_STRING pLocalString)
  309. {
  310. if (!pLocalString->Buffer)
  311. {
  312. pLocalString->Buffer = (PWSTR) AllocHeap(pClientString->Length + 2);
  313. if (pLocalString->Buffer == NULL)
  314. {
  315. return;
  316. }
  317. pLocalString->MaximumLength = pClientString->Length + 2;
  318. }
  319. RtlZeroMemory(pLocalString->Buffer, pLocalString->MaximumLength);
  320. if (!ReadMemory(pClientString->Buffer, pClientString->Length, pLocalString->Buffer))
  321. {
  322. pLocalString->Length = pClientString->Length;
  323. }
  324. else
  325. {
  326. DebuggerOut("\nWarning: could not read string @%x\n", pClientString->Buffer);
  327. }
  328. }
  329. void PrintSid(PVOID pvSid)
  330. {
  331. SID Sid;
  332. PSID pSid;
  333. UNICODE_STRING ucsSid = {0};
  334. DebuggerOut(" UserSid \t0x%lx ", pvSid);
  335. if (pvSid)
  336. {
  337. if (ReadMemory(pvSid, sizeof(SID), &Sid))
  338. {
  339. DebuggerOut("Could not read from %x\n", pvSid);
  340. }
  341. pSid = AllocHeap(RtlLengthRequiredSid(Sid.SubAuthorityCount));
  342. if (pSid == NULL)
  343. {
  344. return;
  345. }
  346. if (ReadMemory(pvSid, RtlLengthRequiredSid(Sid.SubAuthorityCount), pSid))
  347. {
  348. DebuggerOut("Could not read from %x\n", pvSid);
  349. }
  350. RtlConvertSidToUnicodeString(&ucsSid, pSid, TRUE);
  351. if ( ucsSid.Buffer )
  352. {
  353. DebuggerOut(" %wZ", &ucsSid);
  354. RtlFreeUnicodeString(&ucsSid);
  355. }
  356. FreeHeap(pSid);
  357. }
  358. DebuggerOut("\n");
  359. }
  360. VOID
  361. PrintEType(
  362. ULONG EType
  363. )
  364. {
  365. switch(EType)
  366. {
  367. case KERB_ETYPE_NULL:
  368. DebuggerOut("KERB_ETYPE_NULL\n"); break;
  369. case KERB_ETYPE_DES_CBC_CRC:
  370. DebuggerOut("KERB_ETYPE_DES_CBC_CRC\n"); break;
  371. case KERB_ETYPE_DES_CBC_MD4:
  372. DebuggerOut("KERB_ETYPE_DES_CBC_MD4\n"); break;
  373. case KERB_ETYPE_DES_CBC_MD5:
  374. DebuggerOut("KERB_ETYPE_DES_CBC_MD5\n"); break;
  375. case KERB_ETYPE_OLD_RC4_MD4:
  376. DebuggerOut("KERB_ETYPE_OLD_RC4_MD4\n"); break;
  377. case KERB_ETYPE_OLD_RC4_PLAIN:
  378. DebuggerOut("KERB_ETYPE_OLD_RC4_PLAIN\n"); break;
  379. case KERB_ETYPE_OLD_RC4_LM:
  380. DebuggerOut("KERB_ETYPE_OLD_RC4_LM\n"); break;
  381. case KERB_ETYPE_OLD_RC4_SHA:
  382. DebuggerOut("KERB_ETYPE_OLD_RC4_SHA\n"); break;
  383. case KERB_ETYPE_OLD_DES_PLAIN:
  384. DebuggerOut("KERB_ETYPE_OLD_DES_PLAIN\n"); break;
  385. case KERB_ETYPE_RC4_MD4:
  386. DebuggerOut("KERB_ETYPE_RC4_MD4\n"); break;
  387. case KERB_ETYPE_RC4_PLAIN2:
  388. DebuggerOut("KERB_ETYPE_RC4_PLAIN2\n"); break;
  389. case KERB_ETYPE_RC4_LM:
  390. DebuggerOut("KERB_ETYPE_RC4_LM\n"); break;
  391. case KERB_ETYPE_RC4_SHA:
  392. DebuggerOut("KERB_ETYPE_RC4_SHA\n"); break;
  393. case KERB_ETYPE_DES_PLAIN:
  394. DebuggerOut("KERB_ETYPE_DES_PLAIN\n"); break;
  395. case KERB_ETYPE_RC4_PLAIN:
  396. DebuggerOut("KERB_ETYPE_RC4_PLAIN\n"); break;
  397. case KERB_ETYPE_RC4_HMAC_OLD:
  398. DebuggerOut("KERB_ETYPE_RC4_HMAC_OLD\n"); break;
  399. case KERB_ETYPE_RC4_HMAC_OLD_EXP:
  400. DebuggerOut("KERB_ETYPE_RC4_HMAC_OLD_EXP\n"); break;
  401. case KERB_ETYPE_RC4_PLAIN_EXP:
  402. DebuggerOut("KERB_ETYPE_RC4_PLAIN_EXP\n"); break;
  403. case KERB_ETYPE_DSA_SIGN:
  404. DebuggerOut("KERB_ETYPE_DSA_SIGN\n"); break;
  405. case KERB_ETYPE_RSA_PRIV:
  406. DebuggerOut("KERB_ETYPE_RSA_PRIV\n"); break;
  407. case KERB_ETYPE_RSA_PUB:
  408. DebuggerOut("KERB_ETYPE_RSA_PUB\n"); break;
  409. case KERB_ETYPE_RSA_PUB_MD5:
  410. DebuggerOut("KERB_ETYPE_RSA_PUB_MD5\n"); break;
  411. case KERB_ETYPE_RSA_PUB_SHA1:
  412. DebuggerOut("KERB_ETYPE_RSA_PUB_SHA1\n"); break;
  413. case KERB_ETYPE_PKCS7_PUB:
  414. DebuggerOut("KERB_ETYPE_PKCS7_PUB\n"); break;
  415. case KERB_ETYPE_DES_CBC_MD5_NT:
  416. DebuggerOut("KERB_ETYPE_DES_CBC_MD5_NT\n"); break;
  417. default:
  418. DebuggerOut("Unknown EType: 0x%lx\n", EType); break;
  419. }
  420. }
  421. VOID
  422. ShowKerbContext(
  423. IN PVOID pContext
  424. )
  425. {
  426. KERB_CONTEXT Context;
  427. CHAR TimeBuf[80];
  428. SECURITY_STRING sLocal;
  429. sLocal.Buffer = NULL;
  430. if (ReadMemory( pContext, sizeof( KERB_CONTEXT), &Context ))
  431. {
  432. DebuggerOut(" Could not read context\n");
  433. return;
  434. }
  435. CTimeStamp( &Context.Lifetime, TimeBuf );
  436. DebuggerOut(" Lifetime \t%s\n", TimeBuf );
  437. CTimeStamp( &Context.RenewTime, TimeBuf );
  438. DebuggerOut(" RenewTime \t%s\n", TimeBuf );
  439. MapString( &Context.ClientName, &sLocal);
  440. DebuggerOut(" ClientName \t%ws\n", sLocal.Buffer);
  441. FreeHeap(sLocal.Buffer);
  442. sLocal.Buffer = NULL;
  443. MapString( &Context.ClientRealm, &sLocal);
  444. DebuggerOut(" ClientRealm \t%ws\n", sLocal.Buffer);
  445. FreeHeap(sLocal.Buffer);
  446. sLocal.Buffer = NULL;
  447. DebuggerOut(" Process ID \t0x%lx\n", Context.ClientProcess);
  448. DebuggerOut(" LogonId \t0x%lx : 0x%lx\n", Context.LogonId.LowPart, Context.LogonId.HighPart );
  449. DebuggerOut(" TokenHandle \t0x%lx\n", Context.TokenHandle );
  450. DebuggerOut(" CredentialHandle\t0x%lx\n", Context.CredentialHandle);
  451. DebuggerOut(" SessionKey type \t");
  452. PrintEType(Context.SessionKey.keytype);
  453. DebuggerOut(" SessionKey length \t0x%lx\n", Context.SessionKey.keyvalue.length);
  454. DebuggerOut(" Nonce \t0x%lx\n", Context.Nonce);
  455. DebuggerOut(" ReceiveNonce \t0x%lx\n", Context.ReceiveNonce);
  456. DebuggerOut(" ContextFlags \t0x%lx\n", Context.ContextFlags);
  457. PrintContextAttributes(Context.ContextAttributes);
  458. DebuggerOut(" EncryptionType \t");
  459. PrintEType(Context.EncryptionType);
  460. PrintSid(Context.UserSid);
  461. DebuggerOut(" ContextState \t%s\n", ContextState[Context.ContextState]);
  462. DebuggerOut(" Retries \t0x%lx\n", Context.Retries );
  463. DebuggerOut(" TicketKey type \t");
  464. PrintEType(Context.TicketKey.keytype);
  465. DebuggerOut(" TicketKey length\t0x%lx\n", Context.TicketKey.keyvalue.length);
  466. DebuggerOut(" TicketCacheEntry\t0x%lx\n", Context.TicketCacheEntry);
  467. }
  468. VOID
  469. DumpContext(
  470. HANDLE hProcess,
  471. HANDLE hThread,
  472. DWORD dwCurrentPc,
  473. PNTSD_EXTENSION_APIS lpExt,
  474. LPSTR pszCommand)
  475. {
  476. PVOID pContext;
  477. InitDebugHelp( hProcess,
  478. hThread,
  479. lpExt);
  480. pContext = GetExpr( pszCommand );
  481. if ( pContext == NULL ) {
  482. return;
  483. }
  484. ShowKerbContext( pContext );
  485. }
  486. void PrintLogonType(SECURITY_LOGON_TYPE LogonType)
  487. {
  488. switch(LogonType)
  489. {
  490. case Interactive:
  491. DebuggerOut("Interactive\n"); break;
  492. case Network:
  493. DebuggerOut("Network\n"); break;
  494. case Batch:
  495. DebuggerOut("Batch\n"); break;
  496. case Service:
  497. DebuggerOut("Service\n"); break;
  498. case Proxy:
  499. DebuggerOut("Proxy\n"); break;
  500. case Unlock:
  501. DebuggerOut("Unlock\n"); break;
  502. default:
  503. DebuggerOut("Unknown Logon Type: 0x%lx\n", LogonType); break;
  504. }
  505. }
  506. VOID
  507. ShowKerbTCacheEntry(PVOID pCache)
  508. {
  509. /*
  510. typedef struct _KERB_TICKET_CACHE_ENTRY {
  511. KERBEROS_LIST_ENTRY ListEntry;
  512. PKERB_INTERNAL_NAME ServiceName;
  513. PKERB_INTERNAL_NAME TargetName;
  514. UNICODE_STRING DomainName;
  515. UNICODE_STRING TargetDomainName;
  516. UNICODE_STRING AltTargetDomainName;
  517. PKERB_INTERNAL_NAME ClientName;
  518. ULONG TicketFlags;
  519. ULONG CacheFlags;
  520. KERB_ENCRYPTION_KEY SessionKey;
  521. TimeStamp KeyExpirationTime;
  522. TimeStamp StartTime;
  523. TimeStamp EndTime;
  524. TimeStamp RenewUntil;
  525. KERB_TICKET Ticket;
  526. TimeStamp TimeSkew;
  527. } KERB_TICKET_CACHE_ENTRY, *PKERB_TICKET_CACHE_ENTRY;
  528. */
  529. KERB_TICKET_CACHE_ENTRY Cache;
  530. CHAR TimeBuf[64];
  531. SECURITY_STRING sLocal;
  532. ULONG Temp;
  533. sLocal.Buffer = NULL;
  534. if (ReadMemory( pCache, sizeof( KERB_TICKET_CACHE_ENTRY), &Cache))
  535. {
  536. DebuggerOut(" Could not read ticket cache entry\n");
  537. return;
  538. }
  539. DebuggerOut(" ServiceName \t0x%lx\n", Cache.ServiceName);
  540. DebuggerOut(" TargetName \t0x%lx\n", Cache.TargetName);
  541. MapString( &Cache.DomainName, &sLocal);
  542. DebuggerOut(" DomainName \t%ws\n", sLocal.Buffer);
  543. FreeHeap(sLocal.Buffer);
  544. sLocal.Buffer = NULL;
  545. MapString( &Cache.TargetDomainName, &sLocal);
  546. DebuggerOut(" TargetDomainName \t%ws\n", sLocal.Buffer);
  547. FreeHeap(sLocal.Buffer);
  548. sLocal.Buffer = NULL;
  549. MapString( &Cache.AltTargetDomainName, &sLocal);
  550. DebuggerOut(" AltTargetDomainName \t%ws\n", sLocal.Buffer);
  551. FreeHeap(sLocal.Buffer);
  552. sLocal.Buffer = NULL;
  553. DebuggerOut(" ClientName \t0x%lx\n", Cache.ClientName);
  554. DebuggerOut(" TicketFlags \t0x%lx\n", Cache.TicketFlags);
  555. DebuggerOut(" CacheFlags \t0x%lx\n", Cache.CacheFlags);
  556. DebuggerOut(" EncryptionType \t");
  557. PrintEType(Cache.SessionKey.keytype);
  558. CTimeStamp( &Cache.StartTime, TimeBuf );
  559. DebuggerOut(" StartTime \t%s\n", TimeBuf );
  560. CTimeStamp( &Cache.EndTime, TimeBuf );
  561. DebuggerOut(" Endtime \t%s\n", TimeBuf );
  562. CTimeStamp( &Cache.RenewUntil, TimeBuf );
  563. DebuggerOut(" RenewUntil \t%s\n", TimeBuf );
  564. }
  565. VOID
  566. ShowKerbLSession(
  567. IN PVOID pSession
  568. )
  569. {
  570. KERB_LOGON_SESSION Session;
  571. CHAR TimeBuf[64];
  572. SECURITY_STRING sLocal;
  573. ULONG_PTR Temp;
  574. sLocal.Buffer = NULL;
  575. if (ReadMemory( pSession, sizeof( KERB_LOGON_SESSION), &Session))
  576. {
  577. DebuggerOut(" Could not read logon session\n");
  578. return;
  579. }
  580. //DebuggerOut(" Credential \t0x%lx\n", Session.SspCredentials);
  581. DebuggerOut(" LogonId \t0x%lx : 0x%lx\n", Session.LogonId.LowPart, Session.LogonId.HighPart );
  582. CTimeStamp( &Session.Lifetime, TimeBuf );
  583. DebuggerOut(" Lifetime \t%s\n", TimeBuf );
  584. //PrintPCred(Session.PrimaryCredentials);
  585. MapString( &Session.PrimaryCredentials.UserName, &sLocal);
  586. DebuggerOut(" UserName \t%ws\n", sLocal.Buffer);
  587. FreeHeap(sLocal.Buffer);
  588. sLocal.Buffer = NULL;
  589. MapString( &Session.PrimaryCredentials.DomainName, &sLocal);
  590. DebuggerOut(" DomainName \t%ws\n", sLocal.Buffer);
  591. FreeHeap(sLocal.Buffer);
  592. sLocal.Buffer = NULL;
  593. DebuggerOut(" Passwords \t0x%lx\n", Session.PrimaryCredentials.Passwords);
  594. DebuggerOut(" OldPasswords \t0x%lx\n", Session.PrimaryCredentials.OldPasswords);
  595. DebuggerOut(" PublicKeyCreds \t0x%lx\n", Session.PrimaryCredentials.PublicKeyCreds);
  596. DebuggerOut(" LogonSessionFlags\t0x%lx\n", Session.LogonSessionFlags);
  597. // ServerTicketCache
  598. Temp = (ULONG_PTR)pSession+ FIELD_OFFSET(KERB_LOGON_SESSION, PrimaryCredentials) + FIELD_OFFSET(KERB_PRIMARY_CREDENTIAL, ServerTicketCache);
  599. DebuggerOut(" ServerTicketCache \t0x%p\n", Temp);
  600. // AuthenticationTicketCache
  601. Temp = (ULONG_PTR)pSession+ FIELD_OFFSET(KERB_LOGON_SESSION, PrimaryCredentials) + FIELD_OFFSET(KERB_PRIMARY_CREDENTIAL, AuthenticationTicketCache);
  602. DebuggerOut(" AuthenticationTicketCache \t0x%p\n", Temp );
  603. }
  604. VOID
  605. DumpLSession(
  606. HANDLE hProcess,
  607. HANDLE hThread,
  608. DWORD dwCurrentPc,
  609. PNTSD_EXTENSION_APIS lpExt,
  610. LPSTR pszCommand)
  611. {
  612. PVOID pSession;
  613. InitDebugHelp( hProcess,
  614. hThread,
  615. lpExt);
  616. pSession = GetExpr( pszCommand );
  617. if ( pSession == NULL ) {
  618. return;
  619. }
  620. ShowKerbLSession( pSession);
  621. }
  622. VOID
  623. DumpTCacheEntry(
  624. HANDLE hProcess,
  625. HANDLE hThread,
  626. DWORD dwCurrentPc,
  627. PNTSD_EXTENSION_APIS lpExt,
  628. LPSTR pszCommand)
  629. {
  630. PVOID pCache;
  631. InitDebugHelp( hProcess,
  632. hThread,
  633. lpExt);
  634. pCache = GetExpr( pszCommand );
  635. if ( pCache == NULL ) {
  636. return;
  637. }
  638. ShowKerbTCacheEntry( pCache);
  639. }
  640. /*
  641. VOID
  642. ShowDomainList(PVOID pDomain)
  643. {
  644. PLIST_ENTRY DomainList = (PLIST_ENTRY) pDomain;
  645. SECURITY_STRING sLocal;
  646. PLIST_ENTRY ListEntry;
  647. PKDC_DOMAIN_INFO Domain;
  648. for (ListEntry = DomainList->Flink;
  649. ListEntry != DomainList ;
  650. ListEntry = ListEntry->Flink )
  651. {
  652. Domain = (PKDC_DOMAIN_INFO) CONTAINING_RECORD(ListEntry, KDC_DOMAIN_INFO, Next);
  653. MapString( &Domain->DnsName, &sLocal);
  654. DebuggerOut(" DomainName \t%ws\n", sLocal.Buffer);
  655. FreeHeap(sLocal.Buffer);
  656. sLocal.Buffer = NULL;
  657. if (Domain->ClosestRoute == NULL)
  658. {
  659. DebuggerOut(" No closest route\n");
  660. }
  661. else
  662. {
  663. MapString( Domain->ClosestRoute, &sLocal);
  664. DebuggerOut(" Closest Route \t%ws\n", sLocal.Buffer);
  665. FreeHeap(sLocal.Buffer);
  666. sLocal.Buffer = NULL;
  667. }
  668. if (Domain->Parent == NULL)
  669. {
  670. DebuggerOut(" No parent\n");
  671. }
  672. else
  673. {
  674. MapString( &Domain->Parent->DnsName, &sLocal);
  675. DebuggerOut(" Parent \t%ws\n", sLocal.Buffer);
  676. FreeHeap(sLocal.Buffer);
  677. sLocal.Buffer = NULL;
  678. }
  679. }
  680. }
  681. VOID
  682. DumpReferralTree(
  683. HANDLE hProcess,
  684. HANDLE hThread,
  685. DWORD dwCurrentPc,
  686. PNTSD_EXTENSION_APIS lpExt,
  687. LPSTR pszCommand)
  688. {
  689. PVOID pDomain;
  690. InitDebugHelp( hProcess,
  691. hThread,
  692. lpExt);
  693. pDomain = GetExpr( pszCommand );
  694. if ( pDomain == NULL ) {
  695. return;
  696. }
  697. ShowDomainList(pDomain);
  698. }
  699. */
  700. VOID
  701. DumpContextFlags(
  702. HANDLE hProcess,
  703. HANDLE hThread,
  704. DWORD dwCurrentPc,
  705. PNTSD_EXTENSION_APIS lpExt,
  706. LPSTR pszCommand)
  707. {
  708. PVOID pContext;
  709. InitDebugHelp( hProcess,
  710. hThread,
  711. lpExt);
  712. pContext = GetExpr( pszCommand );
  713. if ( pContext == NULL ) {
  714. return;
  715. }
  716. PrintContextFlags( (ULONG)((ULONG_PTR)pContext) );
  717. }
  718. VOID
  719. DumpCTimeStamp(
  720. HANDLE hProcess,
  721. HANDLE hThread,
  722. DWORD dwCurrentPc,
  723. PNTSD_EXTENSION_APIS lpExt,
  724. LPSTR pszCommand)
  725. {
  726. PVOID pContext;
  727. CHAR TimeBuf[100];
  728. InitDebugHelp( hProcess,
  729. hThread,
  730. lpExt);
  731. pContext = GetExpr( pszCommand );
  732. if ( pContext == NULL ) {
  733. return;
  734. }
  735. ContextTimeStamp( (PTimeStamp) pContext, TimeBuf );
  736. DebuggerOut(" TimeStamp \t%s\n", TimeBuf );
  737. }
  738. void
  739. Help( HANDLE hProcess,
  740. HANDLE hThread,
  741. DWORD dwCurrentPc,
  742. PNTSD_EXTENSION_APIS lpExt,
  743. LPSTR pszCommand)
  744. {
  745. InitDebugHelp(hProcess, hThread, lpExt);
  746. DebuggerOut("Kerberos Exts Debug Help\n");
  747. DebuggerOut(" DumpContext <addr> \tDumps a Kerberos context\n");
  748. DebuggerOut(" DumpLSession <addr> \tDumps a Kerberos logon session\n");
  749. DebuggerOut(" DumpTCacheEntry <addr> \tDumps a Kerberos ticket cache entry\n");
  750. DebuggerOut(" DumpContextFlags <hex ulong>\tDumps an SSPI context flags\n");
  751. DebuggerOut(" DumpCTimeStamp <hex ulong>\tDumps a Context Expiry Time\n");
  752. }