Home

Awesome

<div align="center"> <br/> <a href="https://purpleteam-labs.com" title="purpleteam"> <img width=900px src="https://github.com/purpleteam-labs/purpleteam/blob/main/assets/images/purpleteam-banner.png" alt="PurpleTeam logo"> </a> <br/> <br/> <h2>purpleteam CLI</h2><br/> CLI component of <a href="https://purpleteam-labs.com/" title="purpleteam"><em>PurpleTeam</em></a> - Currently in alpha <br/><br/> <a href="https://purpleteam-labs.com/doc/" title="documentation"> <img src="https://img.shields.io/badge/-documentation-blueviolet" alt="documentation"> </a> <a href="https://github.com/purpleteam-labs/purpleteam/commits/main" title="pipeline status"> <img src="https://github.com/purpleteam-labs/purpleteam/workflows/Node.js%20CI/badge.svg" alt="pipeline status"> </a> <a href='https://coveralls.io/github/purpleteam-labs/purpleteam?branch=main'> <img src='https://coveralls.io/repos/github/purpleteam-labs/purpleteam/badge.svg?branch=main' alt='test coverage'> </a> <a href="https://github.com/purpleteam-labs/purpleteam/releases" title="latest release"> <img src="https://img.shields.io/github/v/release/purpleteam-labs/purpleteam?color=%23794fb8&include_prereleases" alt="GitHub release (latest SemVer including pre-releases)"> </a> <br/><br/> <a href="https://youtu.be/ACuaP-ZToKw" title="purpleteam"> <img width=900px src="https://user-images.githubusercontent.com/2862029/134789647-515d18db-6d5c-4704-864c-2ee5bcc1d015.png" alt="Full System Run"> </a>

<br/><br/>

</div>

If you are planning on running the local environment, once you have installed, configured and are ready to run the PurpleTeam CLI, head back to the local setup documentation and make sure all of the other PurpleTeam components are also set-up and ready to run. After that work through the local workflow documentation.

If you are planning on targeting the cloud environment, the PurpleTeam CLI is all you need to have set-up.

If you have any issues with the set-up, be sure to check the trouble shooting page.

Contents

Minimum Supported Versions

NodeJS: v14

Install

There are several options.

Clone the git repository

If you are planning on running/debugging purpleteam stand-alone, cloning is a good option.

From a directory that you would like the CLI cloned to run the following command:

git clone https://github.com/purpleteam-labs/purpleteam.git

Install the dependencies with the following command:

npm install

Another option with cloning if you want the CLI (purpleteam) to be available as a system wide command is to use the following command from the repositories root directory:

npm link

NPM install locally

If you are planning on running/debugging purpleteam from another NodeJS process, for example a CI/nightly build/build pipeline project of your own, installing via NPM is a good option.

For the locally installed via NPM option the purpleteam-labs Team uses the purpleteam-build-test-cli project as an example to test that this option works as expected. The following example package.json and index.js files are from the purpleteam-build-test-cli example project. Feel free to clone it, or use your own project to follow along.

This example exports two environment variables:

Using the above mentioned example build project files, and for the sake of this example, let's assume your NodeJS build project has the same following files:

<div id="purpleteam-build-test-cli"></div>

package.json

{
  "name": "purpleteam-build-test-cli",
  "description": "Used to test that the purpleteam CLI runs within a build pipeline successfully",
  "main": "index.js",
  "scripts": {
    "// Don't forget to export any required env vars before running the purpleteam CLI. For example": "NODE_ENV=local and PURPLETEAM_UI=noUi",
    "// Invoke purpleteam binary from NPM script": "npm run purpleteam",
    "purpleteam": "NODE_ENV=local purpleteam",
    "// Start your node app": "npm start",
    "start": "NODE_ENV=local PURPLETEAM_UI=noUi node index.js",
    "// Debug your node app": "npm run debugApp",
    "debugApp": "NODE_ENV=local PURPLETEAM_UI=noUi node --inspect-brk=localhost:9230 index.js",
    "// Debug your node app and the purpleteam CLI": "npm run debugAppAndCli",
    "debugAppAndCli": "NODE_ENV=local PURPLETEAM_UI=noUi DEBUG_PURPLETEAM=true node --inspect-brk=localhost:9230 index.js"
  },
  "dependencies": {
    "purpleteam": "*"
  }
}

