Is this binary Naughty or Nice? How Google leverages ML and Santa to detect persistence on MacOS

Kristin Smith (Security Engineer · Google)

BSides Canberra VIII (2025) · Day 2 · Main Track

Overview

In an insightful talk at BSides Canberra, Kristin Smith, a Security Engineer at Google, unveiled a sophisticated machine learning-backed solution designed to tackle the persistent and noisy problem of detecting malicious file access and persistence on macOS. Titled "Is this binary Naughty or Nice? How Google leverages ML and Santa to detect persistence on MacOS," the presentation detailed Google's journey to move beyond traditional, reactive security measures by proactively identifying suspicious file system interactions that often precede or enable credential theft and system persistence. Smith, known as Krispy, collaborated with Sard Miy, a software engineer specializing in deep learning for risk detection, and Kathy, the Identity Task Force tech lead, to develop this innovative approach.

Watch on YouTube

Visual summary for Is this binary Naughty or Nice? How Google leverages ML and Santa to detect persistence on MacOS by Kristin Smith
Visual summary for Is this binary Naughty or Nice? How Google leverages ML and Santa to detect persistence on MacOS by Kristin Smith

Key moments

  1. 2:20 The problem: detecting credential theft
  2. 4:40 Mimicking human investigation of suspicious activity
  3. 8:00 Santa: Google's open-source macOS security agent
  4. 10:10 Featurizing log data using embeddings
  5. 16:30 Anomaly scoring with nearest neighbor search
  6. 18:00 Model performance and exercise results
  7. 20:00 Applying the model to detect macOS persistence
  8. 25:30 Model limitations and future improvements

Is this binary Naughty or Nice? How Google leverages ML and Santa to detect persistence on MacOS

Speakers: Kristin Smith (Security Engineer, Google)

Conference: BSides Canberra

YouTube: https://www.youtube.com/watch?v=YJWfkTU6MLc

Overview

In an insightful talk at BSides Canberra, Kristin Smith, a Security Engineer at Google, unveiled a sophisticated machine learning-backed solution designed to tackle the persistent and noisy problem of detecting malicious file access and persistence on macOS. Titled "Is this binary Naughty or Nice? How Google leverages ML and Santa to detect persistence on MacOS," the presentation detailed Google's journey to move beyond traditional, reactive security measures by proactively identifying suspicious file system interactions that often precede or enable credential theft and system persistence. Smith, known as Krispy, collaborated with Sard Miy, a software engineer specializing in deep learning for risk detection, and Kathy, the Identity Task Force tech lead, to develop this innovative approach.

The core motivation for this project stems from the limitations of conventional antivirus (AV) software, which primarily relies on signature-based detections and known bad heuristics. While effective against widespread, well-understood malware, these tools often fail to catch sophisticated or novel threats that interact with the file system in unexpected ways. Google, with its vast user base and sensitive corporate data, faces a critical need to detect compromise earlier in the attack chain, particularly concerning the abuse and theft of credentials, tokens, and cookies. This talk elucidated how leveraging machine learning, specifically deep learning models for text and contextual embeddings, combined with the open-source Santa macOS security agent, offers a scalable and effective solution to a problem that generates an unmanageable volume of log data.

Background

▶ Watch: The problem: detecting credential theft (2:20)

The landscape of modern cybersecurity demands a shift from reactive incident response to proactive threat detection. Kristin Smith highlighted a critical gap in traditional security strategies: while detecting credential abuse is beneficial, intervention often occurs too late in the attack chain. The fundamental question for Google's security team was not just that credentials were stolen, but how the theft occurred in the first place. This necessitates monitoring activities closer to the source of compromise, such as malware interacting with the host file system.

Traditional antivirus solutions, as Smith explained, excel at identifying known threats through signature-based detections and known bad heuristics. This approach is effective for malware that has been previously cataloged and analyzed, allowing security tools to look for specific patterns or file hashes. However, sophisticated malware is designed to evade these static detections. These advanced threats, even when polymorphic or obfuscated, still fundamentally need to interact with the file system to achieve their objectives—whether it's reading sensitive data, writing configuration files for persistence, or modifying system settings. Traditional tools often struggle here because they are not designed to identify anomalous behavior at the file system level, only known malicious files or attack patterns.

