Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get login to work on MS Telnet #15

Closed
styper opened this issue Nov 11, 2018 · 4 comments
Closed

Can't get login to work on MS Telnet #15

styper opened this issue Nov 11, 2018 · 4 comments

Comments

@styper
Copy link

styper commented Nov 11, 2018

I can't seem to get this to work with MS Telnet Server. The program just hangs

This is an output of a successful connection:

Trying 192.168.50.59...
Connected to 192.168.50.59.
Escape character is '^]'.
Welcome to Microsoft Telnet Service

login: erick
password:

*===============================================================
Microsoft Telnet Server.
*===============================================================

This is the code I'm using:

$host = '192.168.50.59';
$port = 23;
$telnet = TelnetClient::factory();
$telnet->connect("$host:$port");
var_dump($telnet->execute('erick', 'password:'));

This is what I get when I var_dump the buffer:

string(47) "Welcome to Microsoft Telnet Service

login: "

So the connection seems to be working as the buffer is loading but then it just hangs when I try to log in

@john-n-smith
Copy link
Contributor

john-n-smith commented Nov 12, 2018

I'm afraid you're working against some design decisions that were based on telnet implementations from embedded devices. Other implementations (such as this one) seem to work a little differently.

I've released this small change that should allow you to work around them. Could you try the following (some tweaks may be necessary):

$dsn = '192.168.50.59:23';
$client = Graze\TelnetClient\TelnetClient::factory();

// server does not respond with consistent line ending - set this to null
$client->setLineEnding(null);
$client->connect($dsn);

// send something ("\r\n") to the server to trigger its initial response. Look for "login: " in the response
$resp = $client->execute("\r\n", "login: ");

// send username with line ending appended as it is no longer included. Look for "password: " prompt
$resp = $client->execute("erick\r\n", "password: ");

// send password with line ending. Look for welcome banner
$welcomePrompt = "*======="; //... full string or regex
$resp = $client->execute("my password\r\n", $welcomePrompt);
...

As $lineEnding is now null, it will have to be appended to each of your commands (if that's what the server is looking for to denote a send)

Let me know if it works.

@styper
Copy link
Author

styper commented Nov 12, 2018

Thanks for the quick response. I had posted a comment before but deleted it since I forgot to update before the test.

Your change worked like a charm, this is the code used and the results:

$dsn = '192.168.50.59:23';
$client = TelnetClient::factory();
$client->setLineEnding(null);
$client->connect($dsn);
$resp = $client->execute("\r\n", "login: ");
var_dump($resp);
$resp = $client->execute("erick\r\n", "password: ");
var_dump($resp);
$welcomePrompt = "erick>";
$resp = $client->execute("erick\r\n", $welcomePrompt);
var_dump($resp);

object(Graze\TelnetClient\TelnetResponse)#134 (3) {
["isError":protected]=>
bool(false)
["responseText":protected]=>
string(40) "Welcome to Microsoft Telnet Service

"
["promptMatches":protected]=>
array(1) {
[0]=>
string(7) "login: "
}
}
object(Graze\TelnetClient\TelnetResponse)#142 (3) {
["isError":protected]=>
bool(false)
["responseText":protected]=>
string(21) "erick
login: erick
"
["promptMatches":protected]=>
array(1) {
[0]=>
string(10) "password: "
}
}
object(Graze\TelnetClient\TelnetResponse)#134 (3) {
["isError":protected]=>
bool(false)
["responseText":protected]=>
string(171) "

*===============================================================
Microsoft Telnet Server.
*===============================================================
C:\Users"
["promptMatches":protected]=>
array(1) {
[0]=>
string(6) "erick>"
}
}

Thank you very much!

@styper
Copy link
Author

styper commented Nov 12, 2018

For reference this is a Windows 7 Professional machine using standard MS Telnet Server

@styper styper closed this as completed Nov 12, 2018
@john-n-smith
Copy link
Contributor

Glad you got it working 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants