skip to main |
skip to sidebar
Wednesday, April 8, 2015
Posted by
Corey Harrell
Coursera's mission is to "provide universal access to the world's best education." Judging by their extensive course listing it appears as if they are delivering on their mission since the courses are free for anyone to take. I knew about Coursera for some time but only recently did I take one of their courses (Python Programming for Everybody.) In this post I'm sharing some thoughts about my Coursera experience, the course I took, and how I immediately used what I learned.
Why Python? Why Coursera?
Python is a language used often in information security and DFIR. Its usage is varied from simple scripts to extensive programs. My interest in Python was modest; I wanted to be able to modify (if needed) Python tools I use and to write automation scripts to make my job easier. Despite the wealth of resources available to learn Python, I wanted a more structured environment to learn the basics. An environment that leverages lectures, weekly readings, and weekly assignments to explore the topic. My plan was to learn the basics then proceed exploring how Python applies to information security using the books Black Hat Python and Violent Python. Browsing through the Cousera offerings I found the course Programming for Everybody (Python). The course “aims to teach everyone to learn the basics of programming computers using Python. The course has no pre-requisites and avoids all but the simplest mathematics.” Teaches the basics in a span of 10 weeks without the traditional learning to code by mathematics; the course was exactly what I was looking for.
Programming for Everybody (Python)
I’m not providing a full fledge course review but I did want to provide some thoughts on this course. The course itself is “designed to be a first programming course using the popular Python programming language.” This is important and worth repeating. The course is designed to be someone’s first programming course. If you already know how to code in a different language then this course isn’t for you. I didn’t necessary fit the target audience since I know how to script in both batch and Perl. However, I knew this was a beginner’s course going in so I expected things would move slowly. I could easily overlook this one aspect since my interest was to build a foundation in Python. The course leveraged some pretty cool technology for an online format. The recorded lectures used a split screen between the professor, his slides, and his ability to write on the slides as he taught. The assignments had an auto grader where students complete assignments by executing their programs and the grader confirms if the program was written correctly. The text book is Python for Informatics: Exploring Information, which focuses more on trying to solve data analysis problems instead of math problems like traditional programming texts. The basics covered include: variables, conditional code, functions, loops/iteration, strings, files, lists, dictionaries, tuples, and regular expressions.
Overall, spending the past 10 weeks completing this course was time well spent. Sure, at times I wish times moved faster but I did achieve what I wanted to. Exploring the basics of the Python language so I can have a foundation prior to exploring how the language applies to security work. The last thing I wanted to mention about the course, which I highly respect. The entire course from the textbook to the lecture videos is licensed under a Creative Common Attribution making it available for pretty much anyone to use.
Applying What I Learned
The way I tend to judge courses, trainings, and books is by how much of the content can be applied to my work. If the curriculum is not relevant to one’s work than what is the point in wasting time completing it? It’s just my opinion but judging courses and trainings in this manner has proven to be effective. To illustrate this point as it applies to the Python Programming for Everybody course I’m showing how the basics I learned solved a recent issue. One issue I was facing is how to automate parsing online content and consuming it in a SIEM. This is a typical issue for those wishing to use open source threat intelligence feeds. One approach is to manually parse it in to a machine readable form that your SIEM and tools can use. Another and a better approach is to automate as much as possible through scripting. I took the later approach by creating a simple script to automate this process. For those interested in Python usage in DFIR should check out David Cowen's Automating DFIR series or Tom Yarrish's Year of Python series.
There are various open source threat intelligence feeds one can incorporate in to their enterprise detection program. Kyle Maxwell’s presentation Open Source Threat Intelligence touched on some of them. For this post, I’m only discussing one and it was something I was interested in knowing how to do it. Tor is an anonymity service that enables people to hide where they are coming from as they surf the Internet. Tor has a lot of legitimate uses and just because someone is using it does not mean they are doing something wrong. Being able to flagged users connecting to your network from Tor can add context to other activity. Is the SQL injection IDS alert a false positive? Is the SQL injection IDS alert coming from someone who is also using Tor a false positive? See what I mean by adding context. This was an issue that needed a Python solution (or at least a solution where I could apply what I learned.)
To accomplish adding Tor context to activity in my SIEM I first had to identify the IP addresses for the Tor exit nodes. Users using the service will have the IP address of the exit node they are going through. The Tor Project FAQs provides an answer to the question "I want to ban the Tor network from my service." After trying to discourage people from blocking two options are presented by using either the Tor exit relay list or a DNS-based list. The Tor exit relay list webpage has a link to the current list of exit addresses. The screenshot below shows how this information is presented:

Now we’ll explore the script I wrote to parse the Tor exit node IP addresses into a form my SIEM can consume, which is a text file with one IP address per line. The first part –as shown in the image below - imports the urllib2 module that is used to open URLs. This part wasn’t covered in the course but wasn’t too difficult to figure out by Googling. The last line in the image creates a dictionary called urls. A dictionary associates a key with a value and in this case the key is tor-exit with the value being the URL to the Tor exit relay list. Leveraging a dictionary allows the script to be extended to support other feeds without having to make significant changes to the script.

The next portion of the script as shown below is where the first for loop occurs. The for loop will process each entry (key and value pair) in the urls dictionary. The try and except is a method to account for errors such as a URL not working. Inside the try section the URL is opened in to a variable named file and then it is read in to a variable named data using the urllib2 readlines() option. Lastly, a file is created to store the output using the key value and the file handle is named output.

