| 1 |
#!/usr/bin/env ruby |
|---|
| 2 |
# |
|---|
| 3 |
# This user interface listens on a port and provides clients that connect to |
|---|
| 4 |
# it with an msfconsole instance. The nice thing about this interface is that |
|---|
| 5 |
# it allows multiple clients to share one framework instance and thus makes it |
|---|
| 6 |
# possible for sessions to to be shared from a single vantage point. |
|---|
| 7 |
# |
|---|
| 8 |
|
|---|
| 9 |
msfbase = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ |
|---|
| 10 |
$:.unshift(File.join(File.dirname(msfbase), 'lib')) |
|---|
| 11 |
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB'] |
|---|
| 12 |
|
|---|
| 13 |
require 'msf/base' |
|---|
| 14 |
require 'msf/ui' |
|---|
| 15 |
|
|---|
| 16 |
# Declare the argument parser for msfd |
|---|
| 17 |
arguments = Rex::Parser::Arguments.new( |
|---|
| 18 |
"-a" => [ true, "Bind to this IP address instead of loopback" ], |
|---|
| 19 |
"-p" => [ true, "Bind to this port instead of 55554" ], |
|---|
| 20 |
"-f" => [ false, "Run the daemon in the foreground" ], |
|---|
| 21 |
"-h" => [ false, "Help banner" ]) |
|---|
| 22 |
|
|---|
| 23 |
opts = { 'RunInForeground' => true } |
|---|
| 24 |
foreground = false |
|---|
| 25 |
|
|---|
| 26 |
# Parse command line arguments. |
|---|
| 27 |
arguments.parse(ARGV) { |opt, idx, val| |
|---|
| 28 |
case opt |
|---|
| 29 |
when "-a" |
|---|
| 30 |
opts['ServerHost'] = val |
|---|
| 31 |
when "-p" |
|---|
| 32 |
opts['ServerPort'] = val |
|---|
| 33 |
when "-f" |
|---|
| 34 |
foreground = true |
|---|
| 35 |
when "-h" |
|---|
| 36 |
print( |
|---|
| 37 |
"\nUsage: #{File.basename(__FILE__)} <options>\n" + |
|---|
| 38 |
arguments.usage) |
|---|
| 39 |
exit |
|---|
| 40 |
end |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
# Create an instance of the framework |
|---|
| 44 |
$framework = Msf::Simple::Framework.create |
|---|
| 45 |
|
|---|
| 46 |
# Fork into the background if requested |
|---|
| 47 |
begin |
|---|
| 48 |
if (not foreground) |
|---|
| 49 |
exit(0) if Process.fork() |
|---|
| 50 |
end |
|---|
| 51 |
rescue ::NotImplementedError |
|---|
| 52 |
$stderr.puts "[*] Background mode is not available on this platform" |
|---|
| 53 |
end |
|---|
| 54 |
|
|---|
| 55 |
# Run the plugin instance in the foreground. |
|---|
| 56 |
$framework.plugins.load('msfd', opts).run |
|---|