phpseclib icon indicating copy to clipboard operation
phpseclib copied to clipboard

At least one byte needs to be present for successful C / b decodes

Open malohtie opened this issue 4 years ago • 18 comments

Hello, Sometimes we see this in our error logs when trying to login to some random servers we're using the last phpseclib 3 version

$this->sftp->login($this->server->username, $password)

"class": "LengthException",
"message": "At least one byte needs to be present for successful C / b decodes",
"files" : "/var/dms/vendor/phpseclib/phpseclib/phpseclib/Common/Functions/Strings.php:92",
"trace": [
    "/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:2245",
    "/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:2109",
    "/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:2084",
    "/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php:441",
    ...
   ]

malohtie avatar Apr 25 '21 23:04 malohtie

If the server isn't sending any bytes then the server isn't sending any bytes and idk that there's anything phpseclib can do about that.

But maybe the logs will provide more insight. Like maybe the server is sending an error message that's being picked up by filter() before it gets to that point.

Can you post the SSH logs? You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and then echo $ssh->getLog() after the error.

Thanks!

terrafrost avatar Apr 26 '21 14:04 terrafrost

Hi, Unfortunately i couldn't produce this bug locally in our servers, but it still occur in production server so i have no clue why it happening thanks!

malohtie avatar May 02 '21 22:05 malohtie

I've upgraded to v3 and it started occurring as well. Don't know why yet tho. Had similar issue with v2 (#1426) but that was fixed and no longer the case.

simPod avatar Jul 18 '21 08:07 simPod

I've upgraded to v3 and it started occurring as well. Don't know why yet tho. Had similar issue with v2 (#1426) but that was fixed and no longer the case.

Can you post the SSH logs? You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and echo $ssh->getLog() after the error. Since it's v3 you might actually need to do it in a try / catch block.

Thanks!

terrafrost avatar Jul 23 '21 10:07 terrafrost

@terrafrost I have the log, can I send it to you somewhere privately?

simPod avatar Aug 16 '21 18:08 simPod

You can email it to [email protected].

Thanks!

terrafrost avatar Aug 17 '21 05:08 terrafrost

@simPod - got the file. I'll try to take a look in the next few days.

Thanks!

terrafrost avatar Aug 17 '21 14:08 terrafrost

I'm also seeing this issue. I hope it's okay to email you the log.

nateclonch avatar Sep 23 '21 00:09 nateclonch

any update ?

insiderinside avatar Oct 07 '21 11:10 insiderinside

I never quite figured out the problem. It usually works, but if the server takes too long to respond, then I may get the issue I asked you about.

nateclonch avatar Oct 07 '21 11:10 nateclonch

@terrafrost asked me for another log though I have not get to it yet.

simPod avatar Oct 07 '21 11:10 simPod

reopening the issue

malohtie avatar Oct 07 '21 11:10 malohtie

@malohtie / @insiderinside (and really @ just anyone having this issue)... get me logs! You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and then echo $ssh->getLog() after the error.

Without logs, asking me for help is rather like asking some why their computer crashed. The reasons why a computer crashed are endless as are the reasons that this error could occur.

Ultimately, the server sends packets to phpseclib and phpseclib decrypts and then decodes them. If the server just decided to send the letter a repeated over and over again a bunch of times there's 99.999% chance that'd cause things to break. If the server sent over a malformed packet that'd cause things to break as well. Maybe the server doesn't implement the SSH / SFTP protocol very well. Or maybe there's a very specific packet that phpseclib isn't decoding correctly. In any event, the possibilities are endless and I really can't do much without the logs, so please, provide the logs.

Thank you.

terrafrost avatar Oct 08 '21 13:10 terrafrost

@terrafrost In my case the issue is happening systematically, i'm able to connect with sftp command and many other clients, below the log output:

log.txt

Thanks

gadz82 avatar Mar 23 '22 14:03 gadz82

@gadz82 - By systematically do you mean consistently?

Anyway, altho the logs are helpful, a stack trace would also be helpful. Altho if I had to guess I'd guess... assuming you're using 3.0.13 I'm guessing the stack trace would include line 2447 of SSH2.php?

I'm not seeing any evidence of a timeout in the logs.

Would you be able to get me access to the server? Maybe you could email the hostname (and port if it's not 22) to me at [email protected]? idk if an actual account on the server would be needed - your logs show the password being sent but not the server response so it's unclear if a valid username / password is needed to reproduce the issue.

Also, doing sudo /usr/sbin/sshd -ddd -p2222 might yield some useful info (eg. the most verbose debug mode OpenSSH has available)

terrafrost avatar Mar 27 '22 16:03 terrafrost

We had the very same exception with the apple school manager sftp server (upload.appleschoolcontent.com) when we accidentally used a username starting with a space character, i.e. " username" instead of "username".

franzrosenkohl avatar Feb 23 '23 10:02 franzrosenkohl

@franzrosenkohl - can you get me the logs? You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and then echo $ssh->getLog() after the error.

Without logs, asking me for help is rather like asking some why their computer crashed. The reasons why a computer crashed are endless as are the reasons that this error could occur.

Thanks!

terrafrost avatar Feb 25 '23 00:02 terrafrost

We had a similar issue, however ours was a persistent error of At least one byte needs to be present for successful C / b decodes. And I wanted to share the solution for anyone else that finds this page looking for help.

Essentially, to get this to work on our servers, we had to ensure that the private key we used for authentication had its permission set using chmod 600 nameofkey.pem.

It's been a little while since we first encountered this, and I'm not sure if this is something I found in the phpseclib docs or other recommendations, but I can report that it worked for our use case and allowed us to connect to to Azure Blob Storage sFTP successfully. As always this is only possible due to the hard work of the phpseclib team.

roryashfordbentley avatar Mar 03 '23 12:03 roryashfordbentley