通过 WMI 从 Linux 获取 Windows 信息/尝试运行程序

有一个工具可以通过 WMI 从 Linux 获取 Windows 信息,所以我试了一下。

如果这个和ZABBIX能很好的连接起来,看来可以实现真正的无代理(不是通过SNMP)。

安装方法如下

1
2
3
4
# wget http://www.orvant.com/files/packages/source/wmi_1.3.14.orig.tar.bz2
# bzip2 -cd wmi_1.3.14.orig.tar.bz2 | tar xvf -
# cd wmi-1.3.14
# make

如果收到以下信息,
/bin/sh: line 2: ./configure: No such files or directory
用yum 安装autoconf 并再次make。

1
2
# yum install autoconf
# make

制作需要很长时间。

在 make install 之前检查操作。

1
# ./Samba/source/bin/wmic Usage: [-?|--help] [--usage] [-d|--debuglevel DEBUGLEVEL] [--debug-stderr] [-s|--configfile CONFIGFILE] [--option=name=value] [-l|--log-basename LOGFILEBASE] [--leak-report] [--leak-report-full] [-R|--name-resolve NAME-RESOLVE-ORDER] [-O|--socket-options SOCKETOPTIONS] [-n|--netbiosname NETBIOSNAME] [-W|--workgroup WORKGROUP] [--realm=REALM] [-i|--scope SCOPE] [-m|--maxprotocol MAXPROTOCOL] [-U|--user [DOMAIN\]USERNAME[%PASSWORD]] [-N|--no-pass] [--password=STRING] [-A|--authentication-file FILE] [-S|--signing on|off|required] [-P|--machine-pass] [--simple-bind-dn=STRING] [-k|--kerberos STRING] [--use-security-mechanisms=STRING] [-V|--version] [--namespace=STRING] [--delimiter=STRING] //host query Example: wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem" [root@zabbix2 wmi-1.3.14]#

 

我会尝试获取信息。

获取 Windows 信息

1
2
3
4
5
6
7
8
9
10
11
12
# ./Samba/source/bin/wmic -U username%password //192.168.29.40 "Select * From Win32_ComputerSystem"
 
CLASS: Win32_ComputerSystem
AdminPasswordStatus|AutomaticResetBootOption|AutomaticResetCapability|BootOptionOnLimit|BootOptionOnWatchDog|BootROMSupported|BootupState|Caption|ChassisBootupState|CreationClassName|CurrentTimeZone|
DaylightInEffect|Description|Domain|DomainRole|EnableDaylightSavingsTime|FrontPanelResetStatus|InfraredSupported|InitialLoadInfo|InstallDate|KeyboardPasswordStatus|LastLoadInfo|Manufacturer|Model|Name|
NameFormat|NetworkServerModeEnabled|NumberOfLogicalProcessors|NumberOfProcessors|OEMLogoBitmap|OEMStringArray|PartOfDomain|PauseAfterReset|PowerManagementCapabilities|PowerManagementSupported|
PowerOnPasswordStatus|PowerState|PowerSupplyState|PrimaryOwnerContact|PrimaryOwnerName|ResetCapability|ResetCount|ResetLimit|Roles|Status|SupportContactDescription|SystemStartupDelay|SystemStartupOptions|
SystemStartupSetting|SystemType|ThermalState|TotalPhysicalMemory|UserName|WakeUpType|Workgroup
1|True|True|3|3|True|Normal boot|XP-VMCLIENT|3|Win32_ComputerSystem|540|False|AT/AT COMPATIBLE|NSB-LAN|0|True|3|False|NULL|(null)|3|(null)|VMware, Inc.|VMware Virtual Platform|XP-VMCLIENT|(null)|True|3|1|
NULL|([MS_VM_CERT/SHA1/27d66596a61c48dd3dc7216fd715126e33f59ae7],Welcome to the Virtual Machine)|False|3932100000|NULL|False|0|0|3|(null)|his|1|-1|-1|
(LM_Workstation,LM_Server,NT,Potential_Browser,Backup_Browser,Master_Browser)|OK|NULL|30|("Microsoft Windows XP Professional" /noexecute=optin /fastdetect)|0|X86-based PC|3|3220676608|XP-VMCLIENT\j-masuda|6|
(null)

获取有关特定进程的信息 (EpgTimerSrv.exe)

1
2
3
4
5
6
7
8
9
10
# ./Samba/source/bin/wmic -U username%password //192.168.29.40 "Select * From Win32_Process where Caption='EpgTimerSrv.exe'"
CLASS: Win32_Process
Caption|CommandLine|CreationClassName|CreationDate|CSCreationClassName|CSName|Description|ExecutablePath|ExecutionState|Handle|HandleCount|InstallDate|KernelModeTime|MaximumWorkingSetSize|
MinimumWorkingSetSize|Name|OSCreationClassName|OSName|OtherOperationCount|OtherTransferCount|PageFaults|PageFileUsage|ParentProcessId|PeakPageFileUsage|PeakVirtualSize|PeakWorkingSetSize|Priority|
PrivatePageCount|ProcessId|QuotaNonPagedPoolUsage|QuotaPagedPoolUsage|QuotaPeakNonPagedPoolUsage|QuotaPeakPagedPoolUsage|ReadOperationCount|ReadTransferCount|SessionId|Status|TerminationDate|ThreadCount|
UserModeTime|VirtualSize|WindowsVersion|WorkingSetSize|WriteOperationCount|WriteTransferCount
EpgTimerSrv.exe|C:\wintool\HDP2\EpgDataCap_Bon\EpgTimerSrv.exe|Win32_Process|20140125092622.282684+540|Win32_ComputerSystem|XP-VMCLIENT|EpgTimerSrv.exe|C:\wintool\HDP2\EpgDataCap_Bon\EpgTimerSrv.exe|0|11484|
115|(null)|773593750|1413120|204800|EpgTimerSrv.exe|Win32_OperatingSystem|Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1|9817532|161060012|174899|23060480|1020|31715328|78991360|
35393536|8|23060480|11484|4808|65884|6256|70172|36078|76863544|0|(null)|(null)|11|713750000|76890112|5.1.2600|27054080|974246|225966796
[root@zabbix2 wmi-1.3.14]#

获取有关特定流程的信息(仅限值行)

1
2
3
4
# wmic -U username%password //192.168.29.40 "Select * From Win32_Process where Caption='EpgTimerSrv.exe'" | tail -n +3
EpgTimerSrv.exe|C:\wintool\HDP2\EpgDataCap_Bon\EpgTimerSrv.exe|Win32_Process|20140125092622.282684+540|Win32_ComputerSystem|XP-VMCLIENT|EpgTimerSrv.exe|C:\wintool\HDP2\EpgDataCap_Bon\EpgTimerSrv.exe|0|11484|
114|(null)|889218750|1413120|204800|EpgTimerSrv.exe|Win32_OperatingSystem|Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1|11744618|191886458|212378|25841664|1020|32411648|78991360|
36548608|8|25841664|11484|4648|65852|6256|70172|45978|111959645|0|(null)|(null)|9|822812500|74792960|5.1.2600|29843456|1082336|259218725

检查运行后,安装它。

1
2
3
# make istall
# whereis wmic
wmic: /bin/wmic

似乎有一个 RPM(但我还没有尝试过)
http://www.harumaki.net/2012/05/09/centos%E3%81%ABwmi%E3%82%AF%E3%83% A9% E3% 82% A4% E3% 82% A2% E3% 83% B3% E3% 83% 88% E3% 82% 92% E5% 85% A5% E3% 82% 8C% E3% 81% A6% E3% 81% BF% E3% 82% 8B /

顺便说一句,如果要获取文件信息,请执行以下操作。

1
2
3
4
# wmic -U username%password //192.168.29.40 "Select * From CIM_DataFile Where Name = 'c:\\\temp\\\test.txt'"
CLASS: CIM_DataFile
AccessMask|Archive|Caption|Compressed|CompressionMethod|CreationClassName|CreationDate|CSCreationClassName|CSName|Description|Drive|EightDotThreeFileName|Encrypted|EncryptionMethod|Extension|FileName|FileSize|FileType|FSCreationClassName|FSName|Hidden|InstallDate|InUseCount|LastAccessed|LastModified|Manufacturer|Name|Path|Readable|Status|System|Version|Writeable
18809343|True|c:\temp\test.txt|False|(null)|CIM_LogicalFile|20140126190415.202647+540|Win32_ComputerSystem|XP-VMCLIENT|c:\temp\test.txt|c:|c:\temp\test.txt|False|(null)|txt|test|0|テキスト ドキュメント|Win32_FileSystem|NTFS|False|20140126190415.202647+540|0|20140126190415.202647+540|20140126190415.202647+540|(null)|c:\temp\test.txt|\temp\|True|OK|False|(null)|True