The challenge is further compounded by the sheer volume of data generated by file operations. Smith noted that a single machine can generate "tens of thousands of file accesses per day." Scaling this to Google's corporate fleet results in an "absolutely huge" amount of log data, making manual investigation of every suspicious log entry utterly infeasible. This high-volume, noisy data environment is precisely where machine learning offers a transformative advantage. The objective was to codify the logic a human security engineer would employ when investigating a suspicious execution—identifying unusual file paths, command arguments, process lineage, and user context—and apply this logic at an unprecedented scale using an ML-backed solution. Initially focused on sensitive credential access, the project quickly expanded to encompass other critical file-based threats, including the establishment of persistence on macOS.

Key Findings

▶ Watch: Santa: Google's open-source macOS security agent (8:00)

The Google security team's project successfully demonstrated that a machine learning-backed solution can effectively detect sophisticated file-based malware activities, particularly persistence mechanisms, on macOS at a massive scale. The key findings and contributions include:

  • Effective Anomaly Detection in High-Volume Data: The model proved capable of sifting through tens of millions of benign file access logs to identify genuinely anomalous activities. During an internal offensive security exercise, custom binaries designed to read sensitive credentials (like SSO tickets and machine certificates) were consistently flagged with high anomaly scores. For instance, the HTTPS disk binary, used in a sample investigation, received an average rank of 152 out2 of 382,525 unique log tuples, placing it in the top 0.015% of anomalous scores for a one-week period. Another variant scored even higher, ranking 11th overall.
  • Leveraging Open-Source Endpoint Telemetry: The project successfully integrated Santa, an open-source macOS security agent, as the primary data source for file access events. This highlights the value of granular endpoint telemetry in feeding advanced ML models. Santa's ability to log detailed information about process, file, user, and action taken was crucial for featurization.
  • Sophisticated Featurization Techniques: The talk showcased the power of deep learning models for creating meaningful numerical representations (embeddings) of complex, unstructured data:
  • RETSSIM (Resilient and Efficient Text Similarity): Used for embedding file paths and command-line arguments, demonstrating that character-level vectorization and transformer models can accurately capture semantic similarity, allowing the model to detect subtle variations or novel command structures.
  • Facade (Fast and Accurate Contextual Anomaly Detection): Employed for generating user embeddings based on peer graphs and historical interactions, proving that incorporating user context (e.g., role, typical activities, shared attributes) significantly enhances anomaly detection precision by distinguishing truly suspicious behavior from legitimate, albeit unusual, actions by engineers.
  • Scalable Anomaly Scoring: The architecture, utilizing a Scan server for approximate nearest neighbor search, demonstrated the feasibility of performing real-time anomaly scoring against a massive historical dataset of embeddings, enabling the system to identify outliers efficiently.
  • Proven Detection of macOS Persistence: The model was specifically applied and validated for detecting persistence on macOS. A simulated attack involving a Golang program writing a malicious property list (superduperus.plist) to the ~/Library/LaunchAgents/ directory scored 0.4357 out of a maximum of 0.439, making it the second most anomalous log entry among nearly 8,000 unique Launch Agent write events in a 24-hour period. This concrete example underscores the model's ability to catch a critical attack vector.
  • Identification of Key Limitations and Future Work: While successful, the project openly acknowledged limitations such as distribution shift for new binaries, challenges in explainability, high training costs, and the current inability to monitor every file on a host. These insights provide a roadmap for future improvements, including incorporating executable integrity checks (e.g., hashes) and evaluating sequences of events rather than single logs.

Technical Deep Dive

▶ Watch: Anomaly scoring with nearest neighbor search (16:30)

The technical foundation of Google's anomaly detection system for macOS file access is built upon a sophisticated pipeline that transforms raw log data into actionable anomaly scores, mirroring a human security engineer's investigative process but at an unparalleled scale.

The initial step involves capturing comprehensive file access telemetry. Google leverages Santa, an open-source macOS security agent originally developed at Google and now maintained by North Pole Security. Santa's file access authorization feature is configured to log all file access events that match specified policies. These logs are rich in detail, capturing the timestamp, the process attempting the access, the specific file being accessed, the action taken (e.g., read, write), and the policy that triggered the log. This granular data is crucial for monitoring a wide array of threats, including malicious LaunchAgent or LaunchDaemon writes (for persistence), modification of SSH config, and info-stealing activities targeting browser data, session tokens, or cookies.

Once the logs are collected, the core challenge lies in transforming this high-volume, unstructured text data into a format interpretable by machine learning models. This is achieved through a multi-faceted featurization stage, focusing on three key aspects of a log entry: the sensitive file path, the command that accessed it, and the user who ran the command. Each of these features is converted into a numerical representation called an embedding.

For the file path and command-line arguments, the team utilizes RETSSIM (Resilient and Efficient Text Similarity), a multilingual deep learning model. Unlike traditional models that process text at the word or subword level, RETSSIM employs character-level vectorization (REVC). The process involves:

  1. Chunking: The input string (file path or command) is split into manageable pieces, each up to 512 characters long.
  2. REVC Character Encoder: Each Unicode character within a chunk is converted into a compact 24-bit binary representation, transforming text into a dense numerical format.
  3. Transformer Model: A small transformer neural network processes each chunk, analyzing character relationships to create a 256-dimensional vector, or partial embedding, for each chunk.
  4. Embedding Averaging Module: All partial embeddings from the chunks are combined to produce a single, unified 256-dimensional vector that represents the entire input string. The fundamental principle here is that text strings with similar meanings or structures will have embeddings that are numerically "closer" in this high-dimensional space.

The user embedding is more complex and leverages Google's internal Facade (Fast and Accurate Contextual Anomaly Detection) framework. Facade is a high-precision deep learning system designed for anomaly detection, operating as a generalized action context framework. It generates embeddings and an anomaly score based on two sets of features:

  1. Context Features: These model relationships between "principles" (employees in this case) using a peer graph. This bipartite graph connects principles to shared entities or "peer attributes" like meeting IDs or employment groups. A principle's context feature is computed by identifying all other principles reachable within two hops on the graph, effectively capturing who they interact with and in what shared contexts (e.g., colleagues who attended the same meeting).
  2. Action Features: These represent a principle's interaction with a "resource" at a specific point in time. Facade examines past actions on that resource, considering the principles who interacted with it previously. These principles are aggregated into a weighted bag of tokens, where weights indicate the recency and frequency of past interactions.

By combining these context and action features, Facade produces user embeddings that reflect typical behavior, allowing the system to flag deviations from a user's established patterns or their team's norms.

Once all three embeddings (file path, command, user) are generated for a given log entry, they are sent via RPC requests to a Scan server. This server is responsible for performing an approximate nearest neighbor search at a very large scale. The Scan server organizes the vast collection of historical log embeddings into optimized data structures. When a new log's embeddings arrive, it quickly searches its index using a hybrid coarse and fine-grain search method. This involves broadly filtering the data first, then precisely checking the closest candidates to achieve both speed and accuracy. The output of this search is the distance between the query embedding and its next nearest existing embedding. This distance directly translates into an anomaly score: a higher score indicates a greater distance from known benign activities, signifying a higher likelihood of maliciousness.

The entire architecture is supported by a robust backend. An online Scan server continuously performs nearest neighbor searches against a live dataset. This dataset is kept fresh by a daily cron job called the data set creator runner. This runner executes two main components:

  1. training main: Reads yesterday's logs, performs the featurization process, and writes the new embeddings to storage.
  2. merger main: Reads daily datasets from the last six months and merges them into a single, comprehensive search dataset. The online Scan server automatically uses the latest merged dataset, ensuring the model's knowledge base is constantly updated with recent, representative benign activity.

This sophisticated combination of specialized deep learning models for text and contextual embeddings, coupled with scalable nearest neighbor search, enables Google to transform a high-volume, noisy security problem into a manageable and effective anomaly detection system.

Demo / Proof of Concept

▶ Watch: Model performance and exercise results (18:00)

The practical application of this ML-backed system was powerfully demonstrated through its ability to detect macOS persistence, a critical attack vector for adversaries. Kristin Smith outlined how malware often establishes persistence by writing or modifying a property list (plist) file in either the user's ~/Library/LaunchAgents/ or the system-wide /Library/LaunchDaemons/ directory. By setting the RunAtLoad key to true within these plists, malware can ensure automatic execution upon user login (LaunchAgents) or system boot (LaunchDaemons), even before a user signs in. Since this mechanism relies on file write operations, it is an ideal candidate for the model's file access-based detection capabilities.

The demonstration utilized Santa's file access authorization feature to monitor these crucial directories. The setup process involved several steps:

  1. Santa Installation: For development, Santa was installed via Homebrew, with MDM deployment options available for corporate fleets.
  2. Main Configuration Profile Generation: A configuration profile (.mobileconfig) was generated, ideally using the handy config generator provided by North Pole Security to avoid manual XML editing. Key settings included specifying the FileAccessRulesFile (path to the separate policy file) and adjusting the SyncBaseURL interval for development. Verbose JSON logging was also enabled to capture detailed events.
  3. Profile Deployment and Verification: The generated .mobileconfig was installed via the system UI, appearing as a system profile in macOS settings. After granting Full Disk Access, the Santa daemon's status was verified using santactl status.
  4. File Access Authorization Policy Definition: A separate XML .plist file was created to define the specific rules for monitoring. This policy specified the exact file_paths to monitor, such as ~/Library/LaunchAgents/ and /Library/LaunchDaemons/. The audit key was set to true to ensure events were logged without blocking, though Santa supports blocking actions as well.
  5. Rule Activation Verification: santactl status was run again to confirm that the newly defined rules were active under "watch items."

With Santa configured, Smith then simulated a malicious persistence event. A very basic Golang program was executed, designed to write a property list file named superduperus.plist to the user's ~/Library/LaunchAgents/ directory. This action successfully created the file and, crucially, generated a detailed log entry from Santa. The log contained essential information: the user ID, the file path of the written file, and the process name of the executable that performed the write, along with other useful details like the signer.

This generated log was then fed into the ML model for scoring. To ensure a fresh evaluation, the data was run against the model's dataset from two days prior. The results were compelling: across the entire Mac fleet over a 24-hour period, there were 7,886 unique combinations of user processes and file paths for writes to the LaunchAgents directory. The highest anomaly score recorded for the day was approximately 0.439. The simulated superduperus.plist write event received a score of 0.4357, making it the second most anomalous score for the entire day out of nearly 8,000 events. This concrete proof-of-concept unequivocally demonstrated the model's capability to identify novel and malicious persistence attempts with high precision, even in a sea of legitimate activity.

Defensive Implications

▶ Watch: Model limitations and future improvements (25:30)

The Google team's work on detecting file access anomalies and persistence on macOS offers several critical defensive implications for organizations looking to enhance their security posture:

  1. Shift to Proactive, Behavior-Based Detection: The most significant implication is the move away from purely reactive, signature-based detections. Defenders should prioritize solutions that can identify anomalous behavior at the file system level, rather than just known malicious files. This allows for earlier intervention in the attack chain, potentially preventing credential theft or persistence before it can be fully leveraged.
  2. Invest in Granular Endpoint Telemetry: The success of this model heavily relies on the rich, detailed logs provided by agents like Santa. Organizations should ensure their endpoint security agents are capable of logging comprehensive file access events, including process details, user context, file paths, and actions taken. This foundational data is indispensable for any ML-driven detection system.
  3. Prioritize Sensitive File Monitoring: Given the high volume of file operations, it's impractical to monitor everything. Defenders should strategically identify and prioritize sensitive files and directories on their systems—such as credential stores, browser data, SSH configuration files, and persistence locations like LaunchAgents and LaunchDaemons—and configure their logging and detection systems to focus on these critical assets.
  4. Leverage Machine Learning for Scale: Manual investigation of file access logs is simply not scalable in modern enterprise environments. Organizations should explore integrating machine learning techniques, particularly deep learning for embeddings and approximate nearest neighbor search, to automate the identification of anomalous activities from vast datasets. This allows security teams to focus on high-fidelity alerts rather than sifting through noise.
  5. Incorporate User and Contextual Information: The use of Facade for user embeddings highlights the importance of context. Security teams should strive to integrate user identity, role, team, and historical behavior into their anomaly detection models. This helps differentiate legitimate, albeit unusual, actions by technical users from truly malicious deviations.
  6. Understand and Address ML Limitations: Defenders must be aware of the inherent challenges of ML models, as acknowledged by Smith:
  • Distribution Shift: New, legitimate binaries deployed across a fleet may initially trigger high anomaly scores. This requires mechanisms for model retraining and potentially adaptive thresholds.
  • Explainability: ML models can sometimes produce alerts without clear explanations. Defenders should be prepared for manual investigation, often by comparing anomalous logs to their nearest benign neighbors, to understand why a specific event was flagged.
  • Scope and Cost: Comprehensive monitoring of every file on every host might be computationally expensive or technically infeasible. Strategic filtering and phased rollouts are often necessary.
  • Lack of Execution Context: Current models often evaluate single log entries. Future defensive strategies should aim to incorporate sequences of events to build a more holistic picture of an attack.
  • Integrity Checks: Relying solely on raw text is insufficient. Integrating executable integrity checks (e.g., file hashes, code signing information) into the featurization process can significantly improve detection accuracy and prevent evasion.

By embracing these implications, organizations can move towards a more sophisticated, proactive, and scalable security posture, better equipped to detect and mitigate advanced threats that target the file system for initial access and persistence.

Key Takeaways

  • Traditional AV is Insufficient for Advanced Threats: Signature-based antivirus struggles against sophisticated malware that interacts with the file system in novel ways; a machine learning approach is crucial for detecting these evasive threats at scale.
  • Comprehensive Endpoint Telemetry is Foundational: Agents like Santa, providing granular file access logs (process, file path, user, action), are indispensable for feeding the rich data required by advanced ML detection models.
  • Deep Learning Embeddings Transform Noisy Data: Utilizing models like RETSSIM for file path/command embeddings and Facade for user context embeddings allows for the conversion of unstructured log data into meaningful numerical representations, enabling effective anomaly detection.
  • Scalable Anomaly Detection is Achievable: Approximate Nearest Neighbor search, implemented via a Scan server, provides a highly efficient method for comparing new file access events against massive historical datasets to identify outliers and assign anomaly scores.
  • Effective Detection of macOS Persistence: The system successfully identified simulated macOS persistence attempts (e.g., writing to LaunchAgents/LaunchDaemons) with high anomaly scores, demonstrating its practical value in catching critical attack vectors.
  • Continuous Refinement is Key for ML Models: While powerful, ML solutions require ongoing effort to address challenges such as distribution shift, model explainability, training costs, and the need to incorporate broader execution context for optimal performance.

About the Speaker(s)

Kristin Smith (Krispy) is a Security Engineer on Google's Detection and Response team. At the time of working on this project, she was a member of Google's Identity Task Force, specializing in the abuse and theft of credentials, tokens, and cookies from disk. Her work focuses on developing innovative solutions to complex security problems within Google's vast infrastructure.

Sard Miy is a Software Engineer on Google's Brainor team. His expertise lies in utilizing deep learning and large-scale data analysis to enhance authorization and risk detection capabilities across Google, providing critical tools and frameworks that support the security incident detection and response efforts.

Kathy served as the Identity Task Force Tech Lead at Google. Her leadership and technical guidance were instrumental in bringing this project to fruition, guiding the team's efforts in securing user identities and corporate data.

Reviews

→ Top-rated talks at BSides Canberra VIII (2025)

All talks from BSides Canberra VIII (2025)