mirror of
https://github.com/mandiant/capa.git
synced 2025-12-21 23:00:29 -08:00
* Sync capa rules submodule * Sync capa-testfiles submodule * Sync capa rules submodule * changelog * *: remove /x32 and /x64 flavors from number and offset features * *: remove more references to /x32 and /x64 * linter: accept instruction scope * rules: fix max operand index (4) * API: better support A/W functions * vverbose: show lib rule matches * main: accept multiple paths to rules * main: fix removal of default rules path * lint: fix rules path * changelog * capa_as_library: fix rules path is list now * main: better handle multiple rules paths * main: bail if python 3.6 or below closes #964 * ida: readme: remove python 3.6 support * capa2yara: fix rules paths * render: meta: display rule paths on separate lines closes #971 * render: verbose: add doc * verbose: make rule path multiline more concise * vverbose: don't show examples in output closes #970 * vverbose: render subscope name, like "basic block:" closes #963 * build(deps-dev): bump pytest from 7.0.1 to 7.1.1 Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.0.1 to 7.1.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.0.1...7.1.1) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * ci: build: update pip and setuptools * ci: build: bump pyinstall to v4.10 * Sync capa rules submodule * Dotnet mixed mode detect (#969) * feat: start dotnet detection (#955) * feat: start dotnet detection * Apply suggestions from code review Co-authored-by: Willi Ballenthin <willi.ballenthin@gmail.com> * refactor: dn instead of dotnet * refactor: format branches, extractor reorg * refactor: format selection and dotnet detect * feat: get format, arch, os * refactor: log errors and exceptions * ci: also test and build for dotnet-main dev * fix: import path * fix: circular dep * fix: remove buf argument feat: get runtime meta data * fix: log unsupported runtime error * fix: type ignore Co-authored-by: Willi Ballenthin <willi.ballenthin@gmail.com> * fix: imports and add tests * feat: detect mixed mode and tests * feat: start dotnet detection (#955) * feat: start dotnet detection * Apply suggestions from code review Co-authored-by: Willi Ballenthin <willi.ballenthin@gmail.com> * refactor: dn instead of dotnet * refactor: format branches, extractor reorg * refactor: format selection and dotnet detect * feat: get format, arch, os * refactor: log errors and exceptions * ci: also test and build for dotnet-main dev * fix: import path * fix: circular dep * fix: remove buf argument feat: get runtime meta data * fix: log unsupported runtime error * fix: type ignore Co-authored-by: Willi Ballenthin <willi.ballenthin@gmail.com> * fix: imports and add tests Co-authored-by: Willi Ballenthin <willi.ballenthin@gmail.com> * test: checkout submodules recursively Co-authored-by: Capa Bot <capa-dev@mandiant.com> Co-authored-by: Willi Ballenthin <willi.ballenthin@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
import textwrap
|
|
|
|
import capa.rules
|
|
import capa.render.utils
|
|
import capa.features.insn
|
|
import capa.features.common
|
|
import capa.render.result_document
|
|
|
|
|
|
def test_render_number():
|
|
assert str(capa.features.insn.Number(1)) == "number(0x1)"
|
|
|
|
|
|
def test_render_offset():
|
|
assert str(capa.features.insn.Offset(1)) == "offset(0x1)"
|
|
|
|
|
|
def test_render_meta_attack():
|
|
# Persistence::Boot or Logon Autostart Execution::Registry Run Keys / Startup Folder [T1547.001]
|
|
id = "T1543.003"
|
|
tactic = "Persistence"
|
|
technique = "Create or Modify System Process"
|
|
subtechnique = "Windows Service"
|
|
canonical = "{:s}::{:s}::{:s} [{:s}]".format(tactic, technique, subtechnique, id)
|
|
|
|
rule = textwrap.dedent(
|
|
"""
|
|
rule:
|
|
meta:
|
|
name: test rule
|
|
att&ck:
|
|
- {:s}
|
|
features:
|
|
- number: 1
|
|
""".format(
|
|
canonical
|
|
)
|
|
)
|
|
r = capa.rules.Rule.from_yaml(rule)
|
|
rule_meta = capa.render.result_document.convert_meta_to_result_document(r.meta)
|
|
attack = rule_meta["att&ck"][0]
|
|
|
|
assert attack["id"] == id
|
|
assert attack["tactic"] == tactic
|
|
assert attack["technique"] == technique
|
|
assert attack["subtechnique"] == subtechnique
|
|
|
|
assert capa.render.utils.format_parts_id(attack) == canonical
|
|
|
|
|
|
def test_render_meta_mbc():
|
|
# Defense Evasion::Disable or Evade Security Tools::Heavens Gate [F0004.008]
|
|
id = "F0004.008"
|
|
objective = "Defense Evasion"
|
|
behavior = "Disable or Evade Security Tools"
|
|
method = "Heavens Gate"
|
|
canonical = "{:s}::{:s}::{:s} [{:s}]".format(objective, behavior, method, id)
|
|
|
|
rule = textwrap.dedent(
|
|
"""
|
|
rule:
|
|
meta:
|
|
name: test rule
|
|
mbc:
|
|
- {:s}
|
|
features:
|
|
- number: 1
|
|
""".format(
|
|
canonical
|
|
)
|
|
)
|
|
r = capa.rules.Rule.from_yaml(rule)
|
|
rule_meta = capa.render.result_document.convert_meta_to_result_document(r.meta)
|
|
attack = rule_meta["mbc"][0]
|
|
|
|
assert attack["id"] == id
|
|
assert attack["objective"] == objective
|
|
assert attack["behavior"] == behavior
|
|
assert attack["method"] == method
|
|
|
|
assert capa.render.utils.format_parts_id(attack) == canonical
|