# GVM Scanner CLI Application

## Overview

This CLI Application is a command-line tool designed to run Greenbone vulnerability scans against a target site and emails generated reports. It provides a simple and efficient way to setup configurations for a target. 

The cli is written in python and lives inside the cli_app folder.

## Installation

### Prerequisites

Ensure you have Python 3.x installed on your system. You can download it from [Python's official website](https://www.python.org/). You will also need python-venv installed

### Install
Clone repo
```sh
git clone https://bitbucket.org/overdrive/vulnerability_scan.git
```

#### CLI Requirements Install
If using cli app outside of docker image
```sh
git clone https://bitbucket.org/overdrive/vulnerability_scan.git
cd vulnerability_scan/cli_app
./install_requirements.sh
```

#### Greenbone environment
For ease of use and to allow you to skip digging into greenbone docs to configure greenbone docker sockets, the green_bone_docker folder contains a pre-configured docker-compose recipe and some management scripts. Below are instructions for ubuntu. For instructions for other distros check out https://greenbone.github.io/docs/latest/22.4/container/ . For specifics on socket binding, checkout https://greenbone.github.io/docs/latest/22.4/container/workflows.html#exposing-gvmd-unix-socket-for-gmp-access
```sh
sudo apt install ca-certificates curl gnupg
```
Uninstall conflicting packages
```sh
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt remove $pkg; done
```
Install docker
```sh
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo usermod -aG docker $USER && su $USER
```
Install the Green-Bone docker environment. This will also build a docker image of the cli-app for ease of use (run the same thing when you want to update greenbone):
```sh
cd vulnerability_scan/green_bone_docker
./install_greenbone.sh
```
To start greenbone, run 
```sh
./vulnerability_scan/green_bone_docker/start.sh
```
To stop greenbone, run 
```sh
./vulnerability_scan/green_bone_docker/stop.sh
```
To get a stream of greenbone logs, run
```sh
./vulnerability_scan/green_bone_docker/streamlogs.sh
```
To get a cli access to greenbone gvm-tools (see https://greenbone.github.io/gvm-tools/), run 
```sh
./vulnerability_scan/green_bone_docker/getGvmDockerCLI.sh
```

To run cli-app via docker, run 
```sh
./vulnerability_scan/green_bone_docker/cli_app.sh <target_url> [options]
```

## Usage

Run the CLI application using the following syntax, `<target_url>` is required:

```sh
./cli-app.py <target_url> [options]
```

### Available options
Target can be be a colon(:) separated list list of urls to scan 
Note: python doesn't like spaces in the argument values, so replace spaces with underscores(`_`'s). The script will replace the underscores with spaces. The `--portlist`, `--config` and `--scanner` options are from what is configured in your green bone front end, see http://127.0.0.1:9392/login . The first time this script is run against a target, if no options are specified via cli, this script will prompt the user to select from the available options before setting up the target on green bone.
- `-h, --help` - Displays usage information
- `-d, --defaults` - Uses default options when setting up a target for the first time this sets Port Assignment to "All IANA assigned TCP", Configuration to "Full and fast" and scanner to "OpenVAS Default"
  ```sh
  ./cli-app.py timesheets.php8 --defaults
  ```
- `-m, --mail` - Specifies who to send the generated report to. Emails must be a colon(:) separated list 
  ```sh
  ./cli-app.py timesheets.php8 --mail=joshua@overdrive.co.za
  ./cli-app.py eit.php8 --mail=joshua@overdrive.co.za:jaco@overdrive.co.za
  ```
- `-p, --portlist` - Specifies what port list to use for scanning
  ```sh
  ./cli-app.py eit.php8 --portlist="All_IANA_assigned_TCP"
  ```
- `-c, --config` - Specifies what scan configuration to use
  ```sh
  ./cli-app.py eit.php8 --config="Full_and_fast"
  ```
- `-s, --scanner` - Specifies what scanner to use
  ```sh
  ./cli-app.py eit.php8 --scanner="OpenVAS_Default"
  ```
- `-z, --supabase` - Instructs cli to store scan results to supabase

### Example Usage

```sh
./cli-app.py eit.php8 --defaults --mail=joshua@overdrive.co.za
./cli-app.py eit.php8:timesheets.php8 --config="Full_and_fast" --mail=joshua@overdrive.co.za:jaco@overdrive.co.za
```

## Configuration

Some configuration via .env file is required to enable email sending. The .env file can also be used to store greenbone credentials to allow running the script via cron, etc. Check the images in the documentation folder for more information on getting ms outlook credentials setup for emailing or check the following urls (https://stackoverflow.com/questions/46160886/how-to-send-smtp-email-for-office365-with-python-using-tls-ssl and https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade)

```sh
#can read user and password from a .env file as follows:
USERN=admin   #gvm user
PASS=suchASECRETpassword   #gvm password
#mail_host='smtp.gmail.com'
#mail_port=5087
#mail_user="xxx@gmail.com"
#mail_pass="xxx"
#mail_from='xxx@gmail.com'
#https://supabase.com/docs/reference/python/initializing
#SUPABASE_URL=<>
#SUPABASE_KEY=<>
#https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade
#https://stackoverflow.com/questions/46160886/how-to-send-smtp-email-for-office365-with-python-using-tls-ssl
ms_tenant_id="<>"
ms_app_id="<>"
ms_app_secret_val="<>"
```

# Greenbone Connections
By default this script uses a unix socket to connect to greenbone(`/tmp/gvm/gvmd/gvmd.sock`). to connect via ssh, uncomment line 357 and comment out line 355 in the `vulnerability_scan/cli_app/cli.py` file


## Help & Support

For more details, use:

```sh
./cli-app.py timesheets.php8 --help
```

