Class: Ronin::PostEx::System::Process

Inherits:
Resource
  • Object
show all
Defined in:
lib/ronin/post_ex/system/process.rb

Overview

Provides access to the current process and managing child processes.

Supported Control Methods

The Process resource uses the following post-exploitation API methods, defined by the Resource#session object.

  • process_getpid -> Integer
  • process_getppid -> Integer
  • process_getuid -> Integer
  • process_setuid(uid : Integer)
  • process_geteuid -> Integer
  • process_seteuid(euid : Integer)
  • process_getgid -> Integer
  • process_setgid(gid : Integer)
  • process_getegid -> Integer
  • process_setegid(egid : Integer)
  • process_getsid -> Integer
  • process_setsid(sid : Integer) -> Integer
  • process_environ -> Hash[String, String]
  • process_getenv(name : String) -> String | env
  • process_setenv(name : String, value : String)
  • process_unsetenv(name : String)
  • process_kill(pid : Integer, signal : Integer)
  • process_popen(command : String) -> Integer
  • process_read(fd : Integer, length : Integer) -> String
  • process_write(fd : Integer, data : String)
  • process_close(fd : Integer)
  • process_spawn(program : String, *arguments : Array[String]) -> Integer
  • process_exit

Instance Attribute Summary

Attributes inherited from Resource

#session

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #interact, #supports, #supports?

Constructor Details

This class inherits a constructor from Ronin::PostEx::Resource

Instance Method Details

#environHash{String => String} Also known as: env

Note:

Requires the process_environ method be defined by the Resource#session object.

Retrieves the whole environment Hash.

Returns:

  • (Hash{String => String})

    The Hash of environment variables.



276
277
278
# File 'lib/ronin/post_ex/system/process.rb', line 276

def environ
  @session.process_environ
end

#exitObject

Note:

Requires the process_exit method be defined by the Resource#session object.

Exits the current running process.



414
415
416
# File 'lib/ronin/post_ex/system/process.rb', line 414

def exit
  @session.process_exit
end

#getegidInteger Also known as: egid

Note:

Requires the process_getegid method be defined by the Resource#session object.

Gets the effective GID that the current process is running under.

Returns:

  • (Integer)

    The effective GID.



209
210
211
# File 'lib/ronin/post_ex/system/process.rb', line 209

def getegid
  @session.process_getegid
end

#getenv(name) ⇒ String?

Note:

Requires process_getenv or process_environ methods be defined by the Resource#session object.

Retrieves the value of a environment variable.

Parameters:

  • name (String)

    The name of the environment variable.

Returns:

  • (String, nil)

    The value of the environment variable.



298
299
300
301
302
303
304
305
306
# File 'lib/ronin/post_ex/system/process.rb', line 298

def getenv(name)
  if @session.respond_to?(:process_getenv)
    @session.process_getenv(name)
  elsif @session.respond_to?(:process_environ)
    @session.process_environ[name]
  else
    raise(NoMethodError,"#{@session} does not define process_getenv or process_environ")
  end
end

#geteuidInteger Also known as: euid

Note:

Requires the process_geteuid method be defined by the Resource#session object.

Gets the effective UID that the current process is running under.

Returns:

  • (Integer)

    The effective UID.



141
142
143
# File 'lib/ronin/post_ex/system/process.rb', line 141

def geteuid
  @session.process_geteuid
end

#getgidInteger Also known as: gid

Note:

Requires the process_getgid method be defined by the Resource#session object.

Gets the GID that the current process is running under.

Returns:

  • (Integer)

    The current GID.



175
176
177
# File 'lib/ronin/post_ex/system/process.rb', line 175

def getgid
  @session.process_getgid
end

#getpidInteger Also known as: pid

Note:

Requires the process_getpid method be defined by the Resource#session object.

Gets the pid of the current process.

Returns:

  • (Integer)

    The current PID.



73
74
75
# File 'lib/ronin/post_ex/system/process.rb', line 73

def getpid
  @session.process_getpid
end

#getppidInteger Also known as: ppid

Note:

Requires the process_getppid method be defined by the Resource#session object.

Gets the pid of the parent process.

Returns:

  • (Integer)

    The parent PID.



90
91
92
# File 'lib/ronin/post_ex/system/process.rb', line 90

def getppid
  @session.process_getppid
end

#getsidInteger Also known as: sid

Note:

Requires the process_getsid method be defined by the Resource#session object.

Gets the SID of the current process.

