subprocess module call
Medium
- Category
- Dangerous Code Execution
- Content
script_path = os.path.abspath(__file__) cron_line = f"0 6 * * * /usr/bin/python3 {script_path} fetch" try: subprocess.run( f'(crontab -l 2>/dev/null; echo "{cron_line}") | crontab -', shell=True, check=True, capture_output=True )- Confidence
- 97% confidence
- Finding
- This call builds a shell command string and executes it with shell=True to install a crontab entry. If the script path contains shell metacharacters or quotes, it can break out of the quoted context and execute unintended commands, turning a convenience feature into command injection and persistence.
