PowerShell安全專題之攻擊工具篇

玄學醬發表於2017-09-25
本文講的是PowerShell安全專題之攻擊工具篇

PowerShell 成為攻擊工具的演變過程

PowerShell 是一個內建在每個受支援的Windows版本中 (Windows 7 / Windows 2008 R2 和更高版本)的命令列程式,它能夠提供令人難以置信的靈活性和功能化管理 Windows 系統的能力。這種能力使得 PowerShell 正在吸引攻擊者使它逐漸成為一個非常流行且得力的攻擊工具。一旦攻擊者可以在一臺計算機上執行程式碼,他們就會執行 PowerShell 程式碼,因為PS程式碼可以執行在防病毒軟體不能看到的地方如記憶體中。攻擊者還可能會下載 PowerShell 指令碼檔案 (.ps1) 到磁碟中,因為 PowerShell 能夠提供從網站下載程式碼並在記憶體中執行的能力,不過這常常是不必要。

Dave Kennedy & Josh Kelley 在 DEF CON 18(2010 年) 演講了攻擊者如何利用 PowerShell進行攻擊的主題。Matt Graeber 開發了 PowerSploit 並在 Monday.com 發表了博文—— 為什麼 PowerShell 是一個強大的攻擊平臺。”PowerSploit“在 2012 年被髮布後,PowerShell 被用來作為攻擊平臺的趨勢快速上升,直到大約一年後 Mimikatz 開始支援 PowerShell 呼叫 (aka Invoke-Mimikatz) ,這使得 PowerShell 作為攻擊工具的使用變得更為流行。PowerShell 提供了強大的能力,因為它可以執行從其他主機 (或網際網路) 上下載的 .Net 程式碼並動態執行,甚至無需寫到磁碟中執行,也能夠在記憶體中執行。這些特點使得 PowerShell 在獲得和保持對系統的訪問許可權時, 就成為了攻擊者首選的攻擊手段,利用PS的諸多特點攻擊者可以持續攻擊而不會被輕易發現。PowerShell v5 極大的提高了 PowerShell 的安全性並且在 Windows 10系統上執行 PowerShell 時,PowerShell 的攻擊能力將會大大降低。

攻擊者的多種選擇

這篇文章顯然會提到攻擊者可以如何顛覆 PowerShell 最新的安全增強特性,包括 PowerShell v5。請記住,攻擊者還有更多選擇。PowerShell 只是選擇之一,exe則是另一種方式。其他的選擇包括︰

自定義可執行檔案 (Exe,Dll 等)
Windows 命令列工具(CMD)
遠端桌面
Sysinternal 工具集
Windows 指令碼宿主
VBScript
CScript
JavaScript
批處理檔案
PowerShell

PowerShell 的攻擊能力

許多的攻擊者喜歡使用 PowerShell 的原因如下︰

能夠在記憶體中執行程式碼,而不需要寫入磁碟檔案。
能夠從另一個系統中下載並執行程式碼。
能夠直接呼叫.Net 和 Windows API。
內建了遠端操作的功能。
CMD.exe 通常會被限制執行而 PowerShell 不會。
大多數企業組織都不太關注 PowerShell 的活動情況。
很多端點安全產品不具有視覺化 PowerShell 活動的功能。

PowerShell 在客戶端攻擊中常常被利用並且會頻繁地呼叫下列執行選項 (通常是編碼過的命令(bypasses exec. policy)。

以下是幾個典型的 PowerShell 執行選項:

WindowsStyle Hidden
NoProfile
ExecutionPolicy Bypass
File
Command
EncodedCommand

現實世界中的 PowerShell 攻擊工具

PowerSploit

描述︰ 這是眾多 PowerShell 攻擊工具中被廣泛使用的 PowerShell 後期漏洞利用框架。 使用場景︰ 資訊探測,特權提升,憑證竊取,持久化。 作者︰ Matt Graeber (@Mattifestation) & Chris Campbell (@obscuresec)

常用的cmdlets:

Invoke-DllInjection.ps1
Invoke-Shellcode.ps1
Invoke-WmiCommand.ps1
Get-GPPPassword.ps1
Get-Keystrokes.ps1
Get-TimedScreenshot.ps1
Get-VaultCredential.ps1
Invoke-CredentialInjection.ps1
Invoke-Mimikatz.ps1
Invoke-NinjaCopy.ps1
Invoke-TokenManipulation.ps1
Out-Minidump.ps1
VolumeShadowCopyTools.ps1
Invoke-ReflectivePEInjection.ps1

Invoke-Mimikatz

功能特性︰ 能夠在 PowerShell 中執行 Mimikatz,憑證偷竊 & 注入,偽造 Kerberos 票證建立,還有很多很多功能。 使用場景︰ 憑證竊取 & 重用,持久化 作者︰ Joseph Bialek (@clymb3r)

PowerShell安全專題之攻擊工具篇

PowerView

描述︰ 一款純粹的 PowerShell 域/網路態勢感知工具。現在是 PowerSploit 的一部分。 使用︰ 資訊探測 作者︰ Will Harmjoy (@HarmJ0y)

常用的cmslets:

Get-NetUser
Get-NetGroup
Get-NetGroupMember
Get-NetLocalGroup
Get-NetSession
Invoke-UserHunter
Get-NetOU
Find-GPOLocation
Get-NetGPOGroup
Get-ObjectACL
Add-ObjectACL
Invoke-ACLScanner
Set-ADObject
Invoke-DowngradeAccount
Get-NetForest
Get-NetForestTrust
Get-NetForestDomain
Get-NetDomainTrust
Get-MapDomainTrust

PowerShell安全專題之攻擊工具篇

PowerUp

描述︰ 本地特權提升的一些呼叫方法,也是 PowerShell Empire 的一部分。 使用︰ 特權提升 作者︰ Will Harmjoy (@harmj0y)

Get-ServiceUnquoted
Get-ServiceFilePermission
Get-ServicePermission
Invoke-ServiceAbuse
Install-ServiceBinary
Get-RegAutoLogon
Get-VulnAutoRun
Get-VulnSchTask
Get-UnattendedInstallFile
Get-WebConfig
Get-ApplicationHost
Get-RegAlwaysInstallElevated

Nishang

描述︰ PowerShell 滲透測試。 使用場景︰ 資訊探測,憑據竊取,特權提升,持久化。 作者: Nikhil Mitt (@nikhil_mitt)

Get-Unconstrained
Add-RegBackdoor
Add-ScrnSaveBackdoor
Gupt-Backdoor
Invoke-ADSBackdoor
Enabled-DuplicateToken
Invoke-PsUaCme
Remove-Update
Check-VM
Copy-VSS
Get-Information
Get-LSASecret
Get-PassHashes
Invoke-Mimikatz
Show-TargetScreen
Port-Scan
Invoke-PoshRatHttp
Invoke-PowerShellTCP
Invoke-PowerShellWMI
Add-Exfiltration
Add-Persistence
Do-Exfiltration
Start-CaptureServer

PowerShell Empire

PowerShell安全專題之攻擊工具篇

功能特性:

基於 PowerShell 的遠端控制木馬
Python 編寫的服務端元件(Kali Linux)
AES 加密的 C2 通訊通道
可以從憑證資料庫匯出和跟蹤憑證資訊

使用場景︰ 提供前期漏洞利用的整合模組、 資訊探測、 憑據竊取 & 重用,以及持久化。 作者: Will Schroeder (@harmj0y) & Justin Warner (@sixdub) & Matt Nelson (@enigma0x3)

模組如下:

Code Execution
Collection
Credentials
Exfiltration
Exploitation
Lateral Movement
Management
Persistence
Privilege Escalation
Recon
Situational Awareness
Fun & Trollsploit

Cmdlets:

Invoke-DllInjection
Invoke-ReflectivePEInjection
Invoke-ShellCode
Get-ChromeDump
Get-ClipboardContents
Get-FoxDump
Get-IndexedItem
Get-Keystrokes
Get-Screenshot
Invoke-Inveigh
Invoke-NetRipper
Invoke-NinjaCopy
Out-Minidump
Invoke-EgressCheck
Invoke-PostExfil
Invoke-PSInject
Invoke-RunAs
MailRaider
New-HoneyHash
Set-MacAttribute
Get-VaultCredential
Invoke-DCSync
Invoke-Mimikatz
Invoke-PowerDump
Invoke-TokenManipulation
Exploit-Jboss
Invoke-ThunderStruck
Invoke-VoiceTroll
Set-Wallpaper
Invoke-InveighRelay
Invoke-PsExec
Invoke-SSHCommand
Get-SecurityPackages
Install-SSP
Invoke-BackdoorLNK
PowerBreach
Get-GPPPassword
Get-SiteListPassword
Get-System
Invoke-BypassUAC
Invoke-Tater
Invoke-WScriptBypassUAC
PowerUp
PowerView
Get-RickAstley
Find-Fruit
HTTP-Login
Find-TrustedDocuments
Get-ComputerDetails
Get-SystemDNSServer
Invoke-Paranoia
Invoke-WinEnum
Get-SPN
Invoke-ARPScan
Invoke-PortScan
Invoke-ReverseDNSLookup
Invoke-SMBScanner

PowerShell 攻擊工具的使用

最好的 PowerShell 攻擊工具無疑是——Empire,下載 PowerShell Empire zip 檔案並解壓。 解壓之後,在 datamodule_source 中檢視 PS1 檔案。

PowerShell安全專題之攻擊工具篇

PowerShell安全專題之攻擊工具篇

PowerShell安全專題之攻擊工具篇

PowerShell 並不只是 “PowerShell.exe”

阻止對 PowerShell.exe 的訪問是限制 PowerShell 執行的一個比較”簡單”的方法,至少,它看上去很簡單。但現實情況是 PowerShell 並不僅僅是一個可執行檔案這麼簡單。PowerShell 是 Windows 系統的一個核心元件 (且不可移除),它存在於 System.Management.Automation.dll 動態連結庫檔案 (DLL) 中並且可以附加到不同的執行空間中而且可以有效的進行 PowerShell 例項化 (想想 PowerShell.exe 和 PowerShell_ISE.exe)。可以通過程式碼在自定義的 PowerShell 執行空間例項化,所以 PowerShell 可以通過一個自定義的可執行檔案進行啟動 (例如 MyPowershell.exe) 。實際上,已經有一些無需 Powershell.exe 就能執行 PowerShell 程式碼的幾種方法了。Justin Warner (@SixDub) 在 2014 年底發表了一篇博文 如何啟動受限的Powershell.exe ,也叫做 PowerPick)。
由於 PowerShell 程式碼可在不執行 PowerShell.exe 的情況下執行程式碼,因此限制 Powershell.exe 可執行檔案的執行並不是理想的解決方案,也不能很好的阻止攻擊。

這裡有兩個辯論的對立面。

一面是”要限制 PowerShell”。這種做法會有一個積極的結果,由於攻擊者在前期無法執行 PS 程式碼所以一些潛在的攻擊就能被阻斷。但是由於微軟或第三方軟體在一些功能上可能會依賴 PowerShell 的支援,因此這個做法有一定的副作用,因為它限制了 windows management 的功能。
另一面是 “不能限制 PowerShell”,因為有其他方法可以限制攻擊者執行 PowerShell 程式碼而無需限制 PowerShell.exe 的執行。可通過 AppLocker 配置 PowerShell 的保護限制。另外 ,將 Powershell 設定為受限的語言模式的這個方法還有待測試。如果要想了解更多此類資訊,可以檢視後面的章節”限制 PowerShell 的能力”。

PowerShell = System.Management.Automation.dll
應用程式可以執行 PowerShell 程式碼
“PowerShell ps = PowerShell.Create()”
Ben Ten’s AwesomerShell

無需 PowerShell.exe 執行 PS 命令

PowerShell v2: “提供了用於建立管道命令以及同步或非同步呼叫執行空間內的命令的方法。此類還提供了呼叫命令時生成的且包含資料的輸出流的訪問。此類主要用於宿主應用程式以程式設計方式使用 Windows PowerShell 執行任務。在 Windows PowerShell 2.0 中,介紹了此類。

建立引用了 Powershell System.Automation.dll 程式集的 C# 應用程式。
利用 Automation 程式集的功能執行 PowerShell 程式碼。
類似於 PowerShell.exe 的工作方式。

由 Lee Christensen 提出的非託管的 PowerShell 是大多數 PowerShell 攻擊工具在脫離 powershell.exe 就能執行 PowerShell 程式碼的基礎。這種方式在非託管程式的 PowerShell 中啟動 .NET 並且在記憶體中載入並執行自定義的 C# 程式集。 自 2016 年 3 月起,Metasploit PowerShell 模組就是利用了非託管的 PowerShell。

另一種利用非託管的 PowerShell 的 PS 專案是 P0wnedShell ,這是一款 “PowerShell 執行空間後期漏洞利用工具包”。它在 powershell 執行空間環境 (.NET)內執行 PowerShell 命令和函式,並且包含了許多 PowerShell 攻擊工具,其中包括 PowerSploit,PowerCat,Inveigh,Nishang等等,這些攻擊工具都包含在一個單一的可執行檔案中。

PowerShell安全專題之攻擊工具篇

這個專案還提供了一個簡單的 PowerShell 攻擊工具執行示例——“數字排序”用於簡單的執行PS攻擊工具。我將它重新命名為”Calc.exe”,我從來沒有見到執行 Calc 就使用了超過幾 MB 的 RAM,當我使用 Mimikatz 執行它時,”Calc” 竟然使用了大於 180 MB的記憶體。

原文釋出時間為:2017年2月5日
本文作者:絲綢之路
本文來自雲棲社群合作伙伴嘶吼,瞭解相關資訊可以關注嘶吼網站。


相關文章