How to set up a local Mayhem environment

Welcome to Mayhem Tips and Tricks series! Our goal is to help you learn about the best features of Mayhem in small bite-size chunks. Today, we will explain how you can set up a local Mayhem environment.

The tools that you will need to run Mayhem and integrate into our Mayhem Heroes repositories are available on most platforms. We’ve addressed some of the most commonly used tools by putting together the below instructions.

(NOTE: Windows users will need a Linux subsystem. Before running any of the below commands, you will need to open powershell and install WSL):

wsl --install

(NOTE: MacOS users may not have homebrew installed yet. If you do not, you can run these commands to get homebrew; these instructions were lifted from GitHub - Homebrew/install: 📥 Homebrew (un)installer):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

At a minimum, you will need the following tools to run the examples locally: git, Docker, Make, CMake, GCC, Clang, the Mayhem CLI.

Optionally, you’ll need to install the standard go and rust distributions if you’re testing targets written in either language.

Git

Ubuntu/WSL:

sudo apt install git

MacOS:

brew install git

Docker

Ubuntu:

curl -fsSL "https://get.docker.com" -o get-docker.sh
sudo sh ./get-docker.sh
sudo usermod -a -G docker $(whoami)
newgrp docker

MacOS:

  1. Download (Intel Chip): https://desktop.docker.com/mac/main/amd64/Docker.dmg
    OR
  2. Download (M1 Chip): https://desktop.docker.com/mac/main/arm64/Docker.dmg
  3. Follow instructions here: https://docs.docker.com/desktop/mac/install/#install-and-run-docker-desktop-on-mac
    (Make sure you are reading the correct instructions for your architecture!)

Windows:

  1. Download: https://desktop.docker.com/win/main/amd64/Docker Desktop Installer.exe
  2. Follow instructions here: https://docs.docker.com/desktop/windows/install/#install-docker-desktop-on-windows

Make/CMake

Ubuntu/WSL:

sudo apt install make cmake

MacOS:

brew install make cmake

GCC

Ubuntu/WSL:

sudo apt install gcc

MacOS:

brew install gcc

Clang (full LLVM; Mac’s pre-installed version does not include libFuzzer):

Ubuntu/WSL:

sudo apt install clang

MacOS:

brew install llvm

Mayhem

Ubuntu/WSL:

curl --fail -o mayhem "https://mayhem.forallsecure.com/cli/Linux/mayhem" && chmod +x mayhem && sudo mv mayhem /usr/local/bin/

MacOS:

curl --fail -o mayhem.pkg "https://mayhem.forallsecure.com/cli/Darwin/mayhem.pkg" && sudo installer -pkg mayhem.pkg -target / && rm mayhem.pkg

Optional - if you want to test Golang or Rust targets.

Golang

Ubuntu/WSL:

sudo apt install golang

MacOS:

brew install go

Rust

Ubuntu:

curl https://sh.rustup.rs -sSf | sh -s -- -y

MacOS:

brew install rustup
rustup-init

Windows:

curl https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe
./rustup-init.exe

We have auto-install scripts for Ubuntu and MacOS below, as well as a Vagrantfile for setting up a development environment on any machine via Vagrant. We take no responsibility for users running these scripts, but they aim to make installation easier.

Ubuntu:

#Install tools
sudo apt update -y && sudo apt install -y ca-certificates \
curl \
gnupg \
lsb-release \
git \
build-essential \
cmake \
make \
gcc \
clang \
golang

#Install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
sudo usermod -a -G docker $(whoami)
newgrp docker

# Install Rust
curl https://sh.rustup.rs -sSf | sh -s -- -y

# Install Mayhem
curl --fail -o mayhem "https://mayhem.forallsecure.com/cli/Linux/mayhem" && chmod +x mayhem && sudo mv mayhem /usr/local/bin/

MacOS:

# Install brew
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install tools
brew update
brew install xcode
xcode-select --install
brew install cmake
brew install make
brew install gcc
brew install llvm
brew install go

# Install rust
brew install rustup
rustup-init

# Install Docker
brew install docker docker-machine
brew install virtualbox --cask

# Comment out these three lines if you are running a Mac with an x86/Intel Chip. This won't work on M1.
docker-machine create --driver virtualbox default
docker-machine env default
eval "$(docker-machine env default)"

# Install Mayhem
curl --fail -o mayhem.pkg "https://mayhem.forallsecure.com/cli/Darwin/mayhem.pkg" && sudo installer -pkg mayhem.pkg -target / && rm mayhem.pkg

Vagrant:

If you want to use Vagrant, you can try the following Vagrantfile along with these steps:

  1. Download and install Vagrant
  2. Save the below file as “Vagrantfile” and place it in your working directory
  3. Run vagrant up
  4. Run vagrant ssh
Vagrant.configure("2") do |config|
config.vm.box = "generic/ubuntu1804"
config.vm.provision "shell", inline: <<-SHELL

# Install tools
sudo apt update -y && sudo apt install -y ca-certificates \
curl \
gnupg \
lsb-release \
git \
build-essential \
cmake \
make \
gcc \
clang \
golang

# Install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
sudo usermod -a -G docker vagrant
newgrp docker
rm ./get-docker.sh

# Install Rust
curl https://sh.rustup.rs -sSf | sh -s -- -y

# Install Mayhem
curl --fail -o mayhem "https://mayhem.forallsecure.com/cli/Linux/mayhem" && chmod +x mayhem && sudo mv mayhem /usr/local/bin/

SHELL
end

This is it! We hope that you found this Tips and Tricks article helpful.