Home > Security Tips > Threat Monitor > Finding malware on your Windows box (using the command line)
Security Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

THREAT MONITOR

Finding malware on your Windows box (using the command line)


Ed Skoudis
08.16.2007
Rating: -4.48- (out of 5)


Threat Monitor
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


I hope that headline doesn't scare you. A lot of people shun the Windows command line in favor of more complicated graphical user interfaces. But when it comes to investigating malware infections, various command-line tools can be incredibly helpful, since GUI-based tools can't always do the job.

First off, invoke a command prompt. Go to Start --> Run and type in 'cmd.exe.' Putting '.exe' at the end of the entry is important; it is a far safer way of bringing up a command prompt. To trick users, a malicious program might purposely be called 'cmd.com,' and in such a case, the malware would run if just 'cmd' were typed. Thus, go ahead and type 'cmd.exe' instead.

'netstat'
Next, with a command prompt going, run the netstat command and take a gander at the listening ports on your systems. A lot of people know that 'netstat –na' can provide a list of TCP and UDP ports on the machine. Adding an 'o' to the command arguments can reveal the process ID of each process using a port. And, starting with XP SP2, an added 'b' flag will show the EXE name using each port, along with the dynamic link libraries (DLLs) that it has loaded to communicate with the network. Beware of the 'b,' however. The function can chew up some serious CPU time, tying up between 60% and 100% of your processor for up to a minute.

But, wait, there is more. Suppose you want to look at port usage and see how it changes over time. Adding a space and then an integer to that netstat command, as in "netstat –nao 1", will run the command with a frequency equivalent to the integer, in this case, for every one second. The display will be dumped on the screen continuously, as shown below.

[IMAGE]

Of course, to sift for malware that uses TCP and UDP ports, you need an idea of what a system's normal port usage should be. To research the ports that are in use on a box, try searching for specific ports in Google. Also, Microsoft has a list of common ports



that are used by both Windows clients and servers . You can also research ports associated with both Microsoft and third-party applications, as well as official port assignment lists.

If an unusual TCP or UDP port is found to be in use, you might want to do a Google search. Use a "site:" directive that is associated with an antivirus company like Symantec, Sophos, or McAfee. The sites may have a write-up about malware that uses the given port. Here's an example of a helpful search query:

site:symantec.com tcp port 4444.

'reg'
A write-up from the antivirus vendor may give further insight into any registry keys that the malware may have altered. To query these registry keys at the command line, use the reg command. Even if the antivirus Web site doesn't provide any registry keys to look for, you may want to research the most common registry keys altered by malware: keys associated with system startup and user logon. Commonly known as the "run" registry keys, the reg command can help display their values at the command line. Please note that a lot of legitimate software activates itself using these keys. After running the command, you will discover items under these registry keys. Again, a few Google searches for what is displayed will help separate legitimate settings from malware.

C:\> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run
C:\> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Runonce
C:\> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Runonce

I'd recommend running the commands an additional time, replacing HKLM with HKCU. The substitution will find user-centric auto-start registry keys, instead of just the system-wide settings under HKLM.

'dir'
It's also smart to check out the autostart folder for any unexpected programs starting from there. Run the familiar old dir command, using /A to display files with or without any attributes set, as well as hidden and unhidden files.

C:\> dir /A "C:\Documents and Settings\All Users\Start Menu\Programs\Startup"

'net users' and 'localgroup administrators'
Some malware adds an account to the local machine. Therefore, it's important to run the command 'net users,' which checks for accounts defined on the system. Also, because some bots add an account to the local administrators group, make sure to run "localgroup administrators," which should check out this particular group's membership. Do you know all of the people in your administrators group? The figure below shows some sample output.

[IMAGE]

