2005-04-03 21:52:10 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'Rex/Post/File'
|
2005-04-04 01:33:26 +00:00
|
|
|
require 'Rex/Post/DispatchNinja/IO'
|
2005-04-03 21:52:10 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Post
|
|
|
|
module DispatchNinja
|
|
|
|
|
2005-04-04 01:33:26 +00:00
|
|
|
class File < Rex::Post::DispatchNinja::IO
|
|
|
|
|
|
|
|
include Rex::Post::File
|
2005-04-03 21:52:10 +00:00
|
|
|
|
|
|
|
# setup a class variable for our client pointer
|
|
|
|
class <<self
|
|
|
|
attr_accessor :client
|
|
|
|
end
|
|
|
|
|
2005-04-04 01:33:26 +00:00
|
|
|
protected
|
|
|
|
attr_accessor :client
|
|
|
|
public
|
|
|
|
|
|
|
|
# !!! make mode/perms work!
|
|
|
|
def initialize(name, mode="r", perms=0)
|
|
|
|
self.client = self.class.client
|
|
|
|
self.filed = _open(name, mode, perms)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _open(name, mode="r", perms=0)
|
|
|
|
|
|
|
|
client.sendmodule('open')
|
|
|
|
client.sendfilename(name)
|
|
|
|
|
|
|
|
res = client.sockread(4).unpack('l')[0]
|
|
|
|
|
|
|
|
client.checksig()
|
|
|
|
|
|
|
|
if res < 0
|
|
|
|
raise SystemCallError.new(name, -res)
|
|
|
|
end
|
|
|
|
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2005-04-03 21:52:10 +00:00
|
|
|
def File.stat(name)
|
|
|
|
client.filestat.new(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def File.stat_data(file)
|
|
|
|
|
|
|
|
client.sendmodule('stat')
|
|
|
|
client.sendfilename(file)
|
|
|
|
|
|
|
|
data = client.sockread(68)
|
|
|
|
res = data[0, 4].unpack('l')[0]
|
|
|
|
|
|
|
|
client.checksig()
|
|
|
|
|
2005-04-03 23:13:16 +00:00
|
|
|
if res < 0
|
|
|
|
raise SystemCallError.new(file, -res)
|
|
|
|
end
|
|
|
|
|
2005-04-03 21:52:10 +00:00
|
|
|
return data[4 .. -1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end; end; end # DispatchNinja/Post/Rex
|
|
|
|
|