Notes on Static Analysis
To get started with static analysis, I’ll first need malware samples.
First thing to go over is the file type:
- Unzip the malware
- .bin file. The malware hence is defanged with a changed extension.
file type
To analyze file type use HxD.
Some keywords to look for when we’re looking for file types. EXE signatures —>
MZ4D5AThis program cannot be run in DOS modeThese are signatures/keywords that tell us that this is an exe. 4D 5A decodes to MZ.
Sometimes malware hides in an image file. EXEs often hide inside of image files.
Next tool is Cmder. This application support drag-and-drop to enter filepath which is really useful.
file DriveLetter:\malware_filepath\fingerprinting the malware
- Grab the hash and dump in in virustotal
- Hashcalc, Hashmyfiles
Hashcalc also support drag-and-drop to enter filepath directly.
Search for the filehash in Virustotal
Get a better understanding of malware from the VirusTotal reports and the Community section.
Strings
Sometimes we might find very useful information inside the malware files.
- IP addresses
- URLs (C2C)
- Windows API
- Base64 or any other encoding techniques
Powershell uses Base64 encoding.
Back to Cmder run
strings -n 10 DriveLetter:\malware_filepathThis will dump all the strings it can find inside the file of length greater than 10. Each in a new line which is helpful to spot signatures.
Can also put the results in an output file like this
strings -n 10 DriveLetter:\malware_filepath > output.txtOne more tool can be used called BinText
Decrypting encoded strings
Next tool to use is Xorsearch
Encoded strings in a malware sometimes contains URLs.
Xorsearch DriveLetter:\malware_filepath keywordTo look for URLs I can put the keyword http. To look for EXE signature I can put This. Another keyword can be Create
Next tool is Floss
floss -s DriveLetter:\malware_filepathAfter it is done running, Floss will show us the encrypted strings it finds. The content shown is decoded from the file. Sometimes it doesn’t decode anything, sometimes relevant info comes up. Tough luck
Packing
Packing is a technique where malware authors or people who create the malware try and use a tool that modifies the formatting of the code by compressing the code or encrypting the data. They do this because it avoid detection by antiviruses.
The tool to use to see if a malware is packed is a tool called Exeinfo
It shows us what packing technique the malware is using i.e. UPX
It will show us what to do to unpack the malware file.
Like so :
upx -d -o UnpackedMalware.exe DriveLetter:\malware_filepathThe -o here tells it to output the unpacked file into a new UnpackedMalware.exe file.
The unpacked file might be bigger than the original file which makes sense.
There are lots of packing techniques and so many ways to decode them.
pestudio
Another tool is pestudio. This is an all-in-one tool.
It gives us the hashes, the file signatures, packing techniques
It also shows indicators AKA suspicious things that file contains.
It automatically submits it to VirusTotal and shows the results too.
It also shows the strings that it extracts. The bad flags will mostly be found under the indicators tab.