查看当前 WinRM 的白名单 通过在命令行工具中运行下面的命令: Get-Item WSMan:\localhost\Client\TrustedHosts 上面命令行工具中显示了当前的配置情况 设置所有地址 Set-Item WSMan:\localhost\Client\TrustedHosts -Value '*' 添加到列表尾部 如果希望添加不同的地址到当前的信任列表中,但不修改当前的配置的话,需要使用关键字 Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'machineC' -Concatenate https://www.ossez.com/t/
auto-launches on startup. cmd.exe /c net stop winrm cmd.exe /c sc.exe config winrm start= auto Set-Item WSMan as it throws an error $ErrorActionPreference = "Continue" # Remove HTTP listener Remove-Item -Path WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan as it throws an error $ErrorActionPreference = "Continue" # Remove HTTP listener Remove-Item -Path WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan
2>&1 > $null winrm quickconfig -q -force 2>&1 > $null restart-service winrm 2>&1 > $null #Set-Item WSMan winrm set winrm/config/client '@{TrustedHosts="*"}' 2>&1 > $null netstat -ato|findstr :5985 Set-Item WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan winrm set winrm/config/client '@{TrustedHosts="*"}' 2>&1 > $null netstat -ato|findstr :5985 Set-Item WSMan 后要重启机器 #执行完这段Powershell后要重启机器 #执行完这段Powershell后要重启机器 #shutdown -r -t 0 客户端上以管理员身份打开powershell执行Set-Item WSMan
使用session方法 ### import winrm s=winrm.Session('http://10.10.60.14:5985/wsman',auth=('administrator',' print r.std_err 使用Protocol方法 ### import winrm conn = winrm.Protocol(endpoint='http://10.10.60.14:5985/wsman
要完成此操作,请运行以下命令之一:使用通配符允许所有计算机在对此主机进行身份验证时使用NTLM Set-Item WSMan:localhostClientTrustedHosts -Force -Value 或者只将您的IP添加到NTLM身份验证允许列表中 Set-Item WSMan:localhostClientTrustedHosts -Force -Concatenate -Value 192.168.10.100 清除痕迹 如果您的命令之前存在TrustedHosts以自行添加,请更换您的IP并运行以下命令: $newvalue = ((Get-ChildItem WSMan:localhostClientTrustedHosts ).Value).Replace(",192.168.10.100","")Set-Item WSMan:localhostClientTrustedHosts -Force -Value $newvalue 或者,如果您是唯一的TrustedHosts,则可以删除所有TrustedHosts Clear-Item WSMan:localhostClientTrustedHosts 重新启动WinRM服务以完成更改
2>&1 > $null winrm quickconfig -q -force 2>&1 > $null restart-service winrm 2>&1 > $null #Set-Item WSMan winrm set winrm/config/client '@{TrustedHosts="*"}' 2>&1 > $null netstat -ato|findstr :5985 Set-Item WSMan Set-ExecutionPolicy as it throws an error #$ErrorActionPreference = "stop" # Remove listener Remove-Item -Path WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan winrm set winrm/config/client '@{TrustedHosts="*"}' 2>&1 > $null netstat -ato|findstr :5985 Set-Item WSMan
接下来回到宿主机,执行以下命令: Set-Item wsman:localhost\client\trustedhosts -Value * Enable-WSManCredSSP -Role Client Credential Delegation 启用Allow Delegating Fresh Credentials with NTLM-only Server Authentication 策略项并设置值为 WSMAN 确保在宿主机上运行以下命令: Enable-WSManCredSSP -Role Server Set-Item wsman:localhost\client\trustedhosts -Value * Enable-WSManCredSSP -Role Client -DelegateComputer * 并且确保在宿主机上启用以下组策略项,并都指定为wsman/*: Allow Delegating
Address = * Transport = HTTP Port = 5985 Hostname Enabled = true URLPrefix = wsman /usr/bin/python import winrm win2008 = winrm.Session('http://11.22.33.44:5985/wsman',auth=('administrator
2>&1 > $null winrm quickconfig -q -force 2>&1 > $null restart-service winrm 2>&1 > $null #Set-Item WSMan winrm set winrm/config/client '@{TrustedHosts="*"}' 2>&1 > $null netstat -ato|findstr :5985 Set-Item WSMan Set-ExecutionPolicy as it throws an error #$ErrorActionPreference = "stop" # Remove listener Remove-Item -Path WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan winrm set winrm/config/client '@{TrustedHosts="*"}' 2>&1 > $null netstat -ato|findstr :5985 Set-Item WSMan
WinRM的简要概述 "Windows远程管理(WinRM)"是WS-Management协议(Web Services for Management,又名WSMan)的Microsoft实现,WS-Management 作为DCOM和WMI远程管理的替代方法,WinRM用于通过WSMan与远程计算机建立会话,WAMan利用HTTP/S作为传输机制来传递XML格式的消息。 以此配置为例,此时远程主机已经可以通过WS-Management协议访问http://192.168.8.215/wsman连接当前服务器的WinRM服务。 在.NET C#中构建WSMan-WinRM工具,创建新的.NET Framework(4)控制台应用程序项目后,通过在解决方案资源管理器中右键单击“依赖项”菜单并选择“添加COM引用”,接着选择图中的选项 POST /wsman?
Transport = HTTPS Port = 5986 Hostname = SERVER2016 Enabled = true URLPrefix = wsman URLPrefix:要监听的URL前缀,默认为wsman。如果更改此ansiblewinrmpath设置,则必须将主机var设置为相同的值。 删除WinRM侦听器 删除WinRM侦听器: # Remove all listeners Remove-Item -Path WSMan:\localhost\Listener\* -Recurse -Force # Only remove listeners that are run over HTTPS Get-ChildItem -Path WSMan:\localhost\Listener 请执行以下操作: # substitute {path} with the path to the option after winrm/config/Service Set-Item -Path WSMan
as it throws an error $ErrorActionPreference = "Continue" # Remove HTTP listener Remove-Item -Path WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan winrm start= auto winrm quickconfig -q -force 2>&1 > $null winrm quickconfig -q 2>&1 > $null Set-Item WSMan
Set-WSManQuickConfig : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/<em>wsman</em>/1/wsmanfault" Code Set-Item WSMan:localhost\client\trustedhosts -value 10.20.172.106 -Force Set-Item : 客户端无法连接到请求中指定的目标。 Force] [-LocalCredential <System.Management.Automation.PSCredential>] [-PassThru] [-Protocol {DCOM | WSMan Force] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-Protocol {DCOM | WSMan Protocol 参数 : 指定使用WSMan协议。
ShouldProcess {Variable} Certificate ShouldProcess {Cert} WSMan Credentials {WSMan} /* - ShouldProcess: 可支持-whatIf、-Confirm参数 - Credentials: 支持凭据参数(-Credentials)连接数据存储 - Transactions: 支持事务,提交操作,回滚等 */ 如你所见,注册表,别名,环境变量,文件系统,函数,变量,证书和WSMan
其中HTTP 的票据就是winrm的服务票据 PowerShell Remoting 参考:Running Remote Commands Powershell Remoting有两种方式: SSH WSMAN SSH暂且不谈,这里的Wsman就是前面所说的 WS-Management Protocol,也就是WinRM服务。 其他的一些命令 Enable-PSRemoting -force #启用PsRemoting 等同于winrm quickconfig Set-Item WSMan:\localhost\Client\ Value * -Force #设置TrustedHosts 列表 Test-NetConnection <IP> -CommonTCPPort WINRM #测试目标 Listener 是否打开 Test-WsMan {hostname|ip} #和上一个命令类似 Get-Item WSMan:\localhost\Client\TrustedHosts #获取TrustedHosts的值 Invoke-Command
我们可以通过在Powershell中使用Test-WSMan函数来验证目标是否已经配置了WinRM。如果Test-WSMan返回了如图1-1所示的信息,则表示目标系统中的WinRm服务处于监听状态。
as it throws an error $ErrorActionPreference = "Continue" # Remove HTTP listener Remove-Item -Path WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan winrm start= auto winrm quickconfig -q -force 2>&1 > $null winrm quickconfig -q 2>&1 > $null Set-Item WSMan New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer" New-Item -Path WSMan winrm start= auto winrm quickconfig -q -force 2>&1 > $null winrm quickconfig -q 2>&1 > $null Set-Item WSMan
通常,WMI使用DCOM作为通信协议,而CIM使用的是WSMan(或WinRM)。对于DCOM,我们可以做的第一件事是通过端口135寻找初始TCP连接。然后,连接和接收系统将决定使用一个新的端口。 对于WSMan,初始TCP连接使用的是端口5985。 接下来,你需要在事件查看器中查看Microsoft Windows WMI活动/跟踪事件日志。
程序然后安装下面几个 Nuget 库 Microsoft.PowerShell.Commands.Diagnostics Microsoft.PowerShell.SDK Microsoft.WSMan.Management
实现在目标主机远程执行程序后,可对目标主机开放powershell remoting,用作远程连接 条件: 远程连接会有痕迹 本机要开启winRM服务 命令汇总: 列出所有远程信任主机 powershell Get-Item WSMan :\localhost\Client\TrustedHosts设置信任所有主机 powershell Set-Item WSMan:\localhost\Client\TrustedHosts -Value