Post Exploitation Using WMIC (System Command)

This article is about Post Exploitation using the WMIC (Windows Management Instrumentation Command Line). When an Attacker gain a meterpreter session on a Remote PC, then he/she can enumerate a huge amount of information and make effective changes using the WMI Command Line.
To do this, we will first get the meterpreter session on the Remote PC which you can learn from here. After gaining the session, escalate its privilege to Administrator which you can learn from here.
WMIC command line can be accessed through the windows cmd. To access that type “shell” in the meterpreter shell.
Now let’s look at the wmic commands and their working
WMIC
This command shows the global options which are used in the wmic command. WMIC Global Options are used to set properties of the WMIC environment. With the combination of global options and the aliases than we can manage the system through the wmic environment.

Syntax/Example: wmic /?



Get System Roles, User Name, and Manufacturer
We can enumerates lots of information about the Victim System including its Name, Domain, Manufacturer, Model Number and Much more through the computer system alias of wmic command.
We are adding following filters to get specific result.
Roles: It gives all the roles that the victim system play like Workstation, Server, Browser etc.
Manufacturer: It give the manufacturer of the system, sometimes there are certain vulnerabilities in a particular model of a particular model. So we can use this information to search for any direct vulnerabilities.
UserName: It gives the username of the system which is proven very helpful as we can differentiate between administrators and normal users
[/format:list]: To sort the output in a list format.
Example: wmic computersystem get Name, Domain, Manufacturer, Model, Username, Roles /format:list


Get the SIDs
To enumerate these SIDs we will use group alias of wmic.
Syntax/Example: wmic group get Caption, InstallDate, LocalAccount, Domain, SID, Status
As shown in the below image here we have found the Account Name, Domain, Local Group Member status, SID and their status.


We can create many process on the victim’s system using the process alias of wmic command.
This is helpful in running any backdoor or fill up the memory of the victim’s system.
Syntax: wmic process call create "[Process Name]"
Example:  wmic process call create "taskmgr.exe"
As you can see in the below screenshot that this command not only create a process but also gives the “process id” so that we can manipulate that process according to our need.
Note: if the process creates a window like Task Manager, cmd, etc. then this command will open up that window on victim’s system and create suspicion in the mind of victim.


Change Priority of a Process
We can change priority of any process running on the victim’s system with the help of process alias of wmic command.
This is an important feature because it can be used manipulate processes as we can increase the priority of any process of our choice or decrease priority of any process. Decreasing the priority of any process can result in crashing of that particular application and increasing may crash the overall system.
Example: wmic process where name=”explorer.exe” call set priority 64


Terminate a process
We can terminate process running on the victim’s system with the help of process alias of wmic command.
Example: wmic process where name=”explorer.exe” call terminate


Get a list of Executable Files
We can get a list which contains the location of the executable files other than that of windows.
Example: wmic process where “NOT ExecutablePath LIKE ‘%Windows%’” GET ExecutablePath


Get Folder Properties
To extract the basic information about a folder on the victim’s system we can use fsdir alias of wmic command line.
It can enumerate following information about a folder:
Compressed, CompressionMethod, Creation Date, File Size, Readable, Writable, System File or not, Encrypted, Encryption Type and much more.
Example: wmic fsdir where=”drive=’c:’ and filename=’test’” get /format:list


Get File Properties
To extract the basic information about a file on the victim’s system we can use datafile alias of wmic command line.
It can enumerate following information about a file:
Compressed, CompressionMethod, Creation Date, File Size, Readable, Writable, System File or not, Encrypted, Encryption Type and much more.
Syntax: wmic datafile where=’[Path of File]’ get /format:list
Example: wmic datafile where name='c:\\windows\\system32\\demo\\demo.txt' get /format:list


Locate System Files
Extract paths of all the important system files like temp folder, win directory and much more.
Example: wmic environment get Description, VariableValue
From given below image you can read variablevalue with their given description.


Get a list of Installed Applications
We can get a list of applications or softwares installed on the victim’s system
Example: wmic product get name


Get a list of Running Services
We can fetch the list of services which are running and services which start automatically or not.
Example: wmic service where (state=”running”) get caption, name, startmode
From given below image you can observe startmode either as “Auto” or as “Manual” and state “Running” for given services.


Get Startup Services
We can enumerate startup services using startup alias for all the services that run during the windows startup.
Example: wmic startup get Caption, Command


Get System Driver Details
We can enumerate Driver Details like Name, Path and Service Type using the sysdrive alias.
This command gives the path of the driver file, its status (Running or Stopped), Its Type (Kernel or File System)
Example: wmic sysdriver get Caption, Name, PathName, ServiceType, State, Status /format:list



Get OS Details
We can enumerate the location of the victim by using the time zone in which the system is set, this can be extracted using the os alias.
We also get the Last Boot Update Time and The Number of Registered Users and Number of Processors and information about Physical & Virtual Memory, all using os alias.
Example: wmic os get CurrentTimeZone, FreePhysicalMemory, FreeVirtualMemory, LastBootUpdate, NumberofProcesses, NumberofUsers, Organization, RegisteredUsers, Status /format:list


