Friday, August 17, 2007

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

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


RSS FEEDS: Threat Monitor
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.

[NAO]

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.

[localadministrators]

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

[tasklist]

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.




Share - Digg This! Bookmark with Delicious Bookmark with Del.icio.us

RELATED CONTENT
Threat Monitor
Metamorphic malware sets new standard in antivirus evasion
Investigating logic bomb attacks and their explosive effects
Mergers and acquisitions: Building up security after an M&A
Unified communications infrastructure threats and defense strategies
Finding and blocking Web application server attack vectors
Employee profiling: A proactive defense against insider threats
Reputation systems gaining credibility in fight against spam
Polymorphic viruses call for new antimalware defenses
Plentiful VoIP exploits demand careful consideration
The security risks of Google Notebook

Viruses, Worms and Other Malware
Metamorphic malware sets new standard in antivirus evasion
Discovery of malware cesspool triggers attack fears
Is it possible to detect today's peer-to-peer (P2P) botnets?
Does SMS spoofing require as much effort as email spoofing?
Can an antivirus program's behavior-based functions be judged?
Information security book excerpts and reviews
Using VMware for malware analysis
ClamAV clamps down on e-mail security
Symantec plugs dangerous flaw in Norton security software
When signature based antivirus isn't enough

Monitoring Network Traffic and Network Forensics
Black Hat 2007: Forensics software security holes revealed
Black Hat 2007: VoIP security reaches tipping point
What challenges arise when designing a logging mechanism for peer-to-peer networks?
Sourcefire, Nmap deal to open vulnerability scanning
Interop: Vendors update software, demonstrate new security features
Cisco fixes flaws in PIX, ASA appliances
Sourcefire expands strategy in effort to leverage its network real estate
Are rogue DHCP servers a serious network risk?
Snort creator, Sourcefire seek fresh approach
Which flaws allow users to bypass proxy servers?

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

No comments: