Module: PWN::Plugins::FileFu

Defined in:
lib/pwn/plugins/file_fu.rb

Overview

This plugin is primarily used for interacting with files and directories in addition to the capabilities already built within the File and FileUtils built-in ruby classes (e.g. contains an easy to use recursion method that uses yield to interact with each entry on the fly).

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



51
52
53
54
55
# File 'lib/pwn/plugins/file_fu.rb', line 51

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.helpObject

Display Usage for this Module



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pwn/plugins/file_fu.rb', line 59

public_class_method def self.help
  puts "USAGE:
    #{self}.recurse_dir(dir_path: 'optional path to dir defaults to .') {|entry| puts entry}

    #{self}.untar_gz_file(
      tar_gz_file: 'required - path to .tar.gz file',
      destination: 'required - destination folder to save extracted contents'
    )

    #{self}.authors
  "
end

.recurse_dir(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::FileFu.recurse_dir(

dir_path: 'optional path to dir defaults to .'

)



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pwn/plugins/file_fu.rb', line 19

public_class_method def self.recurse_dir(opts = {})
  if opts[:dir_path].nil?
    dir_path = '.'
  else
    dir_path = opts[:dir_path].to_s.scrub if File.directory?(opts[:dir_path].to_s.scrub)
    raise "PWN Error: Invalid Directory #{dir_path}" if dir_path.nil?
  end
  # Execute this like this:
  # recurse_dir(:dir_path => 'path to dir') {|entry| puts entry}
  Dir.glob("#{dir_path}/**/*").each { |entry| yield Shellwords.escape(entry) }
rescue StandardError => e
  raise e
end

.untar_gz_file(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::FileFu.untar_gz_file(

tar_gz_file: 'required - path to .tar.gz file',
destination: 'required - destination folder to save extracted contents'

)



39
40
41
42
43
44
45
46
47
# File 'lib/pwn/plugins/file_fu.rb', line 39

public_class_method def self.untar_gz_file(opts = {})
  tar_gz_file = opts[:tar_gz_file].to_s.scrub if File.exist?(opts[:tar_gz_file].to_s.scrub)
  destination = opts[:destination].to_s.scrub if Dir.exist?(File.dirname(tar_gz_file))
  puts `tar -xzvf #{tar_gz_file} -C #{destination}`

  nil
rescue StandardError => e
  raise e
end