I’ve blogged about WMI before, more for setting up dedicated accounts for monitoring purposes.
Today we are going to have some fun with WMIC, the command line interface for simple and quick query data.
I got these ideas after reading this source blog… and I was curious at what level these worked (admin or not)
Most WMIC commands are issued in the following format:
wmic [Object Class] [Action] [Parameters]
For example, you can collect a list of groups or users on the local system and domain using the following commands:
wmic group list brief wmic useraccount get name,sid
Yup, SIDs are no secret and you can pretty much query the whole domain if there’s been no hardening done. I haven’t tested this on a hardened domain but out of the box all users login name and SID are open for any standard user to query.
You can also perform the same data collection over the network without ever logging into the remote machine provided you know have some administrative credentials that the remote system will accept.
The same command issued against a remote system in another domain looks like this:
wmic /user:"FOREIGN_DOMAIN\Admin" /password:"Password" /node:192.168.33.25 group list brief
I can’t test this in my lab as I don’t have an alternative domain to play with (yet), but let’s see if I can query a member server using a standard domain account:
wmic /node:subca.zewwy.ca group list brief
nope well that’s good…
WMIC can collect a list of the currently running processes similar to what you’d see in “Task Manager” using the following command:
wmic process list wmic process get name
Note that some of the WMIC built-ins can also be used in “brief” mode to display a less verbose output. The process built-in is one of these, so you could collect more refined output using the command:
wmic process list brief
Yup, those all work, even as standard user.
Start an Application
wmic process call create "calc.exe"
Yeah… that worked…
I decided to see if I could somehow exploit these to get elevated rights, so far no dice.. but I did find this randomly while searching for a possible way…
sure enough, if you add start cmd.exe /k “net use” and name it net use.bat it will go into and endless loop. Mhmm interesting and easiest way to do a Denial Of Service attack.
anyway moving on…
System Information and Settings
You can collect a listing of the environment variables (including the PATH) with this command: (standard User works)
wmic environment list
OS/System Report HTML Formatted
wmic /output:c:os.html os get /format:hform
This was literally cause my standard account didn’t have access to C:\temp cause I created the folder using my admin account at some earlier point in time.
Products/Programs Installed Report HTML Formatted
wmic /output:c:product.html product get /format:hform
Turn on Remoted Desktop Remotely
Wmic /node:"servername" /user:"user@domain" /password: "password" RDToggle where ServerName="server name" call SetAllowTSConnections 1
Get Server Drive Space Usage Remotely (any node commands require elevated permissions, standard user fails at these generally)
WMIC /Node:%%A LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size /Format:csv MORE /E +2 >> SRVSPACE.CSV
Get PC Serial Number (works as standard user)
wmic bios get serialnumber
Get PC Product Number (works as standard user)
wmic baseboard get product
Find stuff that starts on boot (works as standard user)
wmic STARTUP GET Caption, Command, User
Reboot or Shutdown (works as standard user)
wmic os get buildnumber wmic os where buildnumber="2600" call reboot
Get Startup List (works as standard user)
wmic startup list full
Information About Harddrives (works as standard user)
wmic logicaldisk where drivetype=3 get name, freespace, systemname, filesystem, size, volumeserialnumber
Information about OS (works as standard user)
wmic os get bootdevice, buildnumber, caption, freespaceinpagingfiles, installdate, name, systemdrive, windowsdirectory /format:htable > c:osinfo.htm
User and Groups
Local user and group information can be obtained using these commands:
wmic useraccount list
wmic group list
wmic sysaccount list
For domain controllers, this should provide a listing of all user accounts and groups in the domain. The “sysaccount” version provides you with system accounts built-in and otherwise,which is useful for any extra accounts that may have been added by rootkits.
Identify any local system accounts that are enabled (guest, etc.)
wmic USERACCOUNT WHERE "Disabled=0 AND LocalAccount=1" GET Name
Number of Logons Per USERID
wmic netlogin where (name like "%skodo") get numberoflogons
Get Domain Names And When Account PWD set to Expire
WMIC UserAccount GET name,PasswordExpires /Value
Need to know if there are any missing patches on the system? WMIC can help you find out with this command:
wmic qfe list
The QFE here stands for “Quick Fix Engineering”.
The results also include the dates of install should that be needed from an auditing standpoint.
Enumeration of all of the local shares can be collected using the command:
wmic share list
The result will also include hidden shares (named with a $ at the end).
Find user-created shares (usually not hidden)
wmic SHARE WHERE "NOT Name LIKE '%$'" GET Name, Path
so far all these are working as standard user, but that doesn’t mean anything.
Use the following command to extract a list of network adapters and IP address information:
wmic nicconfig list
Get Mac Address:
wmic nic get macaddress
Update static IP address:
wmic nicconfig get description, index wmic nicconfig where index=9 call enablestatic("192.168.16.4"), ("255.255.255.0")
Yup got to be an admin for that one
Change network gateway:
wmic nicconfig where index=9 call setgateways("192.168.16.4", "192.168.16.5"),(1,2)
wmic nicconfig where index=9 call enabledhcp
Get List of IP Interfaces
wmic nicconfig where IPEnabled='true'
WMIC can list all of the installed services and their configurations using this command:
wmic service list
The output will include the full command used for starting the service and its verbose description.
wmic service where caption="DHCP Client" call changestartmode "Disabled"
Look at services that are set to start automatically
wmic SERVICE WHERE StartMode="Auto" GET Name, State
Services Report on a Remote Machine HTML Formatted:
wmic /output:c:services.htm /node:server1 service list full / format:htable
Get Startmode of Services
Wmic service get caption, name, startmode, state
Change Start Mode of Service:
wmic service where (name like "Fax" OR name like "Alerter") CALL ChangeStartMode Disabled
Get Running Services Information
Wmic service where (state="running") get caption, name, startmode, state
Another interesting feature of WMIC is its ability to record the run-time command executed and runtime configuration all in one XML file. A recorded session might look something like this:
wmic /record:users_list.xml useraccount list
Of course, since WMIC wasn’t designed as a recording device, there are some caveats to using the XML. First, you can only use XML output, there are no other formats defined.
Obtain a Certain Kind of Event from Eventlog
wmic ntevent where (message like "%logon%") list brief
Clear the Eventlog
wmic nteventlog where (description like "%secevent%") call cleareventlog
Retrieve list of warning and error events not from system or security logs
WMIC NTEVENT WHERE “EventType < 3 AND LogFile != ‘System’ AND LogFile != ‘Security’” GET LogFile, SourceName, EventType, Message, TimeGenerated /FORMAT:”htable.xsl”:” datatype = number”:” sortby = EventType” > c:appevent.htm