出于某种原因,如果你不转换为 \-> \\\,你会得到一个错误(\\ 不起作用)。
此外,如果文件路径包含双字节字符,它会失败,但这仍然没有解决。
我不得不用 WMI 获取每个文件夹中的所有文件,然后用 Grep 提取字符串,但暂时就是这样。

 

如果连接目标是 Windows Vista、2008 或更高版本,安全性很严格,因此您似乎需要
禁用 UAC 或连接本地管理员或具有管理员权限的域用户。

UAC 可以在 GUI 中设置,也可以修改并重新启动注册表。

1
2
3
HKLM¥SOFTWARE¥Microsoft¥Windows¥CurrentVersion¥Policies¥System\EnableLUA
 
DWORD:0

如果可以禁用 UAC 是最快的,但是如果您以具有管理员权限的本地用户身份连接也无法连接,请尝试创建/修改以下注册表。
似乎不需要重新启动。

1
2
3
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy
 
DWORD:1

 

如果无法连接,请检查以下几点。
(如果您是管理员组中的用户,则默认情况下应该没问题,除了防火墙...)

・防火墙设置

如果启用了 WindowsFireWall,请启用以下项目。
[标准配置文件] 或 [域配置文件]
-[Windows 防火墙:允许远程管理例外] (2003)
-[Windows 防火墙:允许传入远程管理例外](2008 或更高版本)

- 检查服务的启动 检查
Windows Management Instrumentation 服务(服务名称:WinMgmt)是否正在运行

-DCOM 访问权限(连接源)

启动dcomcnfg.exe,
打开组件服务->计算机->我的电脑属性,
选择默认属性选项卡,
勾选在这台计算机上启用分布式COM,确认。

 

-DCOM 访问权限(连接目标)

启动dcomcnfg.exe,
打开组件服务->计算机->我的电脑属性,
选择默认属性选项卡,
勾选在这台计算机上启用分布式COM,确认。
-选择[COM安全]选项卡并
检查连接的用户是否具有[编辑限制]的访问权限。

 

-检查 WMI 命名空间的安全性

启动 wmimgmt.msc,查看 WMI 控件中的属性,
并在 Security 选项卡上检查 Root-> CIMV2 的安全性。
确保连接的用户具有权限。
如果这不起作用并且启用了 UAC 安全功能,请 尝试为您自己

用户和管理员组以外的用户所属的组进行设置。

 

 

 

还将安装一个名为 winexe 的工具。
它从 Linux 端的命令行在 Windows 上运行程序。
基本上,您可以执行以下命令。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# winexe -U username%password //192.168.29.40 "ipconfig"
Windows IP Configuration
Ethernet adapter ローカル エリア接続 5:
 
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.29.40
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.29.1
 
Ethernet adapter ローカル エリア接続 7:
 
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.30.40
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :

但是,运行时可能会出现以下错误。

1
[winexe/winexe.c:120:on_ctrl_pipe_error()] ERROR: Failed to install service winexesvc - NT code 0x00000424

在这种情况下,似乎应该在目标 Windows 端执行以下命令。(参考:http://community.zenoss.org/people/chitambira/blog)

1
2
sc create winexesvc binPath= C:\WINDOWS\WINEXESVC.EXE start= auto DisplayName= winexesvc
sc description winexesvc "Remote command provider for Zenoss monitoring"

顺便说一句,这似乎是一个错误,似乎可以
通过修复winexe / service.c文件的以下部分并
再次执行make & make install来修复它。

1
2
3
#define NT_STATUS_SERVICE_DOES_NOT_EXIST NT_STATUS(0xc0000424)
#define NT_STATUS_SERVICE_DOES_NOT_EXIST NT_STATUS(0x00000424)

当我实际尝试时,该服务已自动在 Windows 端注册,并且可以远程执行它。

此外,如果出现以下消息,

1
ERROR: Failed to install service winexesvc - NT_STATUS_UNSUCCESSFUL

好像可以通过输入以下命令一次来解决。

1
sc delete winexesvc

上面的winexe是0.80版本,但是最新版本(1.00)已经出来了,所以如果你需要,点击这里
http://sourceforge.net/projects/winexe/files/

安装方法参考这里
http://junrei.dip.jp/wordpress/winexe/winexe%EF%BC%881-00%EF%BC%89%E3%81%AE%E3%82%A4%E3 % 83% B3% E3% 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB /

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值