Files
metasploit-gs/lib/rex/ui/text/input/socket.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
1.5 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2005-11-28 16:36:06 +00:00
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
2013-08-30 16:28:33 -05:00
2005-11-28 16:36:06 +00:00
#
# Sockets do not currently support readline.
#
def supports_readline
false
end
2013-08-30 16:28:33 -05:00
2005-12-07 03:40:09 +00:00
#
# Reads input from the raw socket.
#
def sysread(len = 1)
2008-05-26 08:42:17 +00:00
@sock.sysread(len)
2005-12-07 03:40:09 +00:00
end
2013-08-30 16:28:33 -05:00
2005-11-28 16:36:06 +00:00
#
# Wait for a line of input to be read from a socket.
#
def gets
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
# Initialize the line buffer
line = ''
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
# Read data one byte at a time until we see a LF
while (true)
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
break if line.include?("\n")
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
# Read another character of input
char = @sock.getc
if char.nil?
@sock.close
return
end
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
# Telnet sends 0x04 as EOF
if (char == 4)
@sock.write("[*] Caught ^D, closing the socket...\n")
@sock.close
return
end
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
# Append this character to the string
line << char
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
# Handle telnet sequences
case line
when /\xff\xf4\xff\xfd\x06/n
2006-01-28 07:12:35 +00:00
@sock.write("[*] Caught ^C, closing the socket...\n")
@sock.close
return
2013-08-30 16:28:33 -05:00
when /\xff\xed\xff\xfd\x06/n
2006-01-28 07:12:35 +00:00
@sock.write("[*] Caught ^Z\n")
2013-03-07 18:16:57 -06:00
return
2006-01-28 07:12:35 +00:00
end
end
2013-08-30 16:28:33 -05:00
2006-01-28 07:12:35 +00:00
return line
2005-11-28 16:36:06 +00:00
end
2013-08-30 16:28:33 -05:00
2005-11-28 16:36:06 +00:00
#
# Returns whether or not EOF has been reached on stdin.
#
def eof?
@sock.closed?
end
2013-08-30 16:28:33 -05:00
2005-11-28 16:36:06 +00:00
#
# Returns the file descriptor associated with a socket.
#
def fd
return @sock
end
end
end
end
end