Windows Command Line Tools


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Windows Command Line Tools

  1. 1. Windows Command Line<br />Prepared by-: Pratik Mavani<br />Technical Security Consultant<br />Aptec Distribution - UAE<br />
  2. 2. Overview of commands<br /><ul><li>RUN AS – Grants the ability to run commands as an alternative user
  3. 3. WMIC – A Command line Interpreter for Windows Management Instrumentation
  4. 4. PSTools – A suite of very useful tools put out by the old Sysinternals crew now owned by Microsoft
  5. 5. Reg – Allows command line access to the registry</li></li></ul><li>RunAs: Shortcut to Admin<br /><ul><li>Yes, it sounds insane but some of them don’t know that it exists and if we know we forget to use it when its required.
  6. 6. Allows a user a run a specific program or tools with different user permissions than the current user logon.
  7. 7. Use Shift + “Right Click” on the program and it gives us an option to run as administrator or as a different user.
  8. 8. from cmd-: runas /user:DomanAdminusername “teamviewer.exe”</li></ul> from cmd -: runas /user:localmachinenameAdminusername “teamviewer.exe”<br />
  9. 9. PSTools<br /><ul><li> Download it from
  10. 10. Unzip the tools in a folder.
  11. 11. Access the Command prompt as administrator (Domain Admin for controlling other machines on Domain). Navigate to the folder where you have unzipped your tools and start using it.</li></li></ul><li>PSTools<br />Use IP address or DNS name of remote machine with PSExec command as shown above<br />You will get the remote machine access as shown below. (check the highlighted IP address<br />As per the pre-requisites “remote registry” service should be started on remote machine<br />
  12. 12. PSTools<br />Use /? As argument to get help on specific PS command<br />Save a list of computers to do an inventory of software installed<br />As per the pre-requisites “remote registry” service should be started on remote machine<br />
  13. 13. PSTools<br />Use this to store the command output to a text file locally<br />As per the pre-requisites “remote registry” service should be started on remote machine<br />
  14. 14. Summary of PSTools<br />PSExec- execute processes remotely<br />PSFile- shows files opened remotely<br />PSGetSid- display the SID of a computer or a user<br />PSinfo - list information about a system<br />PSKill- kill processes by name or process ID<br />PSList - list detailed information about processes<br />PSLoggedon - see who's logged on locally and via resource sharing (full source is included)<br />PSLogList - dump event log records<br />PSPasswd- changes account passwords<br />PSService - view and control services<br />PSShutdown - shuts down and optionally reboots a computer<br />PSSuspent- suspends processes<br />PsUptime- shows you how long a system has been running since its last reboot)<br />As per the pre-requisites “remote registry” service should be started on remote machine<br />
  15. 15. WMIC<br /><ul><li>Object Oriented Command line interface to windows Management interface.
  16. 16. Can be used to trace some really good information.
  17. 17. Easy to use.
  18. 18. Yes, it’s in built windows tool but still useful.
  19. 19. Let’s get into it…..</li></li></ul><li>WMIC<br />How to get to it….<br />Start  Run  PowerShell<br />It will give you the screen as below<br />Type “wmic” at the prompt and press enter<br />It will give you a prompt “wmic:rootcli>”<br />
  20. 20. WMIC<br /> /? Switch will give you the help as usual.<br />
  21. 21. WMIC<br /> Using one the WMIC command to find number of networks shares on a machine<br /><ul><li>Use /node:ipaddress and then the command to execute command on remote machine
  22. 22. It can fetch BIOS Information</li></ul>/node:x.x.x.x bios get name<br /><ul><li>It can get you motherboard info</li></ul>/node:x.x.x.x baseboard get product,manufacturer<br /><ul><li>Processor information</li></ul>/node:x.x.x.x Path Win32_processor Get AddressWidth<br />
  23. 23. Start talking to the OS<br /><ul><li> If you want to get the exact install date and build version of the software use the WMIC command “ product list full”
  24. 24. If you receive an attack alert on your IPS and the remedy information suggests that a particular security patch/service pack should be installed. So to find out whether that is installed on victim machine or not, just reach WMIC use the command</li></ul>“/node:victim_ipaddress qfe list”<br />
  25. 25. Start talking to the OS (REG Command)<br /><ul><li> If you receive an alert of skype traffic going out of your network, and before you physically reach to the machine the user is smart enough to uninstall it.
  26. 26. In such cases take remote shell of that machine through </li></ul>Psexec remotemachine_IP cmd.exe<br /> Use command like “REG Query” to fetch information from registry<br />
  27. 27. Start talking to the OS (REG Command)<br /><ul><li> Notice the last command in the screenshot of previous slide, it fetches the list of uninstalled programs from the registry and saves it to 136_unistinfo.txt
  28. 28. Below is the snipped of the file
  29. 29. To get more information I will run the following command on the remote cmd -:</li></ul>REG QUERY HKLMsoftwareMicrosoftWindowsCurrentVersionUninstallbittorrent<br />I WAS REALLY NOT AWARE OF THIS COMMAND TILL I ATTENDED A SECURITY CONFERENCE ONLINE, THIS COMMAND CAN FETCH YOU TONS OF INFORMATION IF USED PROPERLY.<br />
  30. 30. Compiling all the information<br />You receive an alert in IPS for P2P traffic originating from x.x.x.x (which is a part of your internal segment<br /><ul><li>Get a list of software installed on that machine (Remotely with WMIC)
  31. 31. Check what are the current process running on that machine (Remotely with WMIC)
  32. 32. Is any P2P client running on the machine ? If yes kill the process (WMIC/PSTools) and uninstall the software
  33. 33. If not, check the uninstalled list ? (WMIC) Has the user uninstalled the software recently.
  34. 34. If there is no trace of P2P software client, do netstat on the remote shell of machine and check where is traffic going.
  35. 35. Determine outgoing traffic is going to legitimate domains (by “who is”) .
  36. 36. If not, and you feel it is affected by Botnet/malware, collect the event logs(PSTools) kill the processes remotely and shutdown the machine (WMIC / PS) till its re-installed.
  37. 37. Check the OS install date with WMIC to see that it is actually re-imaged before bringing it online</li></li></ul><li>Some more tips….<br /><ul><li>If you have allowed only some USBs to be used in your corporate network but if some upper level management has privilege to use personal drives and if their machine is affected by a virus. Now to determine which USB did actually transferred the virus, use</li></ul>REG QUERY remotehostipHKLM SystemCurrentControlSetEnumUSBSTOR <br /><ul><li>Security Event log for a particular event</li></ul>WMIC ntevent where “logfile=“Security” AND (eventcode=“529”)” list brief<br /><ul><li>WMIC Process list brief
  38. 38. WMIC Service list brief
  39. 39. WMIC Startup list brief
  40. 40. If you think a particular services is doing some remote connection, try to get more info</li></ul>WMIC process get Name,ExecutablePath,CommandLine,ProcessID /param:list<br />(when you get the information list for all services, and if you are checking for e.g. services.exe is the name of process but executable path is c:windowszi789r8.exe )<br />(it’s time to shout ooooopppppssss)<br />
  41. 41. After Enough Monitoring...Take an Action…..<br /><ul><li> Run a program (Run a Symantec Scan remotely)</li></ul>WMIC /node:remote_ip process call create “C:program filesSymantec Client SecuritySymantec Antivirusdoscan /scanalldrives”<br />I have symantec on my machine so I know the path<br /><ul><li> Install a program</li></ul>WMIC /node:remote_ip process call create “C:location of fileinstaller.exe“<br /><ul><li> Un Install a program</li></ul>WMIC /node:remote_ip product where name =“symantec” call unistall<br />
  42. 42. Some more Action…..<br /><ul><li> Reboot a Machine</li></ul>WMIC /node:remote_ip OS where buildnumber=“2600” call reboot<br /><ul><li>Kill a Process</li></ul>WMIC /node:remote_ip process where name=“greetingcard.exe” call terminate<br /><ul><li> Clear security event Log</li></ul>WMIC /node:remote_ip nteventlog where (description like “%secevent%”) call cleareventlog<br />
  43. 43. A simple attack vector throgh WMIC<br />Re route DNS of a machine in two steps<br />WMIC /node:remote_ip nicconfig list brief<br />(note down the index number from the output)<br />WMIC /node:remote_ip nicconfig where index=9 call SetDNSServerSearchOrder (“”,””)<br />You need patience of a saint after issuing this command…… <br />Waaaaiiittt……..till you see the results<br />
  44. 44. Downloads and Help<br />Download a WMI Script generator from<br /><br />Find More WMIC examples at<br /><br />Books on Amazon<br /><br />