From dbd20a742e802838e65240919f4be1a4817c4463 Mon Sep 17 00:00:00 2001 From: Jack Walker Date: Tue, 21 Jul 2020 11:22:47 +1000 Subject: [PATCH 1/2] Added icamys changes, inverting the logic for the found variable. --- config.yaml | 2 ++ core/main/handlers/hookedbrowsers.rb | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index d4d93e81b9..f263b71863 100644 --- a/config.yaml +++ b/config.yaml @@ -27,6 +27,8 @@ beef: # subnet of IP addresses that can connect to the admin UI #permitted_ui_subnet: ["127.0.0.1/32", "::1/128"] permitted_ui_subnet: ["0.0.0.0/0", "::/0"] + # subnet of IP addresses that cannot be hooked by the framework + excluded_hooking_subnet: [] # slow API calls to 1 every api_attempt_delay seconds api_attempt_delay: "0.05" diff --git a/core/main/handlers/hookedbrowsers.rb b/core/main/handlers/hookedbrowsers.rb index ee15112210..8e897e7724 100644 --- a/core/main/handlers/hookedbrowsers.rb +++ b/core/main/handlers/hookedbrowsers.rb @@ -33,7 +33,7 @@ class HookedBrowsers < BeEF::Core::Router::Router permitted_hooking_subnet = config.get('beef.restrictions.permitted_hooking_subnet') if permitted_hooking_subnet.nil? || permitted_hooking_subnet.empty? BeEF::Core::Logger.instance.register('Target Range', "Attempted hook from outside of permitted hooking subnet (#{request.ip}) rejected.") - error 404 + error 404 end found = false @@ -46,6 +46,20 @@ class HookedBrowsers < BeEF::Core::Router::Router error 404 end + excluded_hooking_subnet = config.get('beef.restrictions.excluded_hooking_subnet') + unless excluded_hooking_subnet.nil? || excluded_hooking_subnet.empty? + found = false + + excluded_hooking_subnet.each do |subnet| + found = true if IPAddr.new(subnet).include?(request.ip) + end + + if found + BeEF::Core::Logger.instance.register('Target Range', "Attempted hook from excluded hooking subnet (#{request.ip}) rejected.") + error 404 + end + end + # @note get zombie if already hooked the framework hook_session_name = config.get('beef.http.hook_session_name') hook_session_id = request[hook_session_name] From 09bcb5b70429fb04f03ef76c7cb5ca1514684f67 Mon Sep 17 00:00:00 2001 From: Jack Walker Date: Tue, 21 Jul 2020 12:03:36 +1000 Subject: [PATCH 2/2] Updated variable naming for clarity of functional use --- core/main/handlers/hookedbrowsers.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/main/handlers/hookedbrowsers.rb b/core/main/handlers/hookedbrowsers.rb index 8e897e7724..4eb5006a97 100644 --- a/core/main/handlers/hookedbrowsers.rb +++ b/core/main/handlers/hookedbrowsers.rb @@ -48,13 +48,13 @@ class HookedBrowsers < BeEF::Core::Router::Router excluded_hooking_subnet = config.get('beef.restrictions.excluded_hooking_subnet') unless excluded_hooking_subnet.nil? || excluded_hooking_subnet.empty? - found = false + excluded_ip_hooked = false excluded_hooking_subnet.each do |subnet| - found = true if IPAddr.new(subnet).include?(request.ip) + excluded_ip_hooked = true if IPAddr.new(subnet).include?(request.ip) end - if found + if excluded_ip_hooked BeEF::Core::Logger.instance.register('Target Range', "Attempted hook from excluded hooking subnet (#{request.ip}) rejected.") error 404 end