-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSafelity.php
91 lines (79 loc) · 2.09 KB
/
Safelity.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
<?php
/* Safelity is a PHP library that enables more secure coding
* Written by Eldar Marcussen (@Wireghoul) - justanotherhacker.com
*
* Version 0.1 - 2020-09-01
*/
function no_stream($string) {
if (strstr($string, ":") === false) {
return true;
}
return false;
}
function error_safely($message) {
error_log(addslashes($message));
exit();
}
function include_safely($dir, $file) {
$err = "No streams allowed";
if (no_stream($dir)) {
$err = "No such directory: $dir";
if (is_dir($dir)) {
$err = "Unable to include file: $file";
if (basename($file) === $file) {
return include($dir . $file);
}
}
}
error_safely($err);
}
function require_safely($dir, $file) {
return include_safely($dir, $file);
}
function fopen_safely($dir, $file, $perms) {
$err = "No streams allowed";
if (no_stream($dir)) {
$err = "No such directory: $dir";
if (is_dir($dir)) {
$err = "Unable to open file: $file";
if (basename($file) === $file) {
return fopen($file, $perms);
}
}
}
error_safely($err);
}
function file_get_contents_safely($dir, $file) {
$err = "No streams allowed";
if (no_stream($dir)) {
$err = "No such directory: $dir";
if (is_dir($dir)) {
$err = "Unable to open file: $file";
if (basename($file) === $file) {
return file_get_contents($dir . $file);
}
}
}
error_safely($err);
}
function funlink_safely($dir, $file) {
$err = "No streams allowed";
if (no_stream($dir)) {
$err = "No such directory: $dir";
if (is_dir($dir)) {
$err = "Unable to unlink file: $file";
if (basename($file) === $file) {
return unlink($dir . $file);
}
}
}
error_safely($err);
}
function exec_safely($cmd, $args) {
$cmd = escapeshellcmd("$cmd ");
foreach ($args as $arg) {
$cmd.=escapeshellarg($arg )." ";
}
return shell_exec($cmd);
}
?>