index.js

import { spawn } from 'child_process';

// You will need to define two debuggers in what ever tool you're using.
// localhost:9230 and localhost:9231
const execArgvDebugString = '--inspect-brk=localhost';
const childProcessInspectPort = 9231;
// You can run any of the purpleteam commands [about|status|test|testplan], `test` is just one example.
const purpleteamArgs = ['purpleteam', 'test'];

const startPurpleteam = () => {
  const purpleteam = spawn('node', [
    ...(process.env.DEBUG_PURPLETEAM
    ? [`${execArgvDebugString}:${childProcessInspectPort}`]
    : []),
    ...purpleteamArgs],
    { cwd: `${process.cwd()}/node_modules/.bin/`, env: process.env, argv0: process.argv[0] }
  );

  purpleteam.stdout.on('data', (data) => {
    process.stdout.write(data);
  });
  purpleteam.stderr.on('data', (data) => {
    process.stdout.write(data);
  });
  purpleteam.on('exit', (code, signal) => {
    console.debug(`Child process "purpleteam" exited with code: "${code}", and signal: "${signal}".`);
  });
  purpleteam.on('close', (code) => {
    console.debug(`"close" event was emitted with code: "${code}" for "purpleteam".`);
  });
  purpleteam.on('error', (err) => {
    process.stdout.write(`Failed to start "purpleteam" sub-process. The error was: ${err}.`);
  });
};

startPurpleteam();

From within your NodeJS build project run the following command to install the PurpleTeam CLI locally into your NodeJS project:

npm install

If running the PurpleTeam CLI as a sub process or from another nodejs program as we do in the above example:

NPM install globally

For example, you may have a build project/pipeline that is written in some language besides JavaScript. In this case the most suitable install technique may be to install the PurpleTeam CLI globally.

To do so, run the following command:

npm install -g purpleteam

Now the PurpleTeam CLI is installed and on your path to invoke from anywhere on your system.

which purpleteam
# Will print where purpleteam is located.
# You will need this to configure it if you choose to install globally.

As mentioned under the Clone section, another option for a system wide install is to use npm link.

Configure

CLI

No matter which install option you decide on the PurpleTeam CLI will require configuration.

If you are planning on using the cloud environment copy the config/config.example.cloud.json to config/config.cloud.json and make the necessary changes. If you are planning on using the local environment copy the config/config.example.local.json to config/config.local.json and make the necessary changes.

Use the config/config.js for documentation and further examples.

loggers.testerProgress.dirname

Configure this property. This is where the CLI logs to. Additional details can be found on the Log and Outcomes files page.

loggers.testPlan.dirname

Configure this property. Using the same value as used for loggers.testerProgress.dirname is an option. This is where the CLI logs the test plans to when running in noUi mode. Additional details can be found on the Log and Outcomes files page.

purpleteamApi

If you are planning on using the local environment you can stick with the default property values. If you are planning on using the cloud environment you will be given this information when you sign-up for a PurpleTeam account.

purpleteamAuth

If you are planning on using the local environment you can stick with the default property values. If you are planning on using the cloud environment you will be given this information when you sign-up for a PurpleTeam account.

<div id="job_fileUri"></div> <!-- Legacy anchor -->

job.fileUri

Configure this property if you do not want to manually pass it as an argument to the CLI. This is the Job file you have configured to specify your System Under Test (SUT) details.

If you installed the PurpleTeam CLI via git clone (You are intending to run PurpleTeam CLI stand-alone), then a relative directory path from the root of the repository ("./testResources/jobs/your_job_file") is acceptable.
If you installed the PurpleTeam CLI via npm install Then it's more likely that you will need this path to be absolute, as the current directory (./) is more than likely not going to be within the PurpleTeam CLI project itself, but rather wherever the purpleteam binary is itself.

This value can be overridden by passing it in as an option to the commands that require it (currently test and testplan).

outcomes.dir

