Class: Rex::Ui::Text::Input::Socket
- Inherits:
-
Rex::Ui::Text::Input
- Object
- Rex::Ui::Text::Input
- Rex::Ui::Text::Input::Socket
- Defined in:
- lib/rex/ui/text/input/socket.rb
Overview
This class implements input against a socket.
Instance Attribute Summary
Attributes inherited from Rex::Ui::Text::Input
#config, #eof, #prompt, #prompt_char
Instance Method Summary collapse
-
#eof? ⇒ Boolean
Returns whether or not EOF has been reached on stdin.
-
#fd ⇒ Object
Returns the file descriptor associated with a socket.
-
#gets ⇒ Object
Wait for a line of input to be read from a socket.
-
#initialize(sock) ⇒ Socket
constructor
A new instance of Socket.
-
#supports_readline ⇒ Object
Sockets do not currently support readline.
-
#sysread(len = 1) ⇒ Object
Reads input from the raw socket.
Methods inherited from Rex::Ui::Text::Input
#auto_color, #disable_color, #disable_readline, #enable_color, #enable_readline, #intrinsic_shell?, #reset_color, #reset_tab_completion, #update_prompt
Constructor Details
#initialize(sock) ⇒ Socket
Returns a new instance of Socket.
14 15 16 |
# File 'lib/rex/ui/text/input/socket.rb', line 14 def initialize(sock) @sock = sock end |
Instance Method Details
#eof? ⇒ Boolean
Returns whether or not EOF has been reached on stdin.
81 82 83 |
# File 'lib/rex/ui/text/input/socket.rb', line 81 def eof? @sock.closed? end |
#fd ⇒ Object
Returns the file descriptor associated with a socket.
88 89 90 |
# File 'lib/rex/ui/text/input/socket.rb', line 88 def fd return @sock end |
#gets ⇒ Object
Wait for a line of input to be read from a socket.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rex/ui/text/input/socket.rb', line 35 def gets # Initialize the line buffer line = '' # Read data one byte at a time until we see a LF while (true) break if line.include?("\n") # Read another character of input char = @sock.getc if char.nil? @sock.close return end # Telnet sends 0x04 as EOF if (char == 4) @sock.write("[*] Caught ^D, closing the socket...\n") @sock.close return end # Append this character to the string line << char # Handle telnet sequences case line when /\xff\xf4\xff\xfd\x06/n @sock.write("[*] Caught ^C, closing the socket...\n") @sock.close return when /\xff\xed\xff\xfd\x06/n @sock.write("[*] Caught ^Z\n") return end end return line end |
#supports_readline ⇒ Object
Sockets do not currently support readline.
21 22 23 |
# File 'lib/rex/ui/text/input/socket.rb', line 21 def supports_readline false end |
#sysread(len = 1) ⇒ Object
Reads input from the raw socket.
28 29 30 |
# File 'lib/rex/ui/text/input/socket.rb', line 28 def sysread(len = 1) @sock.sysread(len) end |