Module: Msf::Auxiliary::ManageEngineXnode::Interact
- Included in:
- Msf::Auxiliary::ManageEngineXnode, BasicChecks
- Defined in:
- lib/msf/core/auxiliary/manage_engine_xnode/interact.rb
Instance Method Summary collapse
-
#create_socket_for_xnode(rhost, rport) ⇒ Array
Create a socket to connect to an Xnode server and rescue any resulting errors.
-
#get_response(sock, action_hash, warning_message = nil, expected_response_key = nil) ⇒ Array
Calls send_to_sock and performs basic checks on the received response to ensure it is valid.
-
#send_to_sock(sock, action_hash) ⇒ Hash?
Sends a request to an Xnode server.
Instance Method Details
#create_socket_for_xnode(rhost, rport) ⇒ Array
Create a socket to connect to an Xnode server and rescue any resulting errors
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/msf/core/auxiliary/manage_engine_xnode/interact.rb', line 9 def create_socket_for_xnode(rhost, rport) vprint_status('Attempting to establish a connection with the remote server...') begin sock = Rex::Socket::Tcp.create( 'PeerHost' => rhost, 'PeerPort' => rport ) rescue => e vprint_status("Encountered the following exception type: #{e.class}") return [1, e.] end vprint_status('Successfully connected to the remote server') [0, sock] end |
#get_response(sock, action_hash, warning_message = nil, expected_response_key = nil) ⇒ Array
Calls send_to_sock and performs basic checks on the received response to ensure it is valid
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/msf/core/auxiliary/manage_engine_xnode/interact.rb', line 67 def get_response(sock, action_hash, =nil, expected_response_key=nil) res = send_to_sock(sock, action_hash) return [1, nil] if res.nil? unless res.instance_of?(Hash) && res.keys.include?('response') && res['response'].instance_of?(Hash) if print_warning() end return [1, res] end if expected_response_key unless res['response'].keys.include?(expected_response_key) if print_warning() end return [1, res] end end [0, res] end |
#send_to_sock(sock, action_hash) ⇒ Hash?
Sends a request to an Xnode server
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/msf/core/auxiliary/manage_engine_xnode/interact.rb', line 30 def send_to_sock(sock, action_hash) unless action_hash.instance_of?(Hash) print_error('The provided Xnode action is not a valid Hash. The request will not be performed.') return nil end begin vprint_status("Sending request: #{action_hash}") sock.put(action_hash.to_json) # using sock.get for reading because the server doesn't send newlines so sock.read doesn't work # sock.recv won't work either since the message length can be (and often is) larger than the max of 65535 r = sock.get rescue StandardError => e print_error("Encountered the following error while trying to interact with the Xnode server:") print_error(e.to_s) return nil end vprint_status("Received response: #{r}") # attempt to JSON parse the response begin return JSON.parse(r) rescue JSON::ParserError => e print_error("Encountered the following error while trying to JSON parse the response from the Xnode server:") print_error(e.to_s) return nil end end |