Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/network/port_scanner/module.rb
1873 views
1
#
2
# Copyright (c) 2006-2026 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
#
7
# Port Scanner Module - javier.marcos
8
# Scan ports in a given hostname, using WebSockets CORS and HTTP with img tags.
9
# It uses the three methods to avoid blocked ports or Same Origin Policy.
10
11
class Port_scanner < BeEF::Core::Command
12
def self.options
13
[
14
{ 'name' => 'ipHost', 'ui_label' => 'Scan IP or Hostname', 'value' => '192.168.1.10' },
15
{ 'name' => 'ports', 'ui_label' => 'Specific port(s) to scan', 'value' => 'top' },
16
{ 'name' => 'closetimeout', 'ui_label' => 'Closed port timeout (ms)', 'value' => '1100' },
17
{ 'name' => 'opentimeout', 'ui_label' => 'Open port timeout (ms)', 'value' => '2500' },
18
{ 'name' => 'delay', 'ui_label' => 'Delay between requests (ms)', 'value' => '600' },
19
{ 'name' => 'debug', 'ui_label' => 'Debug', 'value' => 'false' }
20
]
21
end
22
23
def post_execute
24
content = {}
25
content['port'] = @datastore['port'] unless @datastore['port'].nil?
26
content['fail'] = 'No open ports have been found.' if content.empty?
27
save content
28
29
configuration = BeEF::Core::Configuration.instance
30
return unless configuration.get('beef.extension.network.enable') == true
31
return unless @datastore['results'] =~ /^ip=([\d.]+)&port=(CORS|WebSocket|HTTP): Port (\d+) is OPEN (.*)$/
32
33
ip = Regexp.last_match(1)
34
port = Regexp.last_match(3)
35
service = Regexp.last_match(4)
36
session_id = @datastore['beefhook']
37
proto = 'http'
38
if BeEF::Filters.is_valid_ip?(ip)
39
print_debug("Hooked browser found network service [ip: #{ip}, port: #{port}]")
40
BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, ntype: service)
41
end
42
end
43
end
44
45