Skip to main content
# Attack Surface Meter

[![Latest Version](https://badge.fury.io/py/attacksurfacemeter.svg)](https://badge.fury.io/py/attacksurfacemeter)
[![Build Status](https://secure.travis-ci.org/andymeneely/attack-surface-metrics.svg?branch=master)](https://travis-ci.org/andymeneely/attack-surface-metrics)
[![Coverage Status](https://img.shields.io/coveralls/andymeneely/attack-surface-metrics.svg)](https://coveralls.io/r/andymeneely/attack-surface-metrics)

Attack Surface Meter is a Python package for collecting attack surface metrics from a software system. In its current version, Attack Surface Meter is capable of analyzing software systems written in the C programming language with skeletal support for analyzing software systems written in the Java programming language.

The attack surface metrics collected are:

* Proximity to Entry/Exit/Dangerous - The mean of shortest unweighted path length from a function/file to Entry Points/Exit Points/Dangerous Points.
* Risky Walk - The probability that a function/file will be invoked on a random execution path starting at the attack surface.

## Installation

### PyPI

`pip install attacksurfacemeter`

### Source

`python setup.py install`

## Usage

### API

The Attack Surface Meter works off of the call graph representation of a software system. A call graph is parsed by the correponding *loader* to generate an internal representation. In this version, the Attack Surface Meter is capable of parsing the call graph generated by one of the following utilities:

* [GNU cflow](http://www.gnu.org/software/cflow/ "GNU cflow")
* [GNU gprof](https://sourceware.org/binutils/docs/gprof/ "GNU gprof")

Extending the Attack Surface Meter to analyze a software system written in a programming language other than C or Java would require defining a new *loader* to parse a call graph generated by a particular language-specific utility.

#### Example

The code snippet that follows depicts using the Attack Surface Meter API to analyze the a C program for which a call graph generated by GNU cflow is available.

```
import os
from attacksurfacemeter.call_graph import CallGraph
from attacksurfacemeter.loaders.cflow_loader import CflowLoader

loader = CflowLoader(os.path.expanduser('~/cflow.callgraph.txt'))
call_graph = CallGraph.from_loader(loader)
```

The `call_graph` object is an instance of the `attacksurfacemeter.call_graph.CallGraph` class and supports several methods to collect the proximity and risky metrics for a given function/file. For more information on these methods, please refer to the `call_graph.py` file which has all the methods extensively documented using Python documentation comments.

### Command Line

```
usage: attack_surface_meter.py [-h] [-gr {function,file}] [-c CFLOW]
[--reverse] [-g GPROF] [-p PROCESSES]
[-j JAVACG] [-a [P [P ...]]] [--output OUTPUT]
[--verbose] [--showerrors]

Collect attack surface metrics from the call graph representation of a
software system.

optional arguments:
-h, --help show this help message and exit
-gr {function,file} The granularity at which the call graphs must be
processed at.
-c CFLOW Absolute path of the file containing the textual
representation of the call graph generated by GNU cflow
or of the directory containing the source code of the
software system to be analyzed.
--reverse cflow call graph was generated with the -r option.
-g GPROF Absolute path of the file containing the textual
representation of the call graph generated by GNU gprof
or of a directory containing multiple such text files.
-p PROCESSES Number of processes to spawn when loaded multiple gprof
call graph files. Default is 2.
-j JAVACG Absolute path of the file containing the textual
representation of the call graph generated by java-
callgraph.
-a [P [P ...]] When using java-callgraph for call graph generation of
android apps, specify the fully qualified package name
of the method calls that will be included in the call
graph. This is generally the name of the java package
inside which the app's classes are defined.
--output OUTPUT Absolute path of the file to which the output should be
written to. The format of output is inferred from the
file extension. txt, html, and xml are currently
supported. In cases when the output format cannot be
inferred, txt is used. When an output path is not
specified, standard output is used.
--verbose Output itemized report including metric values
collected for each function/file.
--showerrors Display errors encountered when parsing call graph (if
any).
```

Metadata

Release files for attacksurfacemeter 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for attacksurfacemeter 0.11.0
File Size Uploaded
attacksurfacemeter-0.11.0.tar.gz 499.9 kB Details

Release files / attacksurfacemeter-0.11.0.tar.gz

Download URL attacksurfacemeter-0.11.0.tar.gz
Size 499.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a0a75675a2bab65f5cba9811a49ba6ccd2c1705721b966f8aaa16633134c790e
BLAKE2b-256 checksum
How to use checksums
20439ac79ed75a07f80d1291e969eabefcdfe0b52201062bfc371dd6dda34b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.11.0 This release

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page