Skip to content

Commit 2fdfbce

Browse files
committed
change to use getopts and add log save setting
1 parent d8a23b3 commit 2fdfbce

1 file changed

Lines changed: 76 additions & 30 deletions

File tree

src/WebShellScanner.sh

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,97 @@
11
#!/bin/bash
22

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"
144

15-
telegramEnable=true
5+
scanPath=""
6+
telegramEnable=false
167
telegramBotToken=""
17-
if [ -n "$2" ]; then
18-
telegramBotToken="$2"
19-
else
20-
telegramEnable=false
21-
fi
22-
238
telegramChatId=""
24-
if [ -n "$3" ]; then
25-
telegramChatId="$3"
26-
else
27-
telegramEnable=false
28-
fi
29-
309
hostNameType=""
31-
if [ -n "$4" ]; then
32-
hostNameType="$4"
33-
else
34-
hostNameType=$(hostname )
35-
fi
10+
logfilepath=""
3611

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
3874
if [ ! -f /usr/bin/curl ]; then
3975
echo "You should be install cURL first. Please use 'apt install curl' or 'yum install curl'."
4076
exit 1
4177
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"
4287
fi
4388

4489
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')
4590

4691
scanResultTempFile="/tmp/temp_WebShellScanner_ScanResult.txt"
4792

4893
echo "$scanResult" >> $scanResultTempFile
94+
echo "$scanResult" >> $logfilepath
4995

5096
scanResultTempFileSize=$(ls -l $scanResultTempFile | awk '{ print $5 }' )
5197

0 commit comments

Comments
 (0)