Wafaray – Enhance Your Malware Detection With WAF + YARA (WAFARAY)
WAFARAY is a LAB deployment based on Debian 11.3.0 (stable) x64 made and cooked between two main ingredients WAF + YARA to detect malicious files (e.g. webshells, virus, malware, binaries) typically through web functions (upload files).
The Proof of Concept is based on Debian 11.3.0 (stable) x64 OS system, OWASP CRC v3.3.2 and Yara 4.0.5, you will find the automatic installation script here
Once the Yara Rules were downloaded and compiled. It is similar to when you deploy ModSecurity, you need to customize what kind of rule you need to apply. The following log is an example of when the Web Application Firewall + Yara detected a malicious file, in this case, eicar was detected.
A malicious file is uploaded, and the ModSecurity rules plus Yara denied uploading file to the backend if the file matched with at least one Yara Rule. (Example of Malware:
For this demo, we disable the rule A malicious file is uploaded, and the ModSecurity rules plus Yara denied uploading file to the backend if the file matched with at least one Yara Rule. (Example of Malware Bazaar (RecordBreaker):
In case that you want to download more yara rules, you can see the following repositories: Alex Hernandez aka (@_alt3kx_) Israel Zeron Medina aka @spk085 YaraCompile.py
compiles all the yara rules. (Python3 code)test.conf
is a virtual host that contains the mod security rules. (ModSecurity Code)modsec_yara.py
in order to inspect the file that is trying to upload. (Python3 code)Main Paths:
/YaraRules/Compiled
/YaraRules/rules
/YaraRules/YaraScripts
/etc/apache2/sites-enabled
/temporal
Approach
Blueteamers
: Rule enforcement, best alerting, malware detection on files uploaded through web functions.Redteamers/pentesters
: GreyBox scope , upload and bypass with a malicious file, rule enforcement.Security Officers
: Keep alerting, threat hunting.SOC
: Best monitoring about malicious files.CERT
: Malware Analysis, Determine new IOC.Building Detection Lab
wafaray_install.sh
and an optional manual installation guide can be found here: manual_instructions.txt
also a PHP page has been created as a “mock” to observe the interaction and detection of malicious files using WAF + YARA.Installation (recommended) with shell scripts
Yara Rules
Message: Access denied with code 403 (phase 2). File "/temporal/20220812-184146-YvbXKilOKdNkDfySME10ywAAAAA-file-Wx1hQA" rejected by
the approver script "/YaraRules/YaraScripts/modsec_yara.py": 0 SUSPECTED [YaraSignature: eicar]
[file "/etc/apache2/sites-enabled/test.conf"] [line "56"] [id "500002"]
[msg "Suspected File Upload:eicar.com.txt -> /temporal/20220812-184146-YvbXKilOKdNkDfySME10ywAAAAA-file-Wx1hQA - URI: /upload.php"]Testing WAFARAY… voilà…
Stop / Start ModSecurity
$ sudo service apache2 stop
$ sudo service apache2 startApache Logs
$ cd /var/log
$ sudo tail -f apache2/test_access.log apache2/test_audit.log apache2/test_error.logDemos
Demo 1 – EICAR
Demo 2 – WebShell.php
933110 - PHP Inject Attack
to validate Yara Rules. A malicious file is uploaded, and the ModSecurity rules plus Yara denied uploading file to the backend if the file matched with at least one Yara Rule. (Example of WebShell PHP:
Demo 3 – Malware Bazaar (RecordBreaker) Published: 2022-08-13
YARA Rules sources
References
Roadmap until next release
Authors
Jesus Huerta aka @mindhack03d Contributors
Share:
Warning: Trying to access array offset on value of type bool in /home/u349216201/domains/esystematics.com/public_html/blog/wp-content/plugins/bridge-core/modules/shortcodes/shortcode-elements/_social-share-list/templates/social-share-list.php on line 104