Skip to content

Commit

Permalink
Garak integration (#306)
Browse files Browse the repository at this point in the history
* added code for scanning with Garak
* created a garak config template
* added a separate Containerfile to build an image that includes Garak
* updated README to introduce this feature
  • Loading branch information
jeremychoi authored Feb 25, 2025
1 parent b6d74cf commit b844d25
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ RapiDAST (Rapid DAST) is an open-source security testing tool that automates DAS

RapiDAST provides:

- Automated HTTP/API security scanning using ZAP
- Kubernetes operator scanning using OOBTKUBE
- Automated HTTP/API security scanning leveraging ZAP
- Automated LLM AI scanning leveraging Garak
- Kubernetes operator scanning leveraging OOBTKUBE
- Automated vulnerability scanning using Nessus (requires a Nessus instance)
- Command-line execution with yaml configuration, suitable for integration in [CI/CD pipelines](./examples/)
- Ability to run automated DAST scanning with pre-built or custom container images
Expand Down Expand Up @@ -131,6 +132,7 @@ See templates in the [config](./config/) directory for rapidast configuration ex
- `config-template-zap-long.yaml` : describes a more extensive use of ZAP (all configuration options are presented)
- `config-template-multi-scan.yaml` : describes how to combine multiple scanners in a single configuration
- `config-template-generic-scan.yaml` : describes the use of the generic scanner
- `config-template-garak.yaml` : describes the use of the Garak LLM AI scanner

See [here](./examples/) for examples on how to run RapiDAST in various CI/CD pipelines.

Expand Down Expand Up @@ -470,9 +472,21 @@ scanners:
- 127.0.0.1
```

#### Garak

Garak is an LLM AI scanner developed by NVIDIA. See https://github.com/NVIDIA/garak for more information.

The following is an example to launch a scan:
```yaml
scanners:
garak:
model_type: huggingface
model_name: gpt2
```

#### Generic scanner

RapiDAST can run other scanning tools as well as ZAP. It is possible to request RapiDAST to run a command and process stdout results, using the `generic` plugin.
In addition to the scanners mentioned above, RapiDAST can run any other scanning tools. It is possible to request RapiDAST to run a command and process stdout results, using the `generic` plugin. One use case is to run your own tools or scripts and export the results to Google Cloud Storage.

The following is an example to run a command or a tool in the host where a RapiDAST scan runs:

Expand Down
29 changes: 29 additions & 0 deletions config/config-template-garak.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
config:
# WARNING: `configVersion` indicates the schema version of the config file.
# This value tells RapiDAST what schema should be used to read this configuration.
# Therefore you should only change it if you update the configuration to a newer schema
configVersion: 6

# all the results of all scanners will be stored under that location
# base_results_dir: "./results"

# `application` contains data related to the application, not to the scans.
application:
shortName: "garak-test-1.0"

# `scanners' is a section that configures scanning options
scanners:
garak:
model_type: huggingface # required, e.g. hugginngface, openai, rest
model_name: gpt2 # optional, but a specific model type requires a model name or path
#generators: # optional, providing more options for the selected model type, e.g. RestGenerator
# rest:
# RestGenerator:
# uri:
# method:
# headers:
# response_json_field:
# req_template_json_object:
# request_timeout: 60
#probe_spec: all # default: all, or a list of probes like "probe1,probe2"
#garak_executable_path: /usr/local/bin/garak # default: /usr/local/bin/garak
25 changes: 25 additions & 0 deletions config/schemas/6/rapidast_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,31 @@
"scan",
"server"
]
},
{
"type": "object",
"description": "Garak Scanner",
"properties": {
"model_name": {
"type": "string"
},
"model_type": {
"type": "string"
},
"generators": {
"type": "object",
"properties": {}
},
"probe_spec": {
"type": "string"
},
"garak_executable_path": {
"type": "string"
}
},
"required": [
"model_type"
]
}
]
}
Expand Down
113 changes: 113 additions & 0 deletions containerize/Containerfile.garak
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#####
# Build RapiDAST image with Garak LLM AI scanner: https://github.com/NVIDIA/garak
#####

# Prepare dependencies
FROM registry.access.redhat.com/ubi9-minimal AS deps

# Indicate if dependencies were prefetched using Cachi2
# They must be located at /cachi2/output/deps
ARG PREFETCH=false

# These versions should be consistent with the listed in the artifacts.lock.yaml file
ARG ZAP_VERSION=2.15.0
ARG FF_VERSION=128.6.0esr
ARG K8S_VERSION=1.32.1
ARG TRIVY_VERSION=0.59.0

ARG DEPS_DIR=/tmp/deps
ARG ZAP_FILE=$DEPS_DIR/ZAP.tar.gz
ARG FF_FILE=$DEPS_DIR/firefox.tar.bz2
ARG TRIVY_FILE=$DEPS_DIR/trivy.tar.gz
ARG KCTL_FILE=$DEPS_DIR/kubectl

RUN microdnf install -y tar gzip bzip2 java-11-openjdk nodejs

