From 6dbf64cfa74e10442e033563a6029f5bae39111d Mon Sep 17 00:00:00 2001 From: antisnatchor Date: Sun, 15 Jul 2012 12:57:21 +0100 Subject: [PATCH] Added bind_socket/unbind_socket to AssetHandler --- core/main/network_stack/assethandler.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/main/network_stack/assethandler.rb b/core/main/network_stack/assethandler.rb index 682fb5b14..8801703ee 100644 --- a/core/main/network_stack/assethandler.rb +++ b/core/main/network_stack/assethandler.rb @@ -29,6 +29,7 @@ module Handlers # Starts the AssetHandler instance def initialize @allocations = {} + @sockets = {} @http_server = BeEF::Core::Server.instance @root_dir = File.expand_path('../../../../', __FILE__) end @@ -59,6 +60,29 @@ module Handlers print_info "Url [" + url + "] unmounted" end + # use it like: bind_socket("irc","0.0.0.0",6667) + def bind_socket(name, host, port) + if @sockets[name] != nil + print_error "Thread [#{name}] is already listening on [#{host}:#{port}]." + else + t = Thread.new { + server = TCPServer.new(host,port) + loop do + client = server.accept + client.close + end + } + @sockets[name] = t + print_info "Thread [#{name}] listening on [#{host}:#{port}]." + end + end + + def unbind_socket(name) + t = @sockets[name] + Thread.kill(t) + print_info "Thread [#{name}] killed." + end + # Builds a URL based on the path and extension, if neither are passed a random URL will be generated # @param [String] path URL Path defined by bind() # @param [String] extension Extension defined by bind()