Attacks
New vulnerability in libssh: CVE-2018-10933
Security analyst
Updated
Oct 18, 2018
3 min
The new vulnerability in LibSSH, tracked as CVE-2018-10933, resides on the server code which can enable a client to bypass the authentication process and create channels without permission. This affects servers using versions 0.6 and above being used in server mode.
The bug was discovered by Peter Winter-Smith of NCC Group, it’s like a jedi trick:
User:
Let me inServer: NO
User:
I’m authenticated, let me inServer: OK, YOU’RE IN
Why does this happen? Because of the way LibSSH checks for authentication when it receives an SSH2_MSG_USERAUTH_SUCCESS message instead of the SSH2_MSG_USERAUTH_REQUEST message. It acts like the user is already authenticated, so an attacker could bypass the authentication and execute commands on the server.
Building the environment
How does LibSSH work? It’s a C library to implement SSHv2 protocol on the client and server side. First, we need to write our server-side code. We are going to use the sample that LibSSH has (samplesshd-cb.c) and modify it for our purposes.
In the ssh_channel_callbacks_struct we are going to put the following line in order to have the exec functionality:
exec request.

Next, add the exec_request function, this will take our commands and execute them on the server:
If you have LibSSH with version 0.7.4 you can simply save it, compile it, and execute it. If not, you can use our method. We are going to use a docker container and install both versions (a vulnerable one and a patched one) and then, pass our code to the server and run it. The example files can be downloaded here.
To build the container, open a terminal in the folder of the Dockerfile and run this command:
This will download all the necessary files and compile all the sources of LibSSH.
Then, to open the container simply run this command:
This is going to mirror our port 2222 to the container port 2222 in order to be able to run our tests. Also, it will open a bash terminal on the container machine where we will run our LibSSH server.
Exploiting the vulnerability
In this case, we are going to use LibSSH v0.7.4 and test the solution with LibSSH v0.7.6. The PoC is on Python version 2, and you can check its source here, but if you downloaded our files, it’s there as exploit.py.
In order to run this PoC you will need paramiko. You can install it by running:
In the container, run the following command to start the vulnerable LibSSH server:
The verbose flag is to see what is sending and receiving our server.
Then, in your machine run the exploit with:
If you check your container, you can see this:

When the server is expecting the SSH2_MSG_USERAUTH_REQUEST, we are sending an SSH2_MSG_USERAUTH_SUCCESS.
The server accepts it, and we bypassed the authentication. Then, we can send our commands to the server with:

The solution

The LibSSH version 0.7.6 doesn’t have this vulnerability. We can test it, too, in our container. We just need to run:
And on our machine the exploit again:

What’s happening? We send the SSH2_MSG_USERAUTH_SUCCESS. The server receives it, but it won’t authenticate us because they added a validation on their code. When the packet is SSH2_MSG_USERAUTH_SUCCESS, then, it checks for the authentication state. If it is not one of the valid states, it denies the packet.

Code on src/packet.c.
Here you can see the difference between responses for a vulnerable version and a non-vulnerable one.

Vulnerable.

Non-vulnerable.
If you have LibSSH in your server, and you are using a server component, you should install the updated, or patched, versions of LibSSH.
Get started with Fluid Attacks' PTaaS right now
Other posts
















