Source code of Windows XP (NT5)
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.

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