forked from nil0x42/phpsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPerms.php
More file actions
128 lines (116 loc) · 3.61 KB
/
Copy pathgetPerms.php
File metadata and controls
128 lines (116 loc) · 3.61 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
<?
// getPerms($abspath, $perms_type) (type => string):
// Returns the `human permissions string` of the given
// file path.
//
// $perms_type (string) (default="unix")
// - If $perms_type is "unix", then a full permissions
// string like '-rwxr-xr-x' is returned.
// - Otherwise, the returned string will be related to
// current access of the file for user, in the following
// format: 'drwx'. This format tells if we actually can
// read/write/execute the file, by stupidly testing
// accesses.
//
// $abspath (string):
// This variable should be an existing absolute file path
!import(can_change_mtime)
!import(fileAccess)
!import(dirAccess)
function getPerms($abspath, $perms_format="unix")
{
global $PHPSPLOIT;
$perms = @fileperms($abspath);
// FILE TYPES:
// s: socket
// -: regular file
// b: special file
// d: directory
// c: special char
// p: fifo pipe
// u: unknown type
if (($perms & 0xC000) == 0xC000)
$type = 's';
elseif (($perms & 0xA000) == 0xA000)
$type = 'l';
elseif (($perms & 0x8000) == 0x8000)
$type = '-';
elseif (($perms & 0x6000) == 0x6000)
$type = 'b';
elseif (($perms & 0x4000) == 0x4000)
$type = 'd';
elseif (($perms & 0x2000) == 0x2000)
$type = 'c';
elseif (($perms & 0x1000) == 0x1000)
$type = 'p';
else
$type = 'u';
if ((substr($abspath, -3) == $PHPSPLOIT['PATH_SEP'] . '..') ||
(substr($abspath, -2) == $PHPSPLOIT['PATH_SEP'] . '.'))
$type = 'd';
if ($perms_format == 'unix'){
$info = "";
// myself
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// my group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// others
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));}
else
{
$Rperm = (($perms & 0x0004) ? 'r' : '-');
$Wperm = (($perms & 0x0002) ? 'w' : '-');
$Xperm = (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
if ($type == '-')
{
if (fileAccess($abspath, 'r'))
$Rperm = 'r';
else
$Rperm = '-';
if (can_change_mtime($abspath))
{
if (fileAccess($abspath, 'w'))
$Wperm = 'w';
else
$Wperm = '-';
}
}
elseif ($type == 'd')
{
if (dirAccess($abspath, 'r'))
{
$Rperm = 'r';
$Xperm = 'x';
}
else
{
$Rperm = '-';
$Xperm = '-';
}
if (can_change_mtime($abspath))
{
if (dirAccess($abspath, 'w'))
$Wperm = 'w';
else
$Wperm = '-';
}
}
$info = $Rperm . $Wperm . $Xperm;
}
return ($type . $info);
}
?>