/
file_stat.rb
65 lines (51 loc) · 1.26 KB
/
file_stat.rb
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
# -*- coding: binary -*-
require 'rex/post/file_stat'
require 'rex/post/meterpreter/extensions/stdapi/stdapi'
module Rex
module Post
module Meterpreter
module Extensions
module Stdapi
module Fs
###
#
# This class wrappers gathering information about a given file and implements
# the Rex::Post::FileStat interface in terms of data acquisition.
#
###
class FileStat < Rex::Post::FileStat
class << self
attr_accessor :client
end
##
#
# Constructor
#
##
#
# Returns an instance of a FileStat object.
#
def initialize(file)
super
stat(file) if (file)
end
protected
#
# Gets information about the supplied file and returns a populated
# hash to the requester.
#
def stat(file)
request = Packet.create_request(COMMAND_ID_STDAPI_FS_STAT)
request.add_tlv(TLV_TYPE_FILE_PATH, self.class.client.unicode_filter_decode( file ))
response = self.class.client.send_request(request)
stat_buf = response.get_tlv(TLV_TYPE_STAT_BUF)
unless stat_buf
stat_buf = response.get_tlv(TLV_TYPE_STAT_BUF32)
return update32(stat_buf.value)
end
# Next, we go through the returned stat_buf and fix up the values
# and insert them into a hash
return update(stat_buf.value)
end
end
end; end; end; end; end; end