power shell remoting
2016-01-06 12:02
645 查看
Powershell Remoting建立在windows WinRM服务之上,可以一对一或一对多远程控制,也可以建立HTTP 或 HTTPS的“listeners”,使用WS-MAM协议接收远程传递的命令。
Windows 远程管理(WinRM)是 WS-Management 协议的 Microsoft 实现,该协议为使用 Web 服务的本地计算机和远程计算机之间的通信提供了一种安全的方式。 也就是说在WS-MAN协议基础上,客户端运行环境可以多样化。 比如openwsman。
![](http://p2.itupup.com/pictures/month_1411/201411031620153731.png)
图片来源:v3 Secrets of PowerShell Remoting
![](http://p2.itupup.com/pictures/month_1411/201411031620155834.png)
在windows server 2012中,Powershell Remoting默认开启。
在windows下,powershell默认使用winrm进行远程管理,winrm版本不同默认的监听端口也不同。如下:
The default ports for winrm 1.1 are http port 80 and https port 443
The default ports for winrm 2.x are http port 5985 and https port 5986
可以在参考这里判断winrm版本。
通过
如果要跨域、或指定IP地址执行时我们可以在客户端这里执行下面的代码,需要将所有或单一远程主机添加在信任表中。
删除所有远程信任主机
如果要删除单一远程主机,则可以执行:
更改computer01。
列出所有远程信任主机
在使用远程执行时如果只提供用户名,那么则会弹窗输入密码。此时我们可以建立PSCredential对象将用户名和密码保存在里面。然后再传递给
![](http://p2.itupup.com/pictures/month_1411/201411031620163703.png)
使用
之后写个for循环就可以一对多的执行了。
![](http://p2.itupup.com/pictures/month_1411/201411031620175132.png)
如果输出内容过于冗杂,还可以使用
如果想一对一获取交互式powershell,可以像这样执行
![](http://p2.itupup.com/pictures/month_1411/201411031620188593.png)
得到
![](http://p2.itupup.com/pictures/month_1411/201411031620196192.png)
在windows中有个
那么在powershell就可以这样执行:
获得域之前的信任关系。 如果需要自行开发脚本,也可以参考下面的文档。
除此之外,还记得之前metasploit笔记中那个
两种不同的脚本都通过调用OpenSCManagerA API连接远程主机测试是否成功。
![](http://p2.itupup.com/pictures/month_1411/201411031620202173.png)
Local_admin_search.rb
![](http://p2.itupup.com/pictures/month_1411/201411031620202497.png)
Invoke-CheckLocalAdminAccess
附veil-powerview作者博客中的测试截图:
![](http://p2.itupup.com/pictures/month_1411/201411031620215085.png)
http://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectory.domain(v=vs.110).aspx
https://www.blackhat.com/docs/us-14/materials/arsenal/us-14-Schroeder-The-Veil-Framework-Slides.pdf
https://www.blackhat.com/docs/us-14/materials/arsenal/us-14-Schroeder-The-Veil-Framework-Slides.pdf
v3 Secrets of PowerShell Remoting.pdf
Powershell HID attack toolkit :https://github.com/samratashok/Kautilya
post exploitation :https://github.com/samratashok/nishang
Remote DLL inject :https://github.com/clymb3r
aspx的Powershell webshell :https://github.com/samratashok/nishang/tree/master/Antak- WebShell
Veil Post exploitation :https://github.com/Veil-Framework/Veil-PowerView
A PowerShell Post-Exploitation Framework :https://github.com/mattifestation/PowerSploit
local privilege escalation : https://github.com/HarmJ0y/PowerUp
Windows 远程管理(WinRM)是 WS-Management 协议的 Microsoft 实现,该协议为使用 Web 服务的本地计算机和远程计算机之间的通信提供了一种安全的方式。 也就是说在WS-MAN协议基础上,客户端运行环境可以多样化。 比如openwsman。
![](http://p2.itupup.com/pictures/month_1411/201411031620153731.png)
图片来源:v3 Secrets of PowerShell Remoting
0x02 远程管理
Powershell Remoting在windows server 2008以前默认是不开启的,需要通过administrator用户执行Enable-PSRemoting命令开启。![](http://p2.itupup.com/pictures/month_1411/201411031620155834.png)
在windows server 2012中,Powershell Remoting默认开启。
在windows下,powershell默认使用winrm进行远程管理,winrm版本不同默认的监听端口也不同。如下:
The default ports for winrm 1.1 are http port 80 and https port 443
The default ports for winrm 2.x are http port 5985 and https port 5986
可以在参考这里判断winrm版本。
通过
Enable-PSRemoting命令打开PS远程,默认是启动了Kerberos认证。这个方法只适合两台电脑在相同域或信任域内的指定电脑(名字可以带后缀).但它不支持跨域、域外或IP地址。
如果要跨域、或指定IP地址执行时我们可以在客户端这里执行下面的代码,需要将所有或单一远程主机添加在信任表中。
Set-Item WSMan:\localhost\Client\TrustedHosts -Value * -Force
删除所有远程信任主机
Clear-Item WSMan:\localhost\Client\TrustedHosts
如果要删除单一远程主机,则可以执行:
$newvalue = ((Get-ChildItem WSMan:\localhost\Client\TrustedHosts).Value).Replace("computer01,","") Set-Item WSMan:\localhost\Client\TrustedHosts $newvalue
更改computer01。
列出所有远程信任主机
Get-Item WSMan:\localhost\Client\TrustedHosts
在使用远程执行时如果只提供用户名,那么则会弹窗输入密码。此时我们可以建立PSCredential对象将用户名和密码保存在里面。然后再传递给
-Credential参数。
-ScriptBlock参数后跟要执行的代码。
$UserName = "admin3" $serverpass = "admin123!@" $Password = ConvertTo-SecureString $serverpass -AsPlainText –Force $cred = New-Object System.Management.Automation.PSCredential($UserName,$Password) invoke-command -ComputerName localhost -Credential $cred -ScriptBlock { ipconfig }
![](http://p2.itupup.com/pictures/month_1411/201411031620163703.png)
使用
help * -Parameter computername命令可以列出所有默认可以远程使用的命令。并且认证过程都可以像上面的代码一样传递$cred。
之后写个for循环就可以一对多的执行了。
![](http://p2.itupup.com/pictures/month_1411/201411031620175132.png)
如果输出内容过于冗杂,还可以使用
ConvertTo-Csv或者
ConvertTo-Html将powershell对象的输出转换为html或者csv。
如果想一对一获取交互式powershell,可以像这样执行
Enter-PSSession:
Enter-PSSession -ComputerName 192.168.200.161 -Credential $cred
![](http://p2.itupup.com/pictures/month_1411/201411031620188593.png)
0x03 多任务分发
在使用invoke-command的时候,
computername可为多个参数。在执行的时候可以使用
-Asjob参数将执行过程放在后台。 接收回显的时候可以使用
get-job查看
job id,然后用
receive-job接收全部回显结果。 但是如果我只是想查看某个远程主机的执行结果呢? 那么就可以像下面这样做:
Get-Job -Id 1 | select -ExpandProperty childjobs
得到
child job id之后,再用
receive-job接收回显结果。
![](http://p2.itupup.com/pictures/month_1411/201411031620196192.png)
0x04 域内信息搜集
基本的信息搜集(日志、进程、服务等)可以靠上面列出的命令来收集,但是远程执行invoke-command是需要凭证的,如果是在域内我们是不是可以先用
nltest搜集下信任域?
在windows中有个
System.DirectoryServices.ActiveDirectory命名空间,和windows域有关。 其下有个类Domain,其中
GetAllTrustRelationships()方法可以获得信任域。
那么在powershell就可以这样执行:
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()
获得域之前的信任关系。 如果需要自行开发脚本,也可以参考下面的文档。
除此之外,还记得之前metasploit笔记中那个
local_admin_search模块吗?
veil-powerview中也有通过相同的方式实现了这一过程。
两种不同的脚本都通过调用OpenSCManagerA API连接远程主机测试是否成功。
![](http://p2.itupup.com/pictures/month_1411/201411031620202173.png)
Local_admin_search.rb
![](http://p2.itupup.com/pictures/month_1411/201411031620202497.png)
Invoke-CheckLocalAdminAccess
附veil-powerview作者博客中的测试截图:
![](http://p2.itupup.com/pictures/month_1411/201411031620215085.png)
0x05 参考
http://www.harmj0y.net/blog/redteaming/trusts-you-might-have-missed/http://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectory.domain(v=vs.110).aspx
https://www.blackhat.com/docs/us-14/materials/arsenal/us-14-Schroeder-The-Veil-Framework-Slides.pdf
https://www.blackhat.com/docs/us-14/materials/arsenal/us-14-Schroeder-The-Veil-Framework-Slides.pdf
v3 Secrets of PowerShell Remoting.pdf
0x06 powershell pentest project 学习推荐
整理的过程发现了很多牛人的博客和项目,在这里分享一下。Powershell HID attack toolkit :https://github.com/samratashok/Kautilya
post exploitation :https://github.com/samratashok/nishang
Remote DLL inject :https://github.com/clymb3r
aspx的Powershell webshell :https://github.com/samratashok/nishang/tree/master/Antak- WebShell
Veil Post exploitation :https://github.com/Veil-Framework/Veil-PowerView
A PowerShell Post-Exploitation Framework :https://github.com/mattifestation/PowerSploit
local privilege escalation : https://github.com/HarmJ0y/PowerUp
相关文章推荐
- linux shell基础
- 195. Tenth Line leetcode bash
- 194. Transpose File leetcode Bash
- 193. Valid Phone Numbers leetcode Bash
- 192. Word Frequency My Submissions Question Leetcode Bash
- -bash: ulimit: pipe size: cannot modify limit: Invalid argument
- -bash: ulimit: pipe size: cannot modify limit: Invalid argument
- -bash: ulimit: pipe size: cannot modify limit: Invalid argument
- shell\comdlg32\fileopensave.cpp(9456)\COMDLG32.dll!
- chapte13:学习shell scripts之(3)条件判断式
- shell处理文件
- shell 中常见问题处理记录
- “HINSTANCE ShellExecuteW(HWND,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,INT)”
- 使用Jailkit在CentOS上建立一个受限shell
- 《Linux程序设计》笔记(二)shell程序设计
- Shell的系统变量
- adb shell top用法
- 使用switch制作Powershell命令菜单
- 用ShellExecute执行cmd命令遇到的问题总结
- C程序调用shell脚本共有三种方法