-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcryptophp_removal.php
More file actions
executable file
·257 lines (224 loc) · 8.67 KB
/
Copy pathcryptophp_removal.php
File metadata and controls
executable file
·257 lines (224 loc) · 8.67 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
define('DS',DIRECTORY_SEPARATOR);
session_start();
class ShieldfyCryptoPHPRemoval{
static $checkFiles = array();
static $infectedFiles = array();
static $malwareFiles = array();
static $scriptDuration = 0;
static function scan(){
$time_start = microtime(true);
$rootpath = '.';
$fileinfos = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootpath)
);
foreach($fileinfos as $pathname => $fileinfo) {
if (!$fileinfo->isFile()) continue;
$filetype = pathinfo($pathname, PATHINFO_EXTENSION);
$res = '';
if($filetype == 'php'){
self::$checkFiles[] = '<span class="text-info">checking file:'.$pathname.'</span>';
$res = self::check($pathname);
if(!empty($res)){
self::$checkFiles[] = '<span class="text-danger">found "CryptoPHP" malware in :'.$pathname.' partial infected</span>';
$path = explode(DS,$pathname);
unset($path[count($path) -1]);
$path = implode(DS,$path);
$res = str_replace(array('/','\\'),DS,trim($res[0]," '\""));
$delete_location = $path.DS.$res;
self::$checkFiles[] = '<span class="text-danger">found "CryptoPHP" malware in :'.$delete_location.' full infected</span>';
self::$infectedFiles[] = $pathname;
if(!in_array($delete_location, self::$malwareFiles)){
self::$malwareFiles[] = $delete_location;
}
}
}
}
$time_end = microtime(true);
self::$scriptDuration = $time_end - $time_start;
$_SESSION['sh_cr_cleaner']['infected'] = self::$infectedFiles;
$_SESSION['sh_cr_cleaner']['malware'] = self::$malwareFiles;
unset($fileinfos);
return ;
}
static function fix(){
if(empty($_POST)) exit;
if($_POST['_to'] != $_SESSION['_token']) exit;
$infected = $_SESSION['sh_cr_cleaner']['infected'];
$malware = $_SESSION['sh_cr_cleaner']['malware'];
if(count($infected) > 0){
foreach($infected as $file){
//echo 'bla'.$file;
$file_content = file_get_contents($file);
$pattern = '/(include|include_once|require|require_once)[\s]?\(.*social.*\.png.*\)/isU';
$new_content = preg_replace($pattern,'',$file_content);
$res = file_put_contents($file, $new_content);
if(!$res){
$failed_infected[] = $file;
}
}
}
if(count($malware) > 0){
foreach($malware as $file){
//echo 'bla2'.$file;
$res2 = unlink($file);
if(!$res2){
$failed_malware[] = $file;
}
}
}
if(count($failed_infected) == 0 && count($failed_malware) == 0){
echo 1;
}else{
if(count($failed_infected) > 0){
echo 'failed to fix this file(s) please do it manually <br /> ';
foreach($failed_infected as $file){
echo $file.'<br />';
}
}
if(count($failed_malware) > 0){
echo 'failed to delete this file(s) please do it manually <br />';
foreach($failed_malware as $file){
echo $file.'<br />';
}
}
echo '<br /> if you need help <a href="http://blog.shieldfy.com" target="_blank">read this</a> <br />';
}
}
static function check($file){
$content = file_get_contents($file);
$pattern = '/(include|include_once|require|require_once)[\s]?\((.*)\)/isU';
preg_match_all($pattern,$content,$matches);
$res = array();
if(count($matches[2]) > 0){
foreach($matches[2] as $match){
preg_match('/social(.*)\.png/isU',$match,$match2);
if(!empty($match2[0])){
$res[] = $match;
}
}
}
return $res;
}
}
if(isset($_POST['fix']) && $_POST['fix'] = 'ok'){
ShieldfyCryptoPHPRemoval::fix();
exit;
}
$_token = $_SESSION['_token'] = sha1(md5(time() * mt_rand() * uniqid(mt_rand()))) ;
ShieldfyCryptoPHPRemoval::scan();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CryptoPHP Malware removal | Shieldfy</title>
<!-- Bootstrap -->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
.check_files{
height: 400px;
overflow-y:scroll;
}
.navbar-footer{
margin-top:20px;
margin-bottom: 0;
color:#ffffff;
text-align: center;
padding-top:12px;
}
.navbar-footer a{
color:#ffffff;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<a href="https://github.com/shieldfy/CryptoPHP-malware-removal" target="_blank" class="navbar-brand">Shieldfy | CryptoPHP Malware removal</a>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-sm-6">
<h3>Final Result :- </h3>
<div class="well">
<?php if(count(ShieldfyCryptoPHPRemoval::$infectedFiles) == 0 && count(ShieldfyCryptoPHPRemoval::$malwareFiles) == 0): ?>
<p class="text-success">Congratulations your website is Clean</p>
<p class="text-info"> <?php echo count(ShieldfyCryptoPHPRemoval::$checkFiles) ?> of files scanned in : <?php echo round(ShieldfyCryptoPHPRemoval::$scriptDuration,3) ?> seconds</p>
<?php else: ?>
<p class="text-danger"> Your website infected with CryptoPHP malware</p>
<ul>
<?php foreach(ShieldfyCryptoPHPRemoval::$infectedFiles as $infected): ?>
<li class="text-danger"><?php echo $infected; ?></li>
<?php endforeach; ?>
<?php foreach(ShieldfyCryptoPHPRemoval::$malwareFiles as $malware): ?>
<li class="text-danger"><?php echo $malware; ?></li>
<?php endforeach; ?>
</ul>
<p class="text-info"> <?php echo count(ShieldfyCryptoPHPRemoval::$checkFiles) ?> of files scanned in : <?php echo round(ShieldfyCryptoPHPRemoval::$scriptDuration,3) ?> seconds</p>
<a href="javascript:;" class="btn btn-default btn-fix-malware"><i class="glyphicon glyphicon-wrench"></i> Fix my website </a>
<br />
<div class="are_you_sure text-warning text-warning-for-fix" style="display:none">
<br />
You are about to remove some lines from the following files :<br />
<?php foreach(ShieldfyCryptoPHPRemoval::$infectedFiles as $infected): ?>
<span class="text-danger"> » <?php echo $infected; ?></span><br />
<?php endforeach; ?>
And completely delete this files : <br />
<?php foreach(ShieldfyCryptoPHPRemoval::$malwareFiles as $malware): ?>
<span class="text-danger"> » <?php echo $malware; ?></span><br />
<?php endforeach; ?>
<br />
Are you sure ? <br />
<a href="javascript:;" class="btn btn-success btn-do-fix"> Yes </a>
<a href="javascript:;" class="btn btn-danger"> No i will do it manually </a>
</div>
<div class="loader" style="display:none;">
<img src="http://cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif">
</div>
<div class="alert">
</div>
<?php endif; ?>
</div>
</div>
<div class="col-sm-6">
<h3>Full Log :- </h3>
<div class="check_files">
<?php echo implode('<br />', ShieldfyCryptoPHPRemoval::$checkFiles); ?>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-inverse navbar-footer" role="navigation">
<p>Made with <span class="glyphicon glyphicon-heart"></span> by <a href="http://shieldfy.com" target="_blank">Shieldfy Security Team</a> </p>
</nav>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(function(){
$('.btn-fix-malware').on('click',function(){
$('.text-warning-for-fix').show();
});
$('.btn-do-fix').on('click',function(){
$('.are_you_sure').hide();
$('.loader').show();
$.post('',{fix:'ok',_to:"<?php echo $_token; ?>"},function(data){
$('.loader').hide();
if(data == 1){
$('.alert').addClass('alert-success').html('Congratulations fix success')
}else{
$('.alert').addClass('alert-danger').html(data);
}
});
});
});
</script>
</body>
</html>