Class: Ronin::PostExploitation::Command

Inherits:
Resource
  • Object
show all
Includes:
Enumerable, IO
Defined in:
lib/ronin/post_exploitation/command.rb

Overview

The Command class represents commands being executed on remote systems. The Command class wraps around the shell_exec method defined in the object controller shell access.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Attributes included from IO

#eof, #fd, #pos

Attributes inherited from Resource

#controller

Instance Method Summary collapse

Methods included from IO

#append_buffer, #autoclose=, #autoclose?, #binmode, #binmode?, #clear_buffer!, #close, #close_on_exec=, #close_on_exec?, #close_read, #close_write, #closed?, #each_block, #each_byte, #each_char, #each_codepoint, #each_line, #empty_buffer?, #eof?, #fcntl, #fileno, #flush, #fsync, #getbyte, #getc, #gets, #io_close, #io_initialize, #ioctl, #isatty, #lineno, #lineno=, #open, #pid, #prepend_buffer, #print, #printf, #putc, #puts, #read, #read_buffer, #readbyte, #readchar, #readline, #readlines, #readpartial, #rewind, #seek, #stat, #sync, #sync=, #sysseek, #to_io, #tty?, #ungetbyte, #ungetc, #write

Methods inherited from Resource

#console, #requires_method!, resource_method, resource_methods, #supports, #supports?

Constructor Details

#initialize(controller, program, *arguments) ⇒ Command

Creates a new Command.

Raises:

  • (RuntimeError)

    The controller object does not define shell_exec.

Since:

  • 1.0.0


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ronin/post_exploitation/command.rb', line 61

def initialize(controller,program,*arguments)
  unless controller.respond_to?(:shell_exec)
    raise(RuntimeError,"#{controller.inspect} must define shell_exec for #{self.class}")
  end

  @controller = controller
  @program    = program
  @arguments  = arguments

  io_initialize
end

Instance Attribute Details

#argumentsObject (readonly)

The arguments of the program

Since:

  • 1.0.0


44
45
46
# File 'lib/ronin/post_exploitation/command.rb', line 44

def arguments
  @arguments
end

#programObject (readonly)

The program name

Since:

  • 1.0.0


41
42
43
# File 'lib/ronin/post_exploitation/command.rb', line 41

def program
  @program
end

Instance Method Details

#inspectString

Inspects the command.

Since:

  • 1.0.0


111
112
113
# File 'lib/ronin/post_exploitation/command.rb', line 111

def inspect
  "#<#{self.class}: #{self}>"
end

#io_openEnumerator (protected)

Executes and opens the command for reading.

Since:

  • 1.0.0


123
124
125
# File 'lib/ronin/post_exploitation/command.rb', line 123

def io_open
  @controller.enum_for(:shell_exec,@program,*@arguments)
end

#io_readString (protected)

Reads a line of output from the command.

Raises:

  • (EOFError)

    The end of the output stream has been reached.

Since:

  • 1.0.0


137
138
139
140
141
142
143
# File 'lib/ronin/post_exploitation/command.rb', line 137

def io_read
  begin
    @fd.next
  rescue StopIteration
    raise(EOFError,"end of command")
  end
end

#io_write(data) ⇒ Integer (protected)

Writes data to the shell.

Since:

  • 1.0.0


155
156
157
158
159
160
161
# File 'lib/ronin/post_exploitation/command.rb', line 155

def io_write(data)
  if @controller.respond_to?(:shell_write)
    @controller.shell_write(data)
  else
    raise(IOError,"#{@controller.inspect} does not support writing to the shell")
  end
end

#reopen(program, *arguments) ⇒ Command

Reopens the command.

Since:

  • 1.0.0


85
86
87
88
89
90
91
92
# File 'lib/ronin/post_exploitation/command.rb', line 85

def reopen(program,*arguments)
  close

  @program = program
  @arguments = arguments

  return open
end

#to_sString

Converts the command to a String.

Since:

  • 1.0.0


101
102
103
# File 'lib/ronin/post_exploitation/command.rb', line 101

def to_s
  ([@program] + @arguments).join(' ')
end