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
|
<?php
/**
* Test class for GID
*
* @package PhpSecInfo
* @author Ed Finkler <coj@funkatron.com>
*/
/**
* require the PhpSecInfo_Test_Core class
*/
require_once(PHPSECINFO_BASE_DIR.'/Test/Test_Core.php');
/**
* the minimum "safe" UID that php should be executing as. This can vary,
* but in general 100 seems like a good min.
*
*/
define ('PHPSECINFO_MIN_SAFE_GID', 100);
/**
* Test class for GID
*
* @package PhpSecInfo
*/
class PhpSecInfo_Test_Core_Gid extends PhpSecInfo_Test_Core
{
/**
* This should be a <b>unique</b>, human-readable identifier for this test
*
* @var string
*/
var $test_name = "group_id";
var $recommended_value = PHPSECINFO_MIN_SAFE_GID;
/**
* This test only works under Unix OSes
*
* @return boolean
*/
function isTestable() {
if ($this->osIsWindows()) {
return false;
} elseif ($this->getUnixId() === false) {
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_NOTRUN, 'en', 'Functions required to retrieve group ID not available');
return false;
}
return true;
}
function _retrieveCurrentValue() {
$id = $this->getUnixId();
if (is_array($id)) {
$lowest_gid = key($id['groups']);
$this->current_value = $lowest_gid;
} else {
$this->current_value = false;
}
}
/**
* Checks the GID of the PHP process to make sure it is above PHPSECINFO_MIN_SAFE_GID
*
* @see PHPSECINFO_MIN_SAFE_GID
*/
function _execTest() {
if ($this->current_value >= $this->recommended_value) {
return PHPSECINFO_TEST_RESULT_OK;
}
return PHPSECINFO_TEST_RESULT_WARN;
}
/**
* Set the messages specific to this test
*
*/
function _setMessages() {
parent::_setMessages();
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_OK, 'en', 'PHP is executing as what is probably a non-privileged group');
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_WARN, 'en', 'PHP may be executing as a "privileged" group, which could be a serious security vulnerability.');
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_NOTRUN, 'en', 'This test will not run on Windows OSes');
}
}
|