-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathScanWebShell.pl
More file actions
128 lines (118 loc) · 3.39 KB
/
Copy pathScanWebShell.pl
File metadata and controls
128 lines (118 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/perl
#Scan WebShell for LAKE2
#Desc: A small tools that find webshell with perl, it can check ASP/PHP/JSP/ASP.Net script, enjoy hacking :-)
#Author: lakehu[TSRC]
#Date: 2013-10-30
#Version: 1.1.1
use File::Find;
#php webshell str
@php_code_array = (
'\beval(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bassert(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bsystem(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bpassthru(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bexec(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bpcntl_exec(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bshell_exec(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bpopen(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bproc_open(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bpreg_replace(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bcreate_function(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\bob_start(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'\barray_map(\s|\/\*.*?\*\/)*\(\s*.*?\s*\)',
'`.*?`',
'(include|include_once|require|require_once)(\s|\/\*.*?\*\/)*\(\s*.*?\$.*?\)',
'(include|include_once|require|require_once)(\s|\/\*.*?\*\/)*\(?\s*[\'"].*?\.[^p][^h][^p]\w*?[\'"].*?\s*?;',
'(phpspy|4ngel|wofeiwo|c99shell|webshell|php_nst|reDuh)',
'\$[\w-_\'\\[\\]{}\.\$\*/|]+(\s|\/\*.*?\*\/)*\(.*?\)'
);
@asp_code_array = (
''
);
#asp.net webshell str
@aspx_code_array = (
''
);
#jsp webshell str
@jsp_code_array = (
''
);
if(@ARGV!=2){
print "\n";
print "* Simple Scan WebShell by lake2 [ TSRC ] \n";
print "* know it then hack it !\n";
print "* Usage: ScanWebShell.pl <Path> <Type> \n";
print "* Type: 1 - PHP\n";
print " 2 - ASP\n";
print " 3 - ASP.Net\n";
print " 4 - JSP\n";
print "* TSRC Website: http:\\\\security.tencent.com\n";
exit;
}
my $postfix;
$postfix = '';
my @str_code;
if($ARGV[1]==1)
{
$postfix = '\.php$';push(@str_code, @php_code_array);
}
elsif($ARGV[1]==2)
{
print "NO PUBLIC! Do you used ASPSecurity ?\n";exit;
}
elsif($ARGV[1]==3)
{
print "NO PUBLIC!\n";exit;
}
elsif($ARGV[1]==4)
{
print "NO PUBLIC!\n";exit;
}
else
{
print "ERROR: unkown type !\n";exit;
}
#old Perl is not Switch -_-!! FucK !!!!
#switch($ARGV[1]){
# case 0 { print "get out!\n";exit; }
# case 1 { $postfix = '\.php$';push(@str_code, @php_code_array); }
# case 2 { $postfix = '\.(asp|cdx|cer)$';push(@str_code, @asp_code_array); }
# case 3 { $postfix = '\.aspx$';push(@str_code, @aspx_code_array); }
# case 4 { $postfix = '\.jsp$';push(@str_code, @jsp_code_array); }
# else { print "ERROR: unkown type !\n";exit; }
#}
print "start scanning ..... \n-----------------\n";
$scan_path = $ARGV[0];
if(substr($scan_path, length($scan_path)-1, 1) ne "/"){$scan_path.="/";}
find(\&wanted, $scan_path);
print "----------------\ndone !\n ";
sub wanted {
if (-f $File::Find::name) {
if ($File::Find::name=~/$postfix/i) {
checkfile($File::Find::name);
}
}
}
sub checkfile{
my($filepath) = @_;
my($content);
$content = openfile($filepath);
if($content ne ""){
foreach $item (@str_code){
if($content =~ /$item/is){ # fix bug : ig -> is, \s will contain \r\n
print $filepath." -> ".$&."\n";
}
}
}
}
sub openfile{
my($filepath) = @_;
my(@string);
unless (open (MYFILE, $filepath)) {
print ("[-]ERROR: open file $filepath fail !\n");
return "";
}
@string= <MYFILE>;
close(MYFILE);
return join("", @string);
}