-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmalware-scanner.php
701 lines (621 loc) · 35.4 KB
/
malware-scanner.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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
<?php
require("core.php");
head();
if (isset($_POST['save-settings'])) {
$scandir = $_POST['scandir'];
$extensions = $_POST['extensions'];
$ignored = $_POST['ignored'];
$table = $prefix . 'malwarescanner-settings';
$update = $mysqli->query("UPDATE `$table` SET `scan-dir`='$scandir', `file-extensions`='$extensions', `ignored-dirs`='$ignored'");
}
$table = $prefix . 'malwarescanner-settings';
$query = $mysqli->query("SELECT * FROM `$table`");
$srow = mysqli_fetch_array($query);
if (isset($_GET['ignore'])) {
$fileign = $_GET['ignore'];
$ignored = $srow['ignored-dirs'] . "|" . $fileign;
$table = $prefix . 'malwarescanner-settings';
$update = $mysqli->query("UPDATE `$table` SET `ignored-dirs`='$ignored'");
echo '<meta http-equiv="refresh" content="0; url=malware-scanner.php" />';
}
?>
<div class="content-wrapper">
<!--CONTENT CONTAINER-->
<!--===================================================-->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark"><i class="fas fa-search"></i> Malware Scanner</h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="dashboard.php"><i class="fas fa-home"></i> Admin Panel</a></li>
<li class="breadcrumb-item active">Malware Scanner</li>
</ol>
</div>
</div>
</div>
</div>
<!--Page content-->
<!--===================================================-->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card collapsed-card">
<div class="card-header" data-widget="collapse">
<h3 class="card-title">Malware Scanner - Settings</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-widget="collapse">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
<div class="card-body">
<form action="" method="post">
<div class="row form-group">
<div class="col-md-12"><center>
<label>Scan Directory: </label>
<div class="col-sm-12">
<input type="text" name="scandir" class="form-control" value="<?php
echo $srow['scan-dir'];
?>" /><br />
</div>
<label>File Extensions Scanned:</label>
<div class="col-sm-12">
<textarea class="form-control" name="extensions"><?php
echo $srow['file-extensions'];
?></textarea>
(Separate the file extensions with <strong>"|"</strong>)<br /><br />
</div>
<label>Ignored directories and files: </label>
<div class="col-sm-12">
<textarea class="form-control" name="ignored"><?php
echo $srow['ignored-dirs'];
?></textarea>
(Separate the ignored directories and files with <strong>"|"</strong>)<br /><br />
</div>
</div>
</center></div>
</div>
<div class="card-footer">
<input type="submit" name="save-settings" class="btn btn-flat btn-primary" value="Save" />
</div>
</div>
</form>
<div class="card">
<div class="card-header">
<h3 class="card-title">Malware Scanner</h3>
</div>
<div class="card-body">
<div class="col-md-12">
<div class="alert alert-info">
<p>
There is a chance of false-positive results, please analyze the results and verify them. Sometimes the scanning process could take more time according to the files on your host.
</p>
</div>
</div>
<center>
<a href="malware-scanner.php" class="btn btn-flat btn-primary" title="The normal scan scans all files with the simple scan engine"><i class="fas fa-search"></i> Run Normal Scan</a>
<a href="?deep_scan=1" class="btn btn-flat btn-danger" title="The deep scan scans all files with the heaviest scan engine, but could show many false-positive threats."><i class="fas fa-search"></i> Run Deep Scan</a>
</center><br />
<?php
@set_time_limit(360);
ini_set('max_execution_time', 300); //300 Seconds = 5 Minutes
ini_set('memory_limit', '512M');
$fileExt = $srow['file-extensions']; // File extensions
$ignoreDirs = 'phpfunctions-check.php|content-protection.php|password-generator.php|badbots-protection.php|' . $srow['ignored-dirs']; // Directories & Files to ignore
$directory = $srow['scan-dir']; // Directory to scan
$count = 0;
$total_results = 0;
function HumanReadableFilesize($file)
{
$size = filesize($file);
$mod = 1024;
$units = explode(' ', 'B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
@$bdc = 'ba' . 'se' . ((8 + 8 + 8 + 8) * 2) . '_de' . 'co' . 'de';
$stre = 'cjBuaW58bTBydGl4fGlza29ycGl0eHx1cGwwYWR8cjU3c2hlbGx8Yzk5c2hlbGx8c2hlbGxib3R8cGhwc2hlbGx8dm9pZFwucnV8cGhwcmVtb3Rldmlld3xkaXJlY3RtYWlsfGJhc2hfaGlzdG9yeXxjd2luZ3N8dmFuZGFsfGJpdGNoeHxlZ2dkcm9wfGd1YXJkc2VydmljZXN8cHN5Ym5jfGRhbG5ldHx1bmRlcm5ldHx2dWxuc2NhbnxzcHltZXRhfHJhc2xhbjU4fFdlYnNoZWxsfHN0cl9yb3QxM3xGaWxlc01hbnxGaWxlc1Rvb2xzfFdlYiBTaGVsbHxpZnJtfGJja2RycHJtfGhhY2ttZXBsenx3cmdnZ3RoaGR8V1NPc2V0Y29va2llfEhtZWk3fEluYm94IE1hc3MgTWFpbGVyfEhhY2tUZWFtfEhhY2tlYWRvfEphbmlzc2FyaWVzfE1peWFjaHVuZ3xjY3RlYW18QWRtaW5lcnxPT08wMDAwMDB8JEdMT0JBTFN8ZmluZHN5c2ZvbGRlcnxtYWtlcmV0LnJ1fGMwZDNkIGJ5fEMwZGUgRm9yfFBlcmwgQXV0byBSb290ZXIgUGVybCBTY3JpcHR8Y3VybF9tdWx0aV9leGVjfGNyZWF0ZV9mdW5jdGlvbnxiMzc0a3xXZWIgU2hlbGwgYnkgYm9mZnxXZWIgU2hlbGwgYnkgb1JifGRldmlselNoZWxs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hdGV8Z3p1bmNvbXByZXNzfGd6Y29tcHJlc3N8cmVhZGd6ZmlsZXx6bGliX2RlY29kZXx6bGliX2VuY29kZXxnemZpbGV8Z3pnZXR8Z3pwYXNzdGhydXxpZnJhbWV8c3RycmV2fGx6d19kZWNvbXByZXNzfHBhc3N0aHJ1fHNoZWxsX2V4ZWN8cHJvY198cG9wZW58cHJvY19vcGVufGJydXRlZm9yY2V8YnJ1dGUgZm9yY2V8ZWRvY2VkXzQ2ZXNhYnxwYXJzZV9pbmlfZmlsZXxkaXNwbGF5Om5vbmV8ZGlzcGxheT1ub25lfGRpc3BsYXk9XCdub25lXCc=';
$Strings = $bdc($stre);
$DeepScanStrings = $bdc($dstre);
$Patterns = array(
array(
'preg_replace\s*\(\s*[\"\']\s*(\W)(?-s).*\1[imsxADSUXJu\s]*e[imsxADSUXJu\s]*[\"\'].*\)', // [0] = RegEx search pattern
'PHP: preg_replace Eval', // [1] = Name / Title
'Detected preg_replace function that evaluates (executes) matched code. ' . 'This means if PHP code is passed it will be executed.', // [2] = description
'Part example code from http://sucuri.net/malware/backdoor-phppreg_replaceeval'
), // [3] = More Information link
array(
'c999*sh_surl',
'Backdoor: PHP:C99',
'Detected the "C99 Shell"? Backdoor that allows attackers to manage (and ' . 'reinfect) your website remotely. It is often used as part of a ' . 'compromise to maintain access to the hacked sites.',
'http://sucuri.net/malware/backdoor-phpc99045'
),
array(
'preg_match\s*\(\s*\"\s*/\s*bot\s*/\s*\"',
'Backdoor: PHP:R57',
'Detected the "R57 Shell"? Backdoor that allows attackers to access, modify and ' . 'reinfect your site. It is often hidden in the filesystem and hard to ' . 'find without access to the server or logs.',
'http://sucuri.net/malware/backdoor-phpr5701'
),
array(
'eval[\s/\*\#]*\(stripslashes[\s/\*\#]*\([\s/\*\#]*\$_(REQUEST|POST|GET)\s*\[\s*\\\s*[\'\"]\s*asc\s*\\\s*[\'\"]',
'Backdoor: PHP:GENERIC',
'Detected a generic backdoor that allows attackers to upload files, delete ' . 'files, access, modify and/or reinfect your site. It is often hidden ' . 'in the filesystem and hard to find without access to the server or ' . 'logs. It also includes uploadify scripts and similars that offer ' . 'upload options without security. ',
'http://sucuri.net/malware/backdoor-phpgeneric07'
),
/*array('https?\S{1,63}\.ru',
'Russian URL',
'Detected a .RU domain link, as there are many attacks leading the innocent visitors to .RU pages. Maybe it\'s valid link, but leave it to you to check this out.',
),*/
array(
'preg_replace\s*\(\s*[\"\'\”]\s*/\s*\.\s*\*\s*/\s*e\s*[\"\'\”]\s*,\s*[\"\'\”]\s*\\x65\\x76\\x61\\x6c',
'Backdoor: PHP:Filesman:02',
'Detected the “Filesman Shell”? Backdoor that allows attackers to access, modify ' . 'and reinfect your site. It is often hidden in the filesystem and hard ' . 'to find without access to the server or logs.',
'http://sucuri.net/malware/backdoor-phpfilesman02'
),
array(
'(include|require)(_once)*\s*[\"\'][\w\W\s/\*]*php://input[\w\W\s/\*]*[\"\']',
'PHP:\input include',
'Detected the method of reading input through PHP protocol handler in ' . 'include/require statements.'
),
array(
'data:;base64',
'data:;base64 include',
'Detected the method of executing base64 data in include.'
),
array(
'RewriteCond\s*%\{HTTP_REFERER\}',
'.HTACCESS RewriteCond-Referer',
'Your .htaccess file has a conditional redirection based on "HTTP Referer".' . 'This means it redirects according to site/url from where your visitors ' . 'came to your site. Such technique has been used for unwanted redirections ' . 'after coming from Google or other search engines, so check this directive carefully.'
),
array(
'jquery.min.php',
'Fake jQuery Malware',
'This file is infected with the Fake jQuery Malware. Removing the malware is not enough. Make sure your CMS and all its third-party components are up-to-date. All unused stuff should be ruthlessly deleted from server. Some of the compromised websites had malicious WordPress admin users with names like: backup, dpr19, loginfelix. Some of them had been created during past attacks though.'
),
array(
'GIF89a.*[\r\n]*.*<\?php',
'PHP file desguised as GIF image',
'Detected a PHP file that was most probably uploaded as an image via webform that loosely only checks file headers.'
),
array(
'\$ip[\w\W\s/\*]*=[\w\W\s/\*]*getenv\(["\']REMOTE_ADDR["\']\);[\w\W\s/\*]*[\r\n]\$message',
'Probably malicious PHP script that "calls home"',
'Detected script variations often used to inform the attackers about found vulnerable website.'
),
array(
'(?:(?:base64_decode|str_rot13)[\s\/\*\w\W\(]*){2,};',
'Multiple encoded, most probably obfuscated code found',
'This pattern could be used in highly encoded, malicious code hidden under ' . 'a loop of code obfuscation function calls. In most cases the decoded ' . 'hacker code goes through an eval call to execute it. This pattern is ' . 'also often used for legitimate purposes, e.g. storing configuration ' . 'information or serialised object data. '
),
array(
'<\s*iframe',
'IFRAME Element',
'Found IFRAME element in code. It\'s mostly benevolent, but often used ' . 'for bad stuff, so please check if it\'s a valid code.'
),
array(
'strrev[\s/\*\#]*\([\s/\*\#]*[\'"]\s*tressa\s*[\'"]\s*\)',
'Reversed string "assert"',
'Assert function name is being hidden behind strrev().'
),
array(
'is_writable[\s/\*\#]*\([\s/\*\#]*getcwd',
'Is the current DIR Writable?',
'This could be harmless, but used in some malware'
),
/*array('(?:\\\\x[0-9A-Fa-f]{1,2}|\\\\[0-7]{1,3}){2,}',
'At least two characters in hexadecimal or octal notation',
'Found at least two characters in hexadecimal or octal notation. It '
. 'doesn\'t mean it is malicious, but it could be code hidding behind '
. 'such notation.'),*/
array(
'\$_F\s*=\s*__FILE__\s*;\s*\$_X\s*=',
'SourceCop encoded code',
'Found the SourceCop encoded code. It is often used for malicious code
hidding, so go and check the code with some online SourceCop decoders'
),
array(
'(?:passthru|shell_exec|proc_|popen)[\w\W\s/\*]*\([\s/\*\#\'\"\w\W\-\_]*(?:\$_GET|\$_POST|\$_REQUEST)',
'Shell command execution from POST/GET variables',
'Found direct shell command execution getting variables from POST/GET,
which is highly dangerous security flaw or a part of malicious webrootkit'
),
/*array('\$\w[\w\W\s/\*]*=[\w\W\s/\*]*`.*`',
'PHP execution operator: backticks (``)',
'PHP execution operator found. Note that these are not single-quotes!
PHP will attempt to execute the contents of the backticks as a shell
command, which might indicate a part of a web rootkit'),*/
array(
'fsockopen\s*\(\s*[ \'\"](?:localhost|127\.0\.0\.1)[ \'\"]',
'Opening socket to localhost',
'Found code opening socket to localhost, it\'s worth investigating more'
),
array(
'fsockopen\s*\(.*,\s*[ \'\"](?:25|587|465|475|2525)[ \'\"]',
'Opening socket to known SMTP ports, possible SPAM script',
'Found opening socket to known SMTP ports, possible SPAM script'
),
array(
'(?:readfile|popen)\s*\(\s*[ \'\"]*\s*(?:file|http[s]*|ftp[s]*|php|zlib|data|glob|phar|ssh2|rar|ogg|expect|\$POST|\$GET|\$REQUEST)',
'Reading streams or superglobal variables with fopen wrappers present',
'Found functions reading data from streams/wrappers - please analyze the code'
),
array(
'array_(?:diff_ukey|diff_uassoc|intersect_uassoc|udiff_uassoc|udiff_assoc|uintersect_assoc|uintersect_uassoc)\s*\(.*(?:\$_REQUEST|\$_POST|\$_GET).*;',
'Callback function comming from REQUEST/POST/GET variable possible',
'Found possible local execution enabling-script receiving data from POST or GET requests'
),
/*array(
'^(((.*)(=|;)(\s*)?)|((@|\s)*))extract\s*\(',
'Extract Function',
'PHP extract function found. Extract creates variables from an array (eg $_POST, $_GET or $_REQUEST). It can be legit, but if there is some strange code execution like $extracted_variable_1($extracted_variable_2) it should be malicious.'
),*/
array(
'^(((.*)(=|;)(\s*)?)|((@|\s)*))(include|require)(_once)?\s*\(?("|\')https?://',
'Remote Include',
'Include or require which includes a remote file. It should be malicious, and vulnerable as card card-body bg-light.'
),
array(
'\\\\x([abcdef0-9]{2}){3,}',
'Hex Encoded String',
'Code which is hex encoded. It can be legit, but not a usual thing. Malicious users can hide their functions in hex encoded expressions.'
)
);
$FileNames = array(
'Probably an OpenFlashChart library demo file that has known input ' . 'validation error (CVE-2009-4140)' => 'ofc_upload_image.php',
'Probably an R57 shell' => 'r57.php',
'Probably a C99 shell' => 'c99.php',
'Probably a C100 shell' => 'c100.php',
'PhpInfo() file? It is advisable to remove such file, as it could reveal too
much info to potential attackers' => 'phpinfo.php',
'PerlInfo() file? It is advisable to remove such file, as it could reveal too
much info to potential attackers' => 'perlinfo.php'
);
// check if DeepScan should be done
if (isset($_GET['deep_scan'])) {
$patterns = array_merge($Patterns, explode('|', $Strings), explode('|', $DeepScanStrings));
} else {
$patterns = array_merge($Patterns, explode('|', $Strings));
}
$ext = explode('|', $fileExt);
function get_filelist($dir)
{
global $ignoreDirs;
$ignoreArr = explode('|', $ignoreDirs);
$path = '../../';
$toResolve = array(
$dir
);
while ($toResolve) {
$thisDir = array_pop($toResolve);
if (@$dirContent = scandir($thisDir)) {
foreach ($dirContent As $content) {
if (!in_array($content, $ignoreArr)) {
$thisFile = "$thisDir/$content";
if (is_file(@$thisFile)) {
scan_file($thisFile);
} else {
$toResolve[] = $thisFile;
}
}
}
}
}
}
function scan_file($path)
{
global $ext, $patterns, $count, $total_results, $FileNames;
$dateformat = "d F Y - H:i:s ";
if (in_array(pathinfo($path, PATHINFO_EXTENSION), $ext) && filesize($path) && !stripos($path, 'malware-scanner.php')) {
if ($malic_file_descr = array_search(pathinfo($path, PATHINFO_BASENAME), $FileNames)) {
echo '<tr>
<td>' . basename($path) . '</td>
<td>Suspicious FileName</td>
<td> - </td>
<td>' . substr(sprintf('%o', fileperms($path)), -4) . '</td>
<td>' . date($dateformat, filemtime($path)) . '</td>
<td><a href="' . $path . '" target="_blank" class="btn btn-flat btn-primary"><i class="fas fa-folder-open"></i> Open</a>
<button data-target="#details-' . pathinfo($path, PATHINFO_FILENAME) . '" data-toggle="modal" class="btn btn-flat btn-success"><i class="fas fa-file-alt"></i> Details</button>
<a href="?ignore=' . basename($path) . '" class="btn btn-flat btn-danger"><i class="fas fa-ban"></i> Ignore</a></td>
<div class="modal fade" id="details-' . pathinfo($path, PATHINFO_FILENAME) . '" role="dialog" tabindex="-1" aria-labelledby="details-' . pathinfo($path, PATHINFO_FILENAME) . '" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Details</h5>
<button data-dismiss="modal" class="close" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label"><i class="fas fa-file-alt"></i> File Name: </label>
<div class="col-sm-12">
<input type="text" name="name" class="form-control" value="' . basename($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-flag"></i> Path:</label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . $path . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-lock"></i> Permission: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . substr(sprintf('%o', fileperms($path)), -4) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-key"></i> Last Accessed: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . date($dateformat, fileatime($path)) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-edit"></i> Last Modified: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . date($dateformat, filemtime($path)) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-folder"></i> File Size: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . HumanReadableFilesize($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-cog"></i> MD5 Hash: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . md5_file($path) . '" readonly /><br />
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-flat btn-primary" type="button">Close</button>
</div>
</div>
</div>
</div>
</tr>';
}
if (!($content = file_get_contents($path))) {
$error = 'Could not check ' . $path;
} else {
foreach ($patterns As $pattern) {
if (is_array($pattern)) {
preg_match_all('#' . $pattern[0] . '#isS', $content, $found, PREG_OFFSET_CAPTURE);
} else {
preg_match_all('#' . $pattern . '#isS', $content, $found, PREG_OFFSET_CAPTURE);
}
$all_results = $found[0];
$results_count = count($all_results);
$total_results += $results_count;
if (!empty($all_results)) {
$count++;
if (is_array($pattern)) {
echo '<tr>
<td>' . basename($path) . '</td>
<td><font color="red"><i>' . $pattern[1] . '</i></font></td>
<td>' . $results_count . '</td>
<td>' . substr(sprintf('%o', fileperms($path)), -4) . '</td>
<td>' . date($dateformat, filemtime($path)) . '</td>
<td><a href="' . $path . '" target="_blank" class="btn btn-flat btn-primary"><i class="fas fa-folder-open"></i> Open</a>
<button data-target="#details-' . $count . '" data-toggle="modal" class="btn btn-flat btn-success"><i class="fas fa-file-alt"></i> Details</button>
<a href="?ignore=' . basename($path) . '" class="btn btn-flat btn-danger"><i class="fas fa-ban"></i> Ignore</a></td>
<div id="" class="zoom-anim-dialog modal-block modal-header-color modal-block-danger mfp-hide">
<div class="modal fade" id="details-' . $count . '" role="dialog" tabindex="-1" aria-labelledby="details-' . $count . '" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Details</h5>
<button data-dismiss="modal" class="close" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label"><i class="fas fa-file-alt"></i> File Name: </label>
<div class="col-sm-12">
<input type="text" name="name" class="form-control" value="' . basename($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-flag"></i> Path:</label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . $path . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-lock"></i> Permission: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . substr(sprintf('%o', fileperms($path)), -4) . '" readonly />
';
$permissions = substr(sprintf('%o', fileperms($path)), -4);
if (intval($permissions) == 777) {
$permissions = '<font color="orange">(Please note: The file have full access permissions)</font><br /><br />';
} else {
echo '<br />';
}
echo '
</div>
<label class="control-label"><i class="fas fa-key"></i> Last Accessed: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . date($dateformat, fileatime($path)) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-edit"></i> Last Modified: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . date($dateformat, filemtime($path)) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-folder"></i> File Size: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . HumanReadableFilesize($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-cog"></i> MD5 Hash: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . md5_file($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-folder"></i> Threat Description: </label>
<div class="col-sm-12">
<textarea type="text" class="form-control" rows="7" readonly />' . $pattern[2] . '</textarea><br />
</div>
';
foreach ($all_results as $match) {
echo '<span class="offset">Line #: ', calculate_line_number($match[1], $content), '</span>', "<code>... " . htmlentities(substr($content, $match[1], 200), ENT_QUOTES) . " ...</code>\n";
}
echo '
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-flat btn-primary" type="button">Close</button>
</div>
</div>
</div>
</div>
';
} else {
echo '<tr>
<td>' . basename($path) . '</td>
<td><font color="red"><i>' . $pattern . '</i></font></td>
<td>' . $results_count . '</td>
<td>' . substr(sprintf('%o', fileperms($path)), -4) . '</td>
<td>' . date($dateformat, filemtime($path)) . '</td>
<td><a href="' . $path . '" target="_blank" class="btn btn-flat btn-primary"><i class="fas fa-folder-open"></i> Open</a>
<button data-target="#details-' . $count . '" data-toggle="modal" class="btn btn-flat btn-success"><i class="fas fa-file-alt"></i> Details</button>
<a href="?ignore=' . basename($path) . '" class="btn btn-flat btn-danger"><i class="fas fa-ban"></i> Ignore</a></td>
<div id="" class="zoom-anim-dialog modal-block modal-header-color modal-block-danger mfp-hide">
<div class="modal fade" id="details-' . $count . '" role="dialog" tabindex="-1" aria-labelledby="details-' . $count . '" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Details</h5>
<button data-dismiss="modal" class="close" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label"><i class="fas fa-file-alt"></i> File Name: </label>
<div class="col-sm-12">
<input type="text" name="name" class="form-control" value="' . basename($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-flag"></i> Path:</label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . $path . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-lock"></i> Permission: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . substr(sprintf('%o', fileperms($path)), -4) . '" readonly />
';
$permissions = substr(sprintf('%o', fileperms($path)), -4);
if (intval($permissions) == 777) {
$permissions = '<font color="orange">(Please note: The file have full access permissions)</font><br /><br />';
} else {
echo '<br />';
}
echo '
</div>
<label class="control-label"><i class="fas fa-key"></i> Last Accessed: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . date($dateformat, fileatime($path)) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-edit"></i> Last Modified: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . date($dateformat, filemtime($path)) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-folder"></i> File Size: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . HumanReadableFilesize($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-cog"></i> MD5 Hash: </label>
<div class="col-sm-12">
<input type="text" class="form-control" value="' . md5_file($path) . '" readonly /><br />
</div>
<label class="control-label"><i class="fas fa-folder"></i> Threat Description: </label>
<div class="col-sm-12">
<textarea type="text" class="form-control" rows="7" readonly />Suspicious string used: ' . $pattern . '</textarea><br />
</div>
';
foreach ($all_results as $match) {
echo '<br /><span class="offset">Line #: ', calculate_line_number($match[1], $content), '</span>', "<pre><code>... " . htmlentities(substr($content, $match[1], 200), ENT_QUOTES) . " ...</code></pre>\n";
}
echo '
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-flat btn-primary" type="button">Close</button>
</div>
</div>
</div>
</div>
';
}
echo '
</tr>
';
}
}
unset($content);
}
}
}
function calculate_line_number($offset, $file_content)
{
@list($first_part) = str_split($file_content, $offset);
$line_nr = strlen($first_part) - strlen(str_replace("\n", "", $first_part)) + 1;
return $line_nr;
}
?>
<table id="dt-basic" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Infected File</th>
<th>Malware Type</th>
<th>Occurences</th>
<th>File Permissions</th>
<th>Last Modified</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$before = microtime(true);
get_filelist($directory);
?>
</tbody>
</table><br />
<?php
$after = microtime(true);
$totaltime = mb_substr(($after - $before), 0, 4);
echo 'The scan found <strong>', $total_results, ' suspicious malware code spots</strong> in <u>', $count, ' different files</u>!<br/>';
echo 'Scanning time was <strong>' . $totaltime . ' seconds</strong> <br>';
?>
</div>
</div>
</div>
</div>
</div>
</div>
<!--===================================================-->
<!--End page content-->
</div>
<!--===================================================-->
<!--END CONTENT CONTAINER-->
</div>
<script>
$(document).ready(function() {
$('#dt-basic').dataTable( {
"responsive": true,
"language": {
"paginate": {
"previous": '<i class="fas fa-angle-left"></i>',
"next": '<i class="fas fa-angle-right"></i>'
}
}
} );
} );
</script>
<?php
footer();
?>