This part of the blog is dedicated to Windows commands that can be used from Penetration Testers (yea who is your tester?) and Information Security Administrators. In this page I will periodically post Windows tiny simple scripts and commands that a Penetration tester or a Security Administrator can use to:
1. Perform Administration Security tasks (e.g do patch enforcement, silently uninstall software e.t.c).
2. Run Vulnerability Scans (e.g Identify null sessions, test for LANMAN services e.t.c).
3. Do pivoting (e.g after compromising a machine use windows tools to escalate e.t.c).
Test for installed patches
In order to run WMIC you just open up a command prompt and type wmic and you imminently get an interactive command shell with root accesses.
Identifying the windows security patches using WMIC
- wmic qfe get description,installedOn
Identifying windows services
- sc query type= service (running services)
- sc query type= service state= inactive (exist but don't run)
- sc query type= service state= all (running and not running)
This commands are reporting the start up programs:
- wmic startup
- wmic startup list full
- wmic startup list brief
- wmic startup list system
- wmic /node:machinename startup list full
- wmic STARTUP GET Caption, Command, User
Identifying windows network cards
WMIC can also give you lots of information about the network cards and drivers:
- wmic nicconfig list
- wmic nicconfig where IPEnabled='true'
- wmic nicconfig where index=9 call enablestatic("192.168.16.4"), ("255.255.255.0")
- wmic nicconfig where index=9 call setgateways("192.168.16.4", "192.168.16.5"),(1,2)
- wmic nicconfig where index=9 call enabledhcp
- wmic service where caption="DHCP Client" call changestartmode "Disabled"
- wmic service where caption="DHCP Client" call changestartmode "Automatic"
- wmic service where caption="DHCP Client" call changestartmode "Manual"
- wmic /node:machinename nicconfig where Index=1 call EnableDHCP
- wmic /node:machinename nicconfig where Index=1 call EnableStatic ("172.16.10.10"), ("255.255.0.0")
Handle Windows Process life-cycle
The above sets of commands lets you handle all type of process manipulation:
- wmic process
- wmic process list brief
- wmic process list full
- wmic process list system
- wmic /record:processes.xml process list brief
- wmic /record:processes.xml process list full
- wmic /record:processes.xml process list system
- wmic process where name='process_name.exe'
- wmic process where name='process_name.exe' list brief
- wmic process where name='process_name.exe' list full
- wmic process where name='process_name.exe' list system
- wmic process where name='process_name.exe' delete
- wmic process | more
- wmic process | findstr "process name"
- wmic /output:wmic.html process list full /format:hform
- wmic /node:machinename process list brief /every:1
- wmic process where name="cmd.exe" call getowner
- wmic process where name="cmd.exe" call getownersid
ICMP and DNS network sweeping
After taking over a windows box you can use it as a pivot, but what happens if it is a restricted box and you cannot download or upload any tools? Well the following commands will do the job:
- for /L %I in (1,1,254) DO @ping -n 1 192.168.1.%I | findstr "TTL=128" >> pinglog.txt
- for /L %I in (1,1,254) DO @nslookup 192.168.1.%I | find "Name:" >> dnslog.txt
- pathping targethost (for a single host only)
- for /L %I in (1,1,254) DO @pingpath -n 192.168.1.%I >> traceping.txt
- for /L %I in (1,1,254) DO @echo -Route: %I- >> trace.txt & @pathping -n 1 192.168.1.%I >> trace.txt
Windows network connection monitoring
- netstat -nab 3 >> netstat.txt
Option: -n
Displays addresses and port numbers in numerical form
Option: -a
Displays all connections and listening ports
Option: -b
Displays the executable involved in creating each connection or listening port. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. In this case the executable name is in [] at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Note that this option can be time-consuming and will fail unless you have sufficient permissions.
Important Note: This tool is very good for identifying malware behavior that does not alter any system functions, because in case you try to disinfect a rootkit it will not be much of a help :).
Handling Windows Users
The following examples displays a list of all user accounts for the local computer (some commands do that along with other useful information):
- net user
- wmic useraccount
- wmic useraccount list brief
The following example displays information about the user account someuser:
- net user someuser
The following example adds a user account for a user whose full name is Jay Jamison and whose user account name is jayj, with logon rights from 8 A.M. to 5 P.M., Monday through Friday (no spaces in time designations), a mandatory password (Cyk4^g3B), and the user's full name:
- net user jayj Cyk4^g3B /add /passwordreq:yes /times:monday-friday,8am-5pm /fullname:"Jay Jamison
Simple add user: net user someuser /add
- net user miked /time:M-F,08:00-17:00
Note: Sets the logon time (8 A.M. to 5 P.M.) for miked by using 24-hour notation:
- net user miked /time:M-F,8AM-5PM
Note: Sets the logon time (8 A.M. to 5 P.M.) for miked by using 12-hour notation:
- net user anibals /time:M,4AM-5PM;T,1PM-3PM;W-F,8:00-17:00
- wmic /node:remotecomputer computersystem get username
List Event Logs
- wmic ntevent list brief --- Brief takes a while, full takes even longer
- wmic nteventlog where (description like "%secevent%") call clearevent
- wmic service list brief
- netsh int ip delete arpcache
Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista Displays information about and performs functions to manipulate audit policies.For examples of how this command can be used, see the Examples section in each topic.
- Auditpol /get /user:{S-1-5-21-1443922412-3030960370-963420232-51} /category:"System","Detailed Tracking","Object Access"
- wmic os where buildnumber="2600" call reboot -- Get build# from OS Info (see below)
- shutdown -r -f -t 2
- shutdown -s -f -t 4
- http://technet.microsoft.com/en-us/library/bb742610.aspx#EEAA
- http://isc.sans.edu/diary.html?storyid=1229
- http://commandwindows.com/tcpiputil.htm
- http://technet.microsoft.com/en-us/library/cc771865(v=ws.10).aspx
- http://theinterw3bs.com/wiki/index.php?title=WMIC_Commands