Pip Download Code Execution
Pip is a package management system written in Python. It can download custom Python package so we can create a malicious package to execute arbitrary code.
Reference: https://github.com/wunderwuzzi23/this_is_fine_wuzzi
Assume the package named "exploitpy". We need to create "setup.py" in the project root, and "init.py", "main.py" in src directory.
Below is the content of the "setup.py".
The arbitrary code is injected in the “RunCommand” method. It is executed when pip download
command.
To package the project, run the following command in the project root.
It generates .tar.gz
file in dist
folder.
We need to host the package using pypi-server
.
Then download the package by the following command. If the pip command can be executed as root, we can also escalate privileges. When downloading, arbitrary code, that we specified in setup.py, will be executed.
References
Last updated