RUN mkdir "${DEPS_DIR}" /tmp/node_modules && if [ "$PREFETCH" == "true" ]; then \
echo "PREFETCH is true: Copying dependencies from /cachi2/output/deps..." && \
cp -r /cachi2/output/deps/generic/* "$DEPS_DIR"; \
else \
echo "PREFETCH is false: Downloading dependencies from remote sources..." && \
curl -sfL "https://github.com/zaproxy/zaproxy/releases/download/v${ZAP_VERSION}/ZAP_${ZAP_VERSION}_Linux.tar.gz" -o "$ZAP_FILE"; \
curl -sfL "https://releases.mozilla.org/pub/firefox/releases/${FF_VERSION}/linux-x86_64/en-US/firefox-${FF_VERSION}.tar.bz2" -o "$FF_FILE"; \
curl -sfL "https://dl.k8s.io/release/v${K8S_VERSION}/bin/linux/amd64/kubectl" -o "$KCTL_FILE"; \
curl -sfL "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" -o "$TRIVY_FILE"; \
fi
## ZAP, build and install scanners in advance (more scanners will be added)
RUN mkdir /opt/zap && \
tar zxvf "$ZAP_FILE" --strip-components=1 -C /opt/zap && \
### Update add-ons
/opt/zap/zap.sh -cmd -silent -addonupdate && \
### Copy them to installation directory
cp /root/.ZAP/plugin/*.zap /opt/zap/plugin/

## Firefox, for Ajax
RUN mkdir -p /opt/firefox && \
tar xjvf "$FF_FILE" -C /opt/firefox

## kubectl
RUN install -o root -g root -m 0755 "$KCTL_FILE" /usr/local/bin/kubectl

## Trivy (https://github.com/aquasecurity/trivy/)
RUN mkdir /tmp/trivy && \
tar xzvf "$TRIVY_FILE" -C /tmp/trivy && \
chmod +x /tmp/trivy/trivy

## redocly (https://github.com/Redocly/redocly-cli)
COPY package.json package-lock.json /tmp/redocly/
RUN mkdir -p /tmp/redocly/node_modules && if [ "$PREFETCH" == "true" ]; then \
npm install --offline --prefix /tmp/redocly; \
else \
npm install --prefix /tmp/redocly; \
fi

# Copy artifacts from deps to build RapiDAST
FROM registry.access.redhat.com/ubi9-minimal

COPY --from=deps /opt/zap /opt/zap
COPY --from=deps /opt/firefox /opt/firefox
COPY --from=deps /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=deps /tmp/trivy/trivy /usr/local/bin/trivy
COPY --from=deps /tmp/redocly/node_modules /opt/redocly/node_modules

ENV PATH $PATH:/opt/zap/:/opt/rapidast/:/opt/firefox/

## RapiDAST
RUN mkdir /opt/rapidast
COPY ./rapidast.py ./requirements.txt /opt/rapidast/
COPY ./scanners/ /opt/rapidast/scanners/
COPY ./tools/ /opt/rapidast/tools/
COPY ./exports/ /opt/rapidast/exports/
COPY ./configmodel/ /opt/rapidast/configmodel/
COPY ./utils/ /opt/rapidast/utils/
COPY ./config/ /opt/rapidast/config/

### Add generic tools in the PATH
COPY ./scanners/generic/tools/convert_trivy_k8s_to_sarif.py /usr/local/bin/

### Overload default config (set 'none' as default container type)
COPY ./containerize/container_default_config.yaml /opt/rapidast/rapidast-defaults.yaml

### Add /opt/{zap,rapidast}/ to the PATH (for any user and future user)
COPY ./containerize/path_rapidast.sh /etc/profile.d/rapidast.sh

### Install RapiDAST requirements, globally, so that it's available to any user
RUN microdnf install -y --setopt=install_weak_deps=0 java-11-openjdk shadow-utils dbus-glib procps git nodejs npm && \
microdnf install -y gtk3 python3.12 rust cargo && \
python3.12 -m ensurepip --upgrade && \
pip3.12 install --upgrade pip && \
pip3.12 install --no-cache-dir -r /opt/rapidast/requirements.txt && \
pip3.12 install -U garak --no-cache-dir && \
microdnf clean all -y && rm -rf /var/cache/dnf /tmp/* && \
ln -s /opt/redocly/node_modules/@redocly/cli/bin/cli.js /usr/local/bin/redocly

RUN useradd -u 1000 -d /opt/rapidast -m -s /bin/bash rapidast && \
chown -R 1000 /opt/rapidast && \
# OpenShift runs containers with arbitrary user ids, belonging to root group
chgrp -R 0 /opt/rapidast && \
chmod -R g=u /opt/rapidast

USER rapidast
WORKDIR /opt/rapidast
ENV HOME /opt/rapidast
ENTRYPOINT ["./rapidast.py"]
39 changes: 39 additions & 0 deletions scanners/garak/garak-config-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
system:
verbose: 0
narrow_output: false
parallel_requests: false
parallel_attempts: false
lite: true
show_z: false

run:
seed:
deprefix: true
eval_threshold: 0.5
generations: 5
probe_tags:

plugins:
model_type:
model_name:
probe_spec: all
detector_spec: auto
extended_detectors: false
buff_spec:
buffs_include_original_prompt: false
buff_max:
detectors: {}
generators: {}
buffs: {}
harnesses: {}
probes:
encoding:
payloads:
- default

reporting:
report_prefix:
taxonomy:
report_dir: garak_runs
show_100_pass_modules: true
Loading

0 comments on commit b844d25

Please sign in to comment.