Module: Msf::Exploit::Remote::Expect

Defined in:
lib/msf/core/exploit/remote/expect.rb

Instance Method Summary collapse

Instance Method Details

#send_expect(line, pattern, sock:, newline: "\n", timeout: 3.5) ⇒ void

This method returns an undefined value.

Send a line and expect a pattern

Parameters:

  • line (String)

    Line to send

  • pattern (Regexp)

    Pattern to expect

  • sock (Socket)

    Socket to send/expect on

  • newline (String) (defaults to: "\n")

    Newline character(s)

  • timeout (Float) (defaults to: 3.5)

    Seconds to expect pattern



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/msf/core/exploit/remote/expect.rb', line 19

def send_expect(line, pattern, sock:, newline: "\n", timeout: 3.5)
  unless sock.respond_to?(:put) && sock.respond_to?(:expect)
    raise ArgumentError, 'sock does not appear to be a socket'
  end

  if line
    print_status("Sending: #{line}")
    sock.put("#{line}#{newline}")
  end

  return unless pattern

  print_status("Expecting: #{pattern.inspect}")
  sock.expect(pattern, timeout) do |res|
    unless res
      raise Timeout::Error, "Pattern not found: #{pattern.inspect}"
    end

    vprint_good("Received: #{res.first}")
  end
end