# # Ronin Exploits - A Ruby library for Ronin that provides exploitation and # payload crafting functionality. # # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # require 'ronin/controls/exceptions/not_implemented' require 'ronin/controls/exceptions/program_not_found' require 'ronin/ui/shell' module Ronin module Controls module Helpers module CommandExec # # @return [Hash] # The environment variables to use in the shell. # # @since 0.3.0 # def env @env ||= {} end # # Execute a given command with optional arguments. # # @param [String] command # The command to execute. # # @param [Array] arguments # The additional command-line arguments to use with the command. # # @since 0.3.0 # def exec(command,*arguments) raise(NotImplemented,"the exec method has not been implemented",caller) end # # Executes the specified _command_ with the given _arguments_, # and prints the output of the command. # # @param [String] command # The command to execute. # # @param [Array] arguments # The additional command-line arguments to use with the command. # # @return [nil] # # @since 0.3.0 # def sh(command,*args) puts exec(command,*args) end # # Changes the current working directory of the shell. # # @param [String] path # The new current directory to use. # # @return [String] # The new current directory. # # @since 0.3.0 # def cd(path) exec('cd',path) return path end # # @return [String] # The current working directory of the shell. # # @since 0.3.0 # def pwd exec('pwd').chomp end # # Lists the contents of a given directory or the current working # directory. # # @param [Array] arguments # Additional command-line arguments. # # @return [Array] # The contents of a directory. # # @since 0.3.0 # def ls(*arguments) exec('dir',*arguments).split(/\n\r?/) end # # Starts an interactive shell for running commands. # def shell UI::Shell.start(:prompt => '$') do |shell,line| sh(line) end end protected # # Raises a ProgramNotFound exception if a program could not be # found. # # @param [String, Symbol] name # The name of the program which could not be found. # # @since 0.3.0 # def program_not_found!(name) name = name.to_s raise(ProgramNotFound,"the program #{name.dump} was not found",caller) end end end end end