yara-l-skill 開源 Agent Skill,協助編寫及檢查 Google SecOps 的 YARA-L 規則
I built an Agent Skill that writes YARA-L rules you can actually paste into Google SecOps
Ajay Nyayapathi 開源 yara-l-skill(github.com/ajaynyayapathi/yara-l-skill),這個 Agent Skill 協助編寫、審查、調校及轉換供 Google SecOps 使用的 YARA-L 2.0 規則。
Ask a general purpose AI assistant for a YARA-L brute force rule and you will get something that looks correct. Paste it into the Google SecOps Rules Editor and it fails on line five, because LOGIN is not a valid UDM event type. The correct value is USER_LOGIN.
Fix that, and the next error is a port compared to the string "443". Fix that, and the compiler complains that an outcome variable uses an event field without an aggregate.
The worst case is the rule that compiles cleanly and never fires. Your Okta parser writes FAIL for a failed login. The rule checks for BLOCK. Nothing errors. Nothing alerts. You find out during an incident review.
I write detection content for a living, and I got tired of fixing the same five mistakes in every AI generated rule. So I built yara-l-skill, an open source Agent Skill that teaches coding agents to write, review, tune, and convert YARA-L 2.0 rules properly.
What an Agent Skill is
An Agent Skill is a folder with a SKILL.md file of instructions, plus any reference docs and scripts the agent needs. The agent loads it only when the task matches the skill's description. You install it once and every YARA-L request picks it up automatically.
The same folder works in Claude Code, Claude.ai, GitHub Copilot, OpenAI Codex, Gemini CLI, Cursor, and any other client that reads the SKILL.md format.
What you get back
Give your agent a threat description, an ATT&CK technique ID, a Sigma rule, or an SPL or KQL query. The skill makes it return six things, in this order:
- A one sentence statement of the detection logic
- A complete YARA-L 2.0 rule with full meta, outcome, and $risk_score
- A list of UDM fields you need to verify against your parser
- The reference lists and data tables to create, with sample rows
- A should fire test and a should not fire test
- The two most likely false positive sources and how to tune them out
Items 3 through 6 matter as much as the rule. A rule without tests and tuning notes is a rule your SOC will disable in week two.
A real example
Here is the prompt:
Write a YARA-L rule for 10 failed logins followed by a success within 30 minutes.
The agent first restates the logic: "Alert when one user has 10 or more failed logins followed by a successful login within 30 minutes." Then it picks the rule shape (multi event with match), maps the fields, and writes this:
rule user_login_bruteforce_then_success {
meta:
author = "community"
description = "Ten or more failed logins for one account followed by a successful login inside 30 minutes."
severity = "HIGH"
priority = "HIGH"
mitre_attack_tactic = "Credential Access"
mitre_attack_technique = "T1110"
reference = "https://attack.mitre.org/techniques/T1110/"
false_positives = "Mobile mail clients retrying an expired password, then the user updating it."
rule_version = "1.0"
yara_version = "YL2.0"
events:
$fail.metadata.event_type = "USER_LOGIN"
// VERIFY: some parsers write FAIL instead of BLOCK for failed logins.
$fail.security_result.action = "BLOCK"
$fail.target.user.userid = $user
$success.metadata.event_type = "USER_LOGIN"
$success.security_result.action = "ALLOW"
$success.target.user.userid = $user
// The success must come after the failures.
$fail.metadata.event_timestamp.seconds < $success.metadata.event_timestamp.seconds
// Tuning hook: service accounts with known retry storms.
not $user in %bruteforce_excluded_accounts
match:
$user over 30m
outcome:
$risk_score = 80
$failed_count = count_distinct($fail.metadata.id)
$fail_source_ips = array_distinct($fail.principal.ip)
$success_source_ips = array_distinct($success.principal.ip)
condition:
#fail >= 10 and $success
}
A few details in that rule come straight from the skill's instructions:
- metadata.event_type comes first. It is indexed, so filtering on it early cuts the volume the engine scans.
- Both event variables join on $user. An unjoined variable in a multi event rule causes a compile error or a cartesian blowup.
- The exclusion lives in a reference list. Your SOC edits %bruteforce_excluded_accounts instead of the rule itself.
- Every outcome field uses an aggregate, because the rule has a match section.
- The uncertain field carries a // VERIFY: comment. The agent tells you what it could not confirm instead of guessing.
Converting from Sigma, SPL, and KQL
Most teams already have detection logic in another language. The skill includes explicit mapping rules:
The skill also tells the agent to state which source constructs have no clean YARA-L equivalent. Silently dropping a filter during conversion is how you end up with a noisy rule nobody trusts.
The offline linter
The skill ships lint_rule.py, a Python 3 script with no dependencies. The agent runs it on every rule before it answers, and you can run it yourself in CI.
Here is a rule with the mistakes I see most often in AI generated YARA-L:
rule bad_login_rule {
meta:
author = "me"
events:
$fail.metadata.event_type = "LOGIN"
$fail.target.port = "443"
$fail.target.user.userid = $user
$success.metadata.event_type = "USER_LOGIN"
re.regex($fail.principal.hostname, `.*corp`)
match:
$user over 30m
outcome:
$src = $fail.principal.ip
condition:
#fail >= 10 and $success
}
And the linter output:
$ python3 scripts/lint_rule.py bad.yaral
[FAIL] bad.yaral
error: unknown metadata.event_type value "LOGIN"
error: integer field ending '.port' compared to a quoted string
error: outcome $src uses an event field without an aggregate
warning: meta missing 'description'
warning: meta missing 'severity'
...
warning: regex starts with .* (slow): .*corp
warning: $success is not assigned to any match placeholder
warning: no $risk_score in outcome
It checks section order, event type values against the UDM enum, integer fields compared to strings, event variables that never join to a match placeholder, unaggregated outcome fields, absence conditions without match, leading .* in regex, and missing meta keys.
A clean lint result does not mean the rule compiles. The linter catches the common mistakes before you paste. The SecOps compiler is still the final word.
Parser fixtures: the gap the linter cannot close
Valid syntax and a rule that fires are two separate problems. The linter solves the first one. Fixtures address the second.
A fixture is a JSON file with three things: a sanitized raw log, the UDM event a specific parser produced from it, and the rule that should or should not fire on it. They live in folders by log type:
fixtures/
AZURE_AD/
device_code_signin_fire.json
device_code_signin_approved_no_fire.json
OKTA/
bruteforce_then_success_fire.json
three_fails_then_success_no_fire.json
WINDOWS_SYSMON/
certutil_urlcache_download_fire.json
certutil_hashfile_no_fire.json
check_fixtures.py confirms every field the rule uses exists in the UDM event, compares literal values and regex conditions, and checks #var thresholds. When a parser writes a different value than the rule expects, you get this:
[FAIL] fixtures/OKTA/bruteforce_then_success_fire.json
error: $fail: 0 event(s) match its conditions, rule needs #fail >= 10
error: security_result.action: rule wants = 'BLOCK', fixture has ['ALLOW', 'FAIL']
That is the FAIL versus BLOCK problem from the top of this post, caught before deployment.
The checker also rejects fixtures that contain public IPs, real email domains, or real GUIDs, so nobody leaks tenant data in a pull request. When the agent writes a rule for a log source that has fixtures, it reads them first to learn which fields that parser actually fills.
Guardrails built into the skill
I wrote four hard limits into SKILL.md, based on what goes wrong when an AI writes detection content:
- It never claims a rule compiles. It tells you to validate in the Rules Editor or through the SecOps API.
- It never invents UDM fields. If a field is not in the reference docs or your sample log, it says so.
- It never sets a rule to alerting by default. It recommends running live with alerting off for 7 days while you review detection volume.
- It keeps real hostnames, IPs, and usernames out of shareable examples.
Install
Copy the skills/yara-l-authoring folder into your agent's skill directory:
git clone https://github.com/ajaynyayapathi/yara-l-skill.git
cp -r yara-l-skill/skills/yara-l-authoring ~/.claude/skills/
Honest limits
- UDM field population varies by parser. That is why // VERIFY: comments and fixtures exist.
- Every fixture in the first release is synthetic, built from public schema docs, and marked verified_against_tenant: false.
- The fixture checker is a field and value check. It ignores match windows, timestamp ordering, and reference list contents. Only the SecOps compiler and a retrohunt prove a rule works.
- Example rules use placeholder list and table names. Replace them before you deploy.
How you can help
The most useful contribution is a real parser fixture from your tenant. Run a UDM search, copy the raw log and the UDM view, sanitize them with the template, and open a pull request. Setting verified_against_tenant: true on one Okta or Entra ID fixture makes the skill more accurate for every team that uses that parser.
If you do not have time for a PR, open a "Parser mismatch" issue and tell me which value your parser writes.
GitHub Actions runs the linter and fixture checker on every pull request, so contributed rules and fixtures get the same checks the agent runs.
Repo: github.com/ajaynyayapathi/yara-l-skill (MIT licensed)
YARA-L, Google Security Operations, and Chronicle are trademarks of Google LLC. This project is not affiliated with or endorsed by Google.
來源:DEV Community · dev.to

