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.
Constant Summary
Constants included from Color
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, #enable_color, #intrinsic_shell?, #reset_color, #reset_tab_completion, #update_prompt
Methods included from Color
#ansi, #colorize, #do_colorize, #reset_color, #substitute_colors
Constructor Details
#initialize(sock) ⇒ Socket
Returns a new instance of Socket.
15 16 17 |
# File 'lib/rex/ui/text/input/socket.rb', line 15 def initialize(sock) @sock = sock end |
Instance Method Details
#eof? ⇒ Boolean
Returns whether or not EOF has been reached on stdin.
82 83 84 |
# File 'lib/rex/ui/text/input/socket.rb', line 82 def eof? @sock.closed? end |
#fd ⇒ Object
Returns the file descriptor associated with a socket.
89 90 91 |
# File 'lib/rex/ui/text/input/socket.rb', line 89 def fd return @sock end |
#gets ⇒ Object
Wait for a line of input to be read from a socket.
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 77 |
# File 'lib/rex/ui/text/input/socket.rb', line 36 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.
22 23 24 |
# File 'lib/rex/ui/text/input/socket.rb', line 22 def supports_readline false end |
#sysread(len = 1) ⇒ Object
Reads input from the raw socket.
29 30 31 |
# File 'lib/rex/ui/text/input/socket.rb', line 29 def sysread(len = 1) @sock.sysread(len) end |