Path: blob/master/modules/network/port_scanner/module.rb
1873 views
#1# Copyright (c) 2006-2026 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5#6# Port Scanner Module - javier.marcos7# Scan ports in a given hostname, using WebSockets CORS and HTTP with img tags.8# It uses the three methods to avoid blocked ports or Same Origin Policy.910class Port_scanner < BeEF::Core::Command11def self.options12[13{ 'name' => 'ipHost', 'ui_label' => 'Scan IP or Hostname', 'value' => '192.168.1.10' },14{ 'name' => 'ports', 'ui_label' => 'Specific port(s) to scan', 'value' => 'top' },15{ 'name' => 'closetimeout', 'ui_label' => 'Closed port timeout (ms)', 'value' => '1100' },16{ 'name' => 'opentimeout', 'ui_label' => 'Open port timeout (ms)', 'value' => '2500' },17{ 'name' => 'delay', 'ui_label' => 'Delay between requests (ms)', 'value' => '600' },18{ 'name' => 'debug', 'ui_label' => 'Debug', 'value' => 'false' }19]20end2122def post_execute23content = {}24content['port'] = @datastore['port'] unless @datastore['port'].nil?25content['fail'] = 'No open ports have been found.' if content.empty?26save content2728configuration = BeEF::Core::Configuration.instance29return unless configuration.get('beef.extension.network.enable') == true30return unless @datastore['results'] =~ /^ip=([\d.]+)&port=(CORS|WebSocket|HTTP): Port (\d+) is OPEN (.*)$/3132ip = Regexp.last_match(1)33port = Regexp.last_match(3)34service = Regexp.last_match(4)35session_id = @datastore['beefhook']36proto = 'http'37if BeEF::Filters.is_valid_ip?(ip)38print_debug("Hooked browser found network service [ip: #{ip}, port: #{port}]")39BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, ntype: service)40end41end42end434445