Module: Ronin::Exploits::Helpers::FileBuilder

Defined in:
lib/ronin/exploits/helpers/file_builder.rb

Overview

Adds methods for building and managing files to be used with an exploit.

Parameters

  • output_dir (Ronin::Config::TMP_DIR) - Directory to save built file in.
  • output_file_name ('exploit') - Name of the file to build.
  • clean_output_files (true) - Specifies whether the built files will be deleted upon exit.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(obj) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ronin/exploits/helpers/file_builder.rb', line 44

def self.extended(obj)
  obj.instance_eval do
    # The output directory for file creation
    parameter :output_dir,
              type: String,
              default: Ronin::Config::TMP_DIR,
              description: 'Directory to save built file in'

    # The name of the output file
    parameter :output_file_name,
              type: String,
              default: 'exploit',
              description: 'Name of the file to build'

    # Whether or not to delete the output file at exit
    parameter :clean_output_files,
              type: true,
              default: true,
              description: 'Delete the file on exit'
  end
end

Instance Method Details

#build_file(name = self.output_file_name) {|file| ... } ⇒ String (protected)

Opens the file to be built.

Examples:

build_file do |file|
  file << 'some data'
end

Generate a specifically named file.

build_file('file1.xml') do |file|
  file << "<evil />"
end

Parameters:

  • name (String) (defaults to: self.output_file_name)

    Optional name of the file to build.

Yields:

  • (file)

    If a block is given, it will be passed the newly opened file. After the block has returned, the file will be closed.

Yield Parameters:

  • file (Tempfile, File)

    The newly opened file.

Returns:

  • (String)

    Path to the built file.


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ronin/exploits/helpers/file_builder.rb', line 106

def build_file(name=self.output_file_name,&block)
  path = nil

  if self.clean_output_files
    Tempfile.open(name,self.output_dir) do |file|
      path = file.path

      print_debug "Building file #{path} ..."
      block.call(file)
    end
  else
    name = File.expand_path(File.join('',name))
    path = File.join(self.output_dir,name)

    print_debug "Building file #{path} ..."
    File.open(self.output_file_path,'w',&block)
  end

  print_info "Built file #{path}"

  self.output_file_paths << path
  return path
end

#output_file_pathsSet

The paths of previously built files.

Returns:

  • (Set)

    The unique set of paths.

Since:

  • 1.0.0


74
75
76
# File 'lib/ronin/exploits/helpers/file_builder.rb', line 74

def output_file_paths
  @output_file_paths ||= Set[]
end