In our digital world, secure authentication methods play a crucial role. SSH is one such method that is widely used, particularly in the IT sector. However, not everyone realises that the security of SSH depends largely on the security of the keys used. Outdated algorithms and less obvious vulnerabilities, such as Fermat factorisation or the Debian OpenSSL bug, can leave keys – and thus the entire authentication process – vulnerable. Most users generate their SSH keys automatically using tools such as OpenSSL or PuTTY. However, these tools may contain vulnerabilities that render the generated keys insecure – usually without users even realising it. And even when such vulnerabilities are fixed, the insecure keys often remain in circulation for a long time. The Badkeys tool enables checking SSH keys for specific issues automatically. We tested this on a GitLab instance and were able to automatically test all users’ keys.
The generation of cryptographic keys is a complex process in which a variety of problems can arise. These are usually hidden deep within the generation tool andare not apparentto users . Known vulnerabilities include, for example:
It is important to emphasise that these issues are not fundamental vulnerabilities in the algorithms or in SSH itself, but rather implementation errors in the respective systems. Vulnerabilities such as these regularly come to light and are usually fixed quickly. For the average user, however, it is virtually impossible to keep up to date with these developments and maintain an overview of which keys were generated using which tools and may need to be updated.
Badkeys is an open-source tool that scans cryptographic keys for a range of known vulnerabilities. It is available online, as a CLI tool and as a Python module.
At the heart of the application is an algorithm that checks public keys for a wide range of known vulnerabilities. The process is straightforward: you provide the tool with the public key to be checked. Badkeys then first identifies the key algorithm, such as RSA, DSA or Ed25519. Based on the recognised algorithm, the tool carries out specific tests.
One example of such a test is Fermat factorisation for RSA keys. Here , Badkeyschecks whether the prime numbers making up the key are too close together, which could significantly compromise security. The tool also checks whether the algorithm used is generally considered secure; in the case of RSA, for example, the key must be at least 2048 bits long. Another important feature of Badkeys is that it compares keys against a database of known insecure keys.
At the end, you receive a list of results for each key tested, with each failed test accompanied by a brief explanation. In this way , Badkeysenables administrators and developers to ensure that their keys remain secure and trustworthy.
We used Badkeys to check the SSH keys of all users in our GitLab instance. To do this , we wrote a Python script that first retrieves all users and their (public) SSH keys from GitLab. With a standard GitLab configuration, no special permissions are required for this. The keys are then checked using the Badkeys Python module and the results are recorded in a CSV file. As Badkeys is run locally in this process, no keys need to be transferred to third parties, thereby maintaining confidentiality. In addition to identifying issues with individual keys, our script also reports on the distribution of the algorithms used, to enable a more comprehensive analysis.
During this check, we were unable to identify any serious vulnerabilities in our case; however, we did notice that the now-obsolete RSA-1024 algorithm was still in use in some instances. It was also interesting to note that some colleagues were using RSA keys with unusual exponents, which was attributable to historical practices in tools such as PuTTY and OpenSSH. Until 2020 ,PuTTY used the exponent 37 for RSA keys , and OpenSSH used the exponent 35 until 2010, instead of the recommended exponent 65537.
By informing the colleagues affected about their problematic keys and recommending that they use Ed25519, we were able to make our cyber security a little more robust and future-proof.
The Python script is publicly available here so that others can also benefit from it. We recommend using the script (specifically for GitLab) and Badkeys regularly to check the SSH keys in your infrastructure for potential vulnerabilities. By regularly checking and updating your SSH keys, you can significantly strengthen your cyber security and better protect your systems against attacks.
Do you have any questions or need assistance?
You can find out more about the IT security options available for your business on our website. Please feel free to get in touch with us.