Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

msfconsole 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env ruby
  2. #
  3. # This user interface provides users with a command console interface to the
  4. # framework.
  5. #
  6. msfbase = __FILE__
  7. while File.symlink?(msfbase)
  8. msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
  9. end
  10. $:.unshift(File.join(File.expand_path(File.dirname(msfbase)), 'lib'))
  11. $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
  12. require 'rex'
  13. require 'msf/ui'
  14. require 'optparse'
  15. if(RUBY_PLATFORM =~ /mswin32/)
  16. $stderr.puts "[*] The msfconsole interface is not supported on the native Windows Ruby\n"
  17. $stderr.puts " interpreter. Things will break, exploits will fail, payloads will not\n"
  18. $stderr.puts " be handled correctly. Please use the msfweb 'console' or install \n"
  19. $stderr.puts " Cygwin or Linux in VMWare.\n\n"
  20. end
  21. class OptsConsole
  22. #
  23. # Return a hash describing the options.
  24. #
  25. def self.parse(args)
  26. options = {}
  27. opts = OptionParser.new do |opts|
  28. opts.banner = "Usage: msfconsole [options]"
  29. opts.separator ""
  30. opts.separator "Specific options:"
  31. opts.on("-d", "-d", "Execute the console as defanged") do
  32. options['Defanged'] = true
  33. end
  34. opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
  35. options['Resource'] = r
  36. end
  37. opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c|
  38. options['Config'] = c
  39. end
  40. opts.on("-m", "-m <directory>", "Specifies an additional module search path") do |m|
  41. options['ModulePath'] = m
  42. end
  43. # Boolean switch.
  44. opts.on("-v", "--version", "Show version") do |v|
  45. options['Version'] = true
  46. end
  47. opts.separator ""
  48. opts.separator "Common options:"
  49. opts.on_tail("-h", "--help", "Show this message") do
  50. puts opts
  51. exit
  52. end
  53. end
  54. opts.parse!(args)
  55. options
  56. end
  57. end
  58. options = OptsConsole.parse(ARGV)
  59. if (options['Version'])
  60. $stderr.puts 'Framework Version: ' + Msf::Framework::Version
  61. exit
  62. end
  63. begin
  64. Msf::Ui::Console::Driver.new(
  65. Msf::Ui::Console::Driver::DefaultPrompt,
  66. Msf::Ui::Console::Driver::DefaultPromptChar,
  67. options
  68. ).run
  69. rescue Interrupt
  70. end