2006-09-24 00:16:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
#
|
2007-03-24 06:14:12 +00:00
|
|
|
# This user interface provides users with a web-based interface to the framework
|
2006-09-24 00:16:23 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
msfbase = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
|
|
|
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
|
2007-03-24 06:14:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/base'
|
2006-09-27 02:48:03 +00:00
|
|
|
require 'rex'
|
2007-03-24 06:14:12 +00:00
|
|
|
require 'stringio'
|
|
|
|
|
2006-09-27 02:48:03 +00:00
|
|
|
|
2006-09-24 00:16:23 +00:00
|
|
|
|
2006-09-24 00:31:07 +00:00
|
|
|
msfroot = File.join(File.dirname(msfbase), 'data', 'msfweb')
|
|
|
|
Dir.chdir(msfroot)
|
|
|
|
|
|
|
|
msfserv = File.join('script', 'server')
|
2006-09-27 02:48:03 +00:00
|
|
|
|
|
|
|
# Declare the argument parser for msfweb
|
|
|
|
arguments = Rex::Parser::Arguments.new(
|
|
|
|
"-a" => [ true, "Bind to this IP address instead of loopback" ],
|
|
|
|
"-p" => [ true, "Bind to this port instead of 55555" ],
|
2006-09-27 03:08:09 +00:00
|
|
|
"-d" => [ false, "Daemonize the web server" ],
|
2007-03-24 06:50:43 +00:00
|
|
|
"-s" => [ false, "Automatically open the browser" ],
|
2006-09-27 02:48:03 +00:00
|
|
|
"-h" => [ false, "Help banner" ])
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
background = false
|
2007-03-24 06:50:43 +00:00
|
|
|
browser_start = false
|
2006-09-27 02:48:03 +00:00
|
|
|
|
|
|
|
# Parse command line arguments.
|
|
|
|
arguments.parse(ARGV) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-a"
|
|
|
|
opts['ServerHost'] = val
|
|
|
|
when "-p"
|
|
|
|
opts['ServerPort'] = val
|
|
|
|
when "-v"
|
|
|
|
opts['LogLevel'] = val
|
|
|
|
when "-d"
|
|
|
|
background = true
|
2007-03-24 06:50:43 +00:00
|
|
|
when "-s"
|
|
|
|
browser_start = true
|
2006-09-27 02:48:03 +00:00
|
|
|
when "-h"
|
|
|
|
print(
|
|
|
|
"\nUsage: msfweb <options>\n" +
|
|
|
|
arguments.usage)
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2007-03-24 06:14:12 +00:00
|
|
|
|
|
|
|
host = (opts['ServerHost'] || '127.0.0.1')
|
|
|
|
port = (opts['ServerPort'] || '55555')
|
|
|
|
|
|
|
|
|
|
|
|
# This is stupid, but we need to override the ARGV constant
|
|
|
|
|
|
|
|
ostderr = $stderr
|
|
|
|
$stderr = StringIO.new
|
|
|
|
|
|
|
|
ARGV = [
|
|
|
|
'-p', port,
|
|
|
|
'-b', host,
|
2007-03-24 23:10:38 +00:00
|
|
|
'-e', 'production',
|
2006-09-27 03:08:09 +00:00
|
|
|
(background ? '-d' : '')
|
2007-03-24 06:14:12 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
$stderr.close
|
|
|
|
$stderr = ostderr
|
|
|
|
|
2007-03-24 06:50:43 +00:00
|
|
|
$browser_url = "http://#{host}:#{port}/"
|
|
|
|
$browser_start = browser_start
|
2007-03-24 06:14:12 +00:00
|
|
|
|
|
|
|
$stderr.puts ""
|
2007-03-24 06:50:43 +00:00
|
|
|
$stderr.puts "[*] Starting msfweb v#{Msf::Framework::Version} on #{$browser_url}"
|
2007-03-24 06:14:12 +00:00
|
|
|
$stderr.puts ""
|
2006-09-24 00:16:23 +00:00
|
|
|
|
2007-03-24 06:14:12 +00:00
|
|
|
load(msfserv)
|
|
|
|
|