EZ LearnEZ Learn
Courses
EZ Board
Dashboard
All articles
Educationyarasnortsuricata

Network Signatures and YARA Rules

Writing YARA rules for endpoint detection and Snort/Suricata rules for network detection: rule structure, string modifiers, condition logic, and how to test and validate both rule types against real samples.

Ashish Revar12 May 202616 min read38 views
1 EZ Byte 1:16 total
Sign in to track your progress

EZ Bytes · quick recaps

YARA at the Endpoint. Snort at the Perimeter. Two Rules. One Defence.

76s

From Analysis to Defence

After analysing a malware sample, the analyst produces defensive signatures that security tools can deploy immediately. Two signature types cover the two detection domains:

  • YARA rules: match file content on disk or in memory at the endpoint
  • Snort/Suricata rules: match network traffic at the sensor

Together they provide defence in depth: YARA stops the file if it reaches a host, Snort/Suricata blocks the C2 communication at the network perimeter.

YARA Rules

YARA is a pattern-matching tool for files and memory. A YARA rule has three sections: metadata, strings, and condition.

Rule structure

rule Detect_Dropper_C2 {
    meta:
        description = "Detects dropper with hardcoded C2"
        author      = "Ashish Revar"
        date        = "2026-05-12"
        hash        = "abc123..."

    strings:
        $mz   = { 4D 5A }                           // PE magic bytes
        $cmd  = "cmd.exe /c" ascii nocase
        $url  = "http://evil.com/gate.php" wide ascii
        $ua   = "Mozilla/5.0 (compatible)" ascii
        $mutex = "Global\\MicrosoftUpdateService3"

    condition:
        $mz at 0 and 2 of ($cmd, $url, $ua, $mutex)
}

String types and modifiers

TypeSyntaxWhat It Matches
Plain string$s = "cmd.exe"Exact byte sequence
ascii$s = "cmd.exe" asciiASCII encoding (default)
wide$s = "cmd.exe" wideUTF-16LE encoding (Windows Unicode)
nocase$s = "cmd.exe" nocaseCase-insensitive
fullword$s = "cmd" fullwordOnly standalone word: not "cmdline"
Hex bytes$s = { 4D 5A ?? 00 }Byte pattern with ?? wildcards
Hex with jumps$s = { 4D 5A [2-4] 50 45 }Variable-length gap between bytes
Regex$s = /https?:\/\/[0-9.]{7,15}\/gate/ nocaseRegular expression

Condition logic

condition:
    $mz at 0                     // PE file (MZ at offset 0)
    and filesize < 500KB          // reasonable size
    and 2 of ($cmd, $url, $ua)   // at least 2 of 3 IOC strings
    and not $mutex               // exclude known false positive

Operators: and, or, not, all of, any of, N of, at, in

Writing effective YARA rules

Good rule: specific enough to avoid false positives, broad enough to catch variants

// Too specific — fails if one byte changes
$url = "http://185.220.101.47/gate.php"

// Better — matches the gate endpoint pattern across IP variants
$url = /https?:\/\/[0-9.]{7,15}\/gate\.php/

// Too broad — matches almost any Windows binary
$cmd = "cmd.exe"

// Better — matches the specific abuse pattern
$cmd = "cmd.exe /c vssadmin delete shadows" nocase

Testing YARA rules

# Test against a single file
yara rule.yar suspicious.exe

# Test recursively against a directory
yara -r rule.yar malware_samples/

# Verify no false positives against clean files
yara rule.yar C:\Windows\System32\notepad.exe
# Should produce NO output

# Scan memory of a running process
yara -p 3412 rule.yar

Snort / Suricata Rules

Snort and Suricata inspect network traffic in real time, alerting when C2 patterns cross the sensor.

Rule structure

action proto src_ip src_port direction dst_ip dst_port (options)
alert tcp $HOME_NET any -> $EXTERNAL_NET $HTTP_PORTS (
    msg:"Malware C2 beacon — custom User-Agent";
    flow:established,to_server;
    content:"User-Agent: Mozilla/5.0 (compatible)";
    content:"POST /gate.php";
    sid:1000042;
    rev:1;
)

Key options

OptionPurposeExample
flowConnection direction and stateflow:established,to_server
contentExact byte matchcontent:"POST /gate.php"
pcrePerl-compatible regexpcre:"/gate\.php\?id=[A-F0-9]{16}/i"
nocaseCase-insensitive matchcontent:"user-agent"; nocase
distanceNext content N bytes after previousdistance:0
withinNext content within N bytes of previouswithin:50
dsizeMatch on packet data sizedsize:>100
thresholdAlert rate limitingthreshold:type limit, track by_src, count 1, seconds 60

Example: DGA domain detection

alert udp $HOME_NET any -> any 53 (
    msg:"Possible DGA domain query — high entropy hostname";
    content:"|01 00 00 01 00 00 00 00 00 00|";
    pcre:"/[a-z]{12,20}\.(com|net|org|info)\x00/i";
    sid:1000043;
    rev:1;
)

flow:established,to_server explained

  • established: TCP three-way handshake completed
  • to_server: traffic flowing from client to server (outbound from $HOME_NET)

This combination matches only genuine C2 POST requests: not SYN packets, not server responses.

Defence in Depth: Combining Both

Network perimeter:
  Snort/Suricata rule → blocks C2 communication
  → Catches malware that reached the host but fires its beacon

Endpoint:
  YARA rule → detects the file on disk or in memory
  → Catches malware before or during execution

Together:
  If YARA misses a new variant → Snort catches the beacon
  If Snort misses encrypted C2 → YARA catches the file

YARA Rule Sources

SourceURLContent
YARA-Rules projectgithub.com/Yara-Rules/rulesCommunity rules for major families
Mandiant/FireEyegithub.com/mandiant/red_team_tool_countermeasuresRules for APT tools
Neo23x0 (Florian Roth)github.com/Neo23x0/signature-baseHigh-quality community rules
CAPE outputLocal CAPE instanceAuto-generated rules from extracted configs

Always test community rules against a clean file corpus before deployment: false positive rates vary significantly.

Assessments

Unit Assessment

In-Depth Malware Analysis

20 questions30 minPass: 60%

Start exam →

Comprehensive Assessment

REMA: Complete Assessment

120 questions90 minPass: 60%

Start final exam →

Practice

Lock it in with a game

Ungraded practice for this topic. Clearing a game or lab for the first time earns EZ Board points when you are signed in.

Lab

YARA Hunt: One Rule, Zero False Positives

6 tasks from this unit. Free to play. Earn 30 EZ Board points on your first clear.

Play

Crossword

In-Depth Malware Analysis

9 key terms from this unit. Free to play.

Play Leaderboard

Race

Unpack Underpass

6 checkpoints from this unit. Free to play. Earn 30 EZ Board points on your first clear.

Play

Related to this topic

Continue learning

Listen

Spotting Forensic Gold in Malware Strings

Discover how malware analysts extract hidden intelligence from embedded strings — URLs, registry paths, API call sequences, and C2 artefacts that reveal attacker behaviour and seed your IOC list.

Reference material

eBook

REMA — eBook

v1.0

Open resource

Cheatsheet

REMA — Cheatsheet

v1.0

Open resource

MCQ Bank

REMA — MCQ Bank

v1.0

Open resource

Question Bank

REMA — Question Bank

v1.0

Open resource

External references

YARA Documentation — Official

Official YARA documentation covering all string types, modifiers, condition operators, and modules.

reference
Neo23x0 Signature Base — Community YARA Rules

High-quality community YARA rules by Florian Roth. Study the rule structure and condition patterns used by experienced analysts.

reference
Suricata Rule Writing Guide

Official Suricata rule documentation covering all options, flow keywords, and content modifiers.

reference

Discussion

Loading comments…
More articlesTest your knowledge
EZ MentorAI · Free

Network Signatures and YARA Rules

Hi! I'm EZ Mentor

Your AI tutor for
Network Signatures and YARA Rules

Sign in to ask, it's free.

EZ Mentor is AI-powered · Answers may not be perfect · 10 free questions / day

EZ LearnEZ Learn

Structured learning across Reverse Engineering, Cloud Security, and Research Methodology, plus games and practice tools in EZ Arena. Free, and open to anyone.

EZ Learn

  • Courses
  • EZ Articles
  • EZ Watch
  • EZ Talks
  • EZ Bytes
  • Cyber Hygiene

EZ Library

  • All Resources
  • eBooks & PDFs
  • Question Banks
  • MCQ Banks
  • Cheatsheets

EZ Exams

  • All Exams
  • REMA
  • Cloud Security
  • Research Methodology
  • Python for Cyber Security
  • Cyber Law & IPR
  • Community
  • EZ Board

EZ Arena

  • EZ Games
  • Live Quiz
  • ML Challenges
  • दिशा - Hygiene
  • सजग - Awareness
  • अभ्यास - Practice

Platform

  • About
  • Contact
  • Terms of Use
  • Disclaimer
  • Verify Certificate
  • Events

© 2026 EZ Learn by EpochZero. Educational content for learning purposes.

Platform Lead: Ashish Revar