Sha256: 94fc554a264f9e6502756fc8b537f19da5c1c156ecf6e04a1afcb7e712eb4ca9

Contents?: true

Size: 1.37 KB

Versions: 43

Compression:

Stored size: 1.37 KB

Contents

require 'rex/ui'

module Rex
module Ui
module Text

###
#
# This class implements input against a socket.
#
###
class Input::Socket < Rex::Ui::Text::Input

	def initialize(sock)
		@sock = sock
	end

	#
	# Sockets do not currently support readline.
	#
	def supports_readline
		false
	end

	#
	# Reads input from the raw socket.
	#
	def sysread(len = 1)
		@sock.sysread(len)
	end

	#
	# Wait for a line of input to be read from a socket.
	#
	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/
					@sock.write("[*] Caught ^C, closing the socket...\n")
					@sock.close
					return
					
				when /\xff\xed\xff\xfd\x06/
					@sock.write("[*] Caught ^Z\n")
					return		
			end
		end
		
		return line
	end

	#
	# Returns whether or not EOF has been reached on stdin.
	#
	def eof?
		@sock.closed?
	end

	#
	# Returns the file descriptor associated with a socket.
	#
	def fd
		return @sock
	end
end

end
end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/ui/text/input/socket.rb
librex-0.0.63 lib/rex/ui/text/input/socket.rb
librex-0.0.54 lib/rex/ui/text/input/socket.rb
librex-0.0.53 lib/rex/ui/text/input/socket.rb
librex-0.0.52 lib/rex/ui/text/input/socket.rb
librex-0.0.51 lib/rex/ui/text/input/socket.rb
librex-0.0.50 lib/rex/ui/text/input/socket.rb
librex-0.0.49 lib/rex/ui/text/input/socket.rb
librex-0.0.48 lib/rex/ui/text/input/socket.rb
librex-0.0.47 lib/rex/ui/text/input/socket.rb
librex-0.0.46 lib/rex/ui/text/input/socket.rb
librex-0.0.44 lib/rex/ui/text/input/socket.rb
librex-0.0.43 lib/rex/ui/text/input/socket.rb
librex-0.0.42 lib/rex/ui/text/input/socket.rb
librex-0.0.41 lib/rex/ui/text/input/socket.rb
librex-0.0.40 lib/rex/ui/text/input/socket.rb
librex-0.0.39 lib/rex/ui/text/input/socket.rb
librex-0.0.38 lib/rex/ui/text/input/socket.rb
librex-0.0.37 lib/rex/ui/text/input/socket.rb
librex-0.0.36 lib/rex/ui/text/input/socket.rb