|
0 |
From: Sophie Brun <[email protected]>
|
|
1 |
Date: Fri, 4 Sep 2020 15:38:48 +0200
|
|
2 |
Subject: Fix Capturing the given block using Kernel#proc is deprecated
|
|
3 |
|
|
4 |
Last-Update: 2020-08-04
|
|
5 |
Bug: https://github.com/iagox86/dnscat2/issues/157
|
|
6 |
Forwarded: https://github.com/iagox86/dnscat2/pull/159
|
|
7 |
---
|
|
8 |
server/libs/dnser.rb | 10 +++++-----
|
|
9 |
server/libs/settings.rb | 4 ++--
|
|
10 |
server/libs/swindow.rb | 8 ++++----
|
|
11 |
server/tunnel_drivers/driver_dns.rb | 4 ++--
|
|
12 |
4 files changed, 13 insertions(+), 13 deletions(-)
|
|
13 |
|
|
14 |
diff --git a/server/libs/dnser.rb b/server/libs/dnser.rb
|
|
15 |
index 69f734e..dd669c7 100644
|
|
16 |
--- a/server/libs/dnser.rb
|
|
17 |
+++ b/server/libs/dnser.rb
|
|
18 |
@@ -837,7 +837,7 @@ class DNSer
|
|
19 |
# This method returns immediately, but spawns a background thread. The thread
|
|
20 |
# will recveive and parse DNS packets, create a transaction, and pass it to
|
|
21 |
# the caller's block.
|
|
22 |
- def on_request()
|
|
23 |
+ def on_request(&block)
|
|
24 |
@thread = Thread.new() do |t|
|
|
25 |
begin
|
|
26 |
loop do
|
|
27 |
@@ -869,7 +869,7 @@ class DNSer
|
|
28 |
|
|
29 |
if(!transaction.sent)
|
|
30 |
begin
|
|
31 |
- proc.call(transaction)
|
|
32 |
+ block.call(transaction)
|
|
33 |
rescue StandardError => e
|
|
34 |
puts("Caught an error: #{e}")
|
|
35 |
puts(e.backtrace())
|
|
36 |
@@ -908,7 +908,7 @@ class DNSer
|
|
37 |
# Send out a query, asynchronously. This immediately returns, then, when the
|
|
38 |
# query is finished, the callback block is called with a DNSer::Packet that
|
|
39 |
# represents the response (or nil, if there was a timeout).
|
|
40 |
- def DNSer.query(hostname, params = {})
|
|
41 |
+ def DNSer.query(hostname, params = {}, &block)
|
|
42 |
server = params[:server] || "8.8.8.8"
|
|
43 |
port = params[:port] || 53
|
|
44 |
type = params[:type] || DNSer::Packet::TYPE_A
|
|
45 |
@@ -926,10 +926,10 @@ class DNSer
|
|
46 |
|
|
47 |
timeout(timeout) do
|
|
48 |
response = s.recv(65536)
|
|
49 |
- proc.call(DNSer::Packet.parse(response))
|
|
50 |
+ block.call(DNSer::Packet.parse(response))
|
|
51 |
end
|
|
52 |
rescue Timeout::Error
|
|
53 |
- proc.call(nil)
|
|
54 |
+ block.call(nil)
|
|
55 |
rescue Exception => e
|
|
56 |
puts("There was an exception sending a query for #{hostname} to #{server}:#{port}: #{e}")
|
|
57 |
ensure
|
|
58 |
diff --git a/server/libs/settings.rb b/server/libs/settings.rb
|
|
59 |
index 6488238..7fb5daf 100644
|
|
60 |
--- a/server/libs/settings.rb
|
|
61 |
+++ b/server/libs/settings.rb
|
|
62 |
@@ -157,13 +157,13 @@ class Settings
|
|
63 |
|
|
64 |
# Create a new setting, or replace an old one. This must be done before a
|
|
65 |
# setting is used.
|
|
66 |
- def create(name, type, default_value, docs)
|
|
67 |
+ def create(name, type, default_value, docs, &block)
|
|
68 |
name = name.to_s()
|
|
69 |
|
|
70 |
@settings[name] = @settings[name] || {}
|
|
71 |
|
|
72 |
@settings[name][:type] = type
|
|
73 |
- @settings[name][:watcher] = proc
|
|
74 |
+ @settings[name][:watcher] = block
|
|
75 |
@settings[name][:docs] = docs
|
|
76 |
@settings[name][:default] = @@mutators[type].call(default_value.to_s())
|
|
77 |
|
|
78 |
diff --git a/server/libs/swindow.rb b/server/libs/swindow.rb
|
|
79 |
index 3095a48..9292c92 100644
|
|
80 |
--- a/server/libs/swindow.rb
|
|
81 |
+++ b/server/libs/swindow.rb
|
|
82 |
@@ -60,14 +60,14 @@ class SWindow
|
|
83 |
|
|
84 |
# This function will trap the TSTP signal (suspend, ctrl-z) and, if possible,
|
|
85 |
# activate the parent window.
|
|
86 |
- def SWindow._catch_suspend()
|
|
87 |
+ def SWindow._catch_suspend(&block)
|
|
88 |
orig_suspend = Signal.trap("TSTP") do
|
|
89 |
if(@@active)
|
|
90 |
@@active.deactivate()
|
|
91 |
end
|
|
92 |
end
|
|
93 |
|
|
94 |
- proc.call()
|
|
95 |
+ block.call()
|
|
96 |
|
|
97 |
Signal.trap("TSTP", orig_suspend)
|
|
98 |
end
|
|
99 |
@@ -182,8 +182,8 @@ class SWindow
|
|
100 |
|
|
101 |
# Set the on_input callback - the function that will be called when input is
|
|
102 |
# received. Very important!
|
|
103 |
- def on_input()
|
|
104 |
- @callback = proc
|
|
105 |
+ def on_input(&block)
|
|
106 |
+ @callback = block
|
|
107 |
end
|
|
108 |
|
|
109 |
def with(params = {})
|
|
110 |
diff --git a/server/tunnel_drivers/driver_dns.rb b/server/tunnel_drivers/driver_dns.rb
|
|
111 |
index 39aa68a..43a8dec 100644
|
|
112 |
--- a/server/tunnel_drivers/driver_dns.rb
|
|
113 |
+++ b/server/tunnel_drivers/driver_dns.rb
|
|
114 |
@@ -242,7 +242,7 @@ class DriverDNS
|
|
115 |
return response
|
|
116 |
end
|
|
117 |
|
|
118 |
- def initialize(parent_window, host, port, domains)
|
|
119 |
+ def initialize(parent_window, host, port, domains, &block)
|
|
120 |
if(domains.nil?)
|
|
121 |
domains = []
|
|
122 |
end
|
|
123 |
@@ -313,7 +313,7 @@ class DriverDNS
|
|
124 |
end
|
|
125 |
|
|
126 |
# Get the response
|
|
127 |
- response = proc.call(name, max_length)
|
|
128 |
+ response = block.call(name, max_length)
|
|
129 |
|
|
130 |
if(response.length > max_length)
|
|
131 |
raise(DnscatException, "The handler returned too much data! This shouldn't happen, please report. (max = #{max_length}, returned = #{response.length}")
|