We can use the baseboard alias of wmic command line to enumerate the motherboard details of victim’s system. Things we can enumerate are Motherboard Manufacturer, Serial Number and Version
Example: wmic baseboard, get Manufacturer, Product, SerialNumber, Version


Get BIOS Serial Number
We can use the bios alias of wmic command line to enumerate the bios details of victim’s system.
Example: wmic bios, get serialNumber
From given below image you can check bios serial number that we have enumerate of victim’s system.


Get Hard Disk Details
We can enumerate information about the System Hard Disk using the diskdrive alias.
We get to know the Interface Type, Manufacturer and Model Name, all through this command.
Syntax: wmic diskdrive get Name, Manufacturer, Model, InterfaceType, MediaLoaded, MediaType /format:list


Get Hard Disk Partitions Details
We can get the information about the Hard Disk Partitions using the logicaldisk alias.
We get the name, compression status, File System (NTFS, FAT) and much more all using this command.
Syntax: wmic logicaldisk where drivetype=3 get Name, Compressed, Description, FileSystem, FreeSpace, SupportsDiskQuotas, VolumeDirty, VolumeName
From given below image you can read description of disk along with filesystem i.e. NTFS and available free space and many more details as per your requirement.


We can get the information about the Memory Cache using memcache alias. We can get the name, block size, purpose and much more all using this command.
Example: wmic memcache get Name, BlockSize, Purpose, MaxCacheSize, Status
From given below image you can observe here it is showing details of two cache memory.


Get Memory Chip Details
We can get the information about the RAM using the memorychip alias.
We get the Serial number of the RAM without removing the RAM or physically being near the system using this command.
Example: wmic memorychip get PartNumber, SerialNumber


Detect If victim system is a host OS or installed via VMware
We can enumerate information about the victim’s system that weather it is running a host operating system i.e. running by directly installing on hard drive or running virtually using VMware or Virtual Box.
Syntax: wmic onboarddevice get Desciption, DeviceType, Enabled, Status /format:list
Here from given below image if you will observe the highlighted text then you see it showing VMware in description.


User Account Management
Lock a User Account
We can restrict a local user from using its account by using useraccount alias, here we are going to lock a User Account.
Example: wmic useraccount where name=’demo’ set disabled=false
From given below image you can observe that we had successfully locked the user account for user “demo”.


We can remove a local user’s requirement of its password for login by using useraccount alias
Example: wmic useraccount where name=’demo’ set PasswordRequired=false


Rename a user account
We can rename a local user by using useraccount alias
Example: wmic useraccount where name=’demo’ rename hacker


Restrict user from changing a password
We can restrict a local user from changing its password by using useraccount alias
Example: wmic useraccount where name=’hacker’ set passwordchangeable=false


Get Antivirus Details
We can enumerate the antivirus installed on the victim’s system along with its location and version.
Syntax: wmic /namespace:\\root\securitycenter2 path antivirusproduct GET displayName, productState, pathToSignedProductExe


Clear System Logs
Wmic can be used to delete system logs using the nteventlog alias. It is a very simple command where we mention the name of log and then using an option nteventlog and clear the log file. It can be an effective command while cleaning up after hacking any system.
Syntax: wmic nteventlog where filename='[logfilename]' cleareventlog
Example: wmic nteventlog where filename='system' cleareventlog


Author: Pavandeep Singh is a Technical Writer, Researcher and Penetration Tester at hackingarticles.in. Contact here

Nmap Scans using Hex Value of Flags

In this article we are going to scan the target machine by sending TCP flags through their hexadecimal value and the actual Flag name can be confirm by analysis of Nmap traffic through Wireshark.
Let’s have a look over Hex value of TCP Flag in given below table which we are going to use in Nmap for port enumeration.


In this scan we are sending the NONE flag of the tcp by using its hexadecimal value on the target machine to enumerate the state of ports is open, closed or filtered.
Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x00 192.168.1.103

From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP-NONE flag, here we have used wireshark for network packet analysis and we found that it is showing TCP-NONE packet for hex value 0x00 coming from 192.168.1.104 on port 21 as shown in given below image. 


FIN Scan
TCP-FIN flag always used for finished the communication with target network. In this scan we are sending the FIN flag of the tcp by using its hexadecimal value on the target machine to enumerate the state of ports is open, closed or filtered.
Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x01 192.168.1.103
From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP-FIN flag, here we have used wireshark for network packet analysis and we found that it is showing TCP-FIN packet for hex value 0x01 coming from 192.168.1.104 on port 21 as shown in given below image. 


SYN Scan
TCP-SYN flag always initiate communication to establish the connection with target network. In this scan we are sending the SYN flag of the tcp by using its hexadecimal value on the target machine to enumerate the state of ports is open, closed or filtered.
Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x02 192.168.1.103
From given below image you can observe we have successfully found port 21 open.


