Skip to content

Commit

Permalink
Add crontab persistence and LoginHook persistence (#29)
Browse files Browse the repository at this point in the history
* Add crontab persistence

#17

* Shorten URL

* Add LoginHook persistence method

* Add comment for removal
  • Loading branch information
alichtman authored May 3, 2019
1 parent b19e8b7 commit fdad053
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/persistence/macOS/LoginHook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This approach is explained in Patrick Wardle's "Methods of Malware
# Persistence on macOS" paper on page 18.
#
# NOTE: Untested.


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


def main():
action = choice("Establish persistence or remove persistence?", [" Establish", " Remove"])

if action == "establish":
print_blue("Establishing macOS persistence with LoginHook")
command = "sudo defaults write com.apple.loginwindow LoginHook"
path = input("Enter the path of a script you'd like to run on login.")
if not os.path.isfile(path):
print_red("ERROR: {} is not a file.".format(path))
sys.exit(1)

# TODO: Print stdout, stderr
run_cmd("{} {}".format(command, path))
print_green("Persistence established.")
elif action == "remove":
print_blue("Removing macOS persistence with LoginHook")
command = "sudo defaults delete com.apple.loginwindow LoginHook"
# TODO: Print stdout, stderr
run_cmd("{} {}".format(command))
print_green("Persistence removed.")


if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions src/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import inquirer
import platform
import subprocess as sp
from colorama import Fore, Style


def get_os_name():
Expand All @@ -16,3 +18,14 @@ def run_cmd(command):
else:
process = sp.run(command, stdout=sp.PIPE, stderr=sp.DEVNULL)
return process


def choice(question, choices):
"""
Displays list of choices and returns the one that was selected.
"""
choice_prompt = [inquirer.List('choice',
message=Fore.GREEN + Style.BRIGHT + question + Fore.BLUE,
choices=choices)
]
return inquirer.prompt(choice_prompt).get('choice').strip()

0 comments on commit fdad053

Please sign in to comment.