Rapid7

module

Python Site-Specific Hook Persistence

Disclosed
Sep 29, 2012
Created
Jan 7, 2026

Description

This module leverages Python's startup mechanism, where some files can be automically processed during the initialization of the Python interpreter. One of those files are startup hooks (site-specific, dist-packages). If these files are present in site-specific or dist-packages directories, any lines beginning with import will be executed automatically. This creates a persistence mechanism, if an attacker has established access to target machine with sufficient permissions.

Author

msutovsky-r7

Platform

Linux,OSX,Windows

Architectures

cmd

Module Options

To display the available options, load the module within the Metasploit console and run the commands 'show options' or 'show advanced':


msf > use exploit/multi/persistence/python_site_specific_hook
msf exploit(python_site_specific_hook) > show targets
...targets...
msf exploit(python_site_specific_hook) > set TARGET < target-id >
msf exploit(python_site_specific_hook) > show options
...show and set options...
msf exploit(python_site_specific_hook) > exploit

Title
Rapid7 Labs

2026 Global Threat Landscape Report

The predictive window has collapsed. Exploitation follows disclosure in days. See how attackers are accelerating and how to stay ahead.