Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 147 lines (114 sloc) 3.558 kb
8865806 @hmoore-r7 /usr/bin/ruby vs /usr/bin/env ruby
hmoore-r7 authored
1 #!/usr/bin/env ruby
514e760 implemented msfd as a plugin
Matt Miller authored
2 #
0e72894 @jduck more cleanups
authored
3 # $Id$
4 #
514e760 implemented msfd as a plugin
Matt Miller authored
5 # This user interface provides users with a command console interface to the
6 # framework.
7 #
0e72894 @jduck more cleanups
authored
8 # $Revision$
9 #
72ad97d fixed up encoding, made payload generation pimper
Matt Miller authored
10
beb0cc7 @hmoore-r7 Patch from Jonathan Steel to fix double-symlinks
hmoore-r7 authored
11 msfbase = __FILE__
12 while File.symlink?(msfbase)
13 msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
14 end
15
bdf8d06 @hmoore-r7 Load from the absolute, not relative path
hmoore-r7 authored
16 $:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
bfc32f4 Adds fastlib and lib/metasploit.fastlib to the include path
HD Moore authored
17 require 'fastlib'
4bcbdc5 @todb Cutting over rails3 to master.
todb authored
18 require 'msfenv'
bfc32f4 Adds fastlib and lib/metasploit.fastlib to the include path
HD Moore authored
19
7d2b2b1 @hmoore-r7 Fix up bad line removals
hmoore-r7 authored
20
bfc32f4 Adds fastlib and lib/metasploit.fastlib to the include path
HD Moore authored
21
271822d @hmoore-r7 Merged revisions 5386-5391 via svnmerge from
hmoore-r7 authored
22 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
9ba20c7 text user interface crap
Matt Miller authored
23
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
24 require 'optparse'
25
f09c67a @hmoore-r7 hdm.drink(0xc0ffee)
hmoore-r7 authored
26 if(RUBY_PLATFORM =~ /mswin32/)
55c2ce5 @hmoore-r7 Fit the text into the standard windows console
hmoore-r7 authored
27 $stderr.puts "[*] The msfconsole interface is not supported on the native Windows Ruby\n"
28 $stderr.puts " interpreter. Things will break, exploits will fail, payloads will not\n"
756e6d2 Remove unsupported msfweb interface. (fixes #503)
Mike Smith authored
29 $stderr.puts " be handled correctly. Please install Cygwin or use Linux in VMWare.\n\n"
3103a04 @hmoore-r7 Add a non-supported note about the Windows ruby interpreter
hmoore-r7 authored
30 end
31
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
32 class OptsConsole
33 #
34 # Return a hash describing the options.
35 #
36 def self.parse(args)
37 options = {}
38
39 opts = OptionParser.new do |opts|
40 opts.banner = "Usage: msfconsole [options]"
41
42 opts.separator ""
43 opts.separator "Specific options:"
44
279c0e3 defanged mode
Matt Miller authored
45 opts.on("-d", "-d", "Execute the console as defanged") do
46 options['Defanged'] = true
47 end
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
48
49 opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
ea0f4d2 @jlee-r7 allow multiple resource files on the command line
jlee-r7 authored
50 options['Resource'] ||= []
51 options['Resource'] << r
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
52 end
53
a1af22d applying a patch to enable easy output to file: ./msfconsole -o output.t...
Jonathan Cran authored
54 opts.on("-o", "-o <filename>", "Output to the specified file") do |o|
55 options['LocalOutput'] = o
56 end
57
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
58 opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c|
59 options['Config'] = c
60 end
61
5870837 ensure that module counts are reflected accurately, and add option to sp...
Matt Miller authored
62 opts.on("-m", "-m <directory>", "Specifies an additional module search path") do |m|
63 options['ModulePath'] = m
64 end
65
21b1945 @jlee-r7 add a commandline switch for loading plugins at startup
jlee-r7 authored
66 opts.on("-p", "-p <plugin>", "Load a plugin on startup") do |p|
67 options['Plugins'] ||= []
68 options['Plugins'] << p
69 end
70
f5f7f55 @hmoore-r7 Allow a database config file to be specified
hmoore-r7 authored
71 opts.on("-y", "--yaml <database.yml>", "Specify a YAML file containing database settings") do |m|
72 options['DatabaseYAML'] = m
73 end
74
afe3168 @hmoore-r7 Enable additional migration-path parameters, use a temporary directory t...
hmoore-r7 authored
75 opts.on("-M", "--migration-path <dir>", "Specify a directory containing additional DB migrations") do |m|
76 options['DatabaseMigrationPaths'] ||= []
77 options['DatabaseMigrationPaths'] << m
78 end
79
f5f7f55 @hmoore-r7 Allow a database config file to be specified
hmoore-r7 authored
80 opts.on("-e", "--environment <production|development>", "Specify the database environment to load from the YAML") do |m|
81 options['DatabaseEnv'] = m
82 end
a2e6f0e @jduck add -q option to suppress banner, improve -n warning
authored
83
84 # Boolean switches
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
85 opts.on("-v", "--version", "Show version") do |v|
86 options['Version'] = true
87 end
0e72894 @jduck more cleanups
authored
88
35fcf8c @hmoore-r7 Swap around rbreadline - load it by default, but also allow the old read...
hmoore-r7 authored
89 opts.on("-L", "--real-readline", "Use the system Readline library instead of RbReadline") do |v|
90 options['RealReadline'] = true
91 end
0e72894 @jduck more cleanups
authored
92
53e2a01 @jduck add -n (disable database) option for msfconsole, gives 33% startup time ...
authored
93 opts.on("-n", "--no-database", "Disable database support") do |v|
94 options['DisableDatabase'] = true
95 end
96
a2e6f0e @jduck add -q option to suppress banner, improve -n warning
authored
97 opts.on("-q", "--quiet", "Do not print the banner on start up") do |v|
98 options['DisableBanner'] = true
99 end
100
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
101 opts.separator ""
102 opts.separator "Common options:"
103
104 opts.on_tail("-h", "--help", "Show this message") do
105 puts opts
106 exit
107 end
108 end
109
d769b45 @jlee-r7 handle invalid options, fixes 542
jlee-r7 authored
110 begin
111 opts.parse!(args)
112 rescue OptionParser::InvalidOption
113 puts "Invalid option, try -h for usage"
114 exit
115 end
aed112f a few trivial whitespace things
kris authored
116
117 options
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
118 end
119 end
120
121 options = OptsConsole.parse(ARGV)
b44a2a1 @jduck delay framework load until after option parsing
authored
122
123 #
124 # NOTE: we don't require this until down here since we may not need it
125 # when processing certain options (currently only -h)
126 #
4199f20 @jduck delay loading rex too
authored
127 require 'rex'
b44a2a1 @jduck delay framework load until after option parsing
authored
128 require 'msf/ui'
4199f20 @jduck delay loading rex too
authored
129
b44a2a1 @jduck delay framework load until after option parsing
authored
130 #
131 # Everything below this line requires the framework.
132 #
133
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
134 if (options['Version'])
135 $stderr.puts 'Framework Version: ' + Msf::Framework::Version
136 exit
137 end
9ba20c7 text user interface crap
Matt Miller authored
138
6063908 @hmoore-r7 Catch ugly Interrupt error in msfconsole, fixed tabs in simpleclient
hmoore-r7 authored
139 begin
3aa4563 @hmoore-r7 Added -c, -r, -v options to msfconsole
hmoore-r7 authored
140 Msf::Ui::Console::Driver.new(
141 Msf::Ui::Console::Driver::DefaultPrompt,
142 Msf::Ui::Console::Driver::DefaultPromptChar,
143 options
144 ).run
6063908 @hmoore-r7 Catch ugly Interrupt error in msfconsole, fixed tabs in simpleclient
hmoore-r7 authored
145 rescue Interrupt
b3ecce5 @jlee-r7 look for files in absolute paths. fixes #252
jlee-r7 authored
146 end
Something went wrong with that request. Please try again.