Analyze Malware-infections on your own - part two
Today we will continue our talk about malware. Let's go one step forward to see how exciting it is once you get infected with malware on your machine, then clean it. I always call this process "CSI - Malware Analysis." (Not yet broadcast folks) Why? Your antivirus is clueless, because either it's not up-to-date, or there are no signatures yet. You have to come to the rescue, or format the system and loss your data, configurations, forgotten files...etc. So, your job start when the antivirus stops.
Once we started inspecting processes, it doesn't mean that we will have the full picture. Malwares has the ability to hide inside your machine's corners. I will give some examples:
After passing by these nasty ways that malwares use to hide/evade itself, i'll show you how to do advanced inspection at the machine/network level.
Starting from the machine level, using a systematic approach will make your job, more organised, professional, and error-free. This approach depends on creating a "Malware Activity log" using a text file, you can write down your findings and connect them to get the full picture and start putting the countermeasures locally and at the gateway.
To start the inspection process, you should consider the following:
- The infected machine may be is busy sending spams outside your network, so if you don't enforce the allowed machines which are the allowed ones to send mails outside at the firewall, this will get your MX record blacklisted and get your mails rejected by mail servers. So be aware that at least one infected machine is a big trouble maker for you. Make sure that your mail server is the only one which is allowed through the firewall.
- The infected machine is scanning the local subnets for other preys, so you can enable windows firewall and block "Windows File sharing" to prevent the virus from reaching the others.
- The infected machine may be is a Bot, and participating in a big "Botnet" as a slave that does the dirty job on behalf of the Botnet's master from DoS'ing other networks, generating spams, open proxy/mail relays, scanning machines, ... etc.
- From my experiance, most of the infection cases that i've seen before, I found the malware was one of the previous cases.
Your Arsenal of tools
We talked about "Process Explorer" before, but you need more tools for your forensics-arsenal. I'll categorize this toolkit to make sure we cover all Windows compnonets:
- Portable Process managers: these managers will help you dig deeper and catch running viruses and collection information about (image path / strings / tcp/ip / ..etc)
- Portable File managers: these managers will help exploring windows files system, and find files because malwares usually disable alot of Windows Explorer settings.
- Portable Registry managers: these managers will help accessing the registry, read, add, delete, and modify keys.
- Portable Anti-rootkits: discover and expose hidden processes/files/tcp/ip connections/services/registry keys/kernel modules/ and alot that "Task Manager" and "Process Explorer" will not.
- Portable Antivirus: Don't always trust the running AV, because it could be corrupted, deleted, uninstalled, stopped, disabled.
- Portable Hashers: hashers will help when you want to verify files hashes for modifications.
- Portable Compressors: to compress files incase you want to backup files /submit a virus sample.
- Portable Sniffers: malwares do alot of traffic that may help you to discover what it's trying to do (ex. SMTP "SPAM" / DNS queries / Netbios-SMB "Access other computers shares / IRC "Botnet" / P2P "Botnet" / HTTP "Botnet - download other codes - register online").
- Portable Browsers: IE may be got currpoted, insecure, or unaccessible.
- Portable AutoRun monitors: these will reveal alot of viruses that try to run next time your reboot the system. 30% of your analysis depends on these monitors.
- VirusTotal Uploader: this nifty tool will help you upload any file to VirusTotal.com and scan it agains 25 AV engine.
After listing our toolskit, let's see the "Analysis Path" that usually you should consider to recover your system back:
- discovering processes
- check for registry modification
- check tcp/ip listening ports / initiated connections
- taking process discovery to the next level by using sophisticated anti-rootkits that will usually reveal hidden objects from the OS
- inspecting system services for modifications (new services, stopped services)
- Virus scan is a primary task here because our main purpose is to clean the system but sometimes the antivirus will not be ready if the virus is hidden perfectly, so killing the main virus process that hides the child processes /files will clear out the dust and make it easier for cleaning
- VirusTotal.com provides a free services to upload sample files to scan it against 25 engines that will give the virus name
- Threatexpert provides online virus-sandbox services in which you submit a sample, and it'll get executed inside a controlled environment then reporting what Windows API calls it makes
After building a full picture of what's going on in your system, it's the time for complete cleaning (delete malwares files, deleting registry keys, restting registry keys to the orginial state, fixing windows shell keys, fixing windows explorer folder options, gaining access to system tools (registry/cmd.exe/taskmanager/...etc), restting IE security settings, full scan under safe-mode, full boot scan, monitor system activity for any malicious behavior.
If your antivirus was not able to catch the virus in the begining this means that it lacks the full signatures to detect it. Or this is a new variant that employs new techniques to hide itself from AV. Most Vendor have online submissions forms or by e-mail to send them these samples and they should update their definitions to detect this virus next time.
The Hunting Begins
To protect our tools-kit from infections, we should use a flash disk - with "Write-protection lock." To keep it as a read-only media only. From many cases, I noticed that malwares try to copy itself to the flash drive, by getting Windows access denied errors - because the disk is protected - so your flash will be shielded against infection.
Incase you can't use a flash-disk, you can burn out the toolkit to RW-CD, so it'll will be easy to add more tools in the future, or update the current versions. You have to be always up-to-date with the latest security tools to fight malwares.
I'm talking about normal situations when Windows is in operation and you can access it. But to expect the worse, we should be ready to access it offline. Yes offline, means accessing using a bootable Windows CD that also contains the previous tools. What this will help us is:
Highly sophisticated rootkits will be in Sleeping-mode, means it's not executed and we can detect it normally, delete it, then go back to Windows and complete the job.
Malwares some times destroy Windows boot files, registry that makes windows unaccessible and we have to fix it by copying the system files again, and start the analysis process.
Human mistakes, when you modify the registry you have to be careful from harming the system, a single mistake could make Windows unbootable next time. Always take back up,
I recommend "ERUNT".
Too be continued ....