-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxshell.php
142 lines (120 loc) · 2.56 KB
/
xshell.php
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
error_reporting(E_ALL);
/********************************************
*** @author:NetCode eslam@netcode.me *******
*** @website:netcode.me ********************
*******************************************/
class xShellMe {
public $checkTypes = array('php','php3','php4','asp','aspx','sh','py');
private $_pattern = '%(passthru|shell_exec|exec|base64_decode|eval|system|proc_open|popen|curl_exec|curl_multi_exec|parse_ini_file|show_source)%'; //system: regex for detect Suspicious behavior
/* TODO: seperate patterns to levels so you can check files and define infecttion level
private $_pattern_level = array(
'1'=> '', // high risk
'2'=>'', // medium risk
'3'=>'' // low risk
);
*/
private $result = array();
/*
*
*/
function __construct() {
//set time limit
//no timeout
set_time_limit(0);
//and set proper permissions
}
/*
*
*/
function start($current = './'){
echo '<h2>Result</h2>';
$this->goDeep($current);
echo '<hr />';
echo '<h2>Details:</h2>';
echo '<pre>';print_r($this->result);echo '</pre>';
}
/*
*
*/
function goDeep($folder){
$contents = scandir($folder);
foreach($contents as $content){
if($content == '.' || $content == '..'){
continue;
}elseif(is_dir($folder.$content)){
$this->goDeep($folder.$content.'/');
}else{
if($content == 'xshell.php' && $folder == './'){ //must recheck
continue;
}
if($this->check($folder.$content)){
echo '<p style="color:red;"> Found Shell: '.$folder.$content.'</p>';
}else{
//echo '<p style="color:green;"> Good: '.$folder.$content.'</p>';
}
}
}
}
/*
*
*/
private function check($file){
//get extention
//$ext = $file;
$ext = substr(strrchr($file, "."), 1);
if(in_array($ext, $this->checkTypes)){
//first check signatures
//$this->checkSignatures($file);
//first check patterns
return $this->checkPatterns($file);
}
}
/*
*
*/
private function checkSignatures($file){
}
/*
*
*/
private function checkPatterns($file){
//echo $file;
$content = file_get_contents($file);
//echo $content;
if(preg_match_all($this->_pattern, $content, $matches)) {
$this->result[$file] = $matches[0];
return true;
}else{
return false;
}
}
/*
*
*/
private function action_move(){
}
/*
*
*/
private function action_delete(){
}
/*
*
*/
private function action_onlineCheck(){
}
/*
*
*/
private function _log(){
}
/*
*
*/
public function update(){
}
}
$xshell = new xShellMe();
$xshell->start();
?>