PHP-Antimalware-Scanner Find Malicious Code
PHP-Antimalware-Scanner Find Malicious Code

PHP-Antimalware-Scanner: Find Malicious Code

This package, written in php, can scan PHP files and analyze your project for find malicious code inside it. It provides a text terminal console interface to scan files in a given directory and find PHP code files the seem to contain malicious code.

This package, written in php, can scan PHP files and analyze your project for find malicious code inside it. It provides a text terminal console interface to scan files in a given directory and find PHP code files the seem to contain malicious code. The package can also scan the PHP files without outputting anything to the terminal console. In that case the results are stored in a log file. This scanner can work on your own php projects and on a lot of others platform. Use this command php -d disable_functions for run the program without issues.

Note

Remember that you will be solely responsible for any damage to your computer system or loss of data that results from such activities. You are solely responsible for adequate protection and backup of the data before execute the scanner.

How to contribute

Have an idea? Found a bug? Please raise to ISSUES or PULL REQUEST. Contributions are welcome and are greatly appreciated! Every little bit helps.

Requirements

  • php 5.4+

Install

Release

You can use one of this method for install the scanner downloading it from github or directly from console.

"
"

Download

Go on GitHub page and press on Releases tab or download the raw file from: here

Console

  1. Run this command from console (scanner will be download on your current directory):
wget https://raw.githubusercontent.com/marcocesarato/PHP-Antimalware-Scanner/master/dist/scanner --no-check-certificate
  1. Run the scanner:
php scanner ./dir-to-scan -a ...

Source

Download

Click on GitHub page “Clone or download” or download from: here

Composer

  1. Install composer
  2. Type composer require marcocesarato/amwscan
  3. Go on vendor/marcocesarato/amwscan/ for have source
  4. Enjoy

Git

  1. Install git
  2. Copy the command and link from below in your terminal:
git clone https://github.com/marcocesarato/PHP-Antimalware-Scanner
  1. Change directories to the new ~/PHP-Antimalware-Scanner directory: cd ~/PHP-Antimalware-Scanner/
  2. To ensure that your master branch is up-to-date, use the pull command:
git pull https://github.com/marcocesarato/PHP-Antimalware-Scanner
  1. Enjoy

Build

For compile /src/ folder to single file /dist/scanner you need to do this:

  1. Install composer requirements: composer install
  2. Change version number on src/Application.php
  3. Run command composer build

Test

For test detection of malware you can try detect they from this collection: here

"
"

Scanning mode

You could find some false positive during scanning. For this you can choice the aggression level as following:

ParamAbbrAggressivityDescription
VERY AGGRESSIVESearch for all functions/exploits on lists and all malware signatures without restrictions
--agile-aMEDIUMSearch for some specific exploits on lists with some restrictions and all malware signatures (on WordPress and others platform could find more malware and more false positive)
--only-signatures-sNORMALSearch for all malware signatures (could be perfect for WordPress and others platform for have less false positive)
--only-exploits-eAGGRESSIVESearch for exploits on lists
--only-functions-fMEDIUMSearch for all functions on lists (on some obfuscated code can’t be detected)

Suggestions

If you are running the scanner on a WordPress project or other popular platform use --only-signatures or --agile flag for have check with less false positive but this could miss some dangerous exploits like nano.

Examples

php -d disable_functions='' scanner -s
php -d disable_functions='' scanner -a

Detection Options

When a malware is detected you will have the following choices (except when scanner is in report scan mode --report):

  • Delete file [--auto-delete]
  • Move to quarantine (move to ./scanner-quarantine) [--auto-quarantine]
  • Dry run evil code fixer (fix code and confirm after a visual check) [--auto-clean]
  • Dry run evil line code fixer (fix code and confirm after a visual check) [--auto-clean-line]
  • Open with vim (need php -d disable_functions='')
  • Open with nano (need php -d disable_functions='')
  • Add to whitelist (add to ./scanner-whitelist.json)
  • Show source
  • Ignore [--auto-skip]

Usage

Command line

Arguments:
<path>                       - Define the path to scan (default: current directory)

Flags:
-a   --agile                 - Help to have less false positive on WordPress and others platforms
                               enabling exploits mode and removing some common exploit pattern
-f   --only-functions        - Check only functions and not the exploits
-e   --only-exploits         - Check only exploits and not the functions,
                               this is recommended for WordPress or others platforms
-s   --only-signatures       - Check only virus signatures (like exploit but more specific)
-h   --help                  - Show the available flags and arguments
-l   --log=""                - Write a log file on 'index.php.log' or the specified filepath
-r   --report                - Report scan only mode without check and remove malware (like --auto-skip).
                               It also write a report with all malware paths found
-b   --backup                - Make a backup of every touched files
-u   --update                - Update index.php to last version
-v   --version               - Get version number

--silent                     - No output and prompt
--disable-colors             - Disable CLI colors

--limit=""                   - Set file mapping limit
--offset=""                  - Set file mapping offset
...

Programmatically

On programmatically silent mode and auto skip are automatically enabled.

use marcocesarato\amwscan\Scanner;

$app = new Scanner();
$report = $app->setPathScan("my/path/to/scan")
              ->enableBackups()
              ->setPathBackups("/my/path/backups")
              ->setAgileMode()
              ->setAutoClean()
              ->run();

Report Object

object(stdClass) (7) {
  ["scanned"]    => int(0)
  ["detected"]   => int(0)
  ["removed"]    => array(0) {}
  ["ignored"]    => array(0) {}
  ["edited"]     => array(0) {}
  ["quarantine"] => array(0) {}
  ["whitelist"]  => array(0) {}
}

Exploits and Functions List

Exploits

  • eval_chreval_pregeval_base64eval_commenteval_executionalignb374kweevely3c99_launchertoo_many_chrconcatconcat_vars_with_spacesconcat_vars_arrayvar_as_funcglobal_var_stringextract_globalescaped_pathinclude_iconbackdoor_codeinfected_commenthex_charhacked_bykillallglobals_concatglobals_assignbase64_longbase64_inclusionclever_includebasedir_bypassbasedir_bypass2non_printabledouble_vardouble_var2global_savehex_varregister_functionsafemode_bypassioncube_loadernanoninjaexecutionexecution2execution3shellshocksilenced_evalsilence_inclusionssi_exechtaccess_handlerhtaccess_typefile_prependiis_comreversedrawurlendcode_rot13serialize_phpversionmd5_create_functiongod_modewordpress_filterpassword_protection_md5password_protection_shacustom_mathcustom_math2uncommon_functiondownload_remote_codedownload_remote_code2download_remote_code3php_unameetc_passwdetc_shadowexplode_chr

Functions

  • il_execshell_execevalsystemcreate_functionexecassertsyslogpassthrudefine_syslog_variablesposix_killposix_unameproc_closeproc_get_statusproc_niceproc_openproc_terminateinject_codeapache_child_terminateapache_notedefine_syslog_variables

Screenshots

PHP-Antimalware-Scanner
PHP-Antimalware-Scanner
Demo PHP-Antimalware-Scanner
Demo PHP-Antimalware-Scanner
Dark Mode

PHP-Antimalware-Scanner (this link opens in a new window) by marcocesarato (this link opens in a new window)

This package, written in php, can scan PHP files and analyze your project for find malicious code inside it. It provides a text terminal console interface to scan files in a given directory and find PHP code files the seem to contain malicious code.