ronin-rb/ronin-exploits

View on GitHub
lib/ronin/exploits/mixins/build_dir.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true
#
# ronin-exploits - A Ruby library for ronin-rb that provides exploitation and
# payload crafting functionality.
#
# Copyright (c) 2007-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# ronin-exploits is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-exploits is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-exploits.  If not, see <https://www.gnu.org/licenses/>.
#

require 'tmpdir'
require 'fileutils'

module Ronin
  module Exploits
    module Mixins
      #
      # Sets up a temporary build directory for the exploit.
      #
      # @api public
      #
      module BuildDir
        # The build directory for the exploit.
        #
        # @return [String, nil]
        attr_reader :build_dir

        #
        # Sets {#build_dir} and then builds the exploit.
        #
        def perform_build
          exploit_name = self.class.id.tr('/','-')
          @build_dir   = Dir.mktmpdir("ronin-exploit-#{exploit_name}-")

          super
        end

        #
        # Cleans up the exploit and deletes the {#build_dir}.
        #
        def perform_cleanup
          super

          FileUtils.rm_r(@build_dir)
          @build_dir = nil
        end
      end
    end
  end
end