2005-12-17 07:46:23 +01:00
|
|
|
#!/usr/bin/env ruby
|
2005-11-28 22:38:48 +01:00
|
|
|
#
|
2010-05-03 19:13:09 +02:00
|
|
|
# $Id$
|
|
|
|
#
|
2005-11-28 22:38:48 +01:00
|
|
|
# This user interface listens on a port and provides clients that connect to
|
|
|
|
# it with an msfconsole instance. The nice thing about this interface is that
|
|
|
|
# it allows multiple clients to share one framework instance and thus makes it
|
|
|
|
# possible for sessions to to be shared from a single vantage point.
|
|
|
|
#
|
2010-05-03 19:13:09 +02:00
|
|
|
# $Revision$
|
|
|
|
#
|
2005-11-28 17:36:06 +01:00
|
|
|
|
2009-01-30 07:27:10 +01:00
|
|
|
msfbase = __FILE__
|
|
|
|
while File.symlink?(msfbase)
|
|
|
|
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
|
|
|
end
|
|
|
|
|
2006-07-31 17:36:08 +02:00
|
|
|
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
|
2008-02-02 22:29:46 +01:00
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2005-11-28 17:36:06 +01:00
|
|
|
|
|
|
|
require 'msf/base'
|
|
|
|
require 'msf/ui'
|
|
|
|
|
2005-11-28 17:38:13 +01:00
|
|
|
# Declare the argument parser for msfd
|
2005-11-28 17:36:06 +01:00
|
|
|
arguments = Rex::Parser::Arguments.new(
|
|
|
|
"-a" => [ true, "Bind to this IP address instead of loopback" ],
|
|
|
|
"-p" => [ true, "Bind to this port instead of 55554" ],
|
2008-12-20 00:18:39 +01:00
|
|
|
"-s" => [ false, "Use SSL" ],
|
2005-11-28 17:52:05 +01:00
|
|
|
"-f" => [ false, "Run the daemon in the foreground" ],
|
2009-01-08 06:04:26 +01:00
|
|
|
"-A" => [ true, "Specify list of hosts allowed to connect" ],
|
|
|
|
"-D" => [ true, "Specify list of hosts not allowed to connect" ],
|
2005-11-28 17:36:06 +01:00
|
|
|
"-h" => [ false, "Help banner" ])
|
|
|
|
|
2005-11-28 22:38:48 +01:00
|
|
|
opts = { 'RunInForeground' => true }
|
2005-11-28 17:36:06 +01:00
|
|
|
foreground = false
|
|
|
|
|
|
|
|
# Parse command line arguments.
|
|
|
|
arguments.parse(ARGV) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-a"
|
|
|
|
opts['ServerHost'] = val
|
|
|
|
when "-p"
|
|
|
|
opts['ServerPort'] = val
|
|
|
|
when "-f"
|
|
|
|
foreground = true
|
2008-12-20 00:18:39 +01:00
|
|
|
when "-s"
|
|
|
|
opts['SSL'] = true
|
2009-01-08 06:04:26 +01:00
|
|
|
when "-A"
|
|
|
|
begin
|
|
|
|
opts['HostsAllowed'] = val.split(',').map { |a|
|
|
|
|
Rex::Socket.resolv_nbo(a)
|
|
|
|
}
|
|
|
|
rescue
|
|
|
|
$stderr.puts "Bad argument for -A: #{$!}"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
when "-D"
|
|
|
|
begin
|
|
|
|
opts['HostsDenied'] = val.split(',').map { |a|
|
|
|
|
Rex::Socket.resolv_nbo(a)
|
|
|
|
}
|
|
|
|
rescue
|
|
|
|
$stderr.puts "Bad argument for -D: #{$!}"
|
|
|
|
exit
|
|
|
|
end
|
2005-11-28 17:36:06 +01:00
|
|
|
when "-h"
|
|
|
|
print(
|
|
|
|
"\nUsage: #{File.basename(__FILE__)} <options>\n" +
|
|
|
|
arguments.usage)
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2009-03-11 01:03:40 +01:00
|
|
|
$stderr.puts "[*] Initializing msfd..."
|
|
|
|
|
2005-11-28 17:36:06 +01:00
|
|
|
# Create an instance of the framework
|
|
|
|
$framework = Msf::Simple::Framework.create
|
|
|
|
|
2009-03-11 01:03:40 +01:00
|
|
|
$stderr.puts "[*] Running msfd..."
|
|
|
|
|
2007-02-26 19:45:12 +01:00
|
|
|
# Fork into the background if requested
|
|
|
|
begin
|
|
|
|
if (not foreground)
|
|
|
|
exit(0) if Process.fork()
|
|
|
|
end
|
|
|
|
rescue ::NotImplementedError
|
2009-03-11 01:10:27 +01:00
|
|
|
$stderr.puts "[-] Background mode is not available on this platform"
|
2007-02-26 19:45:12 +01:00
|
|
|
end
|
2005-11-28 17:36:06 +01:00
|
|
|
|
2005-11-28 22:38:48 +01:00
|
|
|
# Run the plugin instance in the foreground.
|
2009-01-08 06:04:26 +01:00
|
|
|
$framework.plugins.load('msfd', opts).run(opts)
|