Returns:

  • (Integer)

    The current SID.



243
244
245
# File 'lib/ronin/post_ex/system/process.rb', line 243

def getsid
  @session.process_getsid
end

#getuidInteger Also known as: uid

Note:

Requires the process_getuid method be defined by the Resource#session object.

Gets the UID that the current process is running under.

Returns:

  • (Integer)

    The current UID.



107
108
109
# File 'lib/ronin/post_ex/system/process.rb', line 107

def getuid
  @session.process_getuid
end

#kill(pid, signal = 'KILL') ⇒ Object

Note:

Requires the process_kill method be defined by the Resource#session object.

Kills a process.

Parameters:

  • pid (Integer)

    The PID of the process to kill.

  • signal (String) (defaults to: 'KILL')

    The POSIX signal name to send to the process.



359
360
361
# File 'lib/ronin/post_ex/system/process.rb', line 359

def kill(pid,signal='KILL')
  @session.process_kill(pid,signal)
end

#popen(command) ⇒ RemoteProcess

Note:

Requires the process_popen method be defined by the Resource#session object.

Opens a new process.

Parameters:

  • command (String)

    The command string to execute.

Returns:



379
380
381
# File 'lib/ronin/post_ex/system/process.rb', line 379

def popen(command)
  RemoteProcess.new(@session,command)
end

#setegid(new_egid) ⇒ Object Also known as: egid=

Note:

Requires the process_setegid method be defined by the Resource#session object.

Attempts to set the effective GID of the current process.

Parameters:

  • new_egid (Integer)

    The new effective GID.



226
227
228
# File 'lib/ronin/post_ex/system/process.rb', line 226

def setegid(new_egid)
  @session.process_setegid(new_egid)
end

#setenv(name, value) ⇒ Object

Note:

Requires the process_setenv method be defined by the Resource#session object.

Sets the value of a environment variable.

Parameters:

  • name (String)

    The name of the environment variable.

  • value (String)

    The new value for the environment variable.



324
325
326
# File 'lib/ronin/post_ex/system/process.rb', line 324

def setenv(name,value)
  @session.process_setenv(name,value)
end

#seteuid(new_euid) ⇒ Object Also known as: euid=

Note:

Requires the process_seteuid method be defined by the Resource#session object.

Attempts to set the effective UID of the current process.

Parameters:

  • new_euid (Integer)

    The new effective UID.



158
159
160
# File 'lib/ronin/post_ex/system/process.rb', line 158

def seteuid(new_euid)
  @session.process_seteuid(new_euid)
end

#setgid(new_gid) ⇒ Object Also known as: gid=

Note:

Requires the process_setgid method be defined by the Resource#session object.

Attempts to set the GID of the current process.

Parameters:

  • new_gid (Integer)

    The new GID.



192
193
194
# File 'lib/ronin/post_ex/system/process.rb', line 192

def setgid(new_gid)
  @session.process_setgid(new_gid)
end

#setsidObject Also known as: sid!

Note:

Requires the process_setsid method be defined by the Resource#session object.

Sets the SID of the current process.



257
258
259
# File 'lib/ronin/post_ex/system/process.rb', line 257

def setsid
  @session.process_setsid
end

#setuid(new_uid) ⇒ Object Also known as: uid=

Note:

Requires the process_setuid method be defined by the Resource#session object.

Attempts to set the UID of the current process.

Parameters:

  • new_uid (Integer)

    The new UID.



124
125
126
# File 'lib/ronin/post_ex/system/process.rb', line 124

def setuid(new_uid)
  @session.process_setuid(new_uid)
end

#spawn(program, *arguments) ⇒ Integer

Note:

Requires the process_spawn method be defined by the Resource#session object.

Executes a program as a separate child process.

Parameters:

  • program (String)

    The name or path of the program.

  • arguments (Array<String>)

    Additional arguments to execute the program with.

Returns:

  • (Integer)

    The pid of the new process.



402
403
404
# File 'lib/ronin/post_ex/system/process.rb', line 402

def spawn(program,*arguments)
  @session.process_spawn(program,*arguments)
end

#unsetenv(name) ⇒ Object

Note:

Requires the process_unsetenv method be defined by the Resource#session object.

Unsets an environment variable.

Parameters:

  • name (String)

    The name of the environment variable.



341
342
343
# File 'lib/ronin/post_ex/system/process.rb', line 341

def unsetenv(name)
  @session.process_unsetenv(name)
end