Class: Rex::Post::FileStat
- Inherits:
-
Object
- Object
- Rex::Post::FileStat
show all
- Defined in:
- lib/rex/post/file_stat.rb
Overview
This class emulates the ruby FileStat class against a remote entity in a generic fashion. Refer to the ruby documentation for expected behavior.
Constant Summary
collapse
- @@ftypes =
[
'fifo', 'characterSpecial', 'directory',
'blockSpecial', 'file', 'link', 'socket'
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(buf = '') ⇒ FileStat
Returns a new instance of FileStat.
30
31
32
33
|
# File 'lib/rex/post/file_stat.rb', line 30
def initialize(buf='')
self.stathash = {}
update(buf) if (buf and not buf.empty?)
end
|
Instance Attribute Details
#stathash ⇒ Object
Returns the value of attribute stathash.
28
29
30
|
# File 'lib/rex/post/file_stat.rb', line 28
def stathash
@stathash
end
|
Instance Method Details
#atime ⇒ Object
65
66
67
|
# File 'lib/rex/post/file_stat.rb', line 65
def atime
::Time.at(self.stathash['st_atime'])
end
|
#blksize ⇒ Object
59
60
61
|
# File 'lib/rex/post/file_stat.rb', line 59
def blksize
self.stathash['st_blksize']
end
|
#blockdev? ⇒ Boolean
112
113
114
|
# File 'lib/rex/post/file_stat.rb', line 112
def blockdev?
filetype?(060000)
end
|
#blocks ⇒ Object
62
63
64
|
# File 'lib/rex/post/file_stat.rb', line 62
def blocks
self.stathash['st_blocks']
end
|
#chardev? ⇒ Boolean
115
116
117
|
# File 'lib/rex/post/file_stat.rb', line 115
def chardev?
filetype?(020000)
end
|
#ctime ⇒ Object
71
72
73
|
# File 'lib/rex/post/file_stat.rb', line 71
def ctime
::Time.at(self.stathash['st_ctime'])
end
|
#dev ⇒ Object
35
36
37
|
# File 'lib/rex/post/file_stat.rb', line 35
def dev
self.stathash['st_dev']
end
|
#directory? ⇒ Boolean
118
119
120
|
# File 'lib/rex/post/file_stat.rb', line 118
def directory?
filetype?(040000)
end
|
#executable? ⇒ Boolean
171
172
173
|
# File 'lib/rex/post/file_stat.rb', line 171
def executable?
raise NotImplementedError
end
|
#executable_real? ⇒ Boolean
174
175
176
|
# File 'lib/rex/post/file_stat.rb', line 174
def executable_real?
raise NotImplementedError
end
|
#file? ⇒ Boolean
121
122
123
|
# File 'lib/rex/post/file_stat.rb', line 121
def file?
filetype?(0100000)
end
|
#filetype?(mask) ⇒ Boolean
this is my own, just a helper…
107
108
109
110
|
# File 'lib/rex/post/file_stat.rb', line 107
def filetype?(mask)
return true if mode & 0170000 == mask
return false
end
|
#ftype ⇒ Object
134
135
136
|
# File 'lib/rex/post/file_stat.rb', line 134
def ftype
return @@ftypes[(mode & 0170000) >> 13].dup
end
|
#gid ⇒ Object
50
51
52
|
# File 'lib/rex/post/file_stat.rb', line 50
def gid
self.stathash['st_gid']
end
|
#grpowned? ⇒ Boolean
177
178
179
|
# File 'lib/rex/post/file_stat.rb', line 177
def grpowned?
raise NotImplementedError
end
|
#ino ⇒ Object
38
39
40
|
# File 'lib/rex/post/file_stat.rb', line 38
def ino
self.stathash['st_ino']
end
|
#mode ⇒ Object
41
42
43
|
# File 'lib/rex/post/file_stat.rb', line 41
def mode
self.stathash['st_mode']
end
|
#mtime ⇒ Object
68
69
70
|
# File 'lib/rex/post/file_stat.rb', line 68
def mtime
::Time.at(self.stathash['st_mtime'])
end
|
#nlink ⇒ Object
44
45
46
|
# File 'lib/rex/post/file_stat.rb', line 44
def nlink
self.stathash['st_nlink']
end
|
#owned? ⇒ Boolean
180
181
182
|
# File 'lib/rex/post/file_stat.rb', line 180
def owned?
raise NotImplementedError
end
|
#perm?(mask) ⇒ Boolean
S_ISUID 0004000 set UID bit S_ISGID 0002000 set GID bit (see below) S_ISVTX 0001000 sticky bit (see below) S_IRWXU 00700 mask for file owner permissions S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permission S_IRWXG 00070 mask for group permissions S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission S_IRWXO 00007 mask for permissions for others (not in group) S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permisson S_IXOTH 00001 others have execute permission
156
157
158
159
|
# File 'lib/rex/post/file_stat.rb', line 156
def perm?(mask)
return true if mode & mask == mask
return false
end
|
#pipe? ⇒ Boolean
124
125
126
|
# File 'lib/rex/post/file_stat.rb', line 124
def pipe?
filetype?(010000) end
|
#pretty ⇒ Object
Return pretty information about a file.
217
218
219
220
221
222
223
224
225
|
# File 'lib/rex/post/file_stat.rb', line 217
def pretty
" Size: #{size} Blocks: #{blocks} IO Block: #{blksize} Type: #{rdev}\n"\
"Device: #{dev} Inode: #{ino} Links: #{nlink}\n"\
" Mode: #{prettymode}\n"\
" Uid: #{uid} Gid: #{gid}\n"\
"Access: #{atime}\n"\
"Modify: #{mtime}\n"\
"Change: #{ctime}\n"
end
|
#prettymode ⇒ Object
Return pretty information about a file’s permissions.
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/rex/post/file_stat.rb', line 199
def prettymode
m = mode
om = '%06o' % m
perms = ''
3.times {
perms = ((m & 01) == 01 ? 'x' : '-') + perms
perms = ((m & 02) == 02 ? 'w' : '-') + perms
perms = ((m & 04) == 04 ? 'r' : '-') + perms
m >>= 3
}
return "#{om}/#{perms}"
end
|
#rdev ⇒ Object
53
54
55
|
# File 'lib/rex/post/file_stat.rb', line 53
def rdev
self.stathash['st_rdev']
end
|
#readable? ⇒ Boolean
183
184
185
|
# File 'lib/rex/post/file_stat.rb', line 183
def readable?
raise NotImplementedError
end
|
#readable_real? ⇒ Boolean
186
187
188
|
# File 'lib/rex/post/file_stat.rb', line 186
def readable_real?
raise NotImplementedError
end
|
#setgid? ⇒ Boolean
161
162
163
|
# File 'lib/rex/post/file_stat.rb', line 161
def setgid?
perm?(02000)
end
|
#setuid? ⇒ Boolean
164
165
166
|
# File 'lib/rex/post/file_stat.rb', line 164
def setuid?
perm?(04000)
end
|
#size ⇒ Object
56
57
58
|
# File 'lib/rex/post/file_stat.rb', line 56
def size
self.stathash['st_size']
end
|
#socket? ⇒ Boolean
127
128
129
|
# File 'lib/rex/post/file_stat.rb', line 127
def socket?
filetype?(0140000)
end
|
#sticky? ⇒ Boolean
167
168
169
|
# File 'lib/rex/post/file_stat.rb', line 167
def sticky?
perm?(01000)
end
|
#symlink? ⇒ Boolean
130
131
132
|
# File 'lib/rex/post/file_stat.rb', line 130
def symlink?
filetype?(0120000)
end
|
#uid ⇒ Object
47
48
49
|
# File 'lib/rex/post/file_stat.rb', line 47
def uid
self.stathash['st_uid']
end
|
#update(buf) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/rex/post/file_stat.rb', line 75
def update(buf)
skeys = %W{st_dev st_mode st_nlink st_uid st_gid st_rdev st_ino st_size st_atime st_mtime st_ctime}
svals = buf.unpack("VVVVVVQQQQQ")
skeys.each_index do |i|
self.stathash[ skeys[i] ] = svals[i]
end
end
|
#update32(buf) ⇒ Object
This handles the old 32bit st_size buf from old stageless meterpreters for backwards compatibility Maybe we can remove this in the future
87
88
89
90
91
92
93
|
# File 'lib/rex/post/file_stat.rb', line 87
def update32(buf)
skeys = %W{st_dev st_ino st_mode st_pad st_nlink st_uid st_gid st_rdev st_size st_ctime st_atime st_mtime}
svals = buf.unpack("VvvvvvvVVVVV")
skeys.each_index do |i|
self.stathash[ skeys[i] ] = svals[i]
end
end
|
#writeable? ⇒ Boolean
189
190
191
|
# File 'lib/rex/post/file_stat.rb', line 189
def writeable?
raise NotImplementedError
end
|
#writeable_real? ⇒ Boolean
192
193
194
|
# File 'lib/rex/post/file_stat.rb', line 192
def writeable_real?
raise NotImplementedError
end
|