.egg files and EGG-INFO scripts
On import once the egg is on sys.path; EGG-INFO scripts at install time
- Lives in
.egg files in site-packages (registered via easy-install.pth)- Attacker needs
- Supply-chain foothold, Filesystem write access
- Lifecycle
- InstallStartupyour codeModule loadRuntimeREPL
Runs on import or require, for every module the app loads.
How it runs
Eggs came before wheels. An egg is a zip archive that holds a Python package plus metadata. easy_install dropped them into site-packages and registered them on sys.path through easy-install.pth. The same zipimport machinery applies, so an egg can carry an __init__.py with arbitrary code, or modules that shadow standard-library names.
Eggs are deprecated in favor of wheels, but they haven't died out. Legacy codebases, old internal repos and pinned setuptools versions keep them around. The EGG-INFO directory can also hold scripts that easy_install executes during installation, which is a second way to run code at install time.
Defend
Migrate off eggs to wheels; pin modern setuptools; audit easy-install.pth and legacy internal package repos.