The next part of the script –image below - is specific to each threat feed being parsed. This accounts for the differences in the way threat feeds present data. The if statement checks to see if the key matches “tor-exit” and if it does then the second for loop executes. This for loop reads each line in the data variable (hence the data listed at the URL.) As each line is read there is additional actions performed such as skipping blank lines and any line that doesn’t start with the string “ExitAddress.” For the lines that do start with this string, the line is broken up in to a list named words. Basically, it breaks the line up into different values by using the space as a separator. The IP address is the second value so it is contained in the second index location in the words list (words[1]). The IP address is then written to the output file and after each line is processed a message is displayed saying processing completed.
The screenshot below shows the script running.
The end result is a text file containing the Tor exit IP addresses with one address per line. This text file can then be automatically consumed by my SIEM or I can use it when analyzing web logs to flag any activity involving Tor.
It’s Basic but Works
Harlan recently said in his Blogging post “it doesn't matter how new you are to the industry, or if you've been in the industry for 15 years...there's always something new that can be shared, whether it's data, or even just a perspective.” My hope with this post is it would be useful to others who are not programmers but want to learn Python. Coursera is a good option that can teach you the basics. Even just learning the basics can extend your DFIR capabilities as demonstrated by my simple script.
Tuesday, October 28, 2014
Posted by
Corey Harrell
On my to-do list for some time has been to add support back into the Tr3Secure collection script to obtain the NTFS Change Journal ($UsnJrnl). This is a quick post about this functionality being added back to the collection script.
The issue I faced was the following. There are very few tools capable of collecting NTFS artifacts from live systems; even fewer for collecting the $UsnJrnl. The Tr3Secure script uses Joakim Schicht's tool RawCopy to collect files off of live systems. It is one of the few and - as far as I know - the only open source option. Rawcopy pulls files either by their $MFT record number or the file path. Pulling NTFS artifacts requires the $MFT record number. The challenge is the $UsnJrnl does not have a consistent $MFT record number like the other NTFS artifacts. For most scripting languages this wouldn't be an issue but Tr3Secure is a batch script. Batch scripting doesn't support storing a command's output into a variable. Translation: there is not an easy way in batch scripting to query the $UsnJrnl's $MFT record number, store it into a variable, and then use that variable with RawCopy to collect it. This is why adding the functionality back into the script has been and remained on my to-do list until now.
Joakim Schicht's ExtractUsnJrnl
Joakim Schicht does outstanding work producing DFIR tools and releasing them open source. His Github site contains a wealth of tools. He even has a collection of tools for the collection and parsing of NTFS artifacts. For those who aren't familiar with his work then I highly advise you take the time to explore them (also his Google Code wiki page.) He recently released a new tool called ExtractUsnJrnl. The tool - in Joakim's words - does the following:
"$J may be sparse, which would mean parts of the data is just 00's. This may be a significant portion of the total data, and most tools will extract this data stream to its full size (which is annoying and a huge waste of disk space). This is where this tools comes in, as it only extract the actual data for the change journal. That way extraction obviously also goes faster. Why extract 20 GB when you might only need 200 MB?"
The tool not only collects the $UsnJrnl $J alternate data stream but it only extracts the portion containing data. This not only saves space but it makes the collection faster; especially if pulling it over the wire. The tool is command-line making it easy to script with. I updated the Tr3Secure collection script to use the ExtractUsnJrnl tool for grabbing the $UsnJrnl.
ExtractUsnJrnl in Action
ExtractUsnJrnl is really a cool tool so I wanted to take the time to highlight it. I performed a simple test. Collect the $UsnJrnl $J file with one tool (FTK Imager) to see how long it takes and what the file size is then use ExtractUsnJrnl.
The image below shows the $UsnJrnl from a 1TB solid state drive. The file size difference is significant; one file is 4.6GB while the other is 36MB. Both tools were ran locally but ExtractUsnJrnl completed within seconds.
The image below shows the $UsnJrnl from a 300GB removable drive. Again, notice the difference between the file sizes.
Some may be wondering why am I so focused on the resulting file size. The reason is trying to pull a 4.6GB file over the wire from a remote system takes time. A lot of time if that remote system is in a location with a slow network link (think VPN users). By reducing the file size (i.e. 36MB) makes it easier to collect the $UsnJrnl both remotely and locally to an attached storage device.
The next test I ran was to parse both $UsnJrnl $J files to see if the both contain around the same number of records. I said approximate because the hard drives were not write protected and changes may had been made between the collections. Due to this I evaluated the removable store device's NTFS Change Journal since the drive had less activity than the solid state drive.
The image below shows UsnJrnl2Csv successfully parsing the $UsnJrnl $J extracted with FTK Imager.
The image below shows UsnJrnl2Csv successfully parsing the $UsnJrnl $J extracted with ExtractUsnJrnl. Notice how this $J file had significantly less records.
Lastly, the image below shows the comparison of the two parsed $UsnJrnl $J files from the removable media. Both outputs start at the same time with the same file and end at the same time with the same file.
Another Tr3Secure Collection Update
Adding support to collect the $UsnJrnl is not the only update. The change log lists out all of them but I did want to highlight another one. An additional menu option was added to only collect the NTFS artifacts. There are times where I want to create a quick timeline with the NTFS artifacts to get more information about something. For example, an antivirus alert may had flagged a file but I'm interested in if anything else was dropped onto the system. In an instance like this, creating a timeline with both the $MFT and $UsnJrnl can quickly answer this question. I've been using a different collection script to grab just the NTFS artifacts but I decided to incorporate the functionality into the Tr3secure script. The menu option now appears as the following:
Selecting option 5 will only preserve select files then collect the $MFT, $Logfile, and $UsnJrnl.
You can download the TR3Secure Data Collection Script from the following download site. The link is also posted along the right hand side of this blog towards the top.
In the future I plan on doing a post or two illustrating how targeted collections using scripts - such as the Tr3secure collection script - can significantly speed up the time it takes to triage an alert or system.
Tuesday, September 24, 2013
Posted by
Corey Harrell
Triage is the assessment of a security event to determine if
there is a security incident, its priority, and the need for escalation. As it
relates to potential malware incidents the purpose of triaging may vary. A few potential questions triaging may address are: is
malware present on the system, how did it get there, and what was it trying to
accomplish. To answer these questions should not require a deep dive
investigation tying up resources and systems. Remember, someone needs to use
the system in question to conduct business and telling them to take a 2 to 4
hour break unnecessarily will not go over well. Plus, taking too much time to
triage may result in the business side not being happy (especially if it occurs
often), the IT department wanting to just re-image the system and move on, and you limit your ability to look in
to other security events and issues. In this post I'm demonstrating one method
to triage a system for a potential malware incident in less than 30 minutes.
The triage technique and the tools to use is something I've
discussed before. I laid out the technique in my presentation
slides Finding Malware Like Iron Man. The presentation also covered the
tools but so has my blog. The Unleashing
auto_rip post explains the RegRipper auto_rip
script and the Tr3Secure
Data Collection Script Reloaded outlines a script to collect data thus
avoiding the need for the entire hard drive. The information may not be new
(except for one new artifact) but I wanted to demonstrate how one can leverage
the technique and tools I discussed to quickly triage a system suspected of
being infected.
The Incident
As jIIr is my personal blog, I'm unwilling to share any
casework related to my employer. However, this type of sharing isn't even
needed since the demonstration can be conducted on any infected system. In this
instance I purposely infected a system using an active link I found on URLQuery. Infecting the system in this manner
is a common way systems are infected everyday which makes this simulation
worthwhile for demonstration purposes.
Responding to the System
There are numerous ways for a potential malware incident to
be detected. A few include IDS alerts, antivirus detections, employees
reporting suspicious activity, or IT discovering the incident while trying to
resolve a technical issue. Regardless of the detection mechanism, one of the
first things that have to be done is to collect data for it to be analyzed. The
data is not only limited to what is on the system since network logs can
provide a wealth of information as well. My post’s focus is on the system's
data since I find it to be the most valuable for triaging malware incidents.
Leverage the Tr3Secure Data Collection Script to collect the
data of interest from the system. The command below assigns a case number of 9-20,
collects both volatile and non-volatile data (default option), and stores the
collected data to the drive letter F (this can be a removable drive or a mapped
drive).
tr3-collect.bat 9-20 F
The second script to leverage is the TR3Secure Data
Collection Script for a User Account to collect data from the user profile of
interest. Most of the time it's fairly easy to identify the user profile of
interest. The detection mechanism may indicate a user (i.e. antivirus logs),
the person who uses the system may have reported the issue, the IT folks may
know, and lastly whoever is assigned the computer probably contributed to the
malware infection. The command below collects the data from the administrator
and stores it in the folder with the other collected data.
tr3-collect-user.bat
F:\Data-9-20\WIN-556NOJB2SI8-09.20.13-11.40 administrator
The benefit to running the above collection scripts over
taking the entire hard drive is twofold. First, collection scripts are faster
than removing the hard drive and possibly imaging it. Second, it limits the
impact on the person who uses the system in question until there is a
confirmation about the malware incident.
Triaging the System
For those who haven't read my presentation
slides Finding Malware Like Iron Man I highly recommend you do so to fully
understand the triage technique and what to look for. As a reminder the triage
technique involves the following analysis steps:
- Examine the Programs Ran on the System
- Examine the Auto-start Locations
- Examine File System Artifacts
When completing those steps there are a few things to look
for to identify artifacts associated with a malware infection. These aren't
IOCs but artifacts that occur due to either the malware characteristics or
malware running in the Windows environment. Below are the malware indicators to
look for as the analysis steps are performed against the data collected from
the system.
- Programs executing from temporary or cache folders
- Programs executing from user profiles (AppData, Roaming,
Local, etc)
- Programs executing from C:\ProgramData or All Users
profile
- Programs executing from C:\RECYCLER
- Programs stored as Alternate Data Streams (i.e.
C:\Windows\System32:svchost.exe)
- Programs with random and unusual file names
- Windows programs located in wrong folders (i.e.
C:\Windows\svchost.exe)
- Other activity on the system around suspicious files
Examine the Programs Ran on the System
The best way to identify unknown malware on a system is by
examining the program execution artifacts. For more information about these
artifacts refer to my slide deck, Harlan's HowTo:
Determine Program Execution post, and Mandiant's Did It Execute? post. To
parse most of the program execution artifacts run Nirsoft's WinPrefetchView
against the collected prefetch files and auto_rip along
with RegRipper against the collected registry hives. Note: the analysis should
be performed on another system and not system being analyzed. Below is the
command for WinPrefetchView:
winprefetchview.exe
/folder H:\ Data-9-20\WIN-556NOJB2SI8-09.20.13-11.40\preserved-files\Prefetch
Below is the command for auto_rip to parse the program
execution and auto-start artifacts:
auto_rip.exe -s
H:\Data-9-20\WIN-556NOJB2SI8-09.20.13-11.40\nonvolatile-data\registry -n H:\
Data-9-20\WIN-556NOJB2SI8-09.20.13-11.40\nonvolatile-data\registry\lab -u H:\
Data-9-20\WIN-556NOJB2SI8-09.20.13-11.40\nonvolatile-data\registry\lab -c
execution,autoruns
Reviewing the parsed prefetch files revealed a few
interesting items. As shown below there was one executable named 5UAW[1].EXE
executing from the temporary Internet files folder and another executable named
E42MZ.EXE executing from the temp folder.
Looking at the loaded modules for 5UAW[1].EXE prefetch file
showed a reference to the E42MZ.EXE executable; thus tying these two programs
together.
Looking at the loaded modules for the E42MZ.EXE prefetch
file showed references to other files including ones named _DRA.DLL, _DRA.TLB,
and E42MZ.DAT.
These identified
items in the prefetch files are highly suspicious as being malware. Before
moving on to other program execution artifacts the prefetch files were sorted by the last modified time in order to
show the system activity around the time 09/20/2013 15:34:46. As shown below
nothing else of interest turned up.
The parsed program execution artifacts from the registry are
stored in the 06_program_execution_information.txt report produced by auto_rip.
Reviewing the report identified the same programs (E42MZ.EXE and 5UAW[1].EXE)
in the Shim Cache as shown below.
C:\Users\lab\AppData\Local\Microsoft\Windows\Temporary
Internet Files\Content.IE5\I87XK24W\5uAw[1].exe
ModTime: Fri Sep 20 15:34:46 2013 Z
Executed
C:\Users\lab\AppData\Local\Temp\7zS1422.tmp\e42Mz.exe
ModTime: Fri Sep 20 15:34:37 2013 Z
Executed
So far the program execution artifacts revealed a great deal
of information about the possible malware infection. However, there are still
more program execution artifacts on a Windows system that are rarely discussed publicly. One of these artifacts I have been using for some time and
there is nothing about this file on the Internet (not counting the few people
who mention it related to malware infections). The artifact I'm talking about
is the C:\Windows\AppCompat\Programs\RecentFileCache.bcf file on Windows 7 systems.
I'm still working on trying to better understand what this file does, how it
gets populated, and the data it stores. However, the file path indicates it's
for the Windows application compatibility feature and its contents reflect
executables that were on the system. The majority of the time the executables I
find in this artifact were ones that executed on the system. The Tr3Secure Data
Collection Script preserves this file and viewing the file with a hex editor
shows a reference to the 5uAw[1].exe file.

