Changeset 6089

Show
Ignore:
Timestamp:
01/07/09 21:04:26 (6 months ago)
Author:
kris
Message:

Adding host-based access control to msfd

Location:
framework3/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • framework3/trunk/msfd

    r6027 r6089  
    2020        "-s" => [ false, "Use SSL"                                              ], 
    2121        "-f" => [ false, "Run the daemon in the foreground"                     ], 
     22        "-A" => [ true,  "Specify list of hosts allowed to connect"             ], 
     23        "-D" => [ true,  "Specify list of hosts not allowed to connect"         ], 
    2224        "-h" => [ false, "Help banner"                                          ]) 
    2325 
     
    3638                when "-s" 
    3739                        opts['SSL'] = true 
     40                when "-A" 
     41                        begin 
     42                                opts['HostsAllowed'] = val.split(',').map { |a| 
     43                                        Rex::Socket.resolv_nbo(a) 
     44                                } 
     45                        rescue 
     46                                $stderr.puts "Bad argument for -A: #{$!}" 
     47                                exit 
     48                        end 
     49                when "-D" 
     50                        begin 
     51                                opts['HostsDenied'] = val.split(',').map { |a| 
     52                                        Rex::Socket.resolv_nbo(a) 
     53                                } 
     54                        rescue 
     55                                $stderr.puts "Bad argument for -D: #{$!}" 
     56                                exit 
     57                        end 
    3858                when "-h" 
    3959                        print( 
     
    5777 
    5878# Run the plugin instance in the foreground. 
    59 $framework.plugins.load('msfd', opts).run 
     79$framework.plugins.load('msfd', opts).run(opts) 
  • framework3/trunk/plugins/msfd.rb

    r6027 r6089  
    5050        #       ``run'' method. 
    5151        # 
     52        # HostsAllowed 
     53        # 
     54        #       List of hosts (in NBO) allowed to use msfd 
     55        # 
     56        # HostsDenied 
     57        # 
     58        #       List of hosts (in NBO) not allowed to use msfd 
     59        # 
    5260        def initialize(framework, opts) 
    5361                super 
     
    6371                if (opts['RunInForeground'] != true) 
    6472                        Thread.new { 
    65                                 run 
     73                                run(opts) 
    6674                        } 
    6775                end 
     
    8694        # threads to handle the console interface for each client. 
    8795        # 
    88         def run 
     96        def run(opts={}) 
    8997                begin 
    9098                        client = server.accept 
     99 
     100                        addr = Rex::Socket.resolv_nbo(client.getpeername[1]) 
     101 
     102                        if opts['HostsAllowed'] and 
     103                           not opts['HostsAllowed'].find { |x| x == addr } 
     104                                client.close 
     105                                next 
     106                        end 
     107 
     108                        if opts['HostsDenied'] and 
     109                           opts['HostsDenied'].find { |x| x == addr } 
     110                                client.close 
     111                                next 
     112                        end 
    91113 
    92114                        # Spawn a thread for the client connection