/attack_surface_approximation

Module for discovering the attack surface of a vulnerable program ๐Ÿคบ

Primary LanguagePython

attack_surface_approximation ๐Ÿคบ



Description

attack_surface_approximation is the CRS module that deals with the approximation of the attack surface in a vulnerable program.

Some input mechanisms are omitted: elements of the user interface, signals, devices and interrupts. At the moment, the supported mechanisms are the following:

  • Files;
  • Arguments;
  • Standard input;
  • Networking; and
  • Environment variables.

In addition, a custom fuzzer is implemented to discover arguments that trigger different code coverage. It takes arguments from a dictionary which can be handcrafted or generated with an exposed command, with an implemented heuristic.

Examples of arguments dictionaries can be found in examples/dictionaries:

  • man.txt, generated with the man_parsing heurstic and having 6605 entries; and
  • generation.txt, generated with the generation heuristic and having 62 entries.

Limitations

  • ELF format
  • x86 architecture
  • Non-static binaries
  • Symbols present (namely, no stripping is involved)
  • No obfuscation technique involved

How It Works

The module works by automating Ghidra for static binary analysis. It extracts information and apply heuristics to determine if a given input stream is present.

Examples of such heuristics are:

  • For standard input, calls to getc() and gets()
  • For networking, calls to recv() and recvfrom()
  • For arguments, occurrences of argc and argv in the main()'s decompilation.

The argument fuzzer uses Docker and QBDI to detect basic block coverage.

Setup

  1. Ensure you have Docker installed.
  2. Install the required Python 3 packages via poetry install --no-dev.
  3. Ensure the Docker API is accessible by:
    • Running the module as root; or
    • Changing the Docker socket permissions (unsecure approach) via chmod 777 /var/run/docker.sock.

Usage

As a CLI Tool

Arguments Dictionary Generation

โžœ poetry run attack_surface_approximation generate --heuristic man --output args.txt --top 10
Successfully generated dictionary with 10 arguments
โžœ cat args.txt
--and
--get
--get-feedbacks
--no-progress-meter
--print-name
-input
-lmydep2
-miniswhite
-nM
-prune

Input Streams Detection

โžœ ./crackme
Enter the password: pass
Wrong password!
โžœ poetry run attack_surface_approximation detect --elf crackme
Several input mechanisms were detected for the given program:

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Stream                โ”ƒ Present โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ files                 โ”‚   No    โ”‚
โ”‚ arguments             โ”‚   No    โ”‚
โ”‚ stdin                 โ”‚   Yes   โ”‚
โ”‚ networking            โ”‚   No    โ”‚
โ”‚ environment_variables โ”‚   No    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Arguments Fuzzing

โžœ poetry run attack_surface_approximation fuzz --elf /bin/uname --dictionary args.txt
Several arguments were detected for the given program:

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Argument  โ”ƒ      Role      โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ -         โ”‚      FLAG      โ”‚
โ”‚ -a        โ”‚      FLAG      โ”‚
โ”‚ -a string โ”‚ STRING_ENABLER โ”‚
โ”‚ -i        โ”‚      FLAG      โ”‚
โ”‚ -i string โ”‚ STRING_ENABLER โ”‚
โ”‚ -m        โ”‚      FLAG      โ”‚
โ”‚ -m string โ”‚ STRING_ENABLER โ”‚
โ”‚ -n        โ”‚      FLAG      โ”‚
โ”‚ -n string โ”‚ STRING_ENABLER โ”‚
โ”‚ -o        โ”‚      FLAG      โ”‚
โ”‚ -o string โ”‚ STRING_ENABLER โ”‚
โ”‚ -p        โ”‚      FLAG      โ”‚
โ”‚ -p string โ”‚ STRING_ENABLER โ”‚
โ”‚ -r        โ”‚      FLAG      โ”‚
โ”‚ -r string โ”‚ STRING_ENABLER โ”‚
โ”‚ -s        โ”‚      FLAG      โ”‚
โ”‚ -s string โ”‚ STRING_ENABLER โ”‚
โ”‚ -v        โ”‚      FLAG      โ”‚
โ”‚ -v string โ”‚ STRING_ENABLER โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Help

โžœ poetry run attack_surface_approximation
Usage: attack_surface_approximation [OPTIONS] COMMAND [ARGS]...

  Discovers the attack surface of vulnerable programs.

Options:
  --help  Show this message and exit.

Commands:
  analyze   Analyze with all methods.
  detect    Statically detect what input streams are used by an executable.
  fuzz      Fuzz the arguments of an executable.
  generate  Generate dictionaries with arguments, based on heuristics.

As a Python Module

Input Streams Detection

from attack_surface_approximation.static_input_streams_detection import \
    InputStreamsDetector

detector = InputStreamsDetector(elf_filename)
streams_list = detector.detect_all()

Arguments Fuzzing

from attack_surface_approximation.arguments_fuzzing import ArgumentsFuzzer

fuzzer = ArgumentsFuzzer(elf_filename, fuzzed_arguments)
detected_arguments = fuzzer.get_all_valid_arguments()