'tasklist /svc'
There is one more vital area to analyze: running processes. On Windows XP Professional, the tasklist command can provide a wealth of information. By itself, it shows running processes, their process ID numbers and memory usage. But running 'tasklist /svc' reveals all of the services running out of each process, as shown below. This provides more to search for when researching whether the investigated system may be infected with evil programs. In particular, the svchost.exe processes are usually quite busy, running many services. Spyware sometimes inserts additional services into these processes or others to monitor or control a machine surreptitiously.

[IMAGE]

In the end, this handful of commands can provide deeper insight into the configuration of a Windows machine. But practice makes perfect. Spend time analyzing clean systems, so that you grow familiar with what is on a "normal" Windows machine. Then, you can become more sensitive to the weird stuff that malware may inject. With some preparation and practice, command-line skills will significantly improve your understanding of Windows machines and prepare you to battle boldly in the fight against malware.

About the author:
Ed Skoudis is a SANS instructor and a founder and senior security consultant with Intelguardians, a Washington, DC-based information security consulting firm. His expertise includes hacker attacks and defenses, the information security industry and computer privacy issues. In addition to Counter Hack Reloaded, Ed is also the author of Malware: Fighting Malicious Code. He was also awarded 2004, 2005 and 2006 Microsoft MVP awards for Windows Server Security, and is an alumnus of the Honeynet Project. As an expert on SearchSecurity.com, Ed answers your questions related to information security threats.

Rate this Tip
To rate tips, you must be a member of SearchSecurity.com.
Register now to start rating these tips. Log in if you are already a member.




BROWSE BY TAG
Threat Monitor,   Malware, Viruses, Trojans and Spyware,   Information Security Threats,   Network Intrusion Detection and Analysis,   Enterprise Network Security,   Monitoring Network Traffic and Network Forensics,   VIEW ALL TAGS

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Threat Monitor
When BIOS updates become malware attacks
Mac OS memory flaws pose challenges for enterprise endpoint protection
Cybercrime and threat management
How to find and stop automated SQL injection attacks
Short-lived Web malware: Fading fad or future trend?
Security book chapter: The Truth About Identity Theft
How to use (almost) free tools to find sensitive data
How to block adult websites from enterprise users by logging content
Are Windows Vista security features up to par?
How to defend against data-pilfering attacks

Malware, Viruses, Trojans and Spyware
Cybercriminals exploit Michael Jackson, Farrah Fawcett deaths
When BIOS updates become malware attacks
Antispyware buying guide for Indian enterprises
PCI compliance requirement 5: Antivirus
Hacker attack techniques and tactics: Understanding hacking strategies
Rootkit Hunter demo: Detect and remove Linux rootkits
Botnet threats and countermeasures
Conficker worm much smaller than feared
New Conficker variant has ties to Storm botnet
Conficker leaves security industry looking clueless

Monitoring Network Traffic and Network Forensics
Chained Exploits: How to prevent phishing attacks from corporate spies
PCI compliance requirement 10: Auditing
Know when you need IDS, IPS or both
An inside look at security log management forensics investigations
Tying log management and identity management shortens incident response
The telltale signs of a network attack
Cyberattack mapping could alter security defense strategy
Should the government reduce its external Internet connections?
How to use Nmap to scan a network
Screencast: How to scan with Nmap

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
bot worm  (SearchSecurity.com)
directory traversal  (SearchSecurity.com)
government Trojan  (SearchSecurity.com)
Kraken  (SearchSecurity.com)
man in the browser  (SearchSecurity.com)
polymorphic malware  (SearchSecurity.com)
RavMonE virus  (SearchSecurity.com)
RFID virus  (SearchSecurity.com)
Rock Phish  (SearchSecurity.com)
Zotob  (SearchSecurity.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Research Solutions for Network Security, Access Control and Security Threats
More Security Resources for Resellers, VARs and OEMs
TechTarget Security Media
Information Security View this month\\'s issue and subscribe today.
Information Security Decisions Apply online for free conference admission.
SearchSecurity.com
HomeNewsMagazineMultimediaWhite PapersLearningAdviceTopicsEventsAbout Us

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts