工具使用

工具使用

WinRM

WinRM是Windows Remote Managementd(Windows远程管理)的简称。它基于Web服务管理(WebService-Management)标准,WinRM2.0默认端口5985(HTTP端口)或5986(HTTPS端口)。如果所有的机器都是在域环境下,则可以使用默认的5985端口,否则的话需要使用HTTPS传输(5986端口)。使用WinRM我们可以在对方有设置防火墙的情况下远程管理这台服务器,因为启动WinRM服务后,防火墙默认会放行5985端口。WinRM服务在Windows Server 2012以上服务器自动启动。在WindowsVista上,服务必须手动启动。WinRM的好处在于,这种远程连接不容易被察觉到,也不会占用远程连接数!

WinRM官方文档:

https://docs.microsoft.com/en-us/windows/win32/winrm/portal

WinRM的配置

代码语言:javascript代码运行次数:0运行复制#查看WinRM状态

winrm enumerate winrm/config/listener

#开启WinRM远程管理

Enable-PSRemoting –force

#设置WinRM自启动

Set-Service WinRM -StartMode Automatic

#对WinRM服务进行快速配置,包括开启WinRM和开启防火墙异常检测,默认的5985端口

winrm quickconfig -q

#对WinRM服务进行快速配置,包括开启WinRM和开启防火墙异常检测,HTTPS传输,5986端口

winrm quickconfig -transport:https

#查看WinRM的配置

winrm get winrm/config

#查看WinRM的监听器

winrm e winrm/config/listener

#为WinRM服务配置认证

winrm set winrm/config/service/auth '@{Basic="true"}'

#修改WinRM默认端口

winrm set winrm/config/client/DefaultPorts '@{HTTPS="8888"}'

#为WinRM服务配置加密方式为允许非加密:

winrm set winrm/config/service '@{AllowUnencrypted="true"}'

#设置只允许指定IP远程连接WinRM

winrm set winrm/config/Client '@{TrustedHosts="192.168.10.*"}'

#执行命令

winrm invoke create wmicimv2/win32_process -SkipCAcheck -skipCNcheck '@{commandline="calc.exe"}'

#执行指定命令程序

winrm invoke create wmicimv2/win32_process -SkipCAcheck -skipCNcheck '@{commandline="c:\users\administrator\desktop\test.exe"}'开启WinRM的过程,做了如下几件事:

快速配置WinRM

设置只允许指定IP远程连接WinRM

通过WinRM执行程序

执行calc.exe程序

执行指定命令程序,我们这里执行木马

利用WinRM远程连接主机

客户端连接

客户端连接的话,也需要启动WinRM,然后再执行以下命令进行连接。

方法一:使用winrs连接

在cmd窗口执行以下命令

代码语言:javascript代码运行次数:0运行复制winrs -r:http://192.168.10.20:5985 -u:administrator -p:root cmd方法二:使用Enter-PSSession连接

代码语言:javascript代码运行次数:0运行复制Enter-PSSession -computer win2008.xie.com -Credential xie\administrator -Port 5985

New-PSSession -Name test -ComputerName win7.xie.com -Credential xie\administrator

Enter-PSSession -Name test代码语言:javascript代码运行次数:0运行复制查看WinRM远程会话

Get-PSSession

进入ID为2的WinRM会话中

Enter-PSSession -id 2

退出WinRM会话

Exit-PSSession如果是工作组环境运行,或客户端未加入域,则需要在客户端执行此命令:

代码语言:javascript代码运行次数:0运行复制Set-Item wsman:\localhost\Client\TrustedHosts -value *使用Python远程连接WinRM

首先,需要服务端WinRM配置如下,在cmd窗口执行以下命令:

代码语言:javascript代码运行次数:0运行复制#为winrm service 配置auth:

winrm set winrm/config/service/auth @{Basic="true"}

#为winrm service 配置加密方式为允许非加密:

winrm set winrm/config/service @{AllowUnencrypted="true"}以下是python脚本

代码语言:javascript代码运行次数:0运行复制import winrm

while True:

cmd = input("$: ")

wintest = winrm.Session('http://192.168.10.20:5985/wsman',auth=('administrator','root'))

ret = wintest.run_cmd(cmd)

print(ret.std_out.decode("GBK"))

print(ret.std_err.decode())注意事项

这里需要注意的是,通过WinRM远程连接也是受到LocalAccountTokenFilterPolicy的值影响的。在 Windows Vista 以后的操作系统中,LocalAccountTokenFilterPolicy 的默认值为0,这种情况下内置账户 administrator 进行远程连接时会直接得到具有管理员凭证的令牌,而其他账号包括管理员组内账号远程连接时会提示权限不足。而在域环境中,只要是域管理员都可以建立具备管理员权限的远程连接。

如果要允许本地管理员组的其他用户登录WinRM,需要修改注册表设置。

修改 LocalAccountTokenFilterPolicy 为1

代码语言:javascript代码运行次数:0运行复制reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /fWinRM其他命令

代码语言:javascript代码运行次数:0运行复制winrm

winrm help auth

winrm help uris How to construct resource URIs.

winrm help aliases Abbreviations for URIs.

winrm help config Configuring WinRM client and service settings.

winrm help certmapping Configuring client certificate access.

winrm help remoting How to access remote machines.

winrm help auth Providing credentials for remote access.

winrm help input Providing input to create, set, and invoke.

winrm help switches Other switches such as formatting, options, etc.

winrm help proxy Providing proxy information.

相关文章

一元1g流量划算还是套餐划算(一元1gb流量套餐是什么意思)
365bet官网开户

一元1g流量划算还是套餐划算(一元1gb流量套餐是什么意思)

⌚ 08-31 👁️‍🗨️ 7502
锦衾的解释及意思
365bet平台网投

锦衾的解释及意思

⌚ 08-24 👁️‍🗨️ 9551
手机手写输入设置全攻略:轻松开启个性化输入体验
365bet官网开户

手机手写输入设置全攻略:轻松开启个性化输入体验

⌚ 10-02 👁️‍🗨️ 9585