Hunting for Malicious Files with MISP + OSSEC
A few months ago, I wrote a diary called “Unity Makes Strength” which was illustrated with an example of integration between a malware analysis solution and a next-generation firewall. The goal is to increase the ability to block malicious traffic as soon as possible. Today, I’d like to explain how to improve the detection of malware on Windows computers thanks to the integration of MISP and OSSEC. I already presented the Malware Information Sharing Platform in another diary. About OSSEC, in a few words, it is a host-based IDS with many extra features like log centralisation, real-time alerting, file integrity monitoring and much more.
To achieve the detection of malicious files or registry keys on the Windows host, let's use a very interesting feature of OSSEC called "rootcheck" that performs rootkit detection. OSSEC comes with a default configuration that contains interesting examples but the malware landscape changing daily, this configuration is obsolete. The goal is to search a MISP database for recent IOC's and inject them into the OSSEC configuration. Both solutions are really open to the world and an integration is quite easy.
A MISP instance can be fully managed with the available REST API. To simplify the use of this API, there is even a Python library called PyMISP. Here is a very simple example to get the latest events from MISP:
from pymisp import PyMISP from keys import misp_url, misp_key, misp_verifycert misp = init(miss_url, misp_key) result = misp.download_last(“1d”) for event in result: print json.dumps(e) + “\n"
The data flow will be:
MISP > PyMISP.py (via the REST API) > IOC-list > OSSEC > OSSEC agents
I wrote a small script called "MOF" which stands for "MISP OSSEC Feeder". It extracts the interesting file names from MISP. The following type of attributes are extracted:
- Artefacts dropped
- Payload delivery
- Payload installation
To reduce the risk of false positives, only filenames containing Windows environment variables are exported (%TEMP%, %WINDIR%, %APPDATA%, ...). Registry keys are also exported. The script usage:
# ./mof.py -h usage: misp_ossec_export.py [-h] -t TIME [-o OUTPUT] Extract IOC's from MISP and generate an OSSEC rootcheck file. optional arguments: -h, --help show this help message and exit -t TIME, --time TIME Time machine (ex: 5d, 12h, 30m). -o OUTPUT, --output OUTPUT Output file # ./mof.py -o /var/ossec/etc/shared/misp_windows_ioc.txt
The script requires the PyMISP library that can be installed easily via a "pip install pymisp".
The generated rootcheck configuration file looks like below. IOC's are grouped by MISP events.
# # OSSEC RootCheck IOC generated by MOF (MISP OSSEC Feeder) # https://github.com/xme/ # # Generated on: Mon Jul 11 22:06:56 2016 # MISP url: https://misp.home.rootshell.be/ # Wayback time: 30d # [MISP_2073] [any] [Packrat: Seven Years of a South American Threat Actor] r:HKLM\SOFTWARE\Microsoft\Active; r:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer\Run\Policies; r:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\msconfig; [MISP_2200] [any] [Click-Fraud Ramdo Malware Family Continues to Plague Users] r:HKCU\SOFTWARE\Adobe\Acrobat Reader\14.0\Globals\LastLoggedOnProvider; r:HKCU\SOFTWARE\Adobe\Acrobat Reader\14.0\Globals\IconUnderline; r:HKCU\SOFTWARE\Adobe\Acrobat Reader\14.0\Globals\HangDetect; r:HKCU\SOFTWARE\Adobe\Acrobat Reader\14.0\Globals\LastProgress; r:HKCU\SOFTWARE\Adobe\Acrobat Reader\14.0\Globals\ShowTabletKeyboard; r:HKCU\Software\Microsoft\Windows\CurrentVersion\Run\BluetoothManage; [MISP_2210] [any] [Jigsaw Ransomware Decrypted: Will delete your files until you pay the Ransom] f:%USERPROFILE%\AppData\Roaming\Frfx\; f:%USERPROFILE%\AppData\Roaming\Frfx\firefox.exe; f:%USERPROFILE%\AppData\Local\Drpbx\; f:%USERPROFILE%\AppData\Local\Drpbx\drpbx.exe; f:%USERPROFILE%\AppData\Roaming\System32Work\; f:%USERPROFILE%\AppData\Roaming\System32Work\Address.txt; f:%USERPROFILE%\AppData\Roaming\System32Work\dr; f:%USERPROFILE%\AppData\Roaming\System32Work\EncryptedFileList.txt;
The next step is to integrate this new file into your OSSEC agent.txt file. Please have a look at the OSSEC documentation for a complete description of this shared agents configuration. Here is mine (stored in '/var/ossec/etc/shared/agent.conf' by default):
</rootcheck> </ossec_agent> <ossec_agent os="Windows"> <rootcheck> <windows_audit>./shared/win_audit_rcl.txt</windows_audit> <windows_apps>./shared/win_applications_rcl.txt</windows_apps> <windows_malware> ./shared/misp_windows_ioc.txt</windows_malware>
To implement a full automation, install the script on your OSSEC server and execute it from a crontab at a regular interval (example: once a day). Note that the agent.conf is not pushed immediately to agents - it may take a while depending on your configuration! The Python script is available here. And you, how do you search for malicious files across multiple hosts/locations?
Happy hunting!
Xavier Mertens (@xme)
ISC Handler - Freelance Security Consultant
PGP Key
Reverse-Engineering Malware: Advanced Code Analysis | Online | Greenwich Mean Time | Oct 28th - Nov 1st 2024 |
Comments
Anonymous
Jul 14th 2016
8 years ago
Note that I'm using MISP but the generated OSSEC file is very simple and could be easily generated from other threat intelligence sources!
Anonymous
Jul 15th 2016
8 years ago