A native MoonBit threat signature matching and malware scanning engine.
Dependencies
git clone https://github.com/Hjyyutr/MoonYara.git
cd MoonYara
moon version --all
moon update
moon fmt --check
moon check --target all
moon build --target wasm,wasm-gc,js
moon test --target allmoon add Hjyyutr/moonyara
moon updateimport {
"Hjyyutr/moonyara@0.1.5",
}import {
"Hjyyutr/moonyara/src",
}let rules_text =
#|rule PHPWebShell {
#| strings:
#| $eval = "eval"
#| $get = "$_GET"
#| condition:
#| $eval and $get
#|}
let compiled = try! @src.compile_rules(rules_text)
let matches = @src.scan_bytes(compiled, b"<?php eval($_GET['cmd']); ?>")
inspect(matches.length(), content="1")moon run --target js cmd/main -- -r test_rules/webshell.yara -f test_files/webshell.phpVerdict: [ALERT] Malicious signatures found!
Rule matched: WebShellDetectmoon run examples/scan_examplemoon build --target js examples/scan_example
moon build --target wasm-gc examples/scan_examplemoon build --target js examples/scan_example
node scripts/serve_browser.mjsYARA rule text
|
parser
v
YaraRule AST ---- compiler ---- CompiledRule
|
+-----------------------+----------------------+
| | |
Aho-Corasick Hex matcher Thompson NFA
+-----------------------+----------------------+
v
MatchContext
v
Condition VM
v
YaraMatch[]moon fmt --check
moon check --deny-warn --target all
moon build --target wasm,wasm-gc,js
moon info --target all
moon test --deny-warn --target wasm,wasm-gc,js
moon build --target native
moon test --deny-warn --target nativepowershell -NoProfile -File scripts/verify_acceptance.ps1powershell -NoProfile -File scripts/benchmark.ps1moon update
moon fmt --check
moon check --target all
moon test --target all
moon info --target all
git diff --exit-codeA native MoonBit threat signature matching and malware scanning engine.
Dependencies