Python programming language is having an increasing presence in IoT projects. According to a survey of IoT developers conducted in 2016, python is among the top 4 languages they use in their projects. One of the benefits of using python is its variety of powerful packages, which can easily be installed. The very same characteristic, however, could introduce security challenges. In this blog, we discuss how improper python package installation can introduce security risks and look into some examples.
Python packages are created and maintained in an open-source fashion, where the community publishes packages on Python Package Index (PyPi) website. Some malicious people, however, use this ecosystem to trick python programmers and compromise their security.
Typically, installing python packages starts with the command pip install [package-name], which often throws an error on not having enough permissions to complete installation.
The next option for many people is to choose one of the following:
sudo pip install [package-name]
or
pip install --user [package-name]
To motivate the topic of this blog, we first gauge which command our classmates use in a poll:
The claim is that using sudo with python package installation is a bad practice in terms of security. To understand why, we need to understand the basic structure of python packages, as shown in the figure below.
When installing a package, the file setup.py is executed. Now, one could include malicious code in that file and compromise the system when give root access. As demonstrated in class, we were able to remove some root-owned folder by just installing a python package with root privileges. The figure below shows the malicious content of our setup.py.
Example attacks:
Malicious Packages: Packages specifically written to compromise user information or system. Inexperienced users may fall for these traps.
Typosquatting: Packages with names extremely similar to legitimate packages. Users can fall for this trap by simply mis-spelling the installation command.
Unintentional Vulnerabilities: Packages with design issues, which could unintentionally cause compromise in end-users’ security.
The table below shows a few malicious packages that were exploiting using typosquatting.
As a specific example, let's consider the colorama vs. colourama incident. Colorama is a python package for adding colors to windows terminal. On the other hand, hackers developed colourama (British spelling) to install a script on the victim's computer. The script would replace every bitcoin link in the clipboard with the bitcoin link of the malicious developer, redirecting money to the malicious person's account.
The conclusion of this blog is the following: the safer option for installing python packages is to use pip install --user [package-name].
Python packages are created and maintained in an open-source fashion, where the community publishes packages on Python Package Index (PyPi) website. Some malicious people, however, use this ecosystem to trick python programmers and compromise their security.
Typically, installing python packages starts with the command pip install [package-name], which often throws an error on not having enough permissions to complete installation.
The next option for many people is to choose one of the following:
sudo pip install [package-name]
or
pip install --user [package-name]
To motivate the topic of this blog, we first gauge which command our classmates use in a poll:
The claim is that using sudo with python package installation is a bad practice in terms of security. To understand why, we need to understand the basic structure of python packages, as shown in the figure below.
When installing a package, the file setup.py is executed. Now, one could include malicious code in that file and compromise the system when give root access. As demonstrated in class, we were able to remove some root-owned folder by just installing a python package with root privileges. The figure below shows the malicious content of our setup.py.
Example attacks:
Malicious Packages: Packages specifically written to compromise user information or system. Inexperienced users may fall for these traps.
Typosquatting: Packages with names extremely similar to legitimate packages. Users can fall for this trap by simply mis-spelling the installation command.
Unintentional Vulnerabilities: Packages with design issues, which could unintentionally cause compromise in end-users’ security.
The table below shows a few malicious packages that were exploiting using typosquatting.
As a specific example, let's consider the colorama vs. colourama incident. Colorama is a python package for adding colors to windows terminal. On the other hand, hackers developed colourama (British spelling) to install a script on the victim's computer. The script would replace every bitcoin link in the clipboard with the bitcoin link of the malicious developer, redirecting money to the malicious person's account.
The conclusion of this blog is the following: the safer option for installing python packages is to use pip install --user [package-name].
Comments
Post a Comment