Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/ui/text/input/socket.rb
Views: 11704
# -*- coding: binary -*-12module Rex3module Ui4module Text56###7#8# This class implements input against a socket.9#10###11class Input::Socket < Rex::Ui::Text::Input1213def initialize(sock)14@sock = sock15end1617#18# Sockets do not currently support readline.19#20def supports_readline21false22end2324#25# Reads input from the raw socket.26#27def sysread(len = 1)28@sock.sysread(len)29end3031#32# Wait for a line of input to be read from a socket.33#34def gets3536# Initialize the line buffer37line = ''3839# Read data one byte at a time until we see a LF40while (true)4142break if line.include?("\n")4344# Read another character of input45char = @sock.getc46if char.nil?47@sock.close48return49end5051# Telnet sends 0x04 as EOF52if (char == 4)53@sock.write("[*] Caught ^D, closing the socket...\n")54@sock.close55return56end5758# Append this character to the string59line << char6061# Handle telnet sequences62case line63when /\xff\xf4\xff\xfd\x06/n64@sock.write("[*] Caught ^C, closing the socket...\n")65@sock.close66return6768when /\xff\xed\xff\xfd\x06/n69@sock.write("[*] Caught ^Z\n")70return71end72end7374return line75end7677#78# Returns whether or not EOF has been reached on stdin.79#80def eof?81@sock.closed?82end8384#85# Returns the file descriptor associated with a socket.86#87def fd88return @sock89end90end9192end93end94end959697