CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/net/winrm/receive_response_reader.rb
Views: 1904
1
require 'winrm'
2
3
module Net
4
module MsfWinRM
5
# For parsing of output streams (stdout, stderr); subclassed
6
# so MSF can manage retry loops itself
7
class ReceiveResponseReader < WinRM::WSMV::ReceiveResponseReader
8
def send_get_output_message(message)
9
# Overridden without retry loop
10
@transport.send_request(message)
11
end
12
13
# Reads streams sent in one or more receive response messages
14
# @param wsmv_message [WinRM::WSMV::Base] A wsmv message to send to endpoint
15
# @param wait_for_done_state whether to poll for a CommandState of Done
16
# @yieldparam [Hash] Hash representation of stream with type and text
17
# @yieldparam [REXML::Document] Complete SOAP envelope returned to wsmv_message
18
# rubocop:disable Style/OptionalBooleanParameter - want to keep same signature as base class
19
def read_response(wsmv_message, wait_for_done_state = false)
20
# rubocop:enable Style/OptionalBooleanParameter
21
resp_doc = nil
22
until command_done?(resp_doc, wait_for_done_state)
23
logger.debug('[WinRM] Waiting for output...')
24
resp_doc = send_get_output_message(wsmv_message.build)
25
logger.debug('[WinRM] Processing output')
26
read_streams(resp_doc) do |stream|
27
yield stream, resp_doc
28
end
29
end
30
31
if command_done?(resp_doc, true)
32
raise EOFError, 'Program terminated'
33
end
34
end
35
end
36
end
37
end
38
39