Welcome to the Mayhem Demo App!
This demo highlights how Mayhem helps you solve code, API, and SBOM security and stress testing challenges. The app contains:
- An on-car GPS service (code security, OSS security)
- Transmits data to an API (API security, OSS security)
- Stores results in a database (OSS security)
- Used by a user UI to display traveled routes
flowchart LR;
Car -->|GPS Data| API;
API <--> Redis;
API <-->|Points on map| UI;
-
Code Security: The GPS code is a native app that transmits GPS sensor data to a Cloud API. The source ./car/gps_uploader.c contains vulnerabilities such as:
- Integer overflow
- Integer underflow
- Stack-based buffer overflow
- Heap overflow
- Double Free
- Use-after-free
- Memory leaks
-
API Security: The cloud API receives GPS data from cars, and services a UI for displaying that information. The source ./api/app/main.py contains vulnerabilities including:
- SQL Injection
- Path Traversal
- Authentication bypass
- Spec/implementation mismatch.
-
SBOM/SCA Security: There are four images in this repo: redis, car, api, and UI. Each is built with OSS components and has vulnerabilities both on and off the attack surface.
Make sure you have Docker and Docker Compose installed on your machine and then run:
docker compose up --buildThen navigate to http://localhost:3000. In more detail:
- UI: http://localhost:3000. The default username and password is
me@me.comand123456. Written in Javascript React. - API: http://localhost:8000. Written in FastAPI (python).
- OpenAPI: http://localhost:8000/openapi.json. Generated automatically by FastAPI.
Note You can add the --watch flag to sync any changes from the UI or API files to the running docker container.
Note 2: If you've previously run this, please run docker compose down -v to
remove any stale volumes.
Let's unleash some Mayhem! The first thing to do is create a free Mayhem account at https://app.mayhem.security.
Now that you have an account, you can start using Mayhem in your local environment.
-
Install the Mayhem CLIs from https://app.mayhem.security/-/installation
-
Next, create an API token at https://app.mayhem.security/-/settings/user/api-tokens, which is what you’ll use to log in the CLI to the Mayhem server.
-
Use the token to log in with your token with
mayhem login https://app. mayhem.security <your API token> -
Mayhem Dynamic SBOM currently has a separate CLI install, and currently only supports Linux. Install by following https://app.mayhem.security/docs/dynamic-sbom/installation/.
At the end of this, you will have three CLIs:
mayhem, which runs Mayhem for Code analysismapi, which runs Mayhem for API analysismdsbom, which runs Mayhem Dynamic SBOM analysis
Note: All CLIs share authentication information, so you need only log in with one CLI.
Get the code running by:
- Cloning this repo with
git clone https://github.com/forallsecure-CustomerSolutions/mayhem-demoand change into the mayhem-demo directory. - Build and run the docker images with
docker compose up --build
In this step, you’ll run Mayhem for API to check the demo API server. This step uploads the report to Mayhem for viewing, and also produces a local HTML report.
-
Make sure you have the code running with
docker compose up --buildand that you can reach the API on http://localhost:8000. -
Run
mapi run mayhem-demo/api 1m http://localhost:8000/openapi.json --url http://localhost:8000 --html mapi.html --interactive --basic-auth "me@me.com:123456" --experimental-rules --ignore-rule internal-server-error -
That’s it! You can exit when done.
Details:
Mayhem for API requires two things: an API to test, and an OpenAPI spec. In this example, we scanned the locally running copy of the API, and used the OpenAPI spec that is automatically generated by the underlying FastAPI framework.
The specific arguments you used were:
-
mayhem-demo/apiis the project name and target name for the app. By default, Mayhem puts results in your private workspace. You will see results in the Mayhem UI under your personal workspace under this project name. If you want the project in a shared workspace, just prefix the path with the workspace name like:shareworkspace/mayhem-demo/api -
http://localhost:8000/openapi.jsonthe location of the OpenAPI spec. FastAPI automatically generates one for you, as can most frameworks, or write your specification yourself to check your implementation. -
http://localhost:8000/is an URL to the running API. The host must be reachable from the host running themapiCLI, but need not be internet accessible. -
--html mapi.htmlsays to output a local HTML report calledmapi.html -
--interactivesays to run in interactive mode. Note that you can move your cursor through the TUI to dig into results! -
--basic-authtellsmapithe credentials for the endpoints using basic authentication.mapisupports several auth types, and you can find a list withmapi run --help. -
--ignore-rule internal-server-errorsays to ignore internal server errors (5xx HTTP response codes). Some users prefer to see these because they show the server has broken code, and some do not.
TIP: mapi is a superset and more accurate than ZAP API scanner. But we've
also integrated ZAP support just in case, and even have a docker container with
both mapi and zap. Try it out with:
docker run -it -e MAPI_TOKEN <token> forallsecure/mapi:latest run --url 'https://demo-api.mayhem4api.forallsecure.com/api/v3/' mayhem-demo/api 60 'https://demo-api.mayhem4api.forallsecure.com/api/v3/openapi.json' --interactive --zap
Note: Make sure you run docker compose down -v to remove any old volumes from previous
runs. mapi will create new locations each time you run it in redis, and can
quickly create really long responses.
Mayhem Dynamic SBOM works by taking in a docker SBOM/SCA report, and outputting
a new SBOM/SCA report based upon attack surface analysis. We’ll be using docker scout to generate the SBOM for this demo, though Mayhem integrates with any
tool that outputs a CycloneDX or SPDX file.
Pre-requisites:
- Linux system (more OSes coming shortly)
- The demo service docker images are available and you know their path. They
do not need to be running. (
docker compose build). - You have installed
docker, are logged into
docker (
docker login) and have docker scout installed. - You have
mdsbominstalled and you are logged into Mayhem.
Steps:
-
Run
mdsbom scout ghcr.io/forallsecure-customersolutions/mayhem-demo/api:latest --sca-report-out dsbom-api.sarif -
That’s it! View the results on the Mayhem UI.
Details:
The command line about did several things all at once:
- Built an SBOM and SCA report from
docker scout - Identified the attack surface in the
apiimage. - Reduced the SCA findings to only those items on the attack surface. In our
run, 90% of the
docker scoutSBOM/SCA results were irrelevant to security!
In more detail, the arguments:
-
scoutspecified to run docker scout to get the initial SBOM/SCA result. Mayhem supports any SBOM/SCA tool that creates a CycloneDX or SPDX file. You can runmdsbom helpto see other possibilities, like anchore, trivy, and more generally any source using a standardized format. -
ghcr.io/forallsecure-customersolutions/mayhem-demo/api:latestis path to the docker image (docker compose buildwill default to this name). -
``--sca-report-out dsbom-api.sarif
says to output a SARIF format as filedsbom-api.sarif`.
Tip: You can use --workspace <name> to specify a different workspace to
upload results.
Prerequisites
You need to have the built docker images from the docker compose build step,
and a registry you can push the images to. You can also use our pre-built
containers here.
Steps:
-
Push the docker image to a registry such as Dockerhub or Github Container Registry. If you are an enterprise customer, Mayhem comes with a docker registry built-in.
docker tag ghcr.io/forallsecure-customersolutions/mayhem-demo/car:latest <docker id>/mayhem-demo/car:latest docker push <docker id>/mayhem-demo/car:latest -
Start analysis with
mayhem run mayhem-demo/car --image ghcr.io/forallsecure-customersolutions/mayhem-demo/car:latest --duration 1800
And that’s it! You should be able to see results for Mayhem for Code in your project!
Details:
runtells Mayhem to start a run.--image ghcr.io/forallsecure-customersolutions/mayhem-demo/tells Mayhem the location of your app's image.--duration 1800tells Mayhem to run analysis for up to 30 minutes. (If you leave this off, Mayhem will continually pentest your app.)
Now that you’ve run Mayhem on this app, let's look at how to get you started on your own apps. Here are some great starting points to bookmark:
-
Documentation: We’ve compiled extensive documentation and tutorials online at https://app.mayhem.security/docs/overview/
-
Code Examples: Mayhem for Code programming language examples at https://github.com/ForAllSecure/mayhem-examples
-
OSS Examples: Sometimes examples are the best way to learn, and we’ve got you covered. View over 1500 repositories that have integrated Mayhem at https://github.com/orgs/mayhemheroes/repositories
This project is licensed under the MIT License. See the LICENSE.txt file for details.
