How to Write Sysmon Rules: Getting Fancy(Bear) With Sysmon to Find APT Level Cyber Security Threats

Level Up Your Threat Hunting: Crafting Advanced Sysmon Rules to Detect Fancy Bear

In the ever-evolving landscape of cybersecurity, staying ahead of sophisticated adversaries requires moving beyond basic defenses. For threat hunters and security professionals, this means diving deep into system activity to unearth the subtle traces of an intrusion. This is where a properly configured System Monitor (Sysmon) becomes an indispensable ally.

This guide will walk you through the process of building more advanced Sysmon rules, moving beyond the default settings to create a high-fidelity detection system. We’ll use the tactics, techniques, and procedures (TTPs) of the notorious advanced persistent threat (APT) group, Fancy Bear (also known as APT28), as a practical example to craft targeted rules that can bolster your security posture.

Why Go Beyond Basic Sysmon Rules?

Out of the box, Sysmon can generate a significant amount of data. While comprehensive, this raw data stream can be noisy, making it difficult to pinpoint genuinely malicious activity. Imagine trying to find a single malicious network connection amidst thousands of legitimate requests from web browsers. You’d be searching for a needle in a digital haystack.

This is where the power of Sysmon rules comes into play. By creating a custom configuration, you can filter out the noise and focus on the events that truly matter. Advanced rules allow you to:

  • Reduce Alert Fatigue: By excluding benign activity, you can ensure that the alerts your team investigates are more likely to be legitimate threats.
  • Enhance Detection Accuracy: Targeted rules based on known adversary behaviors increase the probability of catching specific attack techniques.
  • Improve System Performance: Filtering unnecessary events can reduce the load on your logging infrastructure and the endpoints themselves.

Understanding the Building Blocks of a Sysmon Rule

A Sysmon configuration is an XML file that defines which events to log and how to filter them. At the heart of this configuration are rule groups and conditions.

  • Rule Groups: These allow you to group individual rules together using logical operators like AND and OR. This is crucial for creating complex detection logic.
  • Conditions: These specify the criteria for a rule to match. You have a variety of conditions at your disposal, including:
    • is: An exact match.
    • contains: The field includes the specified substring.
    • begins with / ends with: The field starts or ends with a specific string.
    • less than / more than: Used for alphabetical or numerical comparisons.
    • is any: Matches any value in a provided list.

By combining these elements, you can create highly granular rules that target specific fields within a Sysmon event.

Getting Fancy: Targeting the TTPs of Fancy Bear

To illustrate the power of advanced Sysmon rules, let’s turn our attention to the infamous Fancy Bear. This group is known for its sophisticated and persistent attacks. We’ll focus on a few of their known techniques, including the use of their “Chopsticks” malware and a clever persistence method involving Microsoft Office registry keys.

Detecting Chopsticks Malware Behavior

The Chopsticks malware is a modular framework used by Fancy Bear for years. Based on threat intelligence reports, we know it exhibits several key behaviors that we can hunt for with Sysmon:

  • Command and Control (C2) Communication: Chopsticks often uses common protocols like HTTP, HTTPS, and SMTP for its C2 communications to blend in with normal network traffic.
  • Hidden File Creation: The malware is known to create hidden files in predictable directories.
  • Registry-Based Data Storage: It encrypts and stores configuration data within the Windows Registry.

Now, let’s translate this intelligence into a set of Sysmon rules:

XML

 
<Sysmon schemaversion="4.81">
  <EventFiltering>
    <RuleGroup name="FancyBear_Chopsticks_Network" groupRelation="or">
      <NetworkConnect onmatch="include">
        <DestinationPort name="HTTP" condition="is">80</DestinationPort>
        <DestinationPort name="HTTPS" condition="is">443</DestinationPort>
        <DestinationPort name="SMTP" condition="is">25</DestinationPort>
      </NetworkConnect>
    </RuleGroup>

    <RuleGroup name="FancyBear_Chopsticks_FileCreate" groupRelation="or">
      <FileCreate onmatch="include">
        <TargetFilename condition="contains all">\Users\Public;.$</TargetFilename>
      </FileCreate>
    </RuleGroup>

    <RuleGroup name="FancyBear_Chopsticks_Registry" groupRelation="or">
      <RegistryEvent onmatch="include">
        <TargetObject condition="contains">HKCU\Software\Microsoft\Windows\CurrentVersion\Run</TargetObject>
      </RegistryEvent>
    </RuleGroup>

    <RuleGroup name="BrowserExclusions_Dangerous" groupRelation="or">
      <NetworkConnect onmatch="exclude">
        <Image condition="ends with">firefox.exe</Image>
        <Image condition="ends with">iexplore.exe</Image>
        <Image condition="ends with">msedge.exe</Image>
      </NetworkConnect>
    </RuleGroup>
  </EventFiltering>
</Sysmon>

A crucial note on exclusions: While it’s tempting to exclude noisy processes like web browsers from network connection logging, be aware of the risks. Attackers can hijack legitimate processes or name their malware after them to evade detection. Use exclusions judiciously and with a clear understanding of the potential blind spots you are creating.

Uncovering Persistence Through Office Registry Keys

Fancy Bear has also been observed using a creative persistence technique that leverages a legitimate Microsoft Office feature. By modifying specific registry keys, they can execute arbitrary code when an Office application, or even Internet Explorer, is launched.

This technique was publicly documented before it was known to be used by Fancy Bear, highlighting the importance of proactive threat hunting. By understanding how such a technique works, we can create a Sysmon rule to detect it, regardless of the actor using it.

Here’s a simple yet effective rule to monitor for this behavior:

XML

 
<Sysmon schemaversion="4.81">
  <EventFiltering>
    <RuleGroup name="FancyBear_Office_Persistence" groupRelation="or">
      <RegistryEvent onmatch="include">
        <TargetObject condition="contains">Software\Microsoft\Office test\Special\Perf</TargetObject>
      </RegistryEvent>
    </RuleGroup>
  </EventFiltering>
</Sysmon>

This rule will alert you whenever a value in this specific registry key is modified, a strong indicator of this persistence technique.

Implementing and Validating Your New Rules

Once you’ve crafted your advanced Sysmon rules, you need to apply them. You can update an active Sysmon agent with your new configuration file using the following command:

sysmon.exe -c your_config_file.xml

To verify that your rules have been loaded correctly, you can use:

sysmon.exe -c

This will display the currently active configuration.

The Takeaway: Proactive Defense Through Intelligence-Driven Monitoring

Sysmon is a powerful tool, but its true potential is unlocked through thoughtful and tailored configuration. By moving beyond the basics and crafting advanced rules based on the known TTPs of adversaries like Fancy Bear, you can transform Sysmon from a simple logging utility into a high-fidelity threat detection engine.

The key is to remain proactive. Continuously research new attack techniques, refine your rules, and never stop hunting for the subtle signs of a compromise. With the right approach, you can significantly raise the cost for attackers and better protect your organization.

See how Insane Cyber transforms security

Our products are designed to work with
you and keep your network protected.