2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-04-03 21:52:10 +00:00
|
|
|
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/post/dispatch_ninja/file'
|
|
|
|
require 'rex/post/dispatch_ninja/file_stat'
|
|
|
|
require 'rex/post/dispatch_ninja/process'
|
|
|
|
require 'rex/post/dispatch_ninja/dir'
|
2005-04-03 21:52:10 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Post
|
|
|
|
module DispatchNinja
|
|
|
|
|
|
|
|
class Client
|
|
|
|
|
|
|
|
private
|
|
|
|
attr_accessor :sock
|
|
|
|
public
|
|
|
|
|
|
|
|
def initialize(sock)
|
|
|
|
self.sock = sock
|
|
|
|
|
|
|
|
checksig()
|
|
|
|
end
|
|
|
|
|
2005-07-08 00:21:11 +00:00
|
|
|
# Get a File-like class
|
2005-04-03 23:13:16 +00:00
|
|
|
def file
|
|
|
|
brand(Rex::Post::DispatchNinja::File)
|
|
|
|
end
|
2005-07-08 00:21:11 +00:00
|
|
|
# Get a File::Stat-like class
|
2005-04-03 21:52:10 +00:00
|
|
|
def filestat
|
2005-04-03 23:13:16 +00:00
|
|
|
brand(Rex::Post::DispatchNinja::FileStat)
|
2005-04-03 21:52:10 +00:00
|
|
|
end
|
2005-07-08 00:21:11 +00:00
|
|
|
# Get a Process-like class
|
2005-04-03 21:52:10 +00:00
|
|
|
def process
|
2005-04-03 23:13:16 +00:00
|
|
|
brand(Rex::Post::DispatchNinja::Process)
|
|
|
|
end
|
2005-07-08 00:21:11 +00:00
|
|
|
# Get a Dir-like class
|
2005-04-03 23:13:16 +00:00
|
|
|
def dir
|
|
|
|
brand(Rex::Post::DispatchNinja::Dir)
|
2005-04-03 21:52:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def sendmodule(name)
|
|
|
|
name = 'lib/Rex/Post/DispatchNinja/modules/' + name
|
2005-04-04 01:33:26 +00:00
|
|
|
data = ::IO.readlines(name, '')[0]
|
2005-04-03 21:52:10 +00:00
|
|
|
sockwrite([data.length].pack('V'))
|
|
|
|
sockwrite(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def checksig
|
|
|
|
if !select( [ sock ], nil, nil, 2)
|
|
|
|
puts "Possible sync problem?"
|
|
|
|
else
|
|
|
|
sig = sockread(4)
|
|
|
|
if sig != "AAAA"
|
|
|
|
puts "Sig #{sig} didn't match"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sendfilename(dir)
|
|
|
|
dir += "\x00" # null terminate filename for easy syscall
|
|
|
|
sockwrite( [ dir.length ].pack('V') )
|
|
|
|
sockwrite(dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
# do true full read/write, blocking. So if I say read 4 bytes, I'll
|
|
|
|
# block until I get all 4 bytes
|
|
|
|
def sockwrite(data)
|
|
|
|
sock.write(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sockread(len)
|
|
|
|
return sock.read(len)
|
|
|
|
end
|
|
|
|
|
2005-07-08 00:21:11 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def brand(klass)
|
|
|
|
klass = klass.dup
|
|
|
|
klass.client = self
|
|
|
|
return klass
|
|
|
|
end
|
2005-04-03 21:52:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end; end; end # DispatchNinja/Post/Rex
|