Configure this property. This is a directory of your choosing that Outcomes files from the PurpleTeam API (orchestrator if running in local env, AWS API Gateway if running in cloud env) will be persisted to. Additional details can be found on the Log and Outcomes files page.

<div id="configure-ui"></div> <!-- Legacy anchor -->

uI

This property is configured by default to use the character user interface (cUi value) (your terminal). This value can be changed in one of the following ways:

uI options:

<br>

The PurpleTeam CLI uses the convict package for it's configuration.

Sensitive Values (cloud environment only)

There are several ways you can handle the sensitive values that need to be read into the PurpleTeam CLI to access your instance of the PurpleTeam cloud service:

The precedence order of where values will be read from is defined by convict.

Job File

The Job file is what purpleteam uses to do the following. Most properties should be self documenting, although the official documentation is here. If you are unsure of any of the properties, start a Github discussion or reach out in the #project-purpleteam channel of OWASP Slack. Examples of Job files that the PurpleTeam-Labs team use can be found here. Once you have defined the location of your SUT, you may want to consider defining some of the following:

Remember to keep it simple to start with.

Run

There are several ways you can run the PurpleTeam CLI. The following options line up with the Install options detailed above. Make sure you have installed and configured purpleteam correctly before attempting to run:

Clone the git repository option

For those that chose to clone the purpleteam:

You can choose to export the NODE_ENV environment variable before running the following commands, or simply do so as part of running the commands. For example: NODE_ENV=local or NODE_ENV=cloud.

Run the bin/purpleteam file via npm script

  1. From the root directory of the purpleteam repository
  2. Run one of the following commands
    • To start the CLI:
      npm start
      # Should print out the PurpleTeam top level help
      
      <div id="purpleteam-top-level-help"></div> <img width=900px src="https://user-images.githubusercontent.com/2862029/107207208-e9664680-6a64-11eb-9ea9-48f40e8ef155.png" alt="purpleteam top level help">
    • To start the CLI and pass commands (status for example):
      npm start status
      # Should print the following message if the orchestrator is not running:
      # ☰  notice     [cUi] orchestrator is down, or an incorrect URL has been specified in the CLI config.
      
    • To start the CLI and pass commands (test for example):
      npm start test
      # Should print the following message if the orchestrator is not running:
      # ✖  critical   [apiDecoratingAdapter] orchestrator is down, or an incorrect URL has been specified in the CLI config.
      
    • To start the CLI and pass commands (test for example) with options:
      npm start test -- --help
      # Should print the available options for the test command:
      
    • To debug the CLI (passing the status command for example):
      npm run debug status
      # Amongst other messages, you should see the following message:
      # Debugger listening on ws://localhost:9230/...
      
      Now open your debugging UI. If you use the chrome developer tools browse to chrome://inspect and click the inspect link and you will be dropped into the purpleteam CLI code-base.

For further details around running and debugging review the documentation.

Run the bin/purpleteam file directly

  1. From the root directory of the purpleteam repository
  2. Run one of the following commands
    • To start the CLI:
      bin/purpleteam.js
      # Should print out the PurpleTeam top level help
      
    • To start the CLI and pass commands (status for example):
      bin/purpleteam.js status
      # Should print the following message if the orchestrator is not running:
      # ☰  notice     [cUi] orchestrator is down, or an incorrect URL has been specified in the CLI config.
      
    • To start the CLI and pass commands (test for example):
      bin/purpleteam.js test
      # Should print the following message if the orchestrator is not running:
      # ✖  critical   [apiDecoratingAdapter] orchestrator is down, or an incorrect URL has been specified in the CLI config.
      
    • To start the CLI and pass commands (test for example) with options:
      bin/purpleteam.js test --help
      # Should print the available options for the test command:
      

Or if you chose to clone the PurpleTeam CLI (purpleteam) repository and npm link it, you can run it as a first class citizen:

purpleteam

NPM install locally option

For those that chose to install locally via npm:

The NODE_ENV environment variable needs to be exported so that the PurpleTeam CLI knows whether it's targeting the cloud or local environment and configuration. In the example build project we have used, NODE_ENV is exported as part of the NPM scripts, and it is using the local environment. Feel free to swap the value to cloud if you have signed up for a cloud account.

Providing your package.json and the JavaScript file (index.js in the above example) that is going to run the PurpleTeam CLI is similar to those configured in the above file examples, you should be able to successfully run the following commands from the root directory of your NodeJS CI/nightly build/build pipeline project.

Run the PurpleTeam CLI directly

npm run purpleteam
# Should print out the PurpleTeam top level help

Run the PurpleTeam CLI directly - with status command

Run the PurpleTeam CLI directly but pass the status command to purpleteam:

npm run purpleteam status
# Should print the following message if the orchestrator is not yet running. Be patient, PurpleTeam CLI retries:
# ☰  notice     [cUi] orchestrator is down, or an incorrect URL has been specified in the CLI config.

Run the PurpleTeam CLI directly - with test command

Run the PurpleTeam CLI directly but pass the test command to purpleteam:

npm run purpleteam test
# Should print the following message if the orchestrator is not yet running:
# ✖  critical   [apiDecoratingAdapter] orchestrator is down, or an incorrect URL has been specified in the CLI config.

Run the PurpleTeam CLI directly - with test options

Run the PurpleTeam CLI directly but you want to see the help options for the test command:

npm run purpleteam test -- --help
# Should print the available options for the test command:

Run your app (build pipeline)

Run your NodeJS CI/nightly build/build pipeline project. This will start the NodeJS application we defined above which will spawn the purpleteam test command.

You could change the const purpleteamArgs = ['purpleteam', 'test']; to use any other PurpleTeam CLI commands, options, or neither.

When running the PurpleTeam CLI from another process, you will usually want to export PURPLETEAM_UI=noUi as mentioned in the NPM install locally sub-section and detailed in the Configure uI sub-section.

npm start
# If the orchestrator is not yet running:
# Should print the following via the purpleteam.stdout.on('data'... handler
# ✖  critical   [apiDecoratingAdapter] orchestrator is down, or an incorrect URL has been specified in the CLI config.

If you get a blank screen or purpleteam help text with an error or warning via a ?⃝ warning logged to your terminal, please confirm you have configured purpleteam correctly.

When running the PurpleTeam CLI embedded, you should expect the behaviours specified under the Configure uI sub-section for the associated PurpleTeam CLI commands.

Debug your app (build pipeline)

If you need to debug your NodeJS CI/nightly build/build pipeline project, run the following command:

npm run debugApp

Now open your debugging UI. If you use the chrome developer tools browse to chrome://inspect and click the inspect link and you will be dropped into your app (index.js in this case).

Debug your app and PurpleTeam CLI

If you need to debug your NodeJS CI/nightly build/build pipeline project as well as the PurpleTeam CLI, do the following:

  1. Make sure your debugging UI is configured to listen on the application and CLI debug ports:
    • localhost:9230 as defined in the above package.json
    • localhost:9231 as defined in the above index.js
  2. run the following command:
    npm run debugAppAndCli
    
  3. Then open your debugging UI. If you use the chrome developer tools browse to chrome://inspect and click the "inspect" link and you will be dropped into your app (index.js in this case)
  4. Step through the index.js file until the purpleteam process is spawned, at which point you will see the second "inspect" link if using the chrome developer tools
  5. Click the second "inspect" link and you should be dropped into the purpleteam source code. Now you can step through and inspect both your application code and the PurpleTeam CLI code

NPM install globally option

For those that chose to install globally via npm:

You can choose to export the NODE_ENV environment variable before running the following commands, or simply do so as part of running the commands.

NODE_ENV=local purpleteam
# Or export NODE_ENV then just run:
purpleteam
# Should print out the PurpleTeam top level help

Run any of the PurpleTeam CLI commands as you would with the install of any other system wide binary.

If you choose to clone the PurpleTeam CLI repository and run npm link from it's root directory, the same applies. Plus you get to continue to modify the PurpleTeam CLI config without reinstalling.

Usage

If you are running the PurpleTeam CLI in the default character user interface (cUi) mode there are some interactions you can perform in the terminal while the CLI is running. The following commands have the associated interactions available:

Trouble-Shooting

If you encounter any problems with the CLI set-up and you have read and applied the directions, check the trouble-shooting page.