4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/msf/core/exploit/remote/x11/read.rb', line 4
def x11_read_response(klass, timeout: 10)
unless klass.fields.field_name?(:response_length)
raise ::ArgumentError, 'X11 class must have the response_length field to be read'
end
remaining = timeout
reply_instance = klass.new
metalength = reply_instance.response_length.num_bytes
buffer, elapsed_time = Rex::Stopwatch.elapsed_time do
sock.read(reply_instance.response_length.abs_offset + metalength, remaining)
end
raise ::EOFError, 'X11: failed to read response' if buffer.nil?
remaining -= elapsed_time
response_length = reply_instance.response_length.read(buffer[-metalength..]).value
response_length *= 4 response_length += 32
while buffer.length < response_length && remaining > 0
chunk, elapsed_time = Rex::Stopwatch.elapsed_time do
sock.read(response_length - buffer.length, remaining)
end
remaining -= elapsed_time
break if chunk.nil?
buffer << chunk
end
unless buffer.length == response_length
if remaining <= 0
raise Rex::TimeoutError, 'X11: failed to read response due to timeout'
end
raise ::EOFError, 'X11: failed to read response'
end
reply_instance.read(buffer)
end
|