Class: Ronin::PostEx::System::FS
- Defined in:
- lib/ronin/post_ex/system/fs.rb
Overview
Provides access to a system's a File System (FS).
Supported API Methods
The File System resource uses the following post-exploitation methods, defined by the Resource#session object:
fs_getcwd() -> String
fs_chdir(path : String)
fs_readlink(path : String) -> String
fs_readdir(path : String) -> Array[String]
fs_glob(pattern : String) -> Array[String]
fs_mktemp(basename : String) -> String
fs_mkdir(new_path : String)
fs_copy(src : String, dest : String)
fs_unlink(path : String)
fs_rmdir(path : String)
fs_move(src : String, dest : String)
fs_link(src : String, dest : String)
fs_chgrp(group : String, path : String)
fs_chown(user : String, path : String)
fs_chmod(mode : Integer, path : String)
fs_stat(path : String) => Hash[Symbol, Object] | nil
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#chdir(path) ⇒ String
Changes the current working directory.
-
#chgrp(group, path) ⇒ true
Changes group ownership on one or more files or directories.
-
#chmod(mode, path) ⇒ true
Changes permissions on one or more file or directory.
-
#chown(owner, path) ⇒ true
Changes ownership of a file or directory.
-
#copy(path, new_path) ⇒ true
Copies a file.
-
#directory?(path) ⇒ Boolean
Tests whether a directory exists.
-
#exists?(path) ⇒ Boolean
Tests whether a file or directory exists.
-
#expand_path(path) ⇒ String
Joins the path with the current working directory.
-
#file?(path) ⇒ Boolean
Tests whether a file exists.
-
#getcwd ⇒ String
(also: #getwd, #pwd)
Gets the current working directory.
-
#glob(pattern) {|path| ... } ⇒ String+
Searches the file-system for matching paths.
-
#hexdump(path, output = STDOUT) ⇒ nil
Hexdumps the contents of a file.
-
#link(path, new_path) ⇒ true
Creates a symbolic link.
-
#mkdir(path) ⇒ true
Creates a directory.
-
#move(path, new_path) ⇒ true
(also: #rename)
Moves a file or directory.
-
#open(path, mode = 'r') {|file| ... } ⇒ RemoteFile?
Opens a file for reading.
-
#pipe?(path) ⇒ Boolean
Tests whether a FIFO pipe exists.
-
#readdir(path) ⇒ RemoteDir
Opens a directory for reading.
-
#readfile(path) ⇒ String
Reads the full contents of a file.
-
#readlink(path) ⇒ String
Reads the destination of a link.
-
#rmdir(path) ⇒ true
Removes a directory.
-
#socket?(path) ⇒ Boolean
Tests whether a UNIX socket exists.
-
#stat(path) ⇒ RemoteFile::Stat
Gathers statistics on a file or directory.
-
#tmpfile(basename) {|tempfile| ... } ⇒ RemoteFile?
Opens a tempfile.
-
#touch(path) ⇒ nil
Touches a file.
-
#unlink(path) ⇒ true
(also: #rm)
Unlinks a file.
-
#write(path, data) ⇒ nil
Writes data to a file.
-
#zero?(path) ⇒ Boolean
(also: #empty?)
Tests whether a file is empty.
Methods inherited from Resource
#initialize, #interact, #supports, #supports?
Constructor Details
This class inherits a constructor from Ronin::PostEx::Resource
Instance Method Details
#chdir(path) ⇒ String
May call the fs_chdir
method, if defined by the Resource#session
object.
Changes the current working directory.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ronin/post_ex/system/fs.rb', line 93 def chdir(path) path = (path) old_cwd = @cwd @cwd = if @session.respond_to?(:fs_chdir) @session.fs_chdir(path) else path end if block_given? yield @cwd chdir(old_cwd) end return @cwd end |
#chgrp(group, path) ⇒ true
Requires the fs_chgrp
method be defined by the Resource#session object.
Changes group ownership on one or more files or directories.
490 491 492 493 |
# File 'lib/ronin/post_ex/system/fs.rb', line 490 def chgrp(group,path) @session.fs_chgrp(group,(path)) return true end |
#chmod(mode, path) ⇒ true
Requires the fs_chmod
method be defined by the Resource#session object.
Changes permissions on one or more file or directory.
514 515 516 517 |
# File 'lib/ronin/post_ex/system/fs.rb', line 514 def chmod(mode,path) @session.fs_chmod(mode,(path)) return true end |
#chown(owner, path) ⇒ true
Requires the fs_chown
method be defined by the Resource#session object.
Changes ownership of a file or directory.
462 463 464 465 466 467 468 469 |
# File 'lib/ronin/post_ex/system/fs.rb', line 462 def chown(owner,path) user, group = owner chgrp(group,path) if group @session.fs_chown(user,(path)) return true end |
#copy(path, new_path) ⇒ true
Requires the fs_copy
method be defined by the Resource#session object.
Copies a file.
353 354 355 356 |
# File 'lib/ronin/post_ex/system/fs.rb', line 353 def copy(path,new_path) @session.fs_copy((path),(new_path)) return true end |
#directory?(path) ⇒ Boolean
Tests whether a directory exists.
582 583 584 585 586 587 588 |
# File 'lib/ronin/post_ex/system/fs.rb', line 582 def directory?(path) begin stat(path).directory? rescue Errno::ENOENT return false end end |
#exists?(path) ⇒ Boolean
Tests whether a file or directory exists.
545 546 547 548 549 550 551 552 |
# File 'lib/ronin/post_ex/system/fs.rb', line 545 def exists?(path) begin stat(path) return true rescue Errno::ENOENT return false end end |
#expand_path(path) ⇒ String
Joins the path with the current working directory.
121 122 123 124 125 126 127 |
# File 'lib/ronin/post_ex/system/fs.rb', line 121 def (path) if (@cwd && path[0,1] != '/') ::File.(::File.join(@cwd,path)) else path end end |
#file?(path) ⇒ Boolean
Tests whether a file exists.
564 565 566 567 568 569 570 |
# File 'lib/ronin/post_ex/system/fs.rb', line 564 def file?(path) begin stat(path).file? rescue Errno::ENOENT return false end end |
#getcwd ⇒ String Also known as: getwd, pwd
May call the fs_getcwd
method, if defined by the Resource#session
object.
Gets the current working directory.
68 69 70 71 72 73 74 |
# File 'lib/ronin/post_ex/system/fs.rb', line 68 def getcwd if @session.respond_to?(:fs_getcwd) @cwd = @session.fs_getcwd end return @cwd end |
#glob(pattern) {|path| ... } ⇒ String+
Requires the fs_glob
method be defined by the Resource#session object.
Searches the file-system for matching paths.
213 214 215 216 217 218 219 |
# File 'lib/ronin/post_ex/system/fs.rb', line 213 def glob(pattern,&block) path = (pattern) paths = @session.fs_glob(pattern) paths.each(&block) if block return paths end |
#hexdump(path, output = STDOUT) ⇒ nil
Hexdumps the contents of a file.
261 262 263 |
# File 'lib/ronin/post_ex/system/fs.rb', line 261 def hexdump(path,output=STDOUT) open(path) { |file| Hexdump.dump(file,output: output) } end |
#link(path, new_path) ⇒ true
Requires the fs_link
method be defined by the Resource#session object.
Creates a symbolic link.
435 436 437 438 |
# File 'lib/ronin/post_ex/system/fs.rb', line 435 def link(path,new_path) @session.fs_link(path,new_path) return true end |
#mkdir(path) ⇒ true
Requires the fs_mkdir
method be defined by the Resource#session object.
Creates a directory.
332 333 334 335 |
# File 'lib/ronin/post_ex/system/fs.rb', line 332 def mkdir(path) @session.fs_mkdir(path) return true end |
#move(path, new_path) ⇒ true Also known as: rename
Requires the fs_move
method be defined by the Resource#session object.
Moves a file or directory.
412 413 414 415 |
# File 'lib/ronin/post_ex/system/fs.rb', line 412 def move(path,new_path) @session.fs_move((path),(new_path)) return true end |
#open(path, mode = 'r') {|file| ... } ⇒ RemoteFile?
Opens a file for reading.
245 246 247 |
# File 'lib/ronin/post_ex/system/fs.rb', line 245 def open(path,mode='r',&block) RemoteFile.open(@session,(path),mode,&block) end |
#pipe?(path) ⇒ Boolean
Tests whether a FIFO pipe exists.
600 601 602 603 604 605 606 |
# File 'lib/ronin/post_ex/system/fs.rb', line 600 def pipe?(path) begin stat(path).pipe? rescue Errno::ENOENT return false end end |
#readdir(path) ⇒ RemoteDir
Requires the fs_readdir
method be defined by the Resource#session
object.
Opens a directory for reading.
178 179 180 181 182 183 |
# File 'lib/ronin/post_ex/system/fs.rb', line 178 def readdir(path) path = (path) entries = @session.fs_readdir(path) return RemoteDir.new(path,entries) end |
#readfile(path) ⇒ String
Requires the fs_readfile
method be defined by the Resource#session
object.
Reads the full contents of a file.
142 143 144 |
# File 'lib/ronin/post_ex/system/fs.rb', line 142 def readfile(path) @session.fs_readfile(path) end |
#readlink(path) ⇒ String
Requires the fs_readlink
method be defined by the Resource#session
object.
Reads the destination of a link.
160 161 162 |
# File 'lib/ronin/post_ex/system/fs.rb', line 160 def readlink(path) @session.fs_readlink(path) end |
#rmdir(path) ⇒ true
Requires the fs_rmdir
method be defined by the Resource#session object.
Removes a directory.
391 392 393 394 |
# File 'lib/ronin/post_ex/system/fs.rb', line 391 def rmdir(path) @session.fs_rmdir((path)) return true end |
#socket?(path) ⇒ Boolean
Tests whether a UNIX socket exists.
618 619 620 621 622 623 624 |
# File 'lib/ronin/post_ex/system/fs.rb', line 618 def socket?(path) begin stat(path).socket? rescue Errno::ENOENT return false end end |
#stat(path) ⇒ RemoteFile::Stat
Gathers statistics on a file or directory.
531 532 533 |
# File 'lib/ronin/post_ex/system/fs.rb', line 531 def stat(path) RemoteFile::Stat.new(@session,(path)) end |
#tmpfile(basename) {|tempfile| ... } ⇒ RemoteFile?
Requires the fs_mktemp
method be defined by the Resource#session object.
Opens a tempfile.
315 316 317 |
# File 'lib/ronin/post_ex/system/fs.rb', line 315 def tmpfile(basename,&block) open(@session.fs_mktemp(basename),&block) end |
#touch(path) ⇒ nil
Touches a file.
290 291 292 |
# File 'lib/ronin/post_ex/system/fs.rb', line 290 def touch(path) open(path) { |file| file << '' } end |
#unlink(path) ⇒ true Also known as: rm
Requires the fs_unlink
method be defined by the Resource#session object.
Unlinks a file.
371 372 373 374 |
# File 'lib/ronin/post_ex/system/fs.rb', line 371 def unlink(path) @session.fs_unlink((path)) return true end |
#write(path, data) ⇒ nil
Writes data to a file.
277 278 279 |
# File 'lib/ronin/post_ex/system/fs.rb', line 277 def write(path,data) open(path) { |file| file.write(data) } end |
#zero?(path) ⇒ Boolean Also known as: empty?
Tests whether a file is empty.
636 637 638 639 640 641 642 |
# File 'lib/ronin/post_ex/system/fs.rb', line 636 def zero?(path) begin stat(path).zero? rescue Errno::ENOENT return false end end |