Skip to content

Commit 80fde02

Browse files
committed
feat: added bin folder with scripts and changed distribute to build
Added bin folder with scripts Changed distribute to build Changed images folders
1 parent 1afcaeb commit 80fde02

16 files changed

+234
-39
lines changed

.cs.php .php_cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

33
return PhpCsFixer\Config::create()
4-
->setUsingCache(false)
4+
->setUsingCache(true)
55
->setRiskyAllowed(true)
6-
//->setCacheFile(__DIR__ . '/.php_cs.cache')
6+
->setCacheFile(__DIR__ . '/.php_cs.cache')
77
->setRules(array(
88
'@PSR1' => true,
99
'@PSR2' => true,
@@ -13,7 +13,7 @@
1313
'align_multiline_comment' => array('comment_type' => 'phpdocs_only'), // PSR-5
1414
'phpdoc_to_comment' => false,
1515
'array_indentation' => true,
16-
//'array_syntax' => ['syntax' => 'short'],
16+
'array_syntax' => array('syntax' => 'long'),
1717
'cast_spaces' => array('space' => 'none'),
1818
'concat_space' => array('spacing' => 'one'),
1919
'compact_nullable_typehint' => true,
@@ -34,7 +34,7 @@
3434
),
3535
))
3636
->setFinder(PhpCsFixer\Finder::create()
37-
->in(__DIR__ . '/src')
38-
->name('*')
37+
->in(__DIR__)
38+
->name('*.php')
3939
->ignoreDotFiles(true)
4040
->ignoreVCS(true));

README.md

+25-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ![amwscan](amwscan.png)
1+
# ![amwscan](images/amwscan.png)
22

33
# AMWSCAN - PHP Antimalware Scanner
44

@@ -21,7 +21,7 @@ Use this command `php -d disable_functions` for run the program without issues.
2121
- php 5+
2222

2323
## Install
24-
24+
2525
### Release
2626

2727
You can use one of this method for install the scanner downloading it from github or directly from console.
@@ -33,7 +33,7 @@ https://raw.githubusercontent.com/marcocesarato/PHP-Antimalware-Scanner/master/d
3333

3434
#### Console
3535

36-
1. Run this command from console (scanner will be download on your current directory):
36+
1. Run this command from console (scanner will be download on your current directory):
3737

3838
`wget https://raw.githubusercontent.com/marcocesarato/PHP-Antimalware-Scanner/master/dist/scanner --no-check-certificate`
3939

@@ -45,16 +45,18 @@ https://raw.githubusercontent.com/marcocesarato/PHP-Antimalware-Scanner/master/d
4545

4646
##### Download
4747

48-
Click on GitHub page "Clone or download" or download from:
48+
Click on GitHub page "Clone or download" or download from:
4949
https://codeload.github.com/marcocesarato/PHP-Antimalware-Scanner/zip/master
5050

5151
##### Composer
52+
5253
1. Install composer
5354
2. Type `composer require marcocesarato/amwscan`
5455
3. Go on `vendor/marcocesarato/amwscan/` for have source
5556
4. Enjoy
5657

5758
##### Git
59+
5860
1. Install git
5961
2. Copy the command and link from below in your terminal:
6062
`git clone https://github.com/marcocesarato/PHP-Antimalware-Scanner`
@@ -64,14 +66,14 @@ https://codeload.github.com/marcocesarato/PHP-Antimalware-Scanner/zip/master
6466
`git pull https://github.com/marcocesarato/PHP-Antimalware-Scanner`
6567
5. Enjoy
6668

67-
## Distribute
69+
## Build
6870

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

7173
1. Install composer requirements:
7274
`composer install`
73-
2. Run distribute script *(replace 0.5.x.x with your version number)*:
74-
`php distribute 0.5.x.x`
75+
2. Run distribute script _(replace 0.5.x.x with your version number)_:
76+
`composer build 0.5.x.x`
7577

7678
## Test
7779

@@ -83,13 +85,13 @@ https://github.com/marcocesarato/PHP-Malware-Collection
8385

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

86-
| Param | Abbr | Aggressivity | Description |
87-
|---------------------|------|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
88-
| | | VERY AGGRESSIVE | Search for all functions/exploits on lists and all malware signatures without restrictions |
89-
| `--agile` | -a | MEDIUM | Search 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) |
90-
| `--only-signatures` | -s | NORMAL | Search for all malware signatures (could be perfect for Wordpress and others platform for have less false positive) |
91-
| `--only-exploits` | -e | AGGRESSIVE | Search for exploits on lists |
92-
| `--only-functions` | -f | MEDIUM | Search for all functions on lists (on some obfuscated code can't be detected) |
88+
| Param | Abbr | Aggressivity | Description |
89+
| ------------------- | ---- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
90+
| | | VERY AGGRESSIVE | Search for all functions/exploits on lists and all malware signatures without restrictions |
91+
| `--agile` | -a | MEDIUM | Search 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) |
92+
| `--only-signatures` | -s | NORMAL | Search for all malware signatures (could be perfect for Wordpress and others platform for have less false positive) |
93+
| `--only-exploits` | -e | AGGRESSIVE | Search for exploits on lists |
94+
| `--only-functions` | -f | MEDIUM | Search for all functions on lists (on some obfuscated code can't be detected) |
9395

9496
### Suggestions
9597

@@ -106,6 +108,7 @@ You could find some false positive during scanning. For this you can choice the
106108
Then if you run the scanner on a Wordpress project or others common platforms type `--only-signatures` or `--agile` as argument for a check with less false positive.
107109

108110
#### Examples:
111+
109112
```
110113
php -d disable_functions='' scanner -s
111114
php -d disable_functions='' scanner -a
@@ -114,6 +117,7 @@ php -d disable_functions='' scanner -a
114117
## Detection Options
115118

116119
When a malware is detected you will have the following choices (except when scanner is in report scan mode `--report`):
120+
117121
- Delete file
118122
- Move to quarantine `(move to ./quarantine)`
119123
- Try remove evil code
@@ -126,7 +130,7 @@ When a malware is detected you will have the following choices (except when scan
126130

127131
## Usage
128132

129-
```
133+
```
130134
Arguments:
131135
<path> - Define the path to scan (default: current directory)
132136
@@ -153,27 +157,29 @@ Flags:
153157
--list - Get default exploit and functions list
154158
--list-exploits - Get default exploits list
155159
--list-functions - Get default functions lists
156-
157-
Notes:
160+
161+
Notes:
158162
For open files with nano or vim run the scripts with "-d disable_functions=''"
159163
160164
Examples: php -d disable_functions='' scanner ./mywebsite/http/ -l -s --only-exploits
161165
php -d disable_functions='' scanner -s --max-filesize="5MB"
162166
php -d disable_functions='' scanner -s -logs="/user/marco/scanner.log"
163167
php -d disable_functions='' scanner --agile --only-exploits
164168
php -d disable_functions='' scanner --exploits="double_var2" --functions="eval, str_replace"
165-
169+
166170
Usage: php scanner [--agile|-a] [--help|-h] [--log|-l] [--report|-r] [--version|-v] [--update|-u] [--only-signatures|-s] [--only-exploits|-e] [--only-functions|-f] [--list] [--list-exploits] [--list-functions] [--exploits <exploits>] [--functions <functions>] [--whitelist-only-path] [<path>]
167171
```
168172

169173
### Exploits and Functions List
170174

171175
#### Exploits
176+
172177
- `eval_chr`, `eval_preg`, `eval_base64`, `eval_comment`, `eval_execution`, `align`, `b374k`, `weevely3`, `c99_launcher`, `too_many_chr`, `concat`, `concat_vars_with_spaces`, `concat_vars_array`, `var_as_func`, `global_var_string`, `extract_global`, `escaped_path`, `include_icon`, `backdoor_code`, `infected_comment`, `hex_char`, `hacked_by`, `killall`, `globals_concat`, `globals_assign`, `base64_long`, `base64_inclusion`, `clever_include`, `basedir_bypass`, `basedir_bypass2`, `non_printable`, `double_var`, `double_var2`, `global_save`, `hex_var`, `register_function`, `safemode_bypass`, `ioncube_loader`, `nano`, `ninja`, `execution`, `execution2`, `execution3`, `shellshock`, `silenced_eval`, `silence_inclusion`, `ssi_exec`, `htaccess_handler`, `htaccess_type`, `file_prepend`, `iis_com`, `reversed`, `rawurlendcode_rot13`, `serialize_phpversion`, `md5_create_function`, `god_mode`, `wordpress_filter`, `password_protection_md5`, `password_protection_sha`, `custom_math`, `custom_math2`, `uncommon_function`, `download_remote_code`, `download_remote_code2`, `download_remote_code3`, `php_uname`, `etc_passwd`, `etc_shadow`, `explode_chr`
173178

174179
#### Functions
180+
175181
- `il_exec`, `shell_exec`, `eval`, `system`, `create_function`, `exec`, `assert`, `syslog`, `passthru`, `define_syslog_variables`, `posix_kill`, `posix_uname`, `proc_close`, `proc_get_status`, `proc_nice`, `proc_open`, `proc_terminate`, `inject_code`, `apache_child_terminate`, `apache_note`, `define_syslog_variables`
176182

177183
## Screenshots
178184

179-
![Screen 1](screenshots/screenshot_1.png)![Screen 2](screenshots/screenshot_2.png)![Screen 3](screenshots/screenshot_3.png)
185+
![Screen 1](images/screenshot_1.png)![Screen 2](images/screenshot_2.png)![Screen 3](images/screenshot_3.png)

distribute bin/build

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
/**
@@ -8,10 +9,12 @@
89
* @link https://github.com/marcocesarato/PHP-Antimalware-Scanner
910
*/
1011

11-
require __DIR__ . '/vendor/autoload.php';
12+
define('ROOT', dirname(__DIR__));
1213

13-
$input = 'src/scanner';
14-
$output = 'dist/scanner';
14+
require ROOT . '/vendor/autoload.php';
15+
16+
$input = ROOT . '/src/scanner';
17+
$output = ROOT . '/dist/cli/scanner';
1518

1619
$jc = new JuggleCode();
1720
$jc->masterfile = $input;

bin/composer

1.84 MB
Binary file not shown.

bin/fix-cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Running php-cs-fixer to format the code on git diff..."
4+
5+
# Variables
6+
# shellcheck disable=SC2164
7+
CURRENT_DIRECTORY="$(cd "$(dirname "$0")"; pwd -P)"
8+
PROJECT_DIRECTORY="$(dirname "${CURRENT_DIRECTORY}")"
9+
10+
# shellcheck disable=SC2164
11+
cd "${PROJECT_DIRECTORY}";
12+
13+
PHP_CS_FIXER="${PROJECT_DIRECTORY}/vendor/bin/php-cs-fixer"
14+
PHP_CS_CONFIG=".php_cs"
15+
16+
git diff --cached --name-only --diff-filter=ACMR HEAD -- '*.php' | while read line; do
17+
echo " - Fixing: ${line}"
18+
# PHP CS Fixer
19+
php "${CURRENT_DIRECTORY}/run" ${PHP_CS_FIXER} fix --config=${PHP_CS_CONFIG} --verbose ${line};
20+
git add "$line";
21+
done
22+
23+
# shellcheck disable=SC2164
24+
cd "${CURRENT_DIRECTORY}";
25+
echo "[Done] Operation completed!"

bin/fix-cs-all

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Running php-cs-fixer to format the code..."
4+
5+
# Variables
6+
# shellcheck disable=SC2164
7+
CURRENT_DIRECTORY="$(cd "$(dirname "$0")"; pwd -P)"
8+
PROJECT_DIRECTORY="$(dirname "${CURRENT_DIRECTORY}")"
9+
10+
# shellcheck disable=SC2164
11+
cd "${PROJECT_DIRECTORY}";
12+
13+
PHP_CS_FIXER="${PROJECT_DIRECTORY}/vendor/bin/php-cs-fixer"
14+
PHP_CS_CONFIG=".php_cs"
15+
16+
# PHP CS Fixer
17+
php "${CURRENT_DIRECTORY}/run" ${PHP_CS_FIXER} fix --config=${PHP_CS_CONFIG} --verbose;
18+
19+
git add "${PROJECT_DIRECTORY}"
20+
21+
# shellcheck disable=SC2164
22+
cd "${CURRENT_DIRECTORY}";
23+
echo "[Done] Operation completed!"

bin/lint

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# Variables
4+
# shellcheck disable=SC2164
5+
CURRENT_DIRECTORY="$(cd "$(dirname "$0")"; pwd -P)"
6+
PROJECT_DIRECTORY="$(dirname "${CURRENT_DIRECTORY}")"
7+
8+
# shellcheck disable=SC2164
9+
cd "${PROJECT_DIRECTORY}";
10+
11+
echo "Checking PHP Lint..."
12+
13+
if [ -z "$1" ]
14+
then
15+
git diff --cached --name-only --diff-filter=ACMR HEAD -- '*.php' | while read line; do
16+
php -l -d display_errors=1 "${PROJECT_DIRECTORY}/$line"
17+
if [ $? != 0 ]
18+
then
19+
echo "[!] Fix the error before(s) commit."
20+
exit 1
21+
fi
22+
FILES="$FILES $PROJECT_DIRECTORY/$line"
23+
done
24+
else
25+
php -l -d display_errors=1 "${PROJECT_DIRECTORY}/$1"
26+
if [ $? != 0 ]
27+
then
28+
echo "[!] Fix the error before(s) commit."
29+
exit 1
30+
fi
31+
fi
32+
33+
echo "[Done] Operation completed!"

bin/pre-commit

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# Variables
4+
# shellcheck disable=SC2164
5+
CURRENT_DIRECTORY="$(cd "$(dirname "$0")"; pwd -P)"
6+
PROJECT_DIRECTORY="$(dirname "${CURRENT_DIRECTORY}")"
7+
8+
# shellcheck disable=SC2164
9+
cd "${PROJECT_DIRECTORY}";
10+
11+
# Check PHP Lint
12+
sh "$CURRENT_DIRECTORY/lint"
13+
14+
[ $? -eq 0 ] || exit 1
15+
16+
# Run php-cs-fixer
17+
php "$CURRENT_DIRECTORY/composer" fix-cs

bin/run

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
// Set working dir
5+
chdir(dirname(__DIR__));
6+
7+
if (is_console()) {
8+
array_shift($argv);
9+
$file = $argv[0];
10+
if (file_exists($file)) {
11+
// Read shebang
12+
$fopen = fopen($file, 'rb');
13+
$shebang = fgets($fopen);
14+
fclose($fopen);
15+
16+
// Detect runner
17+
$runner = 'sh'; // Default bash
18+
19+
if (strpos($shebang, 'bash') !== false) {
20+
$runner = 'sh';
21+
}
22+
23+
if (strpos($shebang, 'php') !== false) {
24+
$runner = "php -d disable_functions=''";
25+
}
26+
27+
if (strpos($shebang, 'node') !== false) {
28+
$runner = 'npm';
29+
}
30+
31+
if(command_exists($runner)) {
32+
$command = $runner . ' ' . implode(' ', $argv);
33+
// Print command for debug
34+
echo '> ' . $command . PHP_EOL;
35+
36+
// Execute command with verbose
37+
passthru($command);
38+
} else {
39+
echo "[ERROR] > You need to install `$runner` on your environment for run this script!";
40+
}
41+
}
42+
}
43+
44+
/**
45+
* Is console.
46+
*
47+
* @return bool
48+
*/
49+
function is_console()
50+
{
51+
return defined('STDIN') ||
52+
php_sapi_name() === 'cli' ||
53+
(empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && count($_SERVER['argv']) > 0);
54+
}
55+
56+
/**
57+
* Determines if a command exists on the current environment
58+
*
59+
* @param string $command The command to check
60+
* @return bool True if the command has been found ; otherwise, false.
61+
*/
62+
function command_exists($command)
63+
{
64+
$whereIsCommand = (PHP_OS === 'WINNT') ? 'where' : 'which';
65+
66+
$process = proc_open(
67+
"$whereIsCommand $command",
68+
array(
69+
0 => ["pipe", "r"], //STDIN
70+
1 => ["pipe", "w"], //STDOUT
71+
2 => ["pipe", "w"], //STDERR
72+
),
73+
$pipes
74+
);
75+
if ($process !== false) {
76+
$stdout = stream_get_contents($pipes[1]);
77+
$stderr = stream_get_contents($pipes[2]);
78+
fclose($pipes[1]);
79+
fclose($pipes[2]);
80+
proc_close($process);
81+
82+
return $stdout != '';
83+
}
84+
85+
return false;
86+
}

0 commit comments

Comments
 (0)