Whee! Memory forensics! It is scary how much information we can get from memory. If there is one thing you should grab from an image, its the memory (in my opinion!).
I am going to use
Volatility- its free, open source, and pretty kickass. That is not to say there are no other memory forensics tools out there, HB Gary has one as does Mandiant. This is just the one I am most comfortable with.
ImageInfo
Before we delve into Volatility, its important for the program to know exactly which image it is trying to parse. Different OS flavors have different memory structures, even different service packs. Therefore it is important to figure out which OS we are dealing with. This is done with the plugin 'imageinfo' which search for KDBG (a certain set of characters found in the image which tells us which OS we are dealing with).
Now there are alot of things which this output tells us, but for us right now the most important thing is the Image Type and Suggested Profiles. We know it is for sure a WinXP image, and the Image Type tells us its Service Pack 3. So now for every command we run we want to add
'--profile WinXPSP3x86' so Volatility knows the correct structure.
Processes
Now there are two different options we can do here- pslist (pstree follows the same concept as pslist) or psscan. What is the difference? Well pslist is following a double-linked list while psscan is simply looking to process headers in the pool. Still not make sense? Heh.. welcome to memory :D
Basically you know how some malware can hide their presence from users? Like you look at running process in Task Manager but don't see evil.exe running? The malware is using Direct Kernel Object Manipulation (DKOM) to unlink itself, therefore a normal LISTing of the process won't show it. However, if one simply SCANs (brute force searches) for the EPROCESS header... the evil.exe will show up. Malware you can run but you can't hide!
So let's run both to show the differences. This is a 'pslist'
And this is a 'psscan'
Psscan can find process that are not only hidden but also terminated as well (as long as the process header has not been overwritten! How handy is that.
Connections
Just like processes, one can walk the connections list or perform a brute force for connections.
We see our good ol friend PID 760. Again. Let's focus on this and see if we can pull anything out of memory about this.
Threads
Threads are the workhorse of processes. They are the ones doing the work. A process without threads is a process doing nothing. Within the thread is a wealth of information. It says the state of the thread, the state of the processor for that thread (think EIP, ESP, EBP), and any Tags associated with it. Now, I dont want to parse thru ALL the threads in my memory dump, I want to focus on the suspicious process. Luckily, with threads we can use the switch --p
and limit our results a bit.
So we see (again) a ton of information. What hits me is the Tag of 'HookedSSDT' as well as the ServiceTable (and based on the address running in kernel space) revealing the file pxhmnhtj.sys... our malicious kernel driver (again correlated with the address where its located).
SSDT
The System Service Description Table is basically a roadmap for the kernel on how to handle userland API calls. It is used by a lot of programs (including your AV) but malware also likes to lurk around here. So without getting into crazy detail,the files ntoskrnl.sys and win32k.sys are normal modules seen in the SSDT. If you could filter our those, it leaves a lot less for one to analyse. Basically if there is a hook for a userland API (EnumerateProcess for example) it can show up here.Based on our results from threads, our pxhmnhtj.sys file should be here..
Ha! CORRELATION! Hooray!
Now I know what you are thinking, wouldn't it be GREAT if we would pull out that driver? Well....
Volatility has a plugin called modules which list all the modules present in memory at the time of capture.It also has one called modscan (same concept again as pslist/psscan). Lets use that but pipe the results thru grep and see if we can figure out where the suspicious module is in memory. We see below we have found the module, sitting in virtual memory address 0xf899a000. Using that address we can extract the kernel level driver for analysis (as seen with moddump)
Now we have another file for analysis. Schaaawing!
Pulling out the Registry
So I remember how bummed everyone was when we didn't grab the NTUSER.DAT hive for our fateful user. Well never fear, volatility can also scan/list all the registry hives found in memory and them we can dump them out! >PHEW<
All we have to do now is use hivedump and provide the virtual address of the hive we would like to peruse, in our case 0xe1de0878. I would recommend saving it off to another file... its a deluge of data!
Oh and remember the MFT? WELL-- today is your lucky day, as there is a plugin for that too in Volatility :)
So one may say: then why should I bother grabbing anything else? Well for multiple reasons, but correlation is the key. If you need to put someone in prisons you want to be darn sure your evidence is backed up by even more evidence. It's all well and good to have the candlestick, but it would be better to have the candlestick, the partial print on the candlestick, a shoe print, and CCTV footage showing Miss Scarlet entering the Dining Room :)