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

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

Open
malohtie opened this issue Apr 25, 2021 · 18 comments
Open

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

malohtie opened this issue Apr 25, 2021 · 18 comments

Comments

@malohtie
Copy link

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",
    ...
   ]
@terrafrost
Copy link
Member

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!

@malohtie malohtie closed this as completed May 2, 2021
@malohtie
Copy link
Author

malohtie commented May 2, 2021

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!

@simPod
Copy link
Contributor

simPod commented Jul 18, 2021

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.

@terrafrost
Copy link
Member

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!

@simPod
Copy link
Contributor

simPod commented Aug 16, 2021

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

@terrafrost
Copy link
Member

You can email it to terrafrost@php.net.

Thanks!

@terrafrost
Copy link
Member

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

Thanks!

@nateclonch
Copy link

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

@insiderinside
Copy link

any update ?

@nateclonch
Copy link

nateclonch commented Oct 7, 2021 via email

@simPod
Copy link
Contributor

simPod commented Oct 7, 2021

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

@malohtie
Copy link
Author

malohtie commented Oct 7, 2021

reopening the issue

@malohtie malohtie reopened this Oct 7, 2021
@terrafrost
Copy link
Member

@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.

@gadz82
Copy link

gadz82 commented Mar 23, 2022

@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

@terrafrost
Copy link
Member

@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 terrafrost@php.net? 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)

@franzrosenkohl
Copy link

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".

@terrafrost
Copy link
Member

@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!

@roryashfordbentley
Copy link

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.

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

8 participants