From: Sophie Brun <[email protected]>
Date: Fri, 4 Sep 2020 15:38:48 +0200
Subject: Fix Capturing the given block using Kernel#proc is deprecated
Last-Update: 2020-08-04
Bug: https://github.com/iagox86/dnscat2/issues/157
Forwarded: https://github.com/iagox86/dnscat2/pull/159
---
server/libs/dnser.rb | 10 +++++-----
server/libs/settings.rb | 4 ++--
server/libs/swindow.rb | 8 ++++----
server/tunnel_drivers/driver_dns.rb | 4 ++--
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/server/libs/dnser.rb b/server/libs/dnser.rb
index 69f734e..dd669c7 100644
--- a/server/libs/dnser.rb
+++ b/server/libs/dnser.rb
@@ -837,7 +837,7 @@ class DNSer
# This method returns immediately, but spawns a background thread. The thread
# will recveive and parse DNS packets, create a transaction, and pass it to
# the caller's block.
- def on_request()
+ def on_request(&block)
@thread = Thread.new() do |t|
begin
loop do
@@ -869,7 +869,7 @@ class DNSer
if(!transaction.sent)
begin
- proc.call(transaction)
+ block.call(transaction)
rescue StandardError => e
puts("Caught an error: #{e}")
puts(e.backtrace())
@@ -908,7 +908,7 @@ class DNSer
# Send out a query, asynchronously. This immediately returns, then, when the
# query is finished, the callback block is called with a DNSer::Packet that
# represents the response (or nil, if there was a timeout).
- def DNSer.query(hostname, params = {})
+ def DNSer.query(hostname, params = {}, &block)
server = params[:server] || "8.8.8.8"
port = params[:port] || 53
type = params[:type] || DNSer::Packet::TYPE_A
@@ -926,10 +926,10 @@ class DNSer
timeout(timeout) do
response = s.recv(65536)
- proc.call(DNSer::Packet.parse(response))
+ block.call(DNSer::Packet.parse(response))
end
rescue Timeout::Error
- proc.call(nil)
+ block.call(nil)
rescue Exception => e
puts("There was an exception sending a query for #{hostname} to #{server}:#{port}: #{e}")
ensure
diff --git a/server/libs/settings.rb b/server/libs/settings.rb
index 6488238..7fb5daf 100644
--- a/server/libs/settings.rb
+++ b/server/libs/settings.rb
@@ -157,13 +157,13 @@ class Settings
# Create a new setting, or replace an old one. This must be done before a
# setting is used.
- def create(name, type, default_value, docs)
+ def create(name, type, default_value, docs, &block)
name = name.to_s()
@settings[name] = @settings[name] || {}
@settings[name][:type] = type
- @settings[name][:watcher] = proc
+ @settings[name][:watcher] = block
@settings[name][:docs] = docs
@settings[name][:default] = @@mutators[type].call(default_value.to_s())
diff --git a/server/libs/swindow.rb b/server/libs/swindow.rb
index 3095a48..9292c92 100644
--- a/server/libs/swindow.rb
+++ b/server/libs/swindow.rb
@@ -60,14 +60,14 @@ class SWindow
# This function will trap the TSTP signal (suspend, ctrl-z) and, if possible,
# activate the parent window.
- def SWindow._catch_suspend()
+ def SWindow._catch_suspend(&block)
orig_suspend = Signal.trap("TSTP") do
if(@@active)
@@active.deactivate()
end
end
- proc.call()
+ block.call()
Signal.trap("TSTP", orig_suspend)
end
@@ -182,8 +182,8 @@ class SWindow
# Set the on_input callback - the function that will be called when input is
# received. Very important!
- def on_input()
- @callback = proc
+ def on_input(&block)
+ @callback = block
end
def with(params = {})
diff --git a/server/tunnel_drivers/driver_dns.rb b/server/tunnel_drivers/driver_dns.rb
index 39aa68a..43a8dec 100644
--- a/server/tunnel_drivers/driver_dns.rb
+++ b/server/tunnel_drivers/driver_dns.rb
@@ -242,7 +242,7 @@ class DriverDNS
return response
end
- def initialize(parent_window, host, port, domains)
+ def initialize(parent_window, host, port, domains, &block)
if(domains.nil?)
domains = []
end
@@ -313,7 +313,7 @@ class DriverDNS
end
# Get the response
- response = proc.call(name, max_length)
+ response = block.call(name, max_length)
if(response.length > max_length)
raise(DnscatException, "The handler returned too much data! This shouldn't happen, please report. (max = #{max_length}, returned = #{response.length}")