FileStat implemented
git-svn-id: file:///home/svn/incoming/trunk@2363 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
1a9852d50e
commit
b81ebdc3f1
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'Rex/Post/FileStat'
|
||||
require 'Rex/Post/Meterpreter/Extensions/Stdapi/Stdapi'
|
||||
|
||||
module Rex
|
||||
module Post
|
||||
module Meterpreter
|
||||
module Extensions
|
||||
module Stdapi
|
||||
|
||||
TLV_TYPE_STAT_BUF = TLV_META_TYPE_COMPLEX | 1220
|
||||
|
||||
class FileStat < Rex::Post::FileStat
|
||||
|
||||
@@struct_stat = [
|
||||
'st_dev', 4, # 0
|
||||
'st_ino', 2, # 4
|
||||
'st_mode', 2, # 6
|
||||
'st_nlink', 2, # 8
|
||||
'st_uid', 2, # 10
|
||||
'st_gid', 2, # 12
|
||||
'pad1', 2, # 14
|
||||
'st_rdev', 4, # 16
|
||||
'st_size', 4, # 20
|
||||
'st_atime', 4, # 24
|
||||
'st_mtime', 4, # 28
|
||||
'st_ctime', 4, # 32
|
||||
]
|
||||
|
||||
class <<self
|
||||
attr_accessor :client
|
||||
end
|
||||
|
||||
def initialize(file)
|
||||
self.stathash = stat(file)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def stat(file)
|
||||
request = Packet.create_request('stdapi_fs_stat')
|
||||
|
||||
request.add_tlv(TLV_TYPE_FILE_PATH, file)
|
||||
|
||||
response = self.class.client.send_request(request)
|
||||
stat_buf = response.get_tlv(TLV_TYPE_STAT_BUF).value
|
||||
|
||||
# Next, we go through the returned stat_buf and fix up the values
|
||||
# and insert them into a hash
|
||||
elem = @@struct_stat
|
||||
hash = {}
|
||||
offset = 0
|
||||
index = 0
|
||||
|
||||
while (index < elem.length)
|
||||
size = elem[index + 1]
|
||||
|
||||
value = stat_buf[offset, size].unpack(size == 2 ? 'S' : 'L')[0]
|
||||
offset += size
|
||||
|
||||
hash[elem[index]] = value
|
||||
|
||||
index += 2
|
||||
end
|
||||
|
||||
return hash
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end; end; end; end; end
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require 'Rex/Post/Meterpreter/Extension'
|
||||
require 'Rex/Post/Meterpreter/Extensions/Stdapi/Dir'
|
||||
require 'Rex/Post/Meterpreter/Extensions/Stdapi/FileStat'
|
||||
require 'Rex/Post/Meterpreter/Extensions/Stdapi/Process'
|
||||
require 'Rex/Post/Meterpreter/Extensions/Stdapi/Registry'
|
||||
|
||||
|
@ -26,6 +27,7 @@ class Stdapi < Extension
|
|||
# Alias the following things on the client object so that they
|
||||
# can be directly referenced
|
||||
client.register_extension_alias('dir', self.dir)
|
||||
client.register_extension_alias('filestat', self.filestat)
|
||||
client.register_extension_alias('process', self.process)
|
||||
client.register_extension_alias('registry', self.registry)
|
||||
end
|
||||
|
@ -40,6 +42,10 @@ class Stdapi < Extension
|
|||
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Dir)
|
||||
end
|
||||
|
||||
def filestat
|
||||
brand(Rex::Post::Meterpreter::Extensions::Stdapi::FileStat)
|
||||
end
|
||||
|
||||
def process
|
||||
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Process)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue