21
Windows Command Line Prepared by-: Pratik Mavani Technical Security Consultant

Windows Command Line Tools

Embed Size (px)

Citation preview

Page 1: Windows Command Line Tools

Windows Command Line

Prepared by-: Pratik MavaniTechnical Security ConsultantAptec Distribution - UAE

Page 2: Windows Command Line Tools

Overview of commands RUN AS – Grants the ability to run commands as an alternative user

WMIC – A Command line Interpreter for Windows Management Instrumentation

PSTools – A suite of very useful tools put out by the old Sysinternals crew now owned by Microsoft

Reg – Allows command line access to the registry

Page 3: Windows Command Line Tools

RunAs: Shortcut to AdminYes, 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.

Allows a user a run a specific program or tools with different user permissions than the current user logon.

Use Shift + “Right Click” on the program and it gives us an option to run as administrator or as a different user.

from cmd -: runas /user:Doman\Adminusername “teamviewer.exe” from cmd -: runas /user:localmachinename\Adminusername “teamviewer.exe”

Page 4: Windows Command Line Tools

PSTools

Download it from http://technet.microsoft.com/en-us/sysinternals/bb896649

Unzip the tools in a folder.

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.

Page 5: Windows Command Line Tools

PSTools

Use IP address or DNS name of remote machine with PSExec command as shown above

You will get the remote machine access as shown below. (check the highlighted IP address

As per the pre-requisites “remote registry” service should be started on remote machine

Page 6: Windows Command Line Tools

PSTools

As per the pre-requisites “remote registry” service should be started on remote machine

Use /? As argument to get help on specific PS command

Save a list of computers to do an inventory of software installed

Page 7: Windows Command Line Tools

PSTools

As per the pre-requisites “remote registry” service should be started on remote machine

Use this to store the command output to a text file locally

Page 8: Windows Command Line Tools

Summary of PSTools

As per the pre-requisites “remote registry” service should be started on remote machine

PSExec- execute processes remotelyPSFile - shows files opened remotelyPSGetSid - display the SID of a computer or a userPSinfo - list information about a systemPSKill- kill processes by name or process IDPSList - list detailed information about processesPSLoggedon - see who's logged on locally and via resource sharing (full source is included)PSLogList - dump event log recordsPSPasswd- changes account passwordsPSService - view and control servicesPSShutdown - shuts down and optionally reboots a computerPSSuspent - suspends processesPsUptime - shows you how long a system has been running since its last reboot)

Page 9: Windows Command Line Tools

WMICObject Oriented Command line interface to windows Management interface.

Can be used to trace some really good information.

Easy to use.

Yes, it’s in built windows tool but still useful.

Let’s get into it…..

Page 10: Windows Command Line Tools

WMICHow to get to it….

Start Run PowerShell

It will give you the screen as below

Type “wmic” at the prompt and press enter

It will give you a prompt “wmic:root\cli>”

Page 11: Windows Command Line Tools

WMIC /? Switch will give you the help as usual.

Page 12: Windows Command Line Tools

WMIC Using one the WMIC command to find number of networks shares on a machine

Use /node:ipaddress and then the command to execute command on remote machine

It can fetch BIOS Information/node:x.x.x.x bios get name

It can get you motherboard info/node:x.x.x.x baseboard get product,manufacturer

Processor information/node:x.x.x.x Path Win32_processor Get AddressWidth

Page 13: Windows Command Line Tools

Start talking to the OS If you want to get the exact install date and build version of the software use the WMIC command “ product list full”

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 “/node:victim_ipaddress qfe list”

Page 14: Windows Command Line Tools

Start talking to the OS (REG Command) 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. In such cases take remote shell of that machine through

Psexec \\remotemachine_IP cmd.exe Use command like “REG Query” to fetch information from registry

Page 15: Windows Command Line Tools

Start talking to the OS (REG Command) 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 Below is the snipped of the file

To get more information I will run the following command on the remote cmd -:

REG QUERY HKLM\software\Microsoft\Windows\CurrentVersion\Uninstall\bittorrent

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.

Page 16: Windows Command Line Tools

Compiling all the informationYou receive an alert in IPS for P2P traffic originating from x.x.x.x (which is a part of your internal segment

Get a list of software installed on that machine (Remotely with WMIC)

Check what are the current process running on that machine (Remotely with WMIC)

Is any P2P client running on the machine ? If yes kill the process (WMIC/PSTools) and uninstall the software

If not, check the uninstalled list ? (WMIC) Has the user uninstalled the software recently.

If there is no trace of P2P software client, do netstat on the remote shell of machine and check where is traffic going.

Determine outgoing traffic is going to legitimate domains (by “who is”) .

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.

Check the OS install date with WMIC to see that it is actually re-imaged before bringing it online

Page 17: Windows Command Line Tools

Some more tips….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

REG QUERY \\remotehostip\HKLM\ System\CurrentControlSet\Enum\USBSTOR

Security Event log for a particular eventWMIC ntevent where “logfile=“Security” AND (eventcode=“529”)” list brief

WMIC Process list brief WMIC Service list brief WMIC Startup list brief

If you think a particular services is doing some remote connection, try to get more infoWMIC process get Name,ExecutablePath,CommandLine,ProcessID /param:list(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:\windows\zi789r8.exe )(it’s time to shout ooooopppppssss)

Page 18: Windows Command Line Tools

After Enough Monitoring...Take an Action…..

Run a program (Run a Symantec Scan remotely)

WMIC /node:remote_ip process call create “C:\program files\Symantec Client Security\Symantec Antivirus\doscan /scanalldrives”

Install a program

WMIC /node:remote_ip process call create “C:\location of file\installer.exe“

I have symantec on my machine so I know the path

Un Install a program

WMIC /node:remote_ip product where name =“symantec” call unistall

Page 19: Windows Command Line Tools

Some more Action…..

Reboot a Machine

WMIC /node:remote_ip OS where buildnumber=“2600” call reboot

Kill a Process

WMIC /node:remote_ip process where name=“greetingcard.exe” call terminate

Clear security event Log

WMIC /node:remote_ip nteventlog where (description like “%secevent%”) call cleareventlog

Page 20: Windows Command Line Tools

A simple attack vector throgh WMICRe route DNS of a machine in two steps

WMIC /node:remote_ip nicconfig list brief

(note down the index number from the output)

WMIC /node:remote_ip nicconfig where index=9 call SetDNSServerSearchOrder (“1.1.1.1”,”2.2.2.2”)

You need patience of a saint after issuing this command……

Waaaaiiittt……..till you see the results

Page 21: Windows Command Line Tools

Downloads and HelpDownload a WMI Script generator from

http://www.robvanderwoude.com/wmigen.php

Find More WMIC examples at http://blogs.technet.com/b/jhoward/archive/2005/02/23/378726.aspx

Books on Amazon http://www.amazon.com/Understanding-Scripting-Instrumentation-Mission-Critical-

Infrastructures/dp/1555582664/ref=sr_1_1?ie=UTF8&s=books&qid=1304833283&sr=8-1