On Thu, 26 Feb 2009 23:32:13 +0100, jkv <j...@unixcluster.dk> wrote:
Jean-Paul Calderone wrote:
   sys.stdout.write('Password: ');
   #IAC DO ECHO     sys.stdout.write('\xFF\xFB\x01')
   password = raw_input()

If the client sends 'qwerty\r\n' everything is fine and the password get stored in the variable. But sometimes, depending on how broken the telnet client are, the client will send 'qwerty\r\000' instead and then my application will hang at 'password = raw_input()' forever.

Any suggestions?

It sounds like you might want to use a real implementation of the telnet
protocol in your application.  Such an implementation would deal with the
fact that telnet encodes \r as \r\0 for you.

Twisted includes a telnet implementation, as well as facilities for reading
stdin asynchronously (which will let you avoid indefinite hangs).
I running this script inside a wrapper (honeyd), so i cant really use twisted since i dont have raw network access - i only got stdout, stdin and stderr to play with.

But i found a solution, posting it here for the archives:

password = ""
while 1:
   c = sys.stdin.read(1)
   if c == '\r' or c == '\n':
       break
   password = password + c


Glad you figured something out.  Just for the record, you can use Twisted
to write applications that interact with stdio, so the fact that you're
using honeyd doesn't prevent you from using Twisted.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to