Contrast CLIコマンド
以下は、Contrastユーザが利用できるContrast CLIコマンドの一覧です。
使用法:contrast [コマンド] [オプション]
認証/接続
保存されている認証情報を表示します。
使用法:
contrast config例:
contrastuser@userc-C02GD0LUMD6TTY ~ % contrast config { version: '1.0.24', host: 'https://app.contrastsecurity.com', apiKey: 'wwEHMnYEIAujE03fFGH', organizationId: '0fde1b36-6986-4a14-b16d-6258aa913e5bceerfj', authorization: 'Z2l1bGlhbmEubWFyaWFuaUBjb250cmFzdHNlY3VyaXR5LmNvbTpDUktMUTE3T1czMDU2NjlLOPDS', numOfRuns: 0 }オプション:
-c、--clear保存されている認証情報を削除します。
Contrast CLIのバージョンを表示します。
使用法:
contrast version例:
contrastuser@usercsa-C02GD0LUMD6TTY ~ % contrast version 1.0.24
メイン機能
作業ディレクトリ内にある依存関係の設定ファイルを検索して依存関係のセキュリティ検査を実行し、結果を返します。
使用法:
contrast audit [オプション]例:
contrastuser@usercsa-C02GD0LUMD6TTY ~ % contrast audit Searching for package manager files from /Users/contrastuser/Documents/ Contrast SCA audit started... Contrast audit complete Found 4 vulnerable libraries with 4 CVEs CONTRAST-001 - [CRITICAL] minimist-1.2.5 introduces 1 vulnerability Issue: 1 Critical [C]CVE-2021-44906 Advice: Update to version 1.2.6 CONTRAST-002 - [CRITICAL] json-schema-0.2.3 introduces 1 vulnerability Issue: 1 Critical [C]CVE-2021-3918 Advice: Update to version 0.4.0 CONTRAST-003 - [HIGH] glob-parent-5.1.1 introduces 1 vulnerability Issue: 1 High [H]CVE-2020-28469 Advice: Update to version 5.1.2 CONTRAST-003 - [HIGH] ansi-regex-0.2.1 introduces 1 vulnerability Issue: 1 High [H]CVE-2021-3807 Advice: Update to version 6.0.1オプション:
--fail検出されたCVEの深刻度に基づいて、ビルドを失敗させます。--severityオプションと一緒に使用します。例えば、contrast audit --fail --severity highです。深刻度を指定しない場合、すべての深刻度で失敗が返ります。失敗が検出された場合、CLIコマンドはコード2で終了します。
--file依存関係が宣言されているディレクトリまたはファイルを指定します(デフォルトでは、Contrast CLIによって現在のディレクトリ内でプロジェクトファイルが検索されます)。ディレクトリ内で複数のプロジェクトファイルが見つかった場合、監査するファイルを確認するプロンプトが表示されます。
エイリアス:
-f--helpauditコマンドの全てのオプションの使用方法を表示します。--ignore-dev検査結果から開発・試験用ライブラリの依存関係を除外します。デフォルトでは、全ての依存関係が結果に含まれます。
エイリアス:
-i--legacyContrast Webインターフェイスにアプリケーションを作成します(旧CLIのワークフロー)。コードの依存関係ツリーを表示し、メタデータを利用します。これは、Contrast CLI V2.0以降でのみ利用可能であることにご注意ください。
--nameカスタムのプロジェクト名を設定します。名前が既に使用されている場合は、そのプロジェクトの検出結果を置き換えます。特殊文字は使用しないで下さい。
--resource-groupSCAプロジェクトの生成時にリソースグループを指定します。リソースグループによって、割り当てたロールに基づいて、ユーザがアクセスできるアプリケーション、プロジェクト、および組織の設定が指定されます。詳細については、リソースグループを参照して下さい。
--saveSBOM(ソフトウェア部品表)をSPDXやCycloneDX形式で生成して保存します。有効なオプション:--save cyclonedx、--save spdx (CycloneDX形式がデフォルト)
エイリアス:
-s--severityビルドを失敗させるCVEの最低レベルの深刻度を指定します。--failオプションと一緒に使用します。例えば、contrast audit --fail --severity highです。深刻度は、critical、high、medium、low、またはnoteです。
--trackデフォルトでは、結果は保持・保存されないため、コンソールでローカルチェックを行うことになります。
--trackフラグを追加すると、Contrast Webインターフェイスのライブラリページにある静的タブに、プロジェクトのSCA結果を表示できます。これは、Contrast CLI V2.0でのみ利用可能であることにご注意ください。
詳細オプション:
--api-keyエンタープライズユーザには必須です。Contrastで提供されるエージェントのAPIキーを指定します。キーの検索方法については、エージェントキーを参照してください。
--application-idContrastに登録されているアプリケーションのIDを指定します。
--application-nameContrastに登録されているアプリケーションの名前です。
--app-groupsアプリケーションのオンボーディング時に、1つ以上の既存のグループにアプリケーションを割り当てます。グループリストは、カンマで区切る必要があります。
--authorizationエンタープライズユーザには必須です。Contrastで提供される認証ヘッダーです。
--codeContrastでアプリケーションに使用するアプリケーションコードです。
--hostエンタープライズユーザには必須です。ホスト名を指定します。(例) https://app.contrastsecurity.com/
--maven-settings-pathmavenのsettings.xmlファイルのパスを表示します。
--metadataアプリケーションに関連付けるユーザ定義のメタデータを指定するための、キーと値のペアのセット(RFC 2253に準拠)を定義します。
--organization-idエンタープライズユーザには必須です。Contrastでの組織IDを指定します。IDの検索方法については、エージェントキーを参照してください。
--tagsアプリケーションにタグを適用します。タグは、カンマ区切りのリストとして書式設定する必要があります。(例) label1,label2,label3
プロキシの設定:
--cacertCaCert(認証局(CA)による証明書)ファイルのパスを表示します。
--certCert(証明書)ファイルのパスを表示します。
--cert-self-signedローカルインストールしたContrastオンプレミス(EOP)をご利用のお客様の場合、SSL証明書をバイパスして自己署名証明書を認識します。
--key証明書の鍵のパスを表示します。
--proxyプロキシサーバ経由の接続を許可します。認証が必要な場合は、ユーザ名とパスワード、プロトコル、ホスト、ポートを例のように指定します。(例) "http://username:password@<host>:<port>"
パイプラインでビルドを失敗させるようauditを使用するには、Contrast SCA Actionを参照してください。
Contrastエージェントを使用しているサーバで、実行時に検出された脆弱性を報告します。
使用法:
contrast assess [オプション]例:
contrastuser@usercsa-C02GD0LUMD6TTY ~ % contrast assess ✔ Configuration file found at "user_path" ✔ Session created. CONTRAST-001 - [HIGH] Path Traversal from "RawQuery" QueryString Parameter on "/pathTraversal/os.Open/:source/:mode" pagePath Traversal from "RawQuery" QueryString Parameter on "/pathTraversal/os.Open/:source/:mode" page App: CLIAssessApplication Source: GET /pathTraversal/os.Open/:source/:mode?input=..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd Location: /opt/homebrew/Cellar/go/1.19.1/libexec/src/os/file.go, line 316, in os.Open() Dataflow: "../../../../../../../../../../../../etc/passwd" Issue: Because there is untrusted data being used as part of the file path, it may be possible for an attacker to read sensitive data or write, update, or delete arbitrary files on the container's file system. The ability to write arbitrary files to the file system is also called Unrestricted or Arbitrary File Uploads. CONTRAST-002 - [HIGH] Path Traversal from "RawQuery" QueryString Parameter on "/pathTraversal/os.ReadFile/:source/:mode" pagePath Traversal from "RawQuery" QueryString Parameter on "/pathTraversal/os.ReadFile/:source/:mode" page App: CLIAssessApplication Source: GET /pathTraversal/os.ReadFile/:source/:mode?input=..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd Location: /opt/homebrew/Cellar/go/1.19.1/libexec/src/os/file.go, line 672, in os.ReadFile() Dataflow: "../../../../../../../../../../../../etc/passwd" Issue: Because there is untrusted data being used as part of the file path, it may be possible for an attacker to read sensitive data or write, update, or delete arbitrary files on the container's file system. The ability to write arbitrary files to the file system is also called Unrestricted or Arbitrary File Uploads. CONTRAST-003 - [HIGH] Path Traversal from "input[0]" Parameter on "/pathTraversal/os.Open/:source/:mode" pagePath Traversal from "input[0]" Parameter on "/pathTraversal/os.Open/:source/:mode" page App: CLIAssessApplication Source: POST /pathTraversal/os.Open/:source/:mode input=..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd Location: /opt/homebrew/Cellar/go/1.19.1/libexec/src/os/file.go, line 316, in os.Open() Dataflow: "../../../../../../../../../../../../etc/passwd" Issue: Because there is untrusted data being used as part of the file path, it may be possible for an attacker to read sensitive data or write, update, or delete arbitrary files on the container's file system. The ability to write arbitrary files to the file system is also called Unrestricted or Arbitrary File Uploads.オプション:
--config-path <path>Assess CLIとContrastエージェントで共有する
contrast_security.yamlファイルのパスまたはディレクトリを指定します。指定しない場合、デフォルトのパスは以下の通りです。
MacOSおよびLinux:
/etc/contrastWindows:
%ProgramData%\Contrast\
エイリアス:
-c--file <filename>出力された脆弱性結果ファイルのパスまたはディレクトリを指定して、Contrastがそのファイルを読み取ってターミナルに結果を表示できるようにします。ファイル名は
contrast-assess-{Date}.jsonlで、{Date}はエポックミリ秒で表されています。例:contrast-assess-1691520302714.jsonlエイリアス:
-f--helpassessコマンドの全てのオプションの使用方法を表示します。--no-watch [true|false]Contrastエージェントを使用してAssessを実行する際に
trueを設定すると、CLIはアクセス可能な脆弱性に対してContrastバックエンドを監視(またはポーリング)しません。CLIは、特定のbuildNumber(ビルド番号)に対して、一度だけ脆弱性を取得します。 デフォルトの設定は、falseです。エイリアス:
-n--output-path <path>脆弱性結果ファイルを出力するパスまたはディレクトリを指定します。出力ファイルは、JSONL形式です。ファイル名は
contrast-assess-{Date}.jsonlとなり、{Date}はエポックミリ秒で表されます。例:contrast-assess-1691520302714.jsonlエイリアス:
-o--report-notes [true|false]trueに設定すると、accessコマンドでは深刻度が「注意」の脆弱性を表示します。 デフォルトの設定はfalseで、深刻度の高い脆弱性が表示されます。エイリアス:
-r
特定のアプリケーションIDに対して、 Contrast AssessおよびContrast SCAの結果が含まれるSARIFファイル(contrast.sari)を生成します。処理が完了すると、ファイルをダウンロードするためのリンクが通知されます。
注記
sarifAPI を使用してSARIF ファイルを生成することもできます。
使用法:
contrast sarif [オプション]例:
contrast sarif --application-id 8f32952c-987c-4b9e-882c-a2b59a2fb4ee --severity high --metadata 'repo=TS,commit=commit-49-61670e50-1e9c-11ef-9109-059d9bfadadd,developer=Dev-49-61670e50-1e9c-11ef-9109-059d9bfadadd'
オプション:
--application-id <id>Contrastに登録されているアプリケーションのIDを指定します。
--severity [レベル]深刻度のレベルを設定して、SARIF出力に含める検出結果をフィルタリングします。深刻度のレベルは、critical、high、medium、lowまたはnoteです。
指定する深刻度レベルは、レポートに含まれる最小レベルです。例えば、
--severity highを指定した場合、レポートには深刻度がhighおよびcriticalの結果が含まれます。--metadataアプリケーションに関連付けるユーザ定義のメタデータを指定するための、キーと値のペアのセット(RFC 2253に準拠)を定義します。
--tool-typeレポートに含まれる検出結果の種類をフィルタリングします。有効な種類はSCAとASSESSです。例えば、
--tool-type ASSESSでは、Contrast Assessの検出結果のみが含まれます。このオプションを指定しない場合、レポートにはSCAとAssessの両方の検出結果が含まれます。
詳細オプション:
--api-keyエンタープライズユーザには必須です。Contrastで提供されるエージェントのAPIキーを指定します。キーの検索方法については、エージェントキーを参照してください。
--authorizationエンタープライズユーザには必須です。Contrastで提供される認証ヘッダーです。
--codeContrastでアプリケーションに使用するアプリケーションコードです。
--hostエンタープライズユーザには必須です。ホスト名を指定します。例: https://app.contrastsecurity.com
--organization-idエンタープライズユーザには必須です。Contrastでの組織IDを指定します。IDの検索方法については、エージェントキーを参照してください。
プロキシの設定:
--cacertCaCert(認証局(CA)による証明書)ファイルのパスを表示します。
--certCert(証明書)ファイルのパスを表示します。
--cert-self-signedローカルインストールしたContrastオンプレミス(EOP)をご利用のお客様の場合、SSL証明書をバイパスして自己署名証明書を認識します。
--key証明書の鍵のパスを表示します。
--proxyプロキシサーバ経由の接続を許可します。認証が必要な場合は、ユーザ名とパスワード、プロトコル、ホスト、ポートを例のように指定します。(例) "http://username:password@<host>:<port>"
SASTスキャンを実行します。
使用法:
contrast scan [オプション]例:
contrastuser@usercsa-C02GD0LUMD6TTY ~ % contrast scan Searching for files to scan from from /Users/contrast/Documents/ Searched 3 directory levels & found... - spring-petclinic-1.5.1.jar - webgoat-server-8.2.2.jar - webgoat.jar Java Scan requires a .war or.jar file. Javascript Scan requires a .js or .zip file. To start a Scan enter "contrast scan -f <path-to-file>" contrastuser@usercsa-C02GD0LUMD6TTY ~ % contrast scan -f webgoat.jar Found existing project... Uploading... Uploaded file successfully. Contrast Scan started. Here are your top priorities to fix CRITICAL sql-injection (2) 1. org/owasp/webgoat/plugin/challenge6/Assigment6.java @43 2. org/owasp/webgoat/plugin/challenge5/challenge6/Assigment5.java @38--branchスキャンするリポジトリ内のブランチを指定します。指定された場合、スキャン結果はメインプロジェクトではなく、現在のブランチの結果に対して集計されます。
エイリアス:
-b--fail検出された脆弱性の深刻度に基づいて、ビルドを失敗させます。--severityオプションと一緒に使用します。例えば、contrast scan --fail --severity highです。深刻度を指定しない場合、すべての深刻度で失敗が返ります。失敗が検出された場合、CLIコマンドはコード2で終了します。
--fileスキャンするファイルのパスを指定します。ファイルが指定されていない場合は、Contrastはサポート対象ファイル(.jar、 .war、.js、.zipファイル)を作業ディレクトリ内で検索します。
エイリアス:
-f--helpscanコマンドの全てのオプションの使用方法を表示します。--hostエンタープライズユーザには必須です。ホスト名を指定します。(例) https://app.contrastsecurity.com/
--language有効な値は、JAVAとJAVASCRIPTです。
重要
このオプションは、多言語ソースコードに対応したスキャンエンジンを使用している場合は無効です。
エイリアス:
-l--memory多言語ソースコードに対応したスキャンエンジンのメモリをオーバーライドします。デフォルトのメモリ設定は2GBです。
--nameContrastのプロジェクト名を指定します。指定されていない場合、Contrastはcontrast.settingsを使用してプロジェクトを識別するか、プロジェクトを作成します。
エイリアス:
-n-rContrastのリソースグループ名を指定します。このオプションは、SaaS版をご利用のお客様でロールベースのアクセス制御が有効になっている場合に必要です。
--save検出結果をSARIF(Static Analysis Results Interchange Format)ファイルでダウンロードします。ファイルは、デフォルトの名前のresults.sarifで現在の作業ディレクトリにダウンロードされます。このファイルは、任意のテキストエディタで表示できます。
エイリアス:
-s--severityパイプラインでビルドをゲートするために使用できる、ビルド失敗のステータスコードを返すContrastの脆弱性の深刻度を指定します。
有効な値:
critical(重大)、high(高)、medium(中)、low(低)、note(注意)指定する値は、ビルド失敗のステータスコードを返す最小の深刻度です。例えば、
--severity highを指定すると、この深刻度(high)以上の検出結果があった場合に、ビルド失敗のステータスコードが返されます。--failオプションと一緒に使用します。例:contrast scan --fail --severity high
--timeoutスキャンが完了するまでの待機時間(wait)を秒数で指定します。デフォルトの値は、300秒です。
エイリアス:
-t
オプション:
詳細オプション:
--api-keyエンタープライズユーザには必須です。Contrastで提供されるエージェントのAPIキーを指定します。キーの検索方法については、エージェントキーを参照してください。
--authorizationエンタープライズユーザには必須です。Contrastで提供される認証ヘッダーです。
--ffファイア・アンド・フォーゲット(Fire-&forget)。実行させておくだけで、結果を監視・待つ必要がありません。
--hostエンタープライズユーザには必須です。ホスト名を指定します。(例) https://app.contrastsecurity.com/
--labelスキャンにラベルを付けます。デフォルトは、CLIツールで開始した日付[現在の日付]です。
--organization-idエンタープライズユーザには必須です。Contrastでの組織IDを指定します。IDの検索方法については、エージェントキーを参照してください。
--project-idスキャンプロジェクトに関連付けられたIDです。IDは、Contrast Webインターフェイスでスキャンプロジェクトを選択した際のURLにある最後の文字列です。
プロキシの設定:
--cacertCaCert(認証局(CA)による証明書)ファイルのパスを表示します。
--certCert(証明書)ファイルのパスを表示します。
--cert-self-signedローカルインストールしたContrastオンプレミス(EOP)をご利用のお客様の場合、SSL証明書をバイパスして自己署名証明書を認識します。
--key証明書の鍵のパスを表示します。
--proxyプロキシサーバ経由の接続を許可します。認証が必要な場合は、ユーザ名とパスワード、プロトコル、ホスト、ポートを例のように指定します。(例) "http://username:password@<host>:<port>"
AWS Lambda関数をスキャンします。スキャンするAWS Lambdaの関数名を指定してください。
使用法:
contrast lambda --function-name <関数名> [オプション]エイリアス:
-fオプション:
--endpoint-urlAWSエンドポイントを上書きします。AWS CLIと同様です。
エイリアス:
-e--helplambdaコマンドの全てのオプションの使用方法を表示します。--regionAWSリージョンを上書きします。デフォルトは、AWS_DEFAULT_REGIONです。AWS CLIと同様です。
エイリアス:
-r--profileAWSの設定プロファイルを上書きします。AWS CLIと同様です。
エイリアス:
-p--json人が判読できるデフォルトのフォーマットではなく、レスポンスをJSON形式で返します。
エイリアス:
-j--verboseターミナルに詳細情報を返します。
エイリアス:
-v--list-functionsスキャン可能なLambda関数を一覧表示します。
-–help使用方法を表示します。
エイリアス:
-h
プロキシの設定:
--cacertCaCert(認証局(CA)による証明書)ファイルのパスを表示します。
--certCert(証明書)ファイルのパスを表示します。
--cert-self-signedローカルインストールしたContrastオンプレミス(EOP)をご利用のお客様の場合、SSL証明書をバイパスして自己署名証明書を認識します。
--key証明書の鍵のパスを表示します。
--proxyプロキシサーバ経由の接続を許可します。認証が必要な場合は、ユーザ名とパスワード、プロトコル、ホスト、ポートを例のように指定します。(例) "http://username:password@<host>:<port>"
ヘルプと学習コンテンツ
使用方法を表示します。CLIコマンドの詳細なヘルプを一覧表示 するには、-hか--helpフラグをコマンドに追加します。
使用法:
contrast help例:
contrastuser@usercsa-C02GD0LUMD6TTY ~ % contrast help Contrast CLI @ v1.0.24 Contrast Scan CLI Pre-requisites Java, Javascript and .NET supported To scan a Java project you will need a .jar or .war file for analysis To scan a Javascript project you will need a single .js or a .zip of multiple .js files To scan a .NET c# webforms project you will need a .exe or a .zip file for analysis The file argument is optional. If no file is given, Contrast will search for a .jar, .war, .exe or .zip file in the working directory. Submitted files are encrypted during upload and deleted in 24 hours. Scan Options -l, --language string (optional): Valid values are JAVA, JAVASCRIPT and DOTNET --label string (optional): adds a label to the scan - defaults to 'Started by CLI tool at current date' -n, --name string (optional): Contrast project name. If not specified, Contrast uses contrast.settings to identify the project or creates a project. -f, --file string (optional): Path of the file you want to scan. If no file is specified, Contrast searches for a .jar, .war, .exe or .zip file in the working directory. -t, --timeout number (optional): Time in seconds to wait for scan to complete. Default value is 300 seconds. --fail (optional): Use with contrast scan or contrast audit. Detects failures based on the severity level specified with the --severity command. For example, "contrast scan --fail --severity high". Returns all failures if no severity level is specified. --severity type (optional): Use with "contrast scan --fail --severity high" or "contrast audit --fail --severity high". Set the severity level to detect vulnerabilities or dependencies. Severity levels are critical, high, medium, low or note. -s, --save string (optional): Saves the Scan Results SARIF to file. Advanced -o, --organization-id string (required for Contrast Enterprise): The ID of your organization as provided by Contrast UI --api-key string (required for Contrast Enterprise): An agent API key as provided by Contrast UI --authorization string (required for Contrast Enterprise): An authorization header as provided by Contrast UI --host string (required for Contrast Enterprise): host name e.g. https://app.contrastsecurity.com --proxy string (optional): Allows for connection via a proxy server. If authentication is required please provide the username and password with the protocol, host and port. For instance: "https://username:password@<host>:<port>". --key string (optional): Path to the Certificate Key --cacert string (optional): Path to the CaCert file --cert string (optional): Path to the Cert file --cert-self-signed (optional):For EOP users with a local Teamserver install, this will bypass the SSL certificate and recognise a self signed certificate. -p, --project-id string (optional): The ID associated with a scan project. Replace <ProjectID> with the ID for the scan project. To find the ID, select a scan project in Contrast and locate the last number in the URL. -l, --language string (optional): Valid values are JAVA, JAVASCRIPT and DOTNET --ff (optional): Fire and forget. Do not wait for the result of the scan. --label string (optional):adds a label to the scan - defaults to 'Started by CLI tool at current date' Need More Help? NEW users Check out: https://support.contrastsecurity.com Learn more at: https://www.contrastsecurity.com/developer Join the discussion: https://www.contrastsecurity.com/developer/community Existing Contrast Licensed user? Read our docs: https://docs.contrastsecurity.com/en/run-contrast-cli.html Want to UP your game? type 'contrast learn' 💰 Advance your security knowledge and become an All-star coder ⭐ with Contrast Secure Code Learning Hub. 😺
エイリアス:
-h
ContrastのSecure Codeラーニングハブを表示します。
使用法:
contrast learn例:
contrastuser@usercsa-C02GD0LUMD6TTY ~ % contrast learn Opening Contrast’s Secure Code Learning Hub... If the page does not open you can open it directly via https://www.contrastsecurity.com/developer/learn