Lucene search
K

SOCKS Proxy Server

🗓️ 23 Sep 2020 17:41:10Reported by sf <[email protected]>, Spencer McIntyre, surefireType 
metasploit
 metasploit
🔗 www.rapid7.com👁 744 Views

This module provides a SOCKS proxy server that uses Metasploit routing to relay connections

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary
  include Msf::Auxiliary::Report
  include Msf::Exploit::Remote::SocketServer

  def initialize
    super(
      'Name' => 'SOCKS Proxy Server',
      'Description' => %q{
        This module provides a SOCKS proxy server that uses the builtin Metasploit routing to relay connections.
      },
      'Author' => [ 'sf', 'Spencer McIntyre', 'surefire' ],
      'License' => MSF_LICENSE,
      'Actions' => [
        [ 'Proxy', { 'Description' => 'Run a SOCKS proxy server' } ]
      ],
      'PassiveActions' => [
        'Proxy'
      ],
      'DefaultAction' => 'Proxy'
    )

    register_options([
      OptPort.new('SRVPORT', [true, 'The port to listen on', 1080]),
      OptEnum.new('VERSION', [ true, 'The SOCKS version to use', '5', %w[4a 5] ]),
      OptString.new('USERNAME', [false, 'Proxy username for SOCKS5 listener'], conditions: %w[VERSION == 5]),
      OptString.new('PASSWORD', [false, 'Proxy password for SOCKS5 listener'], conditions: %w[VERSION == 5]),
    ])
  end

  def setup
    super
    @mutex = ::Mutex.new
    @socks_proxy = nil
  end

  def cleanup
    @mutex.synchronize do
      if @socks_proxy
        print_status('Stopping the SOCKS proxy server')
        @socks_proxy.stop
        @socks_proxy = nil
      end
    end
    super
  end

  def run
    opts = {
      'ServerHost' => bindhost,
      'ServerPort' => bindport,
      'Comm' => _determine_server_comm(bindhost),
      'Context' => { 'Msf' => framework, 'MsfExploit' => self }
    }

    if datastore['VERSION'] == '5'
      opts.merge!({
        'ServerUsername' => datastore['USERNAME'],
        'ServerPassword' => datastore['PASSWORD']
      })
      @socks_proxy = Rex::Proto::Proxy::Socks5::Server.new(opts)
    elsif datastore['VERSION'] == '4a'
      @socks_proxy = Rex::Proto::Proxy::Socks4a.new(opts)
    end

    print_status('Starting the SOCKS proxy server')
    @socks_proxy.start
    @socks_proxy.join
  end
end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation