WMIC 是 Windows Management Instrumentation Command-line 的缩写,它是一个用于管理 Windows 系统的命令行工具。WMIC 提供了一种通过命令行的方式来访问和管理 Windows 管理规范 (WMI) 中的信息和功能。
WMIC 使用 DCOM (Distributed COM) 协议进行通信。DCOM 是一种用于跨进程或跨计算机通信的协议,它允许在远程计算机上执行对象调用。通常需要管理员级别的权限来执行大多数 WMIC 命令。
WMIC 通过 DCOM 协议与远程计算机进行通信,主要使用以下端口:
• TCP 135:这是 DCOM 的默认端口,用于初始连接和定位服务。
• 动态 TCP 端口:一旦通过 135 端口建立了连接,DCOM 可能会使用一个动态分配的 TCP 端口来传输数据。这些端口通常是临时分配的,并且在每次重启或重新配置后可能会改变。默认情况下,这些端口在 49152 到 65535 之间。
1. 查询系统信息:查询硬件配置、操作系统信息、网络设置等。
2. 管理系统资源:启动、停止服务;管理用户账户;控制设备等。
3. 执行命令:执行远程命令,如运行脚本、执行程序等。
4. 故障排除:收集系统日志、查看事件日志等。
wmic /?
我们可以使用useraccount选项来锁定本地用户账号:
wmic useraccount where name='GUEST' set disabled=false
wmic useraccount where name='GUEST' rename hacker
限制本地用户的密码修改操作:
wmic useraccount where name='hacker' set passwordchangeable=false
枚举出大量关于目标系统的信息,包括主机名、域名、制造商以及设备型号等等。
wmic computersystem get Name,Domain,Manufacturer,Model,Username,Roles /format:list
添加下列过滤器来获取更精准的扫描结果:
• computersystem:指定了 WMI 类 Win32_ComputerSystem
,它包含有关计算机系统的详细信息,如制造商、型号、用户名等
• 查询的属性列表。这里查询了以下属性:
• Name
:计算机名称。
• Domain
:计算机所属的域。
• Manufacturer
:计算机制造商。
• Model
:计算机型号。
• Username
:当前登录用户的用户名。
• Roles
:计算机的角色,例如工作站或服务器。
• /format:list:这指定了输出格式为列表形式。
wmic group get Caption, InstallDate, LocalAccount, Domain, SID, Status
• group:指定了 WMI 类 Win32_Group
,它包含有关计算机上本地组的信息
• 查询的属性列表。这里查询了以下属性:
• Caption
:组的名称。
• InstallDate
:组创建或最近修改的日期。
• LocalAccount
:如果为 True,则表示该组是一个本地组;如果为 False,则表示该组是一个域组。
• Domain
:组所在的域。
• SID
:组的安全标识符(Security Identifier)。
• Status
:组的状态
wmic process call create "[Process Name]"
wmic process call create "taskmgr.exe"
• process:指定了 WMI 类 Win32_Process
,它包含了有关计算机上运行的进程的信息。
• call create
: 表示调用 Win32_Process
类中的 Create
方法,该方法用于启动一个新的进程。
• "taskmgr.exe"
: 要启动的可执行文件名,这里是任务管理器。
• ProcessId:为返回的进程ID。
列出所有进程,Full显示所有、Brief显示摘要、Instance显示实例、Status显示状态
wmic process list brief
wmic process where name="jqs.exe" get executablepath
不建议随意更改系统进程的优先级,因为这可能会影响系统的稳定性和响应速度。
wmic process where name="explorer.exe" call setpriority 64
• where name="explorer.exe"
: 选择符合条件的进程,这里的条件是进程名为 explorer.exe
。
• call setpriority
: 调用 Win32_Process
类中的 SetPriority
方法,该方法用于设置进程的优先级。
• BELOW_NORMAL_PRIORITY_CLASS
: 0 (低于标准): 64 - 64 = 0
• NORMAL_PRIORITY_CLASS
: 1 (标准): 64
• ABOVE_NORMAL_PRIORITY_CLASS
: 2(高于标准): 64 + 64 = 128
• HIGH_PRIORITY_CLASS
: 3(高): 64 + 128 = 192
• REALTIME_PRIORITY_CLASS
: 4(实时): 64 + 256 = 320
wmic
的 setpriority
方法实际上接受的是一个内部数值,该数值与 Windows 进程优先级常量相对应。在 Windows 内部,优先级级别是以 64 为单位的,这意味着 64
实际上表示的是标准优先级(NORMAL_PRIORITY_CLASS
),而其他值则是基于 64
的倍数。
wmic process where name="explorer.exe" call terminate
wmic process where processid=<PID> call terminate
wmic process where name="qq.exe" delete #根据进程名称删除进程
wmic process where pid="123" delete #根据PID删除进程
wmic process where ProcessId=1704 get ParentProcessId,commandline,processid,executablepath,name,CreationClassName,CreationDate
wmic process where name="chrome.exe" list full
wmic process where name="frp.exe" get executablepath,name,ProcessId
wmic process where caption="frp.exe" get caption,commandline /value
查询除 Windows 目录以外的所有进程的可执行文件路径
wmic process where "NOT ExecutablePath LIKE '%Windows%'" GET ExecutablePath
WMIC命令的fsdir选项可以提取目标系统中文件目录的基本信息,其中包括压缩方法、创建日期、文件大小、是否可读写、是否为系统文件、加密状态以及加密类型等等:
wmic FSDIR where "drive='c:' and filename='test'" get /format:list
WMIC命令的datafile选项可以获取目标系统中文件的基本信息,其中包括压缩方法、创建日期、文件大小、是否可读写、是否为系统文件、加密状态以及加密类型等等
wmic datafile where name="C:\\test\\names.txt" get /format:list
WMIC可以提取出所有重要系统文件的路径,例如temp目录和win目录等等:
wmic environment get Description, VariableValue
在本地创建一个名为 TestShareName
的共享文件夹,指向 C:\test
目录,并为用户 test
设置完全控制权限
WMIC SHARE CALL Create "","test","3","TestShareName","","c:\test",0
• SHARE
: 指定了 Win32_Share
类,该类包含有关文件共享的信息。
• CALL Create
: 调用 Create
方法来创建一个新的共享。
• 参数列表:
• 第一个空字符串 ""
: 通常用于指定共享的注释,这里为空。
• "test"
: 共享的安全名称(Security Name),通常用于设置权限。
• "3"
: 共享的类型,其中 3
表示“基本网络打印共享”;对于文件共享,应该使用 0
或 2
(0
表示“特殊”共享,2
表示“磁盘”共享)。
• "TestShareName"
: 共享的名称。
• 第二个空字符串 ""
: 通常用于指定密码,这里不需要密码所以为空。
• "c:\test"
: 共享指向的本地路径。
• "0"
: 共享的权限掩码,0
表示没有限制,1
(只读)或 2
(完全控制)。
删除共享
WMIC SHARE where name="C$" call delete
WMIC SHARE where path='c:\test' delete
查看共享
wmic share get name,path
列出c盘下名为test的目录
wmic FSDIR where "drive='c:' and filename='test'" list
删除文件夹
wmic fsdir "c:\test" call delete
重命名
wmic fsdir where "name='c:\\test'" call rename "c:\\abc"
wmic datafile where "name='c:\\1.txt'" call rename "c:\\abc.txt"
复制
wmic fsdir where name="c:\test" call copy "c:\Windows\test"
查询本机所有盘符
wmic logicaldisk list brief
wmic logicaldisk get description,name,size,freespace /value
wmic product get name
获取到正在运行的服务列表之后,WMIC还可以提供服务的启动模式,例如"自动"、"手动"和"运行中":
wmic service where (state="running") get caption, name, startmode
#更改telnet服务启动类型[Auto|Disabled|Manual]
wmic SERVICE where name="tlntsvr" set startmode="Auto"
#运行telnet服务
wmic SERVICE where name="tlntsvr" call startservice
#停止ICS服务
wmic SERVICE where name="ShardAccess" call stopservice
#删除test服务
wmic SERVICE where name="test" call delete
sysdrive选项可以枚举出驱动的名称、路径和服务类型等数据:
wmic sysdriver get Caption, Name, PathName, ServiceType, State, Status /format:list
os选项可以列举出目标系统的上一次启动时间、注册的用户数量、处理器数量、物理/虚拟内存信息和安装的操作系统类型等等:
wmic os get CurrentTimeZone,FreePhysicalMemory,FreeVirtualMemory,LastBootUpTime,NumberofProcesses,NumberofUsers,Organization,RegisteredUser,Status /format:list
查询windows机器版本和服务位数和.net版本
wmic os get caption
wmic os get osarchitecture
wmic OS get Caption,CSDVersion,OSArchitecture,Version
wmic product where "Name like 'Microsoft .Net%'" get Name, Version
wmic baseboard get Manufacturer, Product, SerialNumber, Version
wmic bios get serialNumber
memcache选项可以获取到内存缓存名和块大小等信息:
wmic memcache get Name, BlockSize, Purpose, MaxCacheSize, Status
memorychip选项可以获取到RAM的相关信息,例如序列号等等:
wmic memorychip get PartNumber, SerialNumber
wmic qfe list full /format:htable > 1.html
wmic nicconfig get ipaddress,macaddress
wmic startup list full
根据 onboarddevice 选项返回的信息来判断目标系统到底是真实的主机操作系统。
wmic onboarddevice get Description,DeviceType,Enabled,Status /format:list
wmic bios list full | findstr /i "vmware"
我们可以枚举出目标系统安装的反病毒产品信息,包括安装位置和版本:
wmic /namespace:\\root\securitycenter2 path antivirusproduct GET displayName,productState, pathToSignedProductExe
• /namespace:\\root\securitycenter2
: 指定了 WMI 命名空间 \\root\securitycenter2
,它包含了有关安全中心的信息,包括防病毒产品。
• path antivirusproduct
: 指定了 WMI 类 AntivirusProduct
,它包含了关于安装在计算机上的防病毒产品的信息。
• GET displayName,productState, pathToSignedProductExe
: 这部分指定了要查询的属性列表。这里查询了以下属性:
• displayName
: 防病毒产品的显示名称。
• productState
: 防病毒产品的状态。
• pathToSignedProductExe
: 防病毒产品的已签名可执行文件的路径。
WMIC命令的nteventlog选项还可以清除系统的日志记录,当你入侵了某个系统之后,这个命令可以帮助你掩盖攻击痕迹:
wmic nteventlog where filename='[logfilename]' cleareventlog
wmic nteventlog where filename='system' cleareventlog
查看系统开启的日志
wmic nteventlog get path,filename,writeable
wmic /node:192.168.252.137 /user:WORKGROUP\administrator /password:L@123456 process call create "cmd.exe /c whoami > C:\Windows\Temp\shell.txt"
wmic environment where "name='path' and username='<system>'" set VariableValue="%path%;c:\abc"
获取temp环境变量
wmic environment where "name='temp'" get UserName,VariableValue
列出当前登录到计算机的用户会话
wmic logon list brief
wmic product where "name like '%Office%'" get name
wmic product where name="Office" call uninstall
• desktop
: 指定了 WMI 类 Win32_Desktop
,它包含了关于桌面设置的信息。
• get screensaversecure,screensavertimeout
: 这部分指定了要查询的属性列表。这里查询了以下属性:
• screensaversecure
: 屏幕保护程序的安全设置,指示当屏幕保护程序激活时是否需要密码。
• screensavertimeout
: 屏幕保护程序的超时时间,即多久之后屏幕保护程序会自动启动。
wmic desktop get screensaversecure,screensavertimeout
查询计划任务
wmic job list brief
添加计划任务
wmic job call create "notepad.exe",0,0,true,false,********154800.000000+480
• "notepad.exe"
:要运行的程序。
• 0
:作业的间隔时间(以分钟为单位),0 表示不间隔运行。
• 0
:作业的重复次数,0 表示不重复。
• true
:表示是否为作业提供交互界面(true
表示有界面)。
• false
:表示作业是否在计划时间内执行一次(false
表示不会在计划时间内执行一次)。
• ********154800.000000+480
:作业的计划开始时间。
时间格式 ********154800.000000+480
的解释:
• ********
:保留位,用于指定日期。*
表示忽略该位(即不考虑日期部分)。
• 154800.000000
:计划的时间,格式为 HHMMSS.mmmmmm
,表示 15:48:00。
• +480
:时区偏移量,以分钟为单位。+480
表示东八区,即北京时间(UTC+8)。
wmic job call create "explorer.exe",0,0,1,0,********154600.000000+480
• "explorer.exe"
:要运行的程序。
• 0
:作业的间隔时间(以分钟为单位),0 表示不间隔运行。
• 0
:作业的重复次数,0 表示不重复。
• 1
:表示是否为作业提供交互界面(1 表示有界面)。
• 0
:表示作业是否在计划时间内执行一次(0 表示不会在计划时间内执行一次)。
• ********154600.000000+480
:作业的计划开始时间。
时间格式 ********154600.000000+480
的解释:
• ********
:保留位,用于指定日期。*
表示忽略该位(即不考虑日期部分)。
• 154600.000000
:计划的时间,格式为 HHMMSS.mmmmmm
,表示 15:46:00。
• +480
:时区偏移量,以分钟为单位。+480
表示东八区,即北京时间(UTC+8)。
wmic job call create "calc.exe",0,0,1,0,********113100.000000+480
windows server 2008 测试
wmic process call create "reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v "autorun" /t REG_SZ /d "calc.exe" /f"
参考链接