Our story so far...
The list of IOCs is growing as the group conducts the triage. As they find new files related to the actor, the IR team goes back and searches the previous tools output to ensure everything has been picked up. With new files, mf.bat, ga86.exe, and rar.exe, from the ShimCache review, Frank continues his analysis of the Amcache while the rest of the team finishes up forensics and the timeline. At this point, they have 25 machines that have been involved in the incident.
Amcache Introduction
The Amcache.hve file contains information on the executables that were executed on the system. Yogesh Khatri’s blog post contains a nice table about what’s stored in this Windows NT Registry File formatted file. In regards to mass triage we are initially interested in the following fields: full path and SHA1 hash. While the rest of the fields in this file are incredibly useful, they detract from our main goal, identifying potential actor touched boxes. The other fields do come into play in the analysis after we’ve confirmed the potential actor has accessed boxes that have been identified in this process and/or if there already are known IOCs such as SHA1 hashes, PE header info, or File Version info.
Amcache Analysis
Like the Shimcache analysis, all of the Amcache hives need to be downloaded. The file location is under the Windows directory at: C:\Windows\AppCompat\Programs\Amcache.hve. This can be done via FRAC or some other tool.
Once the files have been collected, let’s start the analysis by kicking off RegRipper on a directory full of Amcache files using a modified version of amcache_tln plugin. The plugin is available at my github site.
To run RegRipper on a set of files, use the following command:
Windows:
find {directory with SYSTEM hives} -print -exec rip.exe -r {} -p amcache_tln ; > amcache{datetime}.txt
*NIX:
find {directory with SYSTEM hives} -print -exec rip.pl -r {} -p amcache_tln \; > amcache{datetime}.txt
Please note that it will take considerably longer to process the Amcaches than it does for Shimcaches.
Below is an example of output from modified version of Carvey’s amcache_tln plugin:
1532029396|AmCache||||Key LastWrite|c:\program files (x86)\solidworks pdm\fileformats\xpsplugin.exe|5016897b8f8127cdf8bd1f4f2bba3d74bdbb7209||0000|./amcache1/Amcache_machineA.hve
On a side note regarding the modified amcache_tln plugin: Carvey’s plugin was altered so that columns will line up in the output regardless of the type of line that was outputted. This helps to ensure that when column 7 (file path and file name) is cut out it is in the same place for each line. Lastly the hive file that the line came from is at the end of every line.
The fields that are initially interesting in are field 7 (file path and name) and field 8 (SHA1 hash). The other thing that should be noted is not all of the columns will have data.
Next cut out the SHA1 hashes from the amcache{datetime}.txt. The hashes will be ran against the NSRL database and any whitelists to reduce what is needed to be reviewed by the analyst.
cut -f8 -d\| amcache{datetime}.txt | sort | uniq | grep -v amcache | sed '/^[[:space:]]*$/d' | grep -v -i "plugins" > amcache{datetime}.sha
The hashes from amcache{datatime}.sha can be ran against databases such as NSRL, MSDN, and whitelists. The main point for checking the hashes against these databases is to rule out benign binaries, identify hack tools, and the unknown binaries. In the end the more that can be reduced, the better. The instructions for generating the SQLite databases for NSRL and whitelists are at the end of this article.
./ir_distill_v0.3.py --nsrl ./nsrl.db --reviewlist ./whitelist.db ./msdn.db --file ./amcache{datetime}.sha --out amcache{datetime}_distill --ignorecase
IR Distil produces two output files. The first one is the one ending with “_match.csv”. This file will contain all of the matches related to the NSRL, MSDN, and the review/white lists.
The “_match.csv” file should be reviewed in the terms of matches to the NSRL or if a blacklist was given to IR_Distill. The NSRL does contain hacker tools and if those tools are identified the organization should review to see if it is authorized to run on the machine it was found on. The column label “ApplicationType” will contain the categories from the NSRL. The following cut command makes the review easy:
cut -d\| -f6 amcache{datetime}_distill_match.csv | sort | uniq -c | less
Below is some sample output from the above cut command:
2 "3d computer graphics and design" 4 "3d computer graphics and design,Graphic/Drawing" 7 "3D Landscaping and Animation" 16 "Accounting" 8 "Accounting,Business Management" 3 "Accounting,Business Management,Financial" 10 "Accounting,Business Manager,Financial" 1 "Accounting,Check creator,Financial" 16 "Accounting,Finance,Software" 7 "Accounting,Financial" 2 "Accounting,Financial,Information,Tax" 8 "Accounting,Financial,Money Management" 1 "Accounting,Management" 2 "Accounting,Money Management" 2 "Accounting,Software,Tool" 53 "Analysis" 2 "Analysis,Networking Tools" 372 "Anti Virus,Antivirus,antispyware" 26 "Anti Virus,Backup and Recovery,FireWall,Utility" 1 "Antivirus,FireWall,Internet Security,antispyware"
The next step is to pull all of the entries listed in the output from SHA1 review and create the first frequency analysis file. Only the no match entries are pulled out. Everything up else has been reviewed up to this point and has been identified. To the unknown out use the following:
grep -f amcache{datetime}.distill_nomatch.txt amcache{datetime}.txt | cut -f7 -d\| | sort | uniq -c | sed -e 's/^[ \t]*//' | sort -t" " -k2 > amache{datetime}_freq.txt
In the output there will be some lines related to amcache filenames. These lines can be ignored. The second thing is some files may show up multiple times within a single amcache file. Just something to keep in mind while reviewing. Finally, the next step is to run the output through ir_distill to reduce things further.
./ir_distill_v0.3.py -f ./os.sqlite --showallmatches --ignorecase -i amcache{datetime}_freq.txt -o amcache_{datetime}_distill2
Finally review “amcache_{datetime}_distill2_nomatch.txt” file. This file is reviewed exactly like the “_nomatch.txt” file was reviewed in Mass Triage Part 4 (Shimcache). Just make sure to mark up the lines that are interesting. Typically, the lines of interest are the following:
- Filenames that are 1 to 4 characters
- Windows OS files in the wrong directory
- Odd filenames
- Binaries running out of odd directories for example:
- C:\Inetpub
- C:\Windows\temp
- C:\temp
- C:\Dell
- C:\Intel
Download Files and Virus Total Review
Once the interesting lines are marked up, the lines can be extract from the “_nomatch.txt” file via a grep command as outlined in Part 4. Basically, the interesting lines are grepped out and prepared to be used to pull the full line out the processed amcache file from Step 1.
grep "#km" amcache_{datetime}_distill2_nomatch.txt | cut -f2- -d\| | cut -f1 -d\# | sed 's/[[:blank:]]*$//' | sed 's/\\/\\\\/g' | sed 's/\"//g' > amcache_{datetime}_finds
To pull the full lines out of the amcache{datetime}.txt:
grep -i -f amcache_{datetime}_finds amcache{datetime}.txt > amcache_{datetime}_finds_complete
Below is an example line that was pulled out:
1531295133|AmCache_IA||||Key LastWrite|c:\windows\x86.exe|9c07abbdd1faa019708cfb54a778748077fe13e3||./MachineA/Amcache.hve
From here there are two things that can be done. First since we know which machine the amcache line came from, the file “c:\windows\x86.exe” can be pulled from the machine. FRAC/RIFT can be used to pull the files. It is recommended that pulling the files are done in a forensically sound manner. Once the files are obtained, they can be reviewed to determine if they are malicious. Note: Keep in mind these methods do find commodity malware and APT malware. It is up to the reviewer to determine which category the files fit in.
The second thing is, taking the SHA1 hash and run the hashes through VirusTotal. For each line cut out field 8 (SHA1 hash), “9c07abbdd1faa019708cfb54a778748077fe13e3” from the example above, from each line. Put all of the interesting hashes into a file. Then run them through the python script.
./virustotal-search.py -o ./amcache_{datetime}_sha_vt –notfound=./ amcache_{datetime}_sha_vt_notfound amcache_{datetime}_sha
Once the python script is done, review the “amcache_{datetime}_sha_vt_notfound” file. Any files with VT hits can be looked up on VT to get more information to determine the nature of the hits. Those files that do not have hits, should be pulled for further review.
Once the files are obtained, they can be reviewed to determine if they are malicious. Keep in mind these methods do find commodity malware and APT malware. It is up to the reviewer to determine which category the files fit in.
Frequency Analysis Review: Amcache
Here is a summary of the steps so far:
- Gather up amcache hives
- Run RegRipper on all amcache hives. Make sure to use the modified version of the plugin.
Windows:
find {directory with amcache hives} -print -exec rip.exe -r {} -p amcache_tln ; > appcache{datetime}.txt
*NIX:find {directory with amcache hives} -print -exec rip.pl -r {} -p amcache_tln \; > appcache{datetime}.txt
- Cut out the SHA1 hashes and run them against the NSRL/MSDN/Review/Whitelist databases to remove known good hashes.
-
cut -f8 -d\| amcache{datetime}.txt | sort | uniq | grep -v amcache | sed '/^[[:space:]]*$/d' | grep -v -i "plugins" > amcache{datetime}.sha
-
./ir_distill_v0.3.py --nsrl ./nsrl.db --reviewlist ./whitelist.db ./msdn.db --file ./amcache{datetime}.sha --out amcache{datetime}_shareview –ignorecase
-
cut -d\| -f6 amcache{datetime}_shareview _match.csv | sort | uniq -c
-
- Cut out the directory path and filename, sort them, and unique them for frequency analysis<\li>
grep -f amcache{datetime}.shareview_nomatch.txt| cut -f7 -d\| | sort | uniq -c | sed -e 's/^[ \t]*//' | sort -t" " -k2 > amache{datetime}_freq.txt
- Reduce output with IR Distill
./ir_distill_v0.3.py -f ./os.sqlite --showallmatches --ignorecase -i amache{datetime}_freq.txt -o amcache_{datetime}_distill2
- Review “amcache_{datetime}_distil_nomatch.txt” file
- Review the binaries
- Pull binaries from source machines
- Run hashes through VT
- Malware analysis of binaries
Create an SQLite NSRL Database Tool Prep
The NSRL database is only available in the CSV format. To make the fastest way possible to search for hashes, it should be converted into a database. The steps outlined below show how to do this.- Download the RDS minimal hash set: https://www.nist.gov/itl/ssd/software-quality-group/nsrl-download/current-rds-hash-sets
- Unpack the zip file
-
mv NSRLFile.txt NSRLFile.csv
-
mv NSRLProd.txt NSRLProd.csv
-
sqlite3 nsrl.db
-
sqlite> .mode csv
-
sqlite> .import NSRLFile.csv nsrl
-
sqlite> .import NSRLProd.csv prod
-
sqlite> CREATE INDEX `sha1` ON `nsrl` ( `SHA-1` COLLATE NOCASE );
-
sqlite> CREATE INDEX `code` ON `prod` ( `ProductCode` COLLATE NOCASE );
-
sqlite> CREATE INDEX `apptype` ON `prod` ( `ApplicationType` COLLATE NOCASE );
-
sqlite> CREATE INDEX `OpSystemCode` ON `prod` ( `OpSystemCode` COLLATE NOCASE );
-
sqlite> .exit
Create White/Review List SQLite
-
echo 'SHA-1|FileName' > review.csv
- Gather new items for the review/whitelist
grep AmCache amcache_{datetime}.txt | awk -v OFS="\|" -F"\|" '{print $8, $7}' >> review.csv
-
sqlite3 review.db
-
sqlite> .mode csv
-
sqlite> .separator "\|"
-
sqlite> .import review.csv review
-
sqlite> .exit
Tool Download List
All of the tools in this post can be downloaded at:
- https://github.com/chaoticmachinery/mass_triage_tools
- https://blog.didierstevens.com/programs/virustotal-tools/
- https://www.nist.gov/itl/ssd/software-quality-group/nsrl-download/current-rds-hash-sets
6.2.5