Using perl with Inetd

Using perl with Inetd

am 27.09.2005 12:16:34 von Ben Brown

I have a perl script I want to run on port 23, my evential goal is to
have a script anonymous users can telnet to so they can sign up an
account on a server.

Before anyone worries about security, this is a NetBSD box that's on a
local network at my place of work, it's not publically accessable.

So far I've just written a very simple test script, a proof of concept
of you will, I don't like running before I can walk :)

I've called my script telnet.pl and have put the following in
/etc/inetd.conf:

telnet stream tcp nowait root /root/bin/telnet.pl
telnet.pl

Here is the script itself:

#!/usr/pkg/bin/perl

$|=1;
print ("Y/n: ");
my $choice = ;
chomp($choice);
if ($choice =~ /\r$/) { chop $choice; }
if ($choice eq "y") {
print ("OK");
} else {
print ("No match");
}
print("\n");
print("Debugging: \$choice = \"$choice\"\n");
exit(0);

If I run it from the command line, it does what you'd expect it to:

Y/n: y
OK
Debugging: $choice = "y"

However, when run from telnet, you get this:

Y/n: y
No match
Debugging: $choice = "y"

Any assistance will be greatfully recieved!

Ben

Re: Using perl with Inetd

am 27.09.2005 12:36:59 von anno4000

Ben Brown wrote in comp.lang.perl.misc:
> I have a perl script I want to run on port 23, my evential goal is to
> have a script anonymous users can telnet to so they can sign up an
> account on a server.
>
> Before anyone worries about security, this is a NetBSD box that's on a
> local network at my place of work, it's not publically accessable.
>
> So far I've just written a very simple test script, a proof of concept
> of you will, I don't like running before I can walk :)
>
> I've called my script telnet.pl and have put the following in
> /etc/inetd.conf:
>
> telnet stream tcp nowait root /root/bin/telnet.pl
> telnet.pl
>
> Here is the script itself:
>
> #!/usr/pkg/bin/perl
>
> $|=1;
> print ("Y/n: ");
> my $choice = ;
> chomp($choice);
> if ($choice =~ /\r$/) { chop $choice; }
> if ($choice eq "y") {
> print ("OK");
> } else {
> print ("No match");
> }
> print("\n");
> print("Debugging: \$choice = \"$choice\"\n");
> exit(0);
>
> If I run it from the command line, it does what you'd expect it to:
>
> Y/n: y
> OK
> Debugging: $choice = "y"
>
> However, when run from telnet, you get this:
>
> Y/n: y
> No match
> Debugging: $choice = "y"

You probably get different line feeds from what you expect. Try (untested)

$choice =~ s/\s+$//;

to verify.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

Re: Using perl with Inetd

am 27.09.2005 12:36:59 von anno4000

Ben Brown wrote in comp.lang.perl.misc:
> I have a perl script I want to run on port 23, my evential goal is to
> have a script anonymous users can telnet to so they can sign up an
> account on a server.
>
> Before anyone worries about security, this is a NetBSD box that's on a
> local network at my place of work, it's not publically accessable.
>
> So far I've just written a very simple test script, a proof of concept
> of you will, I don't like running before I can walk :)
>
> I've called my script telnet.pl and have put the following in
> /etc/inetd.conf:
>
> telnet stream tcp nowait root /root/bin/telnet.pl
> telnet.pl
>
> Here is the script itself:
>
> #!/usr/pkg/bin/perl
>
> $|=1;
> print ("Y/n: ");
> my $choice = ;
> chomp($choice);
> if ($choice =~ /\r$/) { chop $choice; }
> if ($choice eq "y") {
> print ("OK");
> } else {
> print ("No match");
> }
> print("\n");
> print("Debugging: \$choice = \"$choice\"\n");
> exit(0);
>
> If I run it from the command line, it does what you'd expect it to:
>
> Y/n: y
> OK
> Debugging: $choice = "y"
>
> However, when run from telnet, you get this:
>
> Y/n: y
> No match
> Debugging: $choice = "y"

You probably get different line feeds from what you expect. Try (untested)

$choice =~ s/\s+$//;

to verify.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

Re: Using perl with Inetd

am 27.09.2005 12:37:07 von Villy Kruse

On Tue, 27 Sep 2005 11:16:34 +0100,
Ben Brown wrote:


>
> However, when run from telnet, you get this:
>
> Y/n: y
> No match
> Debugging: $choice = "y"
>
> Any assistance will be greatfully recieved!
>

You sure $choice doesn't contain invisible characters? These characters
could come from the telnet client doing protocol negotiation.

Villy

Re: Using perl with Inetd

am 28.09.2005 12:41:20 von Ben Brown

Villy Kruse wrote:
> On Tue, 27 Sep 2005 11:16:34 +0100,
> Ben Brown wrote:
>
>
>
>>However, when run from telnet, you get this:
>>
>>Y/n: y
>>No match
>>Debugging: $choice = "y"
>>
>>Any assistance will be greatfully recieved!
>>
>
>
> You sure $choice doesn't contain invisible characters? These characters
> could come from the telnet client doing protocol negotiation.
>
> Villy

I'm pretty sure that it does have invisible characters, it's trying to
find out what they are I'm having trouble with.

I've tried $choice =~ s/\s+$//; but it's still the same.

Cheers,

Ben

Re: Using perl with Inetd

am 28.09.2005 13:23:33 von Villy Kruse

On Wed, 28 Sep 2005 11:41:20 +0100,
Ben Brown wrote:


>
> I'm pretty sure that it does have invisible characters, it's trying to
> find out what they are I'm having trouble with.
>
> I've tried $choice =~ s/\s+$//; but it's still the same.
>


For example unpack the string:

print unpack('H*', $choice), "\n";

Villy

Re: Using perl with Inetd

am 28.09.2005 14:04:33 von Ben Brown

Villy Kruse wrote:
> On Wed, 28 Sep 2005 11:41:20 +0100,
> Ben Brown wrote:
>
>
>
>>I'm pretty sure that it does have invisible characters, it's trying to
>>find out what they are I'm having trouble with.
>>
>>I've tried $choice =~ s/\s+$//; but it's still the same.
>>
>
>
>
> For example unpack the string:
>
> print unpack('H*', $choice), "\n";
>
> Villy

Thanks for that. Using that it shows that the following is being added
by telnet at the start of the variable:

fffb25fffd26fffb26fffd03fffb18fffb1ffffb20fffb21fffb22fffb27 fffd05

Any ideas how to strip this out?

Re: Using perl with Inetd

am 28.09.2005 14:30:31 von Tad McClellan

Ben Brown wrote:
> Villy Kruse wrote:


>> You sure $choice doesn't contain invisible characters?

> I'm pretty sure that it does have invisible characters, it's trying to
> find out what they are I'm having trouble with.


Then write code that will look for them for you.

Something like:

foreach my $char (split //, $choice) {
my $chnum = ord($char);

next if $chnum >= 32 && $chnum <= 126; # "normal" ASCII

my $hex = sprintf '0x%X', $chnum;
my $oct = sprintf '0%o', $chnum;
print "$chnum $oct ($hex)\n";
}


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas