Files
metasploit-gs/msfd
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
2.7 KiB
Ruby
Raw Normal View History

2005-12-17 06:46:23 +00:00
#!/usr/bin/env ruby
# -*- coding: binary -*-
2005-11-28 21:38:48 +00:00
#
2010-05-03 17:13:09 +00:00
# $Id$
#
2005-11-28 21:38:48 +00: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 17:13:09 +00:00
# $Revision$
#
2005-11-28 16:36:06 +00:00
msfbase = __FILE__
while File.symlink?(msfbase)
2013-09-30 13:47:53 -05:00
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
2012-02-04 00:32:37 -06:00
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
2012-04-15 23:35:38 -05:00
require 'msfenv'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
2005-11-28 16:36:06 +00:00
2021-01-13 11:51:16 +00:00
require 'rex/parser/arguments'
2005-11-28 16:38:13 +00:00
# Declare the argument parser for msfd
2005-11-28 16:36:06 +00:00
arguments = Rex::Parser::Arguments.new(
2013-09-30 13:47:53 -05:00
"-a" => [ true, "Bind to this IP address instead of loopback" ],
"-p" => [ true, "Bind to this port instead of 55554" ],
"-s" => [ false, "Use SSL" ],
"-f" => [ false, "Run the daemon in the foreground" ],
"-A" => [ true, "Specify list of hosts allowed to connect" ],
"-D" => [ true, "Specify list of hosts not allowed to connect" ],
2015-10-07 01:50:36 -05:00
"-q" => [ false, "Do not print the banner on startup" ],
2013-09-30 13:47:53 -05:00
"-h" => [ false, "Help banner" ])
2005-11-28 16:36:06 +00:00
2015-10-08 14:08:45 -05:00
opts = {
'RunInForeground' => true,
'DisableBanner' => false
}
2005-11-28 16:36:06 +00:00
foreground = false
# Parse command line arguments.
arguments.parse(ARGV) { |opt, idx, val|
2013-09-30 13:47:53 -05:00
case opt
when "-a"
opts['ServerHost'] = val
when "-p"
opts['ServerPort'] = val
when "-f"
foreground = true
when "-s"
opts['SSL'] = true
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
2015-10-07 01:50:36 -05:00
when "-q"
opts['DisableBanner'] = true
2013-09-30 13:47:53 -05:00
when "-h"
print(
"\nUsage: #{File.basename(__FILE__)} <options>\n" +
arguments.usage)
exit
end
2005-11-28 16:36:06 +00:00
}
2009-03-11 00:03:40 +00:00
$stderr.puts "[*] Initializing msfd..."
2005-11-28 16:36:06 +00:00
2009-03-11 00:03:40 +00:00
$stderr.puts "[*] Running msfd..."
# Fork into the background if requested
begin
2013-09-30 13:47:53 -05:00
if (not foreground)
exit(0) if Process.fork()
end
rescue ::NotImplementedError
2013-09-30 13:47:53 -05:00
$stderr.puts "[-] Background mode is not available on this platform"
end
2005-11-28 16:36:06 +00:00
# Create an instance of the framework
$framework = Msf::Simple::Framework.create
2005-11-28 21:38:48 +00:00
# Run the plugin instance in the foreground.
2009-01-08 05:04:26 +00:00
$framework.plugins.load('msfd', opts).run(opts)