MCPcopy Create free account
hub / github.com/CCob/lsarelayx / GetFunctionOffsets

Method GetFunctionOffsets

client/Program.cs:455–508  ·  view source on GitHub ↗
(long spmpLookupPackageOffsetHint)

Source from the content-addressed store, hash-verified

453 }
454
455 static InitResponse GetFunctionOffsets(long spmpLookupPackageOffsetHint) {
456
457 IntPtr msvHandle = IntPtr.Zero;
458
459 try {
460
461 msvHandle = LoadLibrary("msv1_0.dll");
462
463 if (msvHandle == IntPtr.Zero) {
464 Console.WriteLine("Failed to load msv1_0.dll");
465 return null;
466 }
467
468 long msvBase = (long)msvHandle;
469
470 IntPtr proc = GetProcAddress(msvHandle, "SpLsaModeInitialize");
471 if (proc == IntPtr.Zero) {
472 Console.WriteLine("Failed to find msv1_0 SpLsaModeInitialize proc");
473 return null;
474 }
475
476 var spLsaModeInitialize = (SpLsaModeInitialize)Marshal.GetDelegateForFunctionPointer(proc, typeof(SpLsaModeInitialize));
477
478 if (spLsaModeInitialize(0x10000, out uint version, out IntPtr tables, out uint tableCount) != 0) {
479 Console.WriteLine("SpLsaModeInitialize failed for msv1_0");
480 return null;
481 }
482
483
484 long spmpLookupPackageOffset = 0;
485
486 if (spmpLookupPackageOffsetHint == 0) {
487 spmpLookupPackageOffset = GetSpmpLookupPackageOffset();
488 }else {
489 Console.WriteLine("[=] Using supplied SpLsaModeInitialize hint, you get this wrong and LSASS WILL CRASH!!!");
490 spmpLookupPackageOffset = spmpLookupPackageOffsetHint;
491 }
492
493 var table = (SECPKG_FUNCTION_TABLE)Marshal.PtrToStructure(tables, typeof(SECPKG_FUNCTION_TABLE));
494
495 return new InitResponse((long)table.InitLsaModeContext - msvBase,
496 (long)table.AcceptLsaModeContext - msvBase,
497 (long)table.QueryContextAttributes - msvBase,
498 (long)table.DeleteContext - msvBase,
499 (long)table.QueryCredentialsAttributes - msvBase,
500 spmpLookupPackageOffset);
501
502 } finally {
503
504 if(msvHandle != IntPtr.Zero) {
505 FreeLibrary(msvHandle);
506 }
507 }
508 }
509
510 public static byte[] StringToByteArray(string hex) {
511 return Enumerable.Range(0, hex.Length)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected