Skip to main content

This library provides the primitives to perform symbolic analysis

Project description

Dangr Runtime Library

dangr_rt is the runtime library for Dangr, a declarative language designed for semantic pattern detection in binary analysis. Built on top of the angr framework, this library provides the necessary abstractions and methods to facilitate symbolic execution, static analysis, and semantic property verification over binary code. Its primary purpose is to simplify the generation and execution of compiled Dangr rules while maintaining a close resemblance to the declarative syntax.

Features

  • Pattern Detection: Analyze binary files to detect patterns defined using Dangr rules.
  • Dependency Verification: Validate dependencies between variables in a binary.
  • Symbolic Execution: Simulate binary execution to explore paths and enforce constraints.
  • Argument Analysis: Retrieve concrete values for function arguments during analysis.
  • Customizable Workflow: Extend the core analysis through inheritance and custom methods.

Workflow

To use dangr_rt, extend the base class DangrAnalysis to define a custom detection workflow. Example:

from dangr_rt import DangrAnalysis

class MyAnalysis(DangrAnalysis):
    def _analyze_asm_match(self, jasm_math):
        # define the analysis here
        msg = "Alloc can be called with 0 as argument"
        alloc_call = jasm_match.addrmatch_from_name("alloc_call").value
        _target = jasm_match.addrmatch_from_name("_target").value
        size = self._create_var_from_argument(Argument(1, alloc_call, 4))
        self._add_constraint(Eq(size, 0))
        found_states = self._simulate(_target)
        if self._satisfiable(found_states):
            return msg

Core Analysis Workflow:

  1. Initialization: Load the binary, generate the Control Flow Graph (CFG), and set up the symbolic analysis environment.
  2. Pattern Matching: Use JASM for static pattern detection.
  3. Dependency Analysis: Verify relationships between variables using the DependencyAnalyzer.
  4. Symbolic Execution: Apply constraints and simulate binary execution using DangrSimulation.
  5. Result Interpretation: Evaluate the satisfiability of final execution states.

Sequence_diagram

Architecture and Design

arquitecture

DangrAnalysis

DangrAnalysis uses the template method design pattern. The skeleton of the analysis is defined in the analyze() method, while specific steps, such as symbolic execution or dependency checks, are delegated to subclasses. Users can override the _analyze_asm_match() method to implement custom logic.

DangrAnalysis

VariableFactory

Generates Variable objects, representing binary-specific elements like registers, memory, literals, or dereferences.

Variable

DependencyAnalyzer

Provides methods to check if a variable depends on another, enabling fine-grained semantic verification.

DependencyAnalyzer

DangrSimulation

Handles symbolic execution, applying constraints and exploring execution paths. Implements the methods add_constraint() and simulate()

Dangr Simulation uses symbolic execution to analyze binaries and verify program properties. Built on angr, it allows users to define constraints and explore execution paths dynamically.

Key features:

  • Symbolic Execution: Variables are represented symbolically, and constraints are translated into SMT queries with Z3 to check feasibility (done by angr).
  • Constraints: Defined as boolean or arithmetic expressions, constraints guide simulation by restricting states at specific checkpoints.
  • Execution Workflow: Simulation starts at a function’s entry and uses checkpoints to associate variables or apply constraints. Diverging paths are analyzed independently, discarding unsatisfiable states.
  • Optimizations: Configurable timeouts and state limits ensure efficient analysis.

ArgumentAnalyzer

Recovers the concrete values of function arguments for further analysis.

ArgumentAnalyzer

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dangr_rt-1.0.1.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dangr_rt-1.0.1-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file dangr_rt-1.0.1.tar.gz.

File metadata

  • Download URL: dangr_rt-1.0.1.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Linux/6.12.13-1-lts

File hashes

Hashes for dangr_rt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f9c83b47ab7d1215df4f003fb537101168bb21a623c9eb859f994af30bd09016
MD5 80c5e4044a0a3d65d81d7413a6c68686
BLAKE2b-256 7793a6cf583633d63ce405ff433329c4a8c67e76c04c7c74b634d3e863f181d5

See more details on using hashes here.

File details

Details for the file dangr_rt-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: dangr_rt-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Linux/6.12.13-1-lts

File hashes

Hashes for dangr_rt-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d739496a6abb6bb0e2fb01dde79b962c1af15408f426fcc33a20b7d528fea33
MD5 b407023fbbcd9ae7452bb52cee55ca40
BLAKE2b-256 63300f0879854950aa169432762f5c30686c0e59e782b65892080dbe130b2cae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page