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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/env ruby
  2. # -*- coding: binary -*-
  3. #
  4. # $Id$
  5. #
  6. # This user interface provides users with a command console interface to the
  7. # framework.
  8. #
  9. # $Revision$
  10. #
  11. msfbase = __FILE__
  12. while File.symlink?(msfbase)
  13. msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
  14. end
  15. @msfbase_dir = File.expand_path(File.dirname(msfbase))
  16. $:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
  17. require 'fastlib'
  18. require 'msfenv'
  19. $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
  20. require 'optparse'
  21. if(RUBY_PLATFORM =~ /mswin32/)
  22. $stderr.puts "[*] The msfconsole interface is not supported on the native Windows Ruby\n"
  23. $stderr.puts " interpreter. Things will break, exploits will fail, payloads will not\n"
  24. $stderr.puts " be handled correctly. Please install Cygwin or use Linux in VMWare.\n\n"
  25. end
  26. class OptsConsole
  27. #
  28. # Return a hash describing the options.
  29. #
  30. def self.parse(args)
  31. options = {
  32. 'DeferModuleLoads' => true
  33. }
  34. opts = OptionParser.new do |opts|
  35. opts.banner = "Usage: msfconsole [options]"
  36. opts.separator ""
  37. opts.separator "Specific options:"
  38. opts.on("-d", "-d", "Execute the console as defanged") do
  39. options['Defanged'] = true
  40. end
  41. opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
  42. options['Resource'] ||= []
  43. options['Resource'] << r
  44. end
  45. opts.on("-o", "-o <filename>", "Output to the specified file") do |o|
  46. options['LocalOutput'] = o
  47. end
  48. opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c|
  49. options['Config'] = c
  50. end
  51. opts.on("-m", "-m <directory>", "Specifies an additional module search path") do |m|
  52. options['ModulePath'] = m
  53. end
  54. opts.on("-p", "-p <plugin>", "Load a plugin on startup") do |p|
  55. options['Plugins'] ||= []
  56. options['Plugins'] << p
  57. end
  58. opts.on("-y", "--yaml <database.yml>", "Specify a YAML file containing database settings") do |m|
  59. options['DatabaseYAML'] = m
  60. end
  61. opts.on("-M", "--migration-path <dir>", "Specify a directory containing additional DB migrations") do |m|
  62. options['DatabaseMigrationPaths'] ||= []
  63. options['DatabaseMigrationPaths'] << m
  64. end
  65. opts.on("-e", "--environment <production|development>", "Specify the database environment to load from the YAML") do |m|
  66. options['DatabaseEnv'] = m
  67. end
  68. # Boolean switches
  69. opts.on("-v", "--version", "Show version") do |v|
  70. options['Version'] = true
  71. end
  72. opts.on("-L", "--real-readline", "Use the system Readline library instead of RbReadline") do |v|
  73. options['RealReadline'] = true
  74. end
  75. opts.on("-n", "--no-database", "Disable database support") do |v|
  76. options['DisableDatabase'] = true
  77. end
  78. opts.on("-q", "--quiet", "Do not print the banner on start up") do |v|
  79. options['DisableBanner'] = true
  80. end
  81. opts.on("-a", "--ask", "Ask before exiting Metasploit or accept 'exit -y'") do |v|
  82. options['ConfirmExit'] = true
  83. end
  84. opts.on("-x", "-x <command>", "Execute the specified string as console commands (use ; for multiples)") do |s|
  85. options['XCommands'] ||= []
  86. options['XCommands'] += s.split(/\s*;\s*/)
  87. end
  88. opts.separator ""
  89. opts.separator "Common options:"
  90. opts.on_tail("-h", "--help", "Show this message") do
  91. puts opts
  92. exit
  93. end
  94. end
  95. begin
  96. opts.parse!(args)
  97. rescue OptionParser::InvalidOption
  98. puts "Invalid option, try -h for usage"
  99. exit
  100. end
  101. options
  102. end
  103. end
  104. options = OptsConsole.parse(ARGV)
  105. #
  106. # NOTE: we don't require this until down here since we may not need it
  107. # when processing certain options (currently only -h)
  108. #
  109. require 'rex'
  110. require 'msf/ui'
  111. #
  112. # Everything below this line requires the framework.
  113. #
  114. if (options['Version'])
  115. $stderr.puts 'Framework Version: ' + Msf::Framework::Version
  116. exit
  117. end
  118. begin
  119. Msf::Ui::Console::Driver.new(
  120. Msf::Ui::Console::Driver::DefaultPrompt,
  121. Msf::Ui::Console::Driver::DefaultPromptChar,
  122. options
  123. ).run
  124. rescue Interrupt
  125. end