Class: Ronin::PostEx::Sessions::RPCSession

Inherits:
Session
  • Object
show all
Defined in:
lib/ronin/post_ex/sessions/rpc_session.rb

Overview

Provides a post-exploitation session which wraps around an RPC client.

Instance Attribute Summary collapse

System Methods collapse

File Methods collapse

File-System methods collapse

Process methods collapse

Shell Methods collapse

Instance Method Summary collapse

Methods inherited from Session

#close, #name, #system, #to_s

Constructor Details

#initialize(client) ⇒ RPCSession

Initializes the RPC session.

Parameters:

  • client (#call)

    The RPC client. It must define a call method.



44
45
46
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 44

def initialize(client)
  @client = client
end

Instance Attribute Details

#client#call (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The RPC client object.

Returns:



36
37
38
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 36

def client
  @client
end

Instance Method Details

#call(method, *arguments) ⇒ Object

Calls the RPC method.

Parameters:

  • method (String)

    The RPC method name to call.

  • arguments (Array)

    Additional arguments for the RPC method.

Returns:

  • (Object)

    The result value from the RPC method.



60
61
62
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 60

def call(method,*arguments)
  @client.call(method,*arguments)
end

#file_close(fd) ⇒ Object

Note:

calls the file.close RPC function.

Closes an opened remote file-descriptor.

Parameters:

  • fd (Integer)

    The remote file descriptor to close.



257
258
259
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 257

def file_close(fd)
  call('file.close',fd)
end

#file_fcntl(fd, command, argument) ⇒ Integer

Note:

calls the file.fcntl RPC function.

Performs a fcntl() operation on the file-descriptor.

Parameters:

  • fd (Integer)

    The remote file descriptor to perform the fcntl() on.

  • command (String, Array<Integer>)

    The fcntl() command String or Array of bytes.

  • argument (Object)

    The additional fcntl() argument.

Returns:

  • (Integer)

    The return value of the fcntl().



228
229
230
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 228

def file_fcntl(fd,command,argument)
  call('file.fcntl',fd,command,argument)
end

#file_ioctl(fd, command, argument) ⇒ Integer

Note:

calls the file.ioctl RPC function.

Performs a ioctl() operation on the file-descriptor.

Parameters:

  • fd (Integer)

    The remote file descriptor to perform the ioctl() on.

  • command (String, Array<Integer>)

    The ioctl() command String or Array of bytes.

  • argument (Object)

    The additional ioctl() argument.

Returns:

  • (Integer)

    The return value of the ioctl().



207
208
209
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 207

def file_ioctl(fd,command,argument)
  call('file.ioctl',fd,command,argument)
end

#file_open(path, mode = 'r') ⇒ Integer

Note:

calls the file.open RPC function.

Opens a file and returns the file-descriptor number.

Parameters:

  • path (String)

    The remote file path to open.

  • mode (String) (defaults to: 'r')

    The mode to open the file.

Returns:

  • (Integer)

    The opened remote file descriptor.



109
110
111
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 109

def file_open(path,mode='r')
  call('file.open',path,mode)
end

#file_read(fd, length) ⇒ String?

Note:

calls the file.read RPC function.

Reads from an opened file-descriptor and returns the read data.

Parameters:

  • fd (Integer)

    The remote file descriptor to read from.

  • length (Integer)

    The length of data in bytes to read from the file descriptor.

Returns:

  • (String, nil)

    Returns the read data or nil if there is no more data to be read.



127
128
129
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 127

def file_read(fd,length)
  call('file.read',fd,length)
end

#file_seek(fd, new_pos, whence) ⇒ Object

Note:

calls the file.seek RPC function.

Seeks to a position within the file.

Parameters:

  • fd (Integer)

    The remote file descriptor to seek.

  • new_pos (Integer)

    The new position to seek to.

  • whence (String)

    How the position should be interpreted. Must be one of the following String values:

    • "SEEK_SET" - seek from beginning of file.
    • "SEEK_CUR" - seek from current position.
    • "SEEK_END" - seek from end of file.
    • "SEEK_DATA" - seek to next data.
    • "SEEK_HOLE" - seek to next hole.


171
172
173
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 171

def file_seek(fd,new_pos,whence)
  call('file.seek',fd,new_pos,whence)
end

#file_stat(fd) ⇒ Hash{Symbol => Object}?

Note:

calls the file.stat RPC function.

Queries file information from the given file-descriptor and returns a Hash of file metadata.

Parameters:

  • fd (Integer)

    The remote file descriptor to query.

Returns:

  • (Hash{Symbol => Object}, nil)

    The Hash of file metadata or nil if the remote file descriptor could not be stat-ed.



245
246
247
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 245

def file_stat(fd)
  call('file.stat',fd)
end

#file_tell(fd) ⇒ Integer

Note:

calls the file.tell RPC function.

Queries the current position within the file.

Parameters:

  • fd (Integer)

    The remote file descriptor to query.

Returns:

  • (Integer)

    The current position of the remote file descriptor.



186
187
188
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 186

def file_tell(fd)
  call('file.tell',fd)
end

#file_write(fd, pos, data) ⇒ Integer

Note:

calls the file.write RPC function.

Writes data to the opened file-descriptor.

Parameters:

  • fd (Integer)

    The remote file descriptor to write to.

  • pos (Integer)

    The position to write the data at.

  • data (String)

    The data to write.

Returns:

  • (Integer)


147
148
149
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 147

def file_write(fd,pos,data)
  call('file.write',fd,pos,data)
end

#fs_chdir(path) ⇒ Object

Note:

calls the fs.chdir RPC function.

Changes the current working directory.

Parameters:

  • path (String)

    The new remote current working directory.



285
286
287
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 285

def fs_chdir(path)
  call('fs.chdir',path)
end

#fs_chgrp(group, path) ⇒ Object

Note:

calls the fs.chgrp RPC function.

Changes the group ownership of a remote file or directory.

Parameters:

  • group (String)

    The new group name for the remote file or directory.

  • path (String)

    The path of the remote file or directory.



461
462
463
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 461

def fs_chgrp(group,path)
  call('fs.chgrp',group,path)
end

#fs_chmod(mode, path) ⇒ Object

Note:

calls the fs.chmod RPC function.

Changes the permissions on a remote file or directory.

Parameters:

  • mode (Integer)

    The permissions mode for the remote file or directory.

  • path (String)

    The path of the remote file or directory.



491
492
493
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 491

def fs_chmod(mode,path)
  call('fs.chmod',mode,path)
end

#fs_chown(user, path) ⇒ Object

Note:

calls the fs.chown RPC function.

Changes the user ownership of remote a file or directory.

Parameters:

  • user (String)

    The new user for the remote file or directory.

  • path (String)

    The path of the remote file or directory.



476
477
478
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 476

def fs_chown(user,path)
  call('fs.chown',user,path)
end

#fs_copy(src, dest) ⇒ Object

Note:

calls the fs.copy RPC function.

Copies a source file to the destination path.

Parameters:

  • src (String)

    The source file.

  • dest (String)

    The destination path.



391
392
393
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 391

def fs_copy(src,dest)
  call('fs.copy',src,dest)
end

#fs_getcwdString

Note:

calls the fs.getcwd RPC function.

Gets the current working directory and returns the directory path.

Returns:

  • (String)

    The remote current working directory.



273
274
275
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 273

def fs_getcwd
  call('fs.getcwd')
end

#fs_glob(pattern) ⇒ Array<String>

Note:

calls the fs.glob RPC function.

Evaluates a directory glob pattern and returns all matching paths.

Parameters:

  • pattern (String)

    The glob pattern to search for remotely.

Returns:

  • (Array<String>)

    The matching paths.



349
350
351
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 349

def fs_glob(pattern)
  call('fs.glob',pattern)
end
Note:

calls the fs.link RPC function.

Creates a remote symbolic link at the destination path pointing to the source path.

Parameters:

  • src (String)

    The source file path for the new symbolic link.

  • dest (String)

    The remote path of the new symbolic link.



446
447
448
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 446

def fs_link(src,dest)
  call('fs.link',src,dest)
end

#fs_mkdir(new_path) ⇒ Object

Note:

calls the fs.mkdir RPC function.

Creates a new remote directory at the given path.

Parameters:

  • new_path (String)

    The new remote directory to create.



376
377
378
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 376

def fs_mkdir(new_path)
  call('fs.mkdir',new_path)
end

#fs_mktemp(basename) ⇒ String

Note:

calls the fs.mktemp RPC function.

Creates a remote temporary file with the given file basename.

Parameters:

  • basename (String)

    The basename for the new temporary file.

Returns:

  • (String)

    The path of the newly created temporary file.



364
365
366
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 364

def fs_mktemp(basename)
  call('fs.mktemp',basename)
end

#fs_move(src, dest) ⇒ Object

Note:

calls the fs.move RPC function.

Moves or renames a remote source file to a new destination path.

Parameters:

  • src (String)

    The source file path.

  • dest (String)

    The destination file path.



430
431
432
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 430

def fs_move(src,dest)
  call('fs.move',src,dest)
end

#fs_readdir(path) ⇒ Array<String>

Note:

calls the fs.readdir RPC function.

Reads the contents of a remote directory and returns an Array of directory entry names.

Parameters:

  • path (String)

    The path of the remote directory to read.

Returns:

  • (Array<String>)

    The entities within the remote directory.



334
335
336
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 334

def fs_readdir(path)
  call('fs.readdir',path)
end

#fs_readfile(path) ⇒ String?

Note:

calls the fs.readfile RPC function.

Reads the entire file at the given path and returns the full file's contents.

Parameters:

  • path (String)

    The remote path to read.

Returns:

  • (String, nil)

    The contents of the remote file or nil if the file could not be read.



302
303
304
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 302

def fs_readfile(path)
  call('fs.readfile',path)
end
Note:

calls the fs.readlink RPC function.

Reads the destination path of a remote symbolic link.

Parameters:

  • path (String)

    The remote path to read.

Returns:

  • (String, nil)

    The destination of the remote symbolic link or nil if the symbolic link could not be read.



318
319
320
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 318

def fs_readlink(path)
  call('fs.readlink',path)
end

#fs_rmdir(path) ⇒ Object

Note:

calls the fs.rmdir RPC function.

Removes an empty directory at the given path.

Parameters:

  • path (String)

    The remote directory path to remove.



415
416
417
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 415

def fs_rmdir(path)
  call('fs.rmdir',path)
end

#fs_stat(path) ⇒ Hash{Symbol => Object}?

Note:

calls the fs.stat RPC function.

Queries file information for the given remote path and returns a Hash of file metadata.

Parameters:

  • path (String)

    The path to the remote file or directory.

Returns:

  • (Hash{Symbol => Object}, nil)

    The metadata for the remote file.



507
508
509
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 507

def fs_stat(path)
  call('fs.stat',path)
end
Note:

calls the fs.unlink RPC function.

Removes a file at the given path.

Parameters:

  • path (String)

    The remote path to remove.



403
404
405
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 403

def fs_unlink(path)
  call('fs.unlink',path)
end

#process_environHash{String => String}

Note:

calls the process.environ RPC function.

Queries all environment variables of the current process. Returns a Hash of the env variable names and values.

Returns:

  • (Hash{String => String})

    The Hash of environment variables.



669
670
671
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 669

def process_environ
  call('process.environ')
end

#process_exitObject

Note:

calls the process.exit RPC function.

Exits the current process.



755
756
757
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 755

def process_exit
  call('process.exit')
end

#process_getegidInteger

Note:

calls the process_getegid RPC function.

Gets the current process's effective group ID (EGID).

Returns:

  • (Integer)

    The effective group ID (EGID) of the current process.



619
620
621
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 619

def process_getegid
  call('process.getegid')
end

#process_getenv(name) ⇒ String?

Note:

calls the process.getenv RPC function.

Gets an individual environment variable. If the environment variable has not been set, nil will be returned.

Parameters:

  • name (String)

    The environment variable name to get.

Returns:

  • (String, nil)

    The environment variable value.



685
686
687
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 685

def process_getenv(name)
  call('process.getenv',name)
end

#process_geteuidInteger

Note:

calls the process.geteuid RPC function.

Gets the current process's effective UID (EUID).

Returns:

  • (Integer)

    the effective UID (EUID) for the current process.



571
572
573
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 571

def process_geteuid
  call('process.geteuid')
end

#process_getgidInteger

Note:

calls the process_getgid RPC function.

Gets the current process's group ID (GID).

Returns:

  • (Integer)

    The group ID (GID) for the current process.



595
596
597
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 595

def process_getgid
  call('process.getgid')
end

#process_getpidInteger

Note:

calls the process.getpid RPC function.

Gets the current process's Process ID (PID).

Returns:

  • (Integer)

    The current process's PID.



523
524
525
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 523

def process_getpid
  call('process.getpid')
end

#process_getppidInteger

Note:

calls the process.getppid RPC function.

Gets the current process's parent Process ID (PPID).

Returns:

  • (Integer)

    The current process's PPID.



535
536
537
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 535

def process_getppid
  call('process.getppid')
end

#process_getsidInteger

Note:

calls the process.getsid RPC function.

Gets the current process's session ID (SID).

Returns:

  • (Integer)

    the session ID (SID) of the current process.



644
645
646
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 644

def process_getsid
  call('process.getsid')
end

#process_getuidInteger

Note:

calls the process.getuid RPC function.

Gets the current process's user ID (UID).

Returns:

  • (Integer)

    The current process's UID.



547
548
549
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 547

def process_getuid
  call('process.getuid')
end

#process_kill(pid, signal) ⇒ Object

Note:

calls the process.kill RPC function.

Kills another process using the given Process ID (POD) and the signal number.

Parameters:

  • pid (Integer)

    The process ID (PID) to kill.

  • signal (Integer)

    The signal to send the process ID (PID).



728
729
730
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 728

def process_kill(pid,signal)
  call('process.kill',pid,signal)
end

#process_setegid(egid) ⇒ Object

Note:

calls the process_setegid RPC function.

Sets the current process's effective group ID (EGID) to the given Integer.

Parameters:

  • egid (Integer)

    The new effective group ID (EGID) for the current process.



632
633
634
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 632

def process_setegid(egid)
  call('process.setegid',egid)
end

#process_setenv(name, value) ⇒ Object

Note:

calls the process.setenv RPC function.

Sets an environment variable to the given value.

Parameters:

  • name (String)

    The environment variable name to set.

  • value (String)

    The new value for the environment variable.



700
701
702
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 700

def process_setenv(name,value)
  call('process.setenv',name,value)
end

#process_seteuid(euid) ⇒ Object

Note:

calls the process_seteuid RPC function.

Sets the current process's effective UID (EUID) to the given Integer.

Parameters:

  • euid (Integer)

    The new effective UID (EUID) for the current process.



583
584
585
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 583

def process_seteuid(euid)
  call('process.seteuid',euid)
end

#process_setgid(gid) ⇒ Object

Note:

calls the process_setgid RPC function.

Sets the current process's group ID (GID) to the given Integer.

Parameters:

  • gid (Integer)

    The new group ID (GID) for the current process.



607
608
609
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 607

def process_setgid(gid)
  call('process.setgid',gid)
end

#process_setsid(sid) ⇒ Object

Note:

calls the process.setsid RPC function.

Sets the current process's session ID (SID).

Parameters:

  • sid (Integer)

    The new session ID (SID) for the current process.



656
657
658
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 656

def process_setsid(sid)
  call('process.setsid',sid)
end

#process_setuid(uid) ⇒ Object

Note:

calls the process.setuid RPC function.

Sets the current process's user ID (UID) to the given Integer.

Parameters:

  • uid (Integer)

    The new UID for the current process.



559
560
561
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 559

def process_setuid(uid)
  call('process.setuid',uid)
end

#process_spawn(program, *arguments) ⇒ Integer

Note:

calls the process.spawn RPC function.

Spawns a new process using the given program and additional arguments.

Parameters:

  • program (String)

    The program name to spawn.

  • arguments (Array<String>)

    Additional arguments for the program.

Returns:

  • (Integer)

    The process ID (PID) of the spawned process.



746
747
748
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 746

def process_spawn(program,*arguments)
  call('process.spawn',program,*arguments)
end

#process_unsetenv(name) ⇒ Object

Note:

calls the process.unsetenv RPC function.

Un-sets an environment variable.

Parameters:

  • name (String)

    The environment variable to unset.



712
713
714
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 712

def process_unsetenv(name)
  call('process.unsetenv',name)
end

#shell_exec(command) ⇒ Object

Note:

calls the shell.exec RPC function.

Executes a new shell command using the given program name and additional arguments.

Parameters:

  • command (String)

    The command to execute.



772
773
774
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 772

def shell_exec(command)
  call('shell.exec',command)
end

#sys_hostnameString

Note:

calls the sys.hostname RPC function.

Gets the system's hostname.

Returns:

  • (String)


87
88
89
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 87

def sys_hostname
  call('sys.hostname')
end

#sys_timeInteger

Note:

calls the sys.time RPC function.

Gets the current time and returns the UNIX timestamp.

Returns:

  • (Integer)

    The current time as a UNIX timestamp.



76
77
78
# File 'lib/ronin/post_ex/sessions/rpc_session.rb', line 76

def sys_time
  call('sys.time')
end