Stars: 1428
Forks: 315
Pull Requests: 39
Issues: 88
Watchers: 76
Last Updated: 2023-05-06 13:33:59
Detect potentially malicious PHP files
License: GNU Lesser General Public License v3.0
Languages: Makefile, Shell, Python, PHP, YARA, Go, Dockerfile
_______ __ __ _______
| ___ || |_| || |
| | | || || ___|
| |___| || || |___ Webshell finder,
| ___|| || ___| kiddies hunter,
| | | ||_|| || | website cleaner.
|___| |_| |_||___|
Detect potentially malicious PHP files.
PHP-malware-finder does its very best to detect obfuscated/dodgy code as well as files using PHP functions often used in malwares/webshells.
The following list of encoders/obfuscators/webshells are also detected:
Of course it's trivial to bypass PMF, but its goal is to catch kiddies and idiots, not people with a working brain. If you report a stupid tailored bypass for PMF, you likely belong to one (or both) category, and should re-read the previous statement.
Detection is performed by crawling the filesystem and testing files against a set of YARA rules. Yes, it's that simple!
Instead of using a hash-based approach,
PMF tries as much as possible to use semantic patterns, to detect things like
"a $_GET
variable is decoded two times, unzipped,
and then passed to some dangerous function like system
".
git clone https://github.com/jvoisin/php-malware-finder.git
cd php-malware-finder && make
or replace the last 2 steps with go install github.com/jvoisin/php-malware-finder
,
which will directly compile and install PMF in your ${GOROOT}/bin
folder.
$ ./php-malware-finder -h
Usage:
php-malware-finder [OPTIONS] [Target]
Application Options:
-r, --rules-dir= Alternative rules location (default: embedded rules)
-a, --show-all Display all matched rules
-f, --fast Enable YARA's fast mode
-R, --rate-limit= Max. filesystem ops per second, 0 for no limit (default: 0)
-v, --verbose Verbose mode
-w, --workers= Number of workers to spawn for scanning (default: 32)
-L, --long-lines Check long lines
-c, --exclude-common Do not scan files with common extensions
-i, --exclude-imgs Do not scan image files
-x, --exclude-ext= Additional file extensions to exclude
-u, --update Update rules
-V, --version Show version number and exit
Help Options:
-h, --help Show this help message
Or if you prefer to use yara
:
$ yara -r ./data/php.yar /var/www
Please keep in mind that you should use at least YARA 3.4 because we're using hashes for the whitelist system, and greedy regexps. Please note that if you plan to build yara from sources, libssl-dev must be installed on your system in order to have support for hashes.
Oh, and by the way, you can run the comprehensive testsuite with make tests
.
If you want to avoid having to install Go and libyara, you can also use our
docker image and simply mount the folder you want to scan to the container's
/data
directory:
$ docker run --rm -v /folder/to/scan:/data ghcr.io/jvoisin/php-malware-finder
Check the whitelist.yar file. If you're lazy, you can generate whitelists for entire folders with the generate_whitelist.py script.
Because:
PHP-malware-finder is licensed under the GNU Lesser General Public License v3.
The amazing YARA project is licensed under the Apache v2.0 license.
Patches, whitelists or samples are of course more than welcome.