|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -scanPath="" |
4 | | -if [ -n "$1" ]; then |
5 | | - scanPath="$1" |
6 | | - if [ ! -d "$scanPath" ]; then |
7 | | - echo "Scan path does not exist." |
8 | | - exit 1 |
9 | | - fi |
10 | | -else |
11 | | - echo "Scan path cannot be empty." |
12 | | - exit 1 |
13 | | -fi |
| 3 | +VER="0.0.2" |
14 | 4 |
|
15 | | -telegramEnable=true |
| 5 | +scanPath="" |
| 6 | +telegramEnable=false |
16 | 7 | telegramBotToken="" |
17 | | -if [ -n "$2" ]; then |
18 | | - telegramBotToken="$2" |
19 | | -else |
20 | | - telegramEnable=false |
21 | | -fi |
22 | | - |
23 | 8 | telegramChatId="" |
24 | | -if [ -n "$3" ]; then |
25 | | - telegramChatId="$3" |
26 | | -else |
27 | | - telegramEnable=false |
28 | | -fi |
29 | | - |
30 | 9 | hostNameType="" |
31 | | -if [ -n "$4" ]; then |
32 | | - hostNameType="$4" |
33 | | -else |
34 | | - hostNameType=$(hostname ) |
35 | | -fi |
| 10 | +logfilepath="" |
36 | 11 |
|
37 | | -if [ "$telegramEnable" = true ]; then |
| 12 | +while getopts "p:t:c:n:l:h" arg; do |
| 13 | + case $arg in |
| 14 | + h) |
| 15 | + echo "WebShellQuickScanner Help Information" |
| 16 | + echo "" |
| 17 | + echo "-p <PATH> Scan Path." |
| 18 | + echo "-t <Telegram Bot Token> Telegram Bot Token." |
| 19 | + echo "-t <Telegram Chat id> Telegram Chat id." |
| 20 | + echo "-n <HostName> Customize HostName." |
| 21 | + echo "-l <PATH> Log file save path(Do not be end with '/')." |
| 22 | + echo "" |
| 23 | + echo "" |
| 24 | + echo "WebShellQuickScanner - Ver: $VER" |
| 25 | + echo "Made by DeepSkyFire" |
| 26 | + echo "https://github.com/DeepSkyFire/WebShellQuickScanner" |
| 27 | + exit 1 |
| 28 | + ;; |
| 29 | + p) |
| 30 | + if [ -n "$OPTARG" ]; then |
| 31 | + scanPath=$OPTARG |
| 32 | + if [ ! -d "$scanPath" ]; then |
| 33 | + echo "Scan path does not exist." |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + else |
| 37 | + echo "Scan path cannot be empty." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + ;; |
| 41 | + t) |
| 42 | + if [ -n "$OPTARG" ]; then |
| 43 | + telegramBotToken="$OPTARG" |
| 44 | + fi |
| 45 | + ;; |
| 46 | + c) |
| 47 | + if [ -n "$OPTARG" ]; then |
| 48 | + telegramChatId="$OPTARG" |
| 49 | + fi |
| 50 | + ;; |
| 51 | + n) |
| 52 | + if [ -n "$OPTARG" ]; then |
| 53 | + hostNameType="$OPTARG" |
| 54 | + fi |
| 55 | + ;; |
| 56 | + l) |
| 57 | + if [ -n "$OPTARG" ]; then |
| 58 | + logfilepath="$OPTARG" |
| 59 | + if [ ! -d "$logfilepath" ]; then |
| 60 | + echo "Log file save path does not exist." |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + fi |
| 64 | + ;; |
| 65 | + ?) |
| 66 | + echo "Invalid parameter. You can using '-h' to check help information." |
| 67 | + exit 1 |
| 68 | + ;; |
| 69 | + esac |
| 70 | +done |
| 71 | + |
| 72 | +if [[ -n $telegramBotToken ]] && [[ -n $telegramChatId ]]; then |
| 73 | + telegramEnable=true |
38 | 74 | if [ ! -f /usr/bin/curl ]; then |
39 | 75 | echo "You should be install cURL first. Please use 'apt install curl' or 'yum install curl'." |
40 | 76 | exit 1 |
41 | 77 | fi |
| 78 | + if [ ! -n $hostNameType ]; then |
| 79 | + hostNameType=$(hostname ) |
| 80 | + fi |
| 81 | +fi |
| 82 | + |
| 83 | +if [ ! -n $logfilepath ]; then |
| 84 | + logfilepath="/dev/null" |
| 85 | +else |
| 86 | + logfilepath="$logfilepath/WebShellScanner_ScanLog_$(date +%Y-%m-%d.%T).txt" |
42 | 87 | fi |
43 | 88 |
|
44 | 89 | scanResult=$(find $scanPath -name "*.php" |xargs egrep -n 'assert|phpspy|c99sh|milw0rm|eval|\(gunerpress|\(base64_decoolcode|spider_bc|shell_exec|passthru|\(\$\_\POST\[|eval \(str_rot13|\.chr\(|\$\{\"\_P|eval\(\$\_R|file_put_contents\(\.\*\$\_|base64_decode') |
45 | 90 |
|
46 | 91 | scanResultTempFile="/tmp/temp_WebShellScanner_ScanResult.txt" |
47 | 92 |
|
48 | 93 | echo "$scanResult" >> $scanResultTempFile |
| 94 | +echo "$scanResult" >> $logfilepath |
49 | 95 |
|
50 | 96 | scanResultTempFileSize=$(ls -l $scanResultTempFile | awk '{ print $5 }' ) |
51 | 97 |
|
|
0 commit comments