Skip to main content

Python Package Installation: to sudo or not to sudo

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



Comments

Popular posts from this blog

Angr: A Multi-Architecture Binary Analysis Toolkit

This blog is quoted from several angr blogs and documentations, click  here  and  here . angr is a multi-architecture binary analysis toolkit, with the capability to perform dynamic symbolic execution (like Mayhem, KLEE, etc.) and various static analyses on binaries. We've tried to make using angr as pain-free as possible - our goal is to create a user-friendly binary analysis suite, allowing a user to simply start up iPython and easily perform intensive binary analyses with a couple of commands. That being said, binary analysis is complex, which makes angr complex. This documentation is an attempt to help out with that, providing narrative explanation and exploration of angr and its design. Several challenges must be overcome to programmatically analyze a binary. They are, roughly: Loading a binary into the analysis program. Translating a binary into an intermediate representation (IR). Performing the actual analysis. This could be: A partial or full-program static

Information Side Channel

By Elaine Cole and Jarek Millburg An information side channel can be used to gain information about the system or data that it processes. A side-channel attack identifies a physical or micro-architectural signal that leaks such desired information and monitors and analyzes that signal as the system operates. While there are many different types of information side channels and even more ways to maliciously exploit them, this blog explores a recent publication that leverages information side channels within IoT devices to aid crime scene investigators in real-time. In this blog, we provide an overview of the general attack procedure, and explore two of the many forms of side channel attacks. Side Channel Attack General Procedure While there are many different forms of side channels, at a high level, a side channel attack requires the following: 1. identify a side channel:  The attacker must first identify  a physical or micro-architectural signal that leaks desired

Introduction to SGX and potential attack method

The Overview of SGX What is the SGX? With more and more attack on systems and bigger danger inside the internet. We get a new technology which named The Security Guard Extensions (The SGX). Actually the SGX aimed to separate the whole applications to two parts: secure part and unsecure part. The secure part named enclave. Which is stored in protected memory. Between the enclave and application, there is an interface is implemented. Which is consists of e-calls and o-calls. The e-calls are inside the enclave for calling to the unsecured code. The o-calls are located in the unsecured code for collecting data inside the enclave. The enclave is totally protected which means any access from external are not allowed. Only when the untrusted part of application call the trusted function then the code inside the enclave can see the data. When it returns, the enclave data are still stays in safe memory. figure.1 Actually while the application’s host in pr