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.47- (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.

Listen to Ed Skoudis's tip

Download Ed's command line tricks to your PC or favorite MP3 player.
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.

For more information

In our Intrusion Defense School, learn other ways to catch Windows malware.

How good is Windows Vista virus protection? Peter H. Gregory explains.

Learn how certain antimalware tools use the command line to update on demand.
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.

'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.

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.




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


RELATED CONTENT
Threat Monitor
Hidden endpoints: Mitigating the threat of non-traditional network devices
Protecting exposed servers from Google hacks (and Google 'dorks')
Countermeasures against targeted attacks in the enterprise
Windows registry forensics guide: Investigating hacker activities
More built-in Windows commands for system analysis
Tracing malware's steps with RE:Trace
Worst practices: Learning from bad security tips
Worst practices: Encryption conniptions
Stopping malware in its tracks
Built-in Windows commands to determine if a system has been hacked

Viruses, Worms and Other Malware
New defenses for automated SQL injection attacks
Information security book excerpts and reviews
Yahoo, McAfee to warn users of dangerous websites
Botnets and ethics
Interview: Jim Kirkhope of NCR
Trojan downloaders, droppers skyrocket, Microsoft says
New phishing, Zeus Trojan technique spreads crimeware
Researchers uncover tool used to infect websites, spread malware
RSA 2008: Defeating botnets
Malware found on HP ProLiant server USB keys

Monitoring Network Traffic and Network Forensics
Windows registry forensics guide: Investigating hacker activities
More built-in Windows commands for system analysis
Is security improved when the number of Internet gateways is reduced?
Screencast: Using Nessus to scan for vulnerabilities
What are the pros and cons of shaping P2P packets?
Built-in Windows commands to determine if a system has been hacked
How will the centralized logging of network flow data benefit an enterprise?
The forensics mindset: Making life easier for investigators
Data Loss Prevention Tools Offer Insight into Where Data Lives
vPro: Making the case for network security on a chip

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
bot worm  (SearchSecurity.com)
directory traversal  (SearchSecurity.com)
Kraken  (SearchSecurity.com)
man in the browser  (SearchSecurity.com)
Mytob  (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.

TechTarget Security Media
Information Security View this month\\'s issue and subscribe today.
Information Security Decisions Apply online for free conference admission.
SearchSecurity.com
HomeNewsMagazineWebcastsWhite PapersLearningAdviceTopicsEventsAbout Us

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

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




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