Changeset 2335

Show
Ignore:
Timestamp:
04/03/05 18:13:16 (3 years ago)
Author:
spoonm
Message:

Added dir, throwing exceptions n shit, what

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • incoming/trunk/lib/rex/post/dispatch_ninja/client.rb

    r2334 r2335  
    44require 'Rex/Post/DispatchNinja/FileStat' 
    55require 'Rex/Post/DispatchNinja/Process' 
     6require 'Rex/Post/DispatchNinja/Dir' 
    67 
    78module Rex 
     
    2122        end 
    2223 
    23         def file 
    24                 klass = Rex::Post::DispatchNinja::File.dup 
     24        def brand(klass) 
     25                klass = klass.dup 
    2526                klass.client = self 
    2627                return klass 
    2728        end 
    2829 
     30        def file 
     31                brand(Rex::Post::DispatchNinja::File) 
     32        end 
    2933        def filestat 
    30                 klass = Rex::Post::DispatchNinja::FileStat.dup 
    31                 klass.client = self 
    32                 return klass 
     34                brand(Rex::Post::DispatchNinja::FileStat) 
    3335        end 
    34          
    3536        def process 
    36                 klass = Rex::Post::DispatchNinja::Process.dup 
    37                 klass.client = self 
    38                 return klass 
     37                brand(Rex::Post::DispatchNinja::Process) 
     38        end 
     39        def dir 
     40                brand(Rex::Post::DispatchNinja::Dir) 
    3941        end 
    4042 
  • incoming/trunk/lib/rex/post/dispatch_ninja/dir.rb

    r2334 r2335  
    11#!/usr/bin/ruby 
    22 
    3 require 'Rex/DispatchNinja/Stat
     3require 'Rex/Post/Dir
    44 
    55module Rex 
     
    77module DispatchNinja 
    88 
    9 class File < Rex::Post::File 
     9class Dir < Rex::Post::Dir 
    1010 
    11         # 
    12         # Class Methods 
    13         # 
    14  
    15         @@structstat = [ 
    16           'st_dev',     2, 
    17           'pad1',       2, 
    18           'st_ino',     4, 
    19           'st_mode',    2, 
    20           'st_nlink',   2, 
    21           'st_uid',     2, 
    22           'st_gid',     2, 
    23           'st_rdev',    2, 
    24           'pad2',       2, 
    25           'st_size',    4, 
    26           'st_blksize', 4, 
    27           'st_blocks',  4, 
    28           'st_atime',   4, 
    29           'unused1',    4, 
    30           'st_mtime',   4, 
    31           'unused2',    4, 
    32           'st_ctime',   4, 
    33           'unused3',    4, 
    34           'unused4',    4, 
    35           'unused5',    4 
    36         ] 
    37  
    38         # setup a class variable for our client pointer 
    3911        class <<self 
    4012                attr_accessor :client 
    4113        end 
    4214 
    43         def File.stat(file) 
    44                 return client.filestat.new(file) 
    45         end 
    46         def ls(dir) 
     15        def Dir.entries(name) 
    4716 
    48                 sendmodule('ls') 
     17                client.sendmodule('ls') 
    4918 
    50                 sendfilename(dir
     19                client.sendfilename(name
    5120                 
    52                 res = sockread(4).unpack('l')[0] # ug, not portable, later... 
     21                res = client.sockread(4).unpack('l')[0] # ug, not portable, later... 
    5322 
    5423                files = [ ] 
    5524 
    5625                while true 
    57                         len = sockread(2).unpack('S')[0] 
     26                        len = client.sockread(2).unpack('S')[0] 
    5827                        break if len == 0 
    59                         files << sockread(len) 
     28                        files << client.sockread(len) 
    6029                end 
    61  
    62                 checksig() 
    63  
    64                 return [ res, files ] 
    65         end 
    66  
    67         def File.stat_hash(file) 
    68  
    69                 client.sendmodule('stat') 
    70                 client.sendfilename(file) 
    71  
    72                 data = client.sockread(68) 
    73                 res = data[0, 4].unpack('l')[0] 
    74  
    75                 # throw exception! blah! 
    7630 
    7731                client.checksig() 
    7832 
    79                 data = data[4 .. -1] 
    80  
    81                 elements = @@structstat 
    82                 hash = { } 
    83                 i = 0 
    84                 o = 0 
    85                 while i < elements.length 
    86                         name = elements[i] 
    87                         size = elements[i + 1] 
    88                         i += 2 
    89  
    90                         e = data[o, size].unpack(size == 2 ? 'S' : 'L')[0] 
    91                         o += size 
    92  
    93                         hash[name] = e 
     33                if res < 0 # eek! error! 
     34                        raise SystemCallError.new(name, -res) 
    9435                end 
    9536 
    96                 return(hash) 
     37                return files 
    9738        end 
    98  
    99         # 
    100         # Instance Methods 
    101         # 
    102          
    103         # setup an instance variable, just for ease and copy it over.. 
    104         # and so you can change it instance wise 
    105         private 
    106         attr_accessor :client 
    107         public 
    108  
    109         def initialize() 
    110                 self.client = self.class.client 
    111         end 
    112  
    11339 
    11440end 
    11541 
    11642end; end; end # DispatchNinja/Post/Rex 
    117  
  • incoming/trunk/lib/rex/post/dispatch_ninja/file.rb

    r2334 r2335  
    3030                client.checksig() 
    3131 
     32                if res < 0 
     33                        raise SystemCallError.new(file, -res) 
     34                end 
     35 
    3236                return data[4 .. -1] 
    3337        end 
  • incoming/trunk/lib/rex/post/dispatch_ninja/process.rb

    r2334 r2335  
    2323                return data.unpack('l3') 
    2424        end 
     25 
     26        def Process.pid() 
     27                client.sendmodule('getpid') 
     28                data = client.sockread(4) 
     29                client.checksig 
     30                return data.unpack('V')[0] 
     31        end 
     32 
     33        def Process.ppid() 
     34                client.sendmodule('getppid') 
     35                data = client.sockread(4) 
     36                client.checksig 
     37                return data.unpack('V')[0] 
     38        end 
    2539end 
    2640