When network admin will captured the incoming traffic he will get packet for TCP-SYN flag, here we have used wireshark for network packet analysis and we found that it is showing TCP-SYN packet for hex value 0x02 coming from 192.168.1.104 on port 21 as shown in given below image. 


Reset Scan
RST flag is used to reset the connection between the sender machine and the target machine. In this scan we are sending the RST flag of the tcp by using its hexadecimal value on the target machine to enumerate the state of ports is open, closed or filtered.
Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x04 192.168.1.103
From given below image you can observe we have found port 21 filtered.




PUSH Scan
In this scan we are sending the PSH flag of the tcp by using its hexadecimal value on the target machine to enumerate the state of ports is open, closed or filtered.
Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x08 192.168.1.103
From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP-PSH flag, here we have used wireshark for network packet analysis and we found that it is showing TCP-PSH packet for hex value 0x08 coming from 192.168.1.104 on port 21 as shown in given below image. 

PUSH flag is used to push the process priority higher of the packet to the target machine.


ACK Scan
Ack flag is used to acknowledge the sender machine whether the packet is received or dropped by the target. So that the sender again send the lost or dropped packet on the target network to complete the communication process. Here we are sending the ACK flag of the tcp by using its hexadecimal value on the target machine to enumerate the state of ports is open, closed or filtered.
Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x10 192.168.1.103
From given below image you can observe we have found port 21 closed.


When network admin will captured the incoming traffic he will get packet for TCP-ACK flag, here we have used wireshark for network packet analysis and we found that it is showing TCP-ACK packet for hex value 0x10 coming from 192.168.1.104 on port 21 as shown in given below image. 

Open and closed ports will both return a RST packet. Nmap then labels them as unfiltered, meaning that they are reachable by the ACK packet, but whether they are open or closed is undetermined. Ports that don't respond, or send certain ICMP error messages back (type 3, code 0, 1, 2, 3, 9, 10, or 13), are labeled filtered. (Form Nmap.org)


Urgent Scan
URG flag is used to set the high process priority of the packet to the target. So that target machine stops processing the current packet and process the URG Flag packet. In this scan we are sending the Urg flag of the tcp by using its hexadecimal value on the target machine to enumerate the state of ports is open, closed or filtered.

Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x20 192.168.1.103
From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP-URG flag, here we have used wireshark for network packet analysis and we found that it is showing TCP-URG packet for hex value 0x20 coming from 192.168.1.104 on port 21 as shown in given below image. 


In this scan we are sending the combination of hexadecimal value of the different flag on the target machine. As we know in Xmas scan combination of three TCP-flags [FIN, PSH, URG] are used to enumerate state of port.
By adding the value of the flag, which is equal to the hexadecimal value of the sender’s hexadecimal value as describe in given below table.


Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x29 192.168.1.103
From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP flags [FIN, PSH, URG] here we have used wireshark for network packet analysis and we found that it is showing TCP-packet of FIN, PSH, URG for hex value 0x29 coming from 192.168.1.104 on port 21 as shown in given below image. 


Manual Combination of Flags [FIN, SYN, PSH]

Let have a quick review over decimal to hexadecimal conversion with the help of following table:


Now repeat the same methodology by changing the combination of flag to enumerate the state of any port.  For example we want to scan any port by sending combination of three flags [FIN, SYN, and PSH] so let identify hex value for sum of three flags.


Now execute given below command for enumerating state of any port, here we want to identify state for port 21.
nmap -p21 --scanflags 0x0B 192.168.1.103
From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP flags [FIN, SYN and PSH] here we have used wireshark for network packet analysis and we found that it is showing TCP-packet of FIN, SYN,PSH for hex value 0x0B coming from 192.168.1.104 on port 21 as shown in given below image. 


Manual Combination of Flags [FIN, RST, PSH]

Now repeat the same methodology by changing the combination of flag to enumerate the state of any port.  For example we want to scan any port by sending combination of three flags [FIN, RST, and PSH] so let identify hex value for sum of three flags.


nmap -p21 --scanflags 0x0D 192.168.1.103
From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP flags [FIN, RST and PSH] here we have used wireshark for network packet analysis and we found that it is showing TCP-packet of FIN, RST,PSH for hex value 0x0D coming from 192.168.1.104 on port 21 as shown in given below image. 



Now repeat the same methodology by changing the combination of flag to enumerate the state of any port.  For example we want to scan any port by sending combination of four flags [FIN, SYN, RST, and PSH] so let identify hex value for sum of four flags.


nmap -p21 --scanflags 0x0F 192.168.1.103
From given below image you can observe we have found port 21 filtered.


When network admin will captured the incoming traffic he will get packet for TCP flags [FIN,SYN, RST and PSH] here we have used wireshark for network packet analysis and we found that it is showing TCP-packet of FIN, SYN, RST,PSH for hex value 0x0F coming from 192.168.1.104 on port 21 as shown in given below image.