Class: Ronin::PostEx::CLI::SystemShell
- Inherits:
-
Core::CLI::CommandShell
- Object
- Core::CLI::CommandShell
- Ronin::PostEx::CLI::SystemShell
- Defined in:
- lib/ronin/post_ex/cli/system_shell.rb
Overview
A shell for System.
Constant Summary collapse
- WHENCE =
Mapping of String whence values to Integer values.
{ 'SEEK_SET' => RemoteFile::SEEK_SET, 'SEEK_CUR' => RemoteFile::SEEK_CUR, 'SEEK_END' => RemoteFile::SEEK_END, 'SEEK_DATA' => RemoteFile::SEEK_DATA, 'SEEK_HOLE' => RemoteFile::SEEK_HOLE }
Instance Method Summary collapse
-
#file_close(file_id) ⇒ Object
Closes an opened file.
-
#file_open(path, mode = "r") ⇒ Object
Opens a file.
-
#file_read(file_id, length) ⇒ Object
Reads data from an opened file.
-
#file_seek(file_id, pos, whence = 'SEEK_SET') ⇒ Object
Seeks to a position within an opened file.
-
#file_unlink(path) ⇒ Object
Removes a file.
-
#file_write(file_id, data) ⇒ Object
Writes data from to an opened file.
-
#files ⇒ Object
Lists opened files.
-
#fs_chdir(path) ⇒ Object
Changes the working directory.
-
#fs_chgrp(group, path) ⇒ Object
Changes group ownership of a file or directory.
-
#fs_chmod(mode, path) ⇒ Object
Changes the permissions of a file or directory.
-
#fs_chown(user, path) ⇒ Object
Changes ownership of a file or directory.
-
#fs_copy(src, dest) ⇒ Object
Copies a file to a destination.
-
#fs_link(src, dest) ⇒ Object
Creates a link to a file or directory.
-
#fs_mv(src, dest) ⇒ Object
Moves a file or directory.
-
#fs_pwd ⇒ Object
Prints the current working directory.
-
#fs_readdir(path) ⇒ Object
Reads the entries of a directory.
-
#fs_readfile(path) ⇒ Object
Reads data from a file.
-
#fs_readlink(path) ⇒ Object
Reads the destination of a link.
-
#fs_rmdir(path) ⇒ Object
Removes an empty directory.
-
#fs_stat(path) ⇒ Object
Stats a file or directory.
-
#hexdump(path) ⇒ Object
Hexdumps a file.
-
#initialize(system, **kwargs) ⇒ SystemShell
constructor
Initializes the file-system shell.
-
#process_egid ⇒ Object
Prints the process'es EGID.
-
#process_env ⇒ Object
Prints the process'es environment variables.
-
#process_euid ⇒ Object
Prints the process'es EUID.
-
#process_getenv(name) ⇒ Object
Prints a specific environment variable from the process.
-
#process_gid ⇒ Object
Prints the process'es GID.
-
#process_kill(pid, signal = 'KILL') ⇒ Object
Kills a process.
-
#process_pid ⇒ Object
Prints the process'es PID.
-
#process_ppid ⇒ Object
Prints the process'es PPID.
-
#process_setegid(new_egid) ⇒ Object
Sets the process'es EGID.
-
#process_setenv(name_and_value) ⇒ Object
Sets a specific environment variable from the process.
-
#process_seteuid(new_euid) ⇒ Object
Sets the process'es EUID.
-
#process_setgid(new_gid) ⇒ Object
Sets the process'es GID.
-
#process_setsid(new_sid) ⇒ Object
Sets the process'es SID.
-
#process_setuid(new_uid) ⇒ Object
Sets the process'es UID.
-
#process_sid ⇒ Object
Prints the process'es SID.
-
#process_spawn(program, *arguments) ⇒ Object
Spawns a new process.
-
#process_uid ⇒ Object
Prints the process'es UID.
-
#process_unsetenv(name) ⇒ Object
Unsets a process environment variable.
-
#shell ⇒ Object
Spawns an interactive command sub-shell.
-
#shell_exec(command) ⇒ Object
Executes a shell command.
-
#sys_hostname ⇒ Object
Prints the system's hostname.
-
#sys_time ⇒ Object
Prints the system's current time.
Constructor Details
#initialize(system, **kwargs) ⇒ SystemShell
Initializes the file-system shell.
44 45 46 47 48 49 50 51 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 44 def initialize(system, **kwargs) super(**kwargs) @system = system @files = {} @next_file_id = 1 end |
Instance Method Details
#file_close(file_id) ⇒ Object
Closes an opened file.
479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 479 def file_close(file_id) file_id = file_id.to_i length = length.to_i if (file = @files[file_id]) file.close @files.delete(file_id) puts "Closed file ##{file_id} for #{file.path}" else print_error "unknown file id: #{file_id}" end end |
#file_open(path, mode = "r") ⇒ Object
Opens a file.
340 341 342 343 344 345 346 347 348 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 340 def file_open(path,mode="r") file = @system.fs.open(path,mode) file_id = @next_file_id @files[file_id] = file @next_file_id += 1 puts "Opened file ##{file_id} for #{file.path}" end |
#file_read(file_id, length) ⇒ Object
Reads data from an opened file.
430 431 432 433 434 435 436 437 438 439 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 430 def file_read(file_id,length) file_id = file_id.to_i length = length.to_i if (file = @files[file_id]) puts(file.read(length)) else print_error "unknown file id: #{file_id}" end end |
#file_seek(file_id, pos, whence = 'SEEK_SET') ⇒ Object
Seeks to a position within an opened file.
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 397 def file_seek(file_id,pos,whence='SEEK_SET') unless WHENCE.has_key?(whence) print_error "unknown file.seek whence value (#{whence}), must be #{WHENCE.keys.join(', ')}" return false end file_id = file_id.to_i pos = pos.to_i whence = WHENCE[whence] if (file = @files[file_id]) file.seek(pos,whence) puts file.pos else print_error "unknown file id: #{file_id}" end end |
#file_unlink(path) ⇒ Object
Removes a file.
180 181 182 183 184 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 180 def file_unlink(path) @system.fs.unlink(path) puts "Removed #{@system.fs.(path)}" end |
#file_write(file_id, data) ⇒ Object
Writes data from to an opened file.
456 457 458 459 460 461 462 463 464 465 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 456 def file_write(file_id,data) file_id = file_id.to_i length = length.to_i if (file = @files[file_id]) puts file.write(length) else print_error "unknown file id: #{file_id}" end end |
#files ⇒ Object
Lists opened files.
355 356 357 358 359 360 361 362 363 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 355 def files @files.each_with_index do |file,index| if file id = index + 1 puts " [#{id}] #{file.path}" end end end |
#fs_chdir(path) ⇒ Object
Changes the working directory.
65 66 67 68 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 65 def fs_chdir(path) @system.fs.chdir(path) puts "Current working directory is now: #{@system.fs.pwd}" end |
#fs_chgrp(group, path) ⇒ Object
Changes group ownership of a file or directory.
282 283 284 285 286 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 282 def fs_chgrp(group,path) @system.fs.chgrp(group,path) puts "Changed group ownership of #{@system.fs.(path)} to #{group}" end |
#fs_chmod(mode, path) ⇒ Object
Changes the permissions of a file or directory.
303 304 305 306 307 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 303 def fs_chmod(mode,path) @system.fs.chmod(mode.to_i(8),path) puts "Changed permissions on #{@system.fs.(path)} to #{mode}" end |
#fs_chown(user, path) ⇒ Object
Changes ownership of a file or directory.
261 262 263 264 265 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 261 def fs_chown(user,path) @system.fs.chown(user,path) puts "Changed ownership of #{@system.fs.(path)} to #{user}" end |
#fs_copy(src, dest) ⇒ Object
Copies a file to a destination.
162 163 164 165 166 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 162 def fs_copy(src,dest) @system.fs.copy(src,dest) puts "Copied #{@system.fs.(src)} -> #{@fs.(dest)}" end |
#fs_link(src, dest) ⇒ Object
Creates a link to a file or directory.
240 241 242 243 244 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 240 def fs_link(src,dest) @system.fs.link(src,dest) puts "Linked #{@system.fs.(src)} -> #{@fs.(dest)}" end |
#fs_mv(src, dest) ⇒ Object
Moves a file or directory.
219 220 221 222 223 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 219 def fs_mv(src,dest) @system.fs.move(src,dest) puts "Moved #{@system.fs.(src)} -> #{@fs.(dest)}" end |
#fs_pwd ⇒ Object
Prints the current working directory.
78 79 80 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 78 def fs_pwd puts "Current working directory: #{@system.fs.getcwd}" end |
#fs_readdir(path) ⇒ Object
Reads the entries of a directory.
126 127 128 129 130 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 126 def fs_readdir(path) @system.fs.readdir(path).each do |entry| puts entry end end |
#fs_readfile(path) ⇒ Object
Reads data from a file.
94 95 96 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 94 def fs_readfile(path) write(@system.fs.readfile(path)) end |
#fs_readlink(path) ⇒ Object
Reads the destination of a link.
110 111 112 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 110 def fs_readlink(path) puts @system.fs.readlink(path) end |
#fs_rmdir(path) ⇒ Object
Removes an empty directory.
198 199 200 201 202 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 198 def fs_rmdir(path) @system.fs.rmdir(path) puts "Removed directory #{@system.fs.(path)}" end |
#fs_stat(path) ⇒ Object
Stats a file or directory.
321 322 323 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 321 def fs_stat(path) stat = @system.fs.stat(path) end |
#hexdump(path) ⇒ Object
Hexdumps a file.
143 144 145 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 143 def hexdump(path) @system.fs.hexdump(path,self) end |
#process_egid ⇒ Object
Prints the process'es EGID.
608 609 610 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 608 def process_egid puts @system.process.getegid end |
#process_env ⇒ Object
Prints the process'es environment variables.
662 663 664 665 666 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 662 def process_env @system.process.env.each do |name,value| puts "#{name}=#{value}" end end |
#process_euid ⇒ Object
Prints the process'es EUID.
553 554 555 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 553 def process_euid puts @system.process.geteuid end |
#process_getenv(name) ⇒ Object
Prints a specific environment variable from the process.
680 681 682 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 680 def process_getenv(name) puts @system.process.getenv(name) end |
#process_gid ⇒ Object
Prints the process'es GID.
581 582 583 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 581 def process_gid puts @system.process.getgid end |
#process_kill(pid, signal = 'KILL') ⇒ Object
Kills a process.
731 732 733 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 731 def process_kill(pid,signal='KILL') @system.process.kill(pid.to_i,signal) end |
#process_pid ⇒ Object
Prints the process'es PID.
501 502 503 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 501 def process_pid puts @system.process.getpid end |
#process_ppid ⇒ Object
Prints the process'es PPID.
513 514 515 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 513 def process_ppid puts @system.process.getppid end |
#process_setegid(new_egid) ⇒ Object
Sets the process'es EGID.
623 624 625 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 623 def process_setegid(new_egid) @system.process.setegid(new_egid.to_i) end |
#process_setenv(name_and_value) ⇒ Object
Sets a specific environment variable from the process.
696 697 698 699 700 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 696 def process_setenv(name_and_value) name, value = name_and_value.split('=',2) @system.process.setenv(name,value) end |
#process_seteuid(new_euid) ⇒ Object
Sets the process'es EUID.
568 569 570 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 568 def process_seteuid(new_euid) @system.process.seteuid(new_euid.to_i) end |
#process_setgid(new_gid) ⇒ Object
Sets the process'es GID.
596 597 598 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 596 def process_setgid(new_gid) @system.process.setgid(new_gid.to_i) end |
#process_setsid(new_sid) ⇒ Object
Sets the process'es SID.
650 651 652 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 650 def process_setsid(new_sid) @system.process.setsid(new_sid.to_i) end |
#process_setuid(new_uid) ⇒ Object
Sets the process'es UID.
540 541 542 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 540 def process_setuid(new_uid) @system.process.setuid(new_uid.to_i) end |
#process_sid ⇒ Object
Prints the process'es SID.
635 636 637 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 635 def process_sid puts @system.process.getsid end |
#process_spawn(program, *arguments) ⇒ Object
Spawns a new process.
750 751 752 753 754 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 750 def process_spawn(program,*arguments) pid = @system.process.spawn(program,*arguments) puts "PID: #{pid}" end |
#process_uid ⇒ Object
Prints the process'es UID.
525 526 527 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 525 def process_uid puts @system.process.getuid end |
#process_unsetenv(name) ⇒ Object
Unsets a process environment variable.
714 715 716 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 714 def process_unsetenv(name) @system.process.unsetenv(name) end |
#shell ⇒ Object
Spawns an interactive command sub-shell.
780 781 782 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 780 def shell ShellShell.start(@system.shell) end |
#shell_exec(command) ⇒ Object
Executes a shell command.
768 769 770 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 768 def shell_exec(command) puts @system.shell.run(command) end |
#sys_hostname ⇒ Object
Prints the system's hostname.
804 805 806 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 804 def sys_hostname puts @system.hostname end |
#sys_time ⇒ Object
Prints the system's current time.
792 793 794 |
# File 'lib/ronin/post_ex/cli/system_shell.rb', line 792 def sys_time puts @system.time end |