Examine the Auto-start Locations
The first analysis step of looking at the program execution
artifacts provided a good indication the system is infected and some leads
about the malware involved. Specifically, the step identified the following
items:
- C:\USERS\LAB\APPDATA\LOCAL\MICROSOFT\WINDOWS\TEMPORARY
INTERNET FILES\CONTENT.IE5\I87XK24W\5UAW[1].EXE
- C:\USERS\LAB\APPDATA\LOCAL\TEMP\7ZS1422.TMP\E42MZ.EXE
- C:\USERS\LAB\APPDATA\LOCAL\TEMP\7ZS1422.TMP\_DRA.DLL
- C:\USERS\LAB\APPDATA\LOCAL\TEMP\7ZS1422.TMP\_DRA.TLB
- C:\USERS\LAB\APPDATA\LOCAL\TEMP\7ZS1422.TMP\E42MZ.DAT
The next analysis step to perform in the triage process is
to examine the auto-start locations. When performing this step one should not
only look for the malware indicators mentioned previously but they should also
look for the items found in the program execution artifacts and the activity on
the system around those items. To parse most of the auto-start locations in the
registry run auto_rip
against the collected registry hives. The previous auto_rip command parsed both
the program execution and auto-start locations at the same time. The parsed
auto-start locations from the registry are stored in the 07_autoruns_information.txt
report produced by auto_rip. Reviewing the report identified the following
beneath the browser helper objects registry key:
bho
Microsoft\Windows\CurrentVersion\Explorer\Browser
Helper Objects
LastWrite
Time Fri Sep 20 15:34:46 2013 (UTC)
{BE3CF0E3-9E38-32B7-DD12-33A8B5D9B67A}
Class => savEnshare
Module => C:\ProgramData\savEnshare\_dRA.dll
LastWrite
=> Fri Sep 20 15:34:46 2013
This item stood out for two reasons. First, the key's last
write time is around the same time when the programs of interest (E42MZ.EXE and
5UAW[1].EXE) executed on the system. The second reason was because the file
name_dRA.dll was the exact same as the DLL referenced in the E42MZ.EXE's
prefetch file (C: \USERS\LAB\APPDATA\LOCAL\TEMP\7ZS1422.TMP\_DRA.DLL).
Examine File System Artifacts
The previous analysis steps revealed a lot of information
about the potential malware infection. It flagged executables in the temp
folders, a DLL in the ProgramData folder, and identified a potential
persistence mechanism (browser helper object). The last analysis step in the
triage process uses the found leads to identify any remaining malware or files
associated with malware on the system. This step is performed by analyzing the
file system artifacts; specifically the master file table ($MFT). To parse the
$MFT there are a range of programs but for this post I'm using TZworks NTFSWalk.
Below is the command for NTFSWalk. Note: the -csvl2t switch makes the output
into a timeline.
ntfswalk.exe -mftfile H:\
Data-9-20\WIN-556NOJB2SI8-09.20.13-11.40\ nonvolatile-data\ntfs\$MFT -csvl2t > mft-timeline.csv
Reviewing the $MFT timeline provides a more accurate picture
about the malware infection. After importing the csv file into Excel and
searching on the keyword 5UAW[1].EXE brought me to the following portion of the
timeline.
The cool thing about the above entry is that the 5UAW[1].EXE
file is still present on the system and it was the initial malware dropped onto
the system. Working my way through the timeline to see what occurred after the 5UAW[1].EXE
file was dropped onto the system showed what was next.
Numerous files were created in the C:\ProgramData\savEnshare
folder. The file names are the exact same that were referenced in the E42MZ.EXE's
prefetch file. The last entries in the timeline that were interesting are
below.
These entries show the program execution artifacts already
identified.
Confirming the Malware Infection
The triage technique
confirmed the system in question does appear to be infected. However, the last
remaining task that had to be done was to confirm if any of the identified items
were in malicious. The TR3Secure Data Collection Script for a User Account
collected a ton of data from the system in question. This data can be searched
to determine if any of the identified items are present. In this instance, the
ProgramData folder was not collected and the temp folder didn't contain the E42MZ.EXE
file. However, the collected the Temporary Internet Files folder contained the 5UAW[1].EXE
file.
The VirusTotal scan against the file confirmed it was
malicious with a 16
out of 46 antivirus scanner detection rate. The quick
behavior analysis on the file using Malwr not only shows the same activity
found on the system (keep in mind Malwr run the executable on XP while the
system in question was Windows 7) but it provided information - including
hashes - about the files dropped into the ProgramData folder.
Malware Incidents Triaging Conclusion
In this post I demonstrated one method to triage a system
for a potential malware incident. The entire triage process takes less than 30
minutes to complete (keep in mind the user profile collection time is dependent
on how much data is present). This is even faster than a common technique
people use to find malware (conducting antivirus scans) as I illustrated in my
post Man
Versus Antivirus Scanner. The demonstration may have used a test system but
the process, techniques, tools, and my scripts are the exact same I've used
numerous times. Each time the end result is very similar to what I
demonstrated. I'm able to answer the triage questions: is malware present on
the system, how did it get there, what's the potential risk to the
organization, and what are the next steps in the response.
Sunday, September 15, 2013
Posted by
Corey Harrell
There are a few movies I saw in my childhood that had an impact on me. One of those movies was Back to the Future. To this day I still have vivid memories leaving the theater after watching it and being filled with wonder and excitement. The final scene in the movie is relevant to the discussion about triage scripts. In the scene, Doc reversed his time-traveling DeLorean onto the road. Marty sitting in the passenger seat says "hey Doc you better back up we don't have enough road to get up to 88". Marty's comment was based on his previous experience with the DeLorean. The car had to reach a speed of 88mph to time travel and to reach that speed required enough road to drive on. Doc said to Marty in response "Roads? Where we're going we don't need roads". Then the time-traveling DeLorean lifted off of the road and flew back at the screen. Whenever I think about triage scripts I paraphrase Doc to myself saying "Hard drives? Where we're going we don't need hard drives". My updated Tr3Secure collection script makes this statement a reality for triaging systems; it makes it possible to go in a direction where we "don't need hard drives".
Re-introducing the Tr3Secure Volatile Data Collection Script
Sometime ago I released the Tr3Secure Volatile Data Collection Script and accompanied the release with the blog post Dual Purpose Volatile Data Collection Script describing it. The script's focus was on the collection of volatile data only and it served a dual purpose. "First and foremost it had to properly preserve and acquire data from live systems". "The second required function was the tool had to help with training people on examining volatile data". The script served its dual purpose but it had its limitations. As a result, I overhauled the script with a focus on improving its capability as a triage tool. In the process as it evolved its name change to properly reflect what the tool is; meet the Tr3Secure Data Collection Script.
Tr3Secure Data Collection Script
It's probably easier to say what in the script remained the same than it is to say what is new. For the practically usage the script retained its: flexibility, organized output, documentation in a collection log, and preservation according to RFC 3227. For the training usage, the script retained the ordered output reports and references pointing to the books Windows Forensic Analysis, 2nd edition and Malware Forensics: Investigating and Analyzing Malicious Code for the volatile data collection. Before going into the changes I have to give a shout out to Troy Larson. Some of the new functionality in this script where inspired by his ideas and the wicked cool For loop to grab the user profile registry hives is his. Now let's move on to the changes starting with the minor updates followed by the significant upgrade.
Minor Updates
The first noticeable modification is the way the script executes. I dropped the need to interact with the script to make it execute with command-line syntax for complete automation. Now you can enter one command to collect volatile data, non-volatile data, or image the memory. Speaking about imagining memory leads me to my next change. I dropped Memoryze and went with the winpmem program. The last minor update I wanted to highlight was an addition to the preservation activities. When the script runs it tries to preserve certain data to prevent evidence from being overwriting. I added the collection of two more items; one of which is the NTUSER.DAT registry hive of the user account running the script. For the other minor updates refer to the change_log.txt accompany the scripts.
Significant Upgrade
The original Tr3Secure Volatile Data Collection Script focused on collecting volatile data such as open files, network connections, and running processes. The one area that I felt was lacking was the script's ability to collect non-volatile data. When I approached upgrading the script I asked myself one simple question. What data would I want from the hard drive if I couldn't have the entire hard drive? The end result is very telling by my paraphrasing the Back to the Future quote: "Hard drives? Where we're going we don't need hard drives". Below is a highlight of the new data collected by the Tr3Secure Data Collection Script.
- Grabs the partition information
- Images the MBR (to help with MBR infectors)
- Images the hard drive from the MBR to the sector of the first partition (to help with MBR infectors)
- Collects all registry hives. By all I mean the ones in the config folder, Regback folder (for Windows 7), and the hives from every user loaded user profile
- Grabs select Windows event logs and in Windows 7 the entire log folder
- Grabs the scheduled tasks
- Grabs the NTFS artifacts $MFT and $LogFile. I opted to go with RawCopy from my post Tools to Grab Locked Files
- Grabs the group policies applied to the system
- Grabs the McAfee logs and quarantine folder (this is for demo purposes and should be customized for your environment)
Tr3Secure Data Collection Script Syntax
Viewing the script with a text editor shows the syntax on how to use the script and all of my detailed comments. Below is syntax to run the script:
tr3-collect.bat [case number] [drive letter for storing collected data] [menu selection #]
[case number] = the unique identifier for the case
[drive letter for storing collected data] = drive letter of where the collected data is to be stored
[menu selection] = optional field and can be used to collect the following:
1 = Acquire Memory Forensic Image
2 = Acquire Volatile Data
3 = Acquire Non-Volatile Data
4 = Acquire Volatile and Non-Volatile Data (default)
5 = Acquire Memory Forensic Image, Volatile, and Non-Volatile Data
i.e.
tr3-collect.bat 2012-09-14_1 F
tr3-collect.bat 2012-09-14_1 F 3
A cool thing to keep in mind. The drive letter to store the collected data can either be a removable media attached to the system or a mapped drive to a network share.
Tr3Secure Data Collection Script for User Account
In my talk Finding Malware Like Iron Man I walked through a mock scenario responding to a system and triaging it for malware. One of the comments I made was that it is faster and more efficient to collect data either by going over the wire or using collection script. Being an incident responder time is of the essence so taking the time to remove and image a hard drive takes too long. Some may see the new functionality in the Tr3Secure Data Collection Script and say to themselves. Wait a second, you aren't collecting certain data so the hard drive is still needed. Those who said this to themselves are correct and my response to them is to check out the new script that accompanies the Tr3Secure Data Collection Script. The Tr3Secure Data Collection Script for User Account collects data from a specified user profile on the system. Below is a highlight of the data collected.
- Grabs the Recent folder contents to including LNK files and jump lists
- Grabs the LNK files in the Office Recent folder
- Grabs the Network Recent folder contents
- Grabs the entire temp folder (great location to find attack vector artifacts)
- Grabs the entire Temporary Internet Files folder
- Grabs the PrivacIE folder (to see why check out my post Malware Root Cause Analysis)
- Grabs the Cookie folder
- Grabs the Java Cache folder contents (Java anyone)
One thing I wanted to be clear about why this second script was needed. In corporate environments and to a certain extent systems used by home users there are multiple loaded user profiles on a system. Pretty much on ever single examination I've done over the last five years my interest has only been on one or two user profiles. The other profiles were old and left on the system. Trying to collect the above data from every loaded user profile is not only inefficient but takes way too much time. Time that is better spent responding to the system as opposed to waiting for the collection script to finish. As such, I put the collection of the user profile data in a separate script so it can be run against the one or two user profiles of interest.
Tr3Secure Collection Script for User Account Syntax
Viewing the script with a text editor shows the syntax on how to use the script and all of my detailed comments. Below is syntax to run the script:
tr3-collect-user.bat [path to store collected data] [user profile name]
[path to store collected data] = the path to store the collected data without any quotes or spaces
[user profile name] = the user account's profile name to collect data from
i.e.
tr3-collect-user.bat F:\Data-demo2\computername-08.12.13-19.14 jsmith
Similar to the Tr3Secure Data Collection Script, the path to store the collected data can either be an attached removable media or a mapped network share.
Where Are We Going
When I made my comment in my Finding Malware Like Iron Man presentation it was because of the capability I have with these triage scripts. I first run the Tr3Secure Data Collection Script to grab the volatile and non-volatile data followed by running the Tr3Secure Data Collection Script for User Account to collect the user data. Both scripts are pretty fast and they provide me with all of the data I would need to triage a system. I can even leverage the triage technique I outlined in the presentation against the collected data to find malware and do root cause analysis in less than 20 minutes. Not bad and hopefully my Back to the Future reference now makes a little more sense: "Hard drives? Where we're going we don't need hard drives".
You can download the TR3Secure Data Collection Script from the following download site.
Tuesday, May 8, 2012
Posted by
Corey Harrell
CyberSpeak Podcast About Volume Shadow Copies
I recently had the opportunity to talk with Ovie about Volume Shadow Copies (VSCs) on his CyberSpeak podcast. It was a great experience to meet Ovie and see what it’s like behind the scenes. (I’ve never been on a podcast before and I found out quickly how tough it is to explain something technical without visuals). The CyberSpeak episode May 7 Volume Shadow Copies is online and in it we talk about examining VSCs. In the interview I mentioned a few different things about VSCs and I wanted to elaborate on a few of them. Specifically, I wanted to discuss running the Regripper plugins to identify volumes with VSCs, using the Sift to access VSCs, comparing a user profile across VSCs, and narrowing down the VSC comparison reports with Grep.
Determining Volumes with VSCs and What Files Are Excluded from VSCs
One of my initial steps on an examination is to profile a system so I can get a better idea about what I’m facing. I information I look at includes: basic operating system info, user accounts, installed software, networking information, and data storage locations. I do this by running Regripper in a batch script to generate a custom report containing the information I want. I blogged about this previously in the post Obtaining Information about the Operating System and I even released my Regripper batch script (general-info.bat). I made some changes to the batch script; specifically I added the VSCs plugins spp_clients.pl and filesnottosnapshot.pl. The spp_clients.pl plugin obtains the volumes monitored by the Volume Shadow Copy service and this is an indication about what volumes may have VSCs available. The filesnottosnapshot.pl plugin gets a list of files/folders that are not included in the VSCs (snapshots). The information the VSCs plugins provide is extremely valuable to know early in an examination since it impacts how I may do things.
While I’m talking about RegRipper, Harlan released RegRipper version 2.5 his post RegRipper: Update, Road Map and further explained how to use the new RegRipper to extract info from VSCs in the excellent post Approximating Program Execution via VSC Analysis with RegRipper. RegRipper is an awesome tool and is one of the few tools I use on every single case. The new update lets RR run directly against VSCs making it even better. That’s like putting bacon on top of bacon.
Using the Sift to Access VSCs
There are different ways to access VSCs stored within an image. Two potential ways are using Encase with the PDE module or the VHD method. Sometime ago Gerald Parsons contacted me about another way to access VSCs; he refers to it as the iSCSI Initiator Method. The method uses a combination of Windows 7 iSCSI Initiator and the Sift workstation. I encouraged Gerald to do a write-up about the method but he was unable to due to time constraints. However, he said I could share the approach and his work with others. In this section of my post I’m only a ghost writer for Gerald Parsons and I’m only conveying the detailed information he provided me including his screenshots. I only made one minor tweak which is to provide additional information about how to access a raw image besides the e01 format.
To use the iSCSI Initiator Method requires a virtual machine running an iSCSI service (I used the Sift workstation inside VMware) and the host operating system running Windows 7. The method involves the following steps:
Sift Workstation Steps
1. Provide access to image in raw format
2. Enable the SIFT iSCSI service
3. Edit the iSCSI configuration file
4. Restart the iscsitarget service
Windows 7 Host Steps
5. Search for iSCSI to locate the iSCSI Initiator program
6. Launch the iSCSI Initiator
7. Enter the Sift IP Address and connect to image
8. Examine VSCs
Sift Workstation Steps
1. Provide access to image in raw format
A raw image needs to be available within the Sift workstation. If the forensic image is already in the raw format and is not split then nothing else needs to be done. However, if the image is a split raw image or is in the e01 format then one of the next commands needs to be used so a single raw image is available.
Split raw image:
sudo affuse path-to-image mount_point
E01 Format use:
sudo mount_ewf.py path-to-image mount_point
2. Enable the SIFT iSCSI service
By default, in Sift 2.1 the iSCSI is turned off so it needs to be turned on. The false value in the /etc/default/iscsitarget configuration file needs to be change to true. The commands below uses the Gedit text editor to accomplish this.
sudo gedit /etc/default/iscsitarget
(Change “false” to “true”)
3. Edit the iSCSI configuration file
The iSCSI configuration file needs to be edited so it points to your raw image. Edit the /etc/ietd.conf configuration file by performing the following (the first command opens the config file in the text editor Gedit):
sudo gedit /etc/ietd.conf
Comment out the following line by adding the # symbol in front of it:
Target iqn.2001-04.com.example:storage.disk2.sys1.xyz
Add the following two lines (the date can be whatever you want (2011-04) but make sure the image path points to your raw image):
Target iqn.2011-04.sift:storage.disk
Lun 0 Path=/media/path-to-raw-image,Type=fileio,IOMode=ro
4. Restart the iscsitarget service
Restart the iSCSI service with the following command:
sudo service iscsitarget restart
Windows 7 Host Steps
5. Search for iSCSI to locate the iSCSI Initiator program
Search for the Windows 7 built-in iSCSI Initiator program
6. Launch the iSCSI Initiator
Run the iSCSI Initiator program
7. Enter the Sift IP Address and connect to image
The Sift workstation will need a valid IP address and the Windows 7 host must be able to connect to the Sift using it. Enter the Sift’s IP address then select the Quick Connect.
A status window should appear showing a successful connection.
8. Examine VSCs
Windows automatically mounts the forensic image’s volumes to the host after a successful iSCSI connection to the Sift. In my testing it took about 30 seconds for the volumes to appear once the connection was established. The picture below shows Gerald’s host system with two volumes from the forensic image mounted.
If there are any VSCs on the mounted volumes then they can be examined with your method of choice (cough cough Ripping VSCs). Gerald provided additional information about how he leverages Dave Hull’s Plotting photo location data with Bing and Cheeky4n6Monkey Diving in to Perl with GeoTags and GoogleMaps to extract metadata from all the VSCs images to create maps. He extracts the metadata by running the programs from the Sift against the VSCs.
Another cool thing about the iSCSI Initiator Method (besides being another free solution to access VSCs) is the ability to access the Sift iSCSI service from multiple computers. In my test I connected a second system on my network to the Sift iSCSI service while my Windows 7 host system was connected to it. I was able to browse the image’s volumes and access the VSCs at the same time from my host and the other system on the network. Really cool…. When finished examining the volumes and VSCs then you can disconnect the iSCSI connection (in my testing it took about a minute to completely disconnect).
Comparing User Profile Across VSCs
I won’t repeat everything I said in the CyberSpeak podcast about my process to examine VSCs and how I focus on the user profile of interest. Focusing on the user profile of interest within VSCs is very powerful because it can quickly identify interesting files and highlight a user’s activity about what files/folders they accessed. Comparing a user profile or any folder across VSCs is pretty simple to do with my vsc-parser script and I wanted to explain how to do this.
The vsc-parser is written to compare the differences between entire VSCs. In some instances this may be needed. However, if I’m interested in what specific users were doing on a computer then the better option is to only compare the user profiles across VSCs since it’s faster and provides me with everything I need to know. You can do this by making two edits to the batch script that does the comparison. Locate the batch file named file-info-vsc.bat inside the vsc-parser folder as shown below.
Open the file with a text editor and find the function named :files-diff. The function executes diff.exe to identify the differences between VSCs. There are two lines (lines 122 and 129) that need to be modified so the file path reflects the user profile. As can be seen in the picture below the script is written to use the root of the mounted image (%mount-point%:\) and VSCs (c:\vsc%%f and c:\vsc!f!).
These paths need to be changed so they reflect the user profile location. For example, let's say we are interested in the user profile named harrell. Both lines just need to be changed to point to the harrell user profile. The screenshot below now shows the updated script.
When the script executes diff.exe there the comparison reports are placed into the Output folder. The picture below shows the reports for comparing the harrell user profile across 25 VSCs.
Reducing the VSCs Comparison Reports
When comparing a folder such as a user profile across VSCs there will be numerous differences that are not relevant to your case. One example could be the activity associated with Internet browsing. The picture below illustrates this by showing the report comparing VSC 12 to VSC11.
The report showing the differences between VSC12 and VSC11 had 720 lines. Looking at the report you can see there are a lot of lines that are not important. A quick way to remove them is to use grep.exe with the –v switch to only display non-matching lines. I wanted to remove the lines in my report involving the Internet activity. The folders I wanted to get rid of were: Temporary Internet Files, Cookies, Internet Explorer, and History.IE5. I also wanted to get rid of the activity involving the AppData\LocalLow\ CryptnetUrlCache folder. The command below shows how I stacked my grep commands to remove these lines and I saved the output into a text file named reduced_files-diff_vsc12-2-vsc11.txt .
grep.exe -v "Temporary Internet Files" files-diff_vsc12-2-vsc11.txt | grep.exe -v Cookies | grep.exe -v "Internet Explorer" | grep.exe -v History.IE5 | grep.exe -v CryptnetUrlCache > reduced_files-diff_vsc12-2-vsc11.txt
I reduced the report from 720 lines to 35. It’s good practice to look at the report again to make sure no obvious lines were missed before running the same command against the other VSC comparison reports. Staking grep commands to reduce the amount of data to look at makes it easier to spot items of potential interest such as documents or Windows link files. It’s pretty easy to see that the harrell user account was accessing a Word document template, an image named staples, and a document named Invoice-#233-Staples-Office-Supplies in the reduced_files-diff_vsc12-2-vsc11.txt report shown below.
I compare user profiles across VSCs because it’s a quick way to identify data of interest inside VSCs. Regardless, if the data is images, documents, user activity artifacts, email files, or anything else that may stored inside a user profile or that a user account accessed.
Tuesday, March 13, 2012
Posted by
Corey Harrell
For the past few months I have been discussing a different approach to examining Volume Shadow Copies (VSCs). I’m referring to the approach as Ripping VSCs and the two different methods to implement the approach are the Practitioner and Developer Methods. The multipart Ripping VSCs series is outlined in the Introduction post. On Thursday (03/15/2012) I’m doing a presentation for a DFIROnline Meet-up about tracking user activity through VSCs using the practitioner method. The presentation is titled Ripping VSCs – Tracking User Activity and the slide deck can be found on my Google sites page.
I wanted to briefly mention a few things about the slides. The presentation is meant to compliment the information I’ve been blogging about in regards to Ripping VSCs. In my Ripping VSCs posts I outlined why the approach is important, how it works, and examples showing anyone can start applying the technique to their casework. I now want to put the technique into context by showing how it might apply to an examination. Numerous types of examinations are interested in what a user was doing on a computer so talking about tracking someone’s activities should be applicable to a wider audience. To help explain put the approach into context I created a fake fraud case study to demonstrate how VSCs provide a more complete picture about what someone did on a computer. The presentation will be a mixture of slides with live demos against a live Windows 7 system. Below are the demos I have lined up (if I am short on time then the last demo is getting axed):
- Previewing VSCs with Shadow Explorer
- Listing VSCs and creating symbolic links to VSCs using vsc-parser
- Parsing the link files in a user profile across VSCs using lslnk-directory-parse2.pl
- Parsing Jump Lists in a user profile across VSCs using Harlan’s jl.pl
- Extracting a Word document’s metadata across VSCs using Exiftool
- Extracting and viewing a Word document from numerous VSCs using vsc-parser and Microsoft Word
I’m not covering everything in the slides but I purposely added additional information so the slides could be used as a reference. One example is the code for the batch scripts. Lastly, I’m working on my presentation skills so please lower your expectations. :)