|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class SuperSakeChecker |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Checks if the supersake file in webroot is protected with htaccess or web.config |
|
9
|
|
|
*/ |
|
10
|
|
|
public function superSakeIsNotProtected() |
|
11
|
|
|
{ |
|
12
|
|
|
if($this->isApache()) { |
|
13
|
|
|
return $this->checkHtAccessProtection(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
if($this->isIIS()) { |
|
17
|
|
|
return $this->checkWebConfigProtection(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
return 'unknown server. please make sure the supersake has no direct access'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return bool|string |
|
25
|
|
|
*/ |
|
26
|
|
View Code Duplication |
protected function checkHtAccessProtection() |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
$file = BASE_PATH . '/.htaccess'; |
|
29
|
|
|
|
|
30
|
|
|
if(!is_file($file) || strpos(file_get_contents($file), '<Files supersake>') !== false) { |
|
31
|
|
|
return 'supersake is not protected in .htaccess'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return false; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return bool|string |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
protected function checkWebConfigProtection() |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$file = BASE_PATH . '/web.config'; |
|
43
|
|
|
|
|
44
|
|
|
if(!is_file($file) || strpos(file_get_contents($file), '<add fileExtension="supersake" allowed="false"/>') !== false) { |
|
45
|
|
|
return 'supersake is not protected in web.config'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Check if the web server is IIS and version greater than the given version. |
|
53
|
|
|
* @return boolean |
|
54
|
|
|
*/ |
|
55
|
|
|
public function isIIS($fromVersion = 7) { |
|
56
|
|
|
if(strpos($this->findWebserver(), 'IIS/') === false) { |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
return substr(strstr($this->findWebserver(), '/'), -3, 1) >= $fromVersion; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
public function isApache() { |
|
66
|
|
|
if(strpos($this->findWebserver(), 'Apache') !== false) { |
|
|
|
|
|
|
67
|
|
|
return true; |
|
68
|
|
|
} else { |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Find the webserver software running on the PHP host. |
|
75
|
|
|
* @return string|boolean Server software or boolean FALSE |
|
76
|
|
|
*/ |
|
77
|
|
|
public function findWebserver() { |
|
|
|
|
|
|
78
|
|
|
// Try finding from SERVER_SIGNATURE or SERVER_SOFTWARE |
|
79
|
|
|
if(!empty($_SERVER['SERVER_SIGNATURE'])) { |
|
80
|
|
|
$webserver = $_SERVER['SERVER_SIGNATURE']; |
|
81
|
|
|
} elseif(!empty($_SERVER['SERVER_SOFTWARE'])) { |
|
82
|
|
|
$webserver = $_SERVER['SERVER_SOFTWARE']; |
|
83
|
|
|
} else { |
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return strip_tags(trim($webserver)); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.