Skip to main content

Contrast CLIコマンド

以下は、CodeSec利用者およびエンタープライズユーザ(企業ユース)が利用できるContrast CLIコマンドの一覧です。

使用法:contrast [コマンド] [オプション]

認証/接続

CodeSec利用者で、Contrastアカウントをお持ちでない場合は、GitHubまたはGoogleアカウントを使用して認証します。ログイン用の新しいブラウザ画面が開きます。

  • 使用法:contrast auth

Contrastのアカウントを既にお持ちの場合は、以下のauthコマンドを実行すると、認証情報がローカルに保存されます。

  • 使用法:

    contrast auth 
    --api-key <your API key> 
    --authorization <your authorization header> 
    --host <your host domain> 
    --organization-id <your organization ID> 

そして、コマンドで解析を実行できます。

保存されている認証情報を表示します。

  • 使用法contrast config

    例:

    contrastuser@userc-C02GD0LUMD6TTY ~ % contrast config
    {  
    version: '1.0.24',  
    host: 'https://ce.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

    • --help

      auditコマンドの全てのオプションの使用方法を表示します。

    • --ignore-dev

      検査結果から開発・試験用ライブラリの依存関係を除外します。デフォルトでは、全ての依存関係が結果に含まれます。

      エイリアス:-i

    • --legacy

      Contrast Webインターフェイスにアプリケーションを作成します(旧CLIのワークフロー)。コードの依存関係ツリーを表示し、メタデータを利用します。これは、Contrast CLI V2.0以降でのみ利用可能であることにご注意ください。

    • --name

      カスタムのプロジェクト名を設定します。名前が既に使用されている場合は、そのプロジェクトの検出結果を置き換えます。特殊文字は使用しないで下さい。

    • --save

      SBOM(ソフトウェア部品表)をSPDXやCycloneDX形式で生成して保存します。有効なオプション:--save cyclonedx--save spdx (CycloneDX形式がデフォルト)

      エイリアス:-s

    • --severity

      ビルドを失敗させるCVEの最低レベルの深刻度を指定します。--failオプションと一緒に使用します。例えば、contrast audit --fail --severity highです。深刻度は、criticalhighmediumlow、またはnoteです。

    • --track

      デフォルトでは、結果は保持・保存されないため、コンソールでローカルチェックを行うことになります。--track フラグを追加すると、Contrast Webインターフェイスのライブラリページにある静的タブに、プロジェクトのSCA結果を表示できます。これは、Contrast CLI V2.0でのみ利用可能であることにご注意ください。

  • 詳細オプション:

    • --api-key

      エンタープライズユーザには必須です。Contrastで提供されるエージェントのAPIキーを指定します。キーの検索方法については、エージェントキーを参照してください。

    • --application-id

      Contrastに登録されているアプリケーションのIDを指定します。

    • --application-name

      Contrastに登録されているアプリケーションの名前です。

    • --app-groups

      アプリケーションのオンボーディング時に、1つ以上の既存のグループにアプリケーションを割り当てます。グループリストは、カンマで区切る必要があります。

    • --authorization

      エンタープライズユーザには必須です。Contrastで提供される認証ヘッダーです。

    • --code

      Contrastでアプリケーションに使用するアプリケーションコードです。

    • --host

      エンタープライズユーザには必須です。ホスト名を指定します。(例) https://app.contrastsecurity.com/

    • --maven-settings-path

      mavenのsettings.xmlファイルのパスを表示します。

    • --metadata

      アプリケーションに関連付けるユーザ定義のメタデータを指定するための、キーと値のペアのセット(RFC 2253に準拠)を定義します。

    • --organization-id

      エンタープライズユーザには必須です。Contrastでの組織IDを指定します。IDの検索方法については、エージェントキーを参照してください。

    • --tags

      アプリケーションにタグを適用します。タグは、カンマ区切りのリストとして書式設定する必要があります。(例) label1,label2,label3

  • プロキシの設定:

    • --cacert

      CaCert(認証局(CA)による証明書)ファイルのパスを表示します。

    • --cert

      Cert(証明書)ファイルのパスを表示します。

    • --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/contrast

      • Windows: %ProgramData%\Contrast\

      エイリアス:-c

    • --file <filename>

      出力された脆弱性結果ファイルのパスまたはディレクトリを指定して、Contrastがそのファイルを読み取ってターミナルに結果を表示できるようにします。ファイル名は contrast-assess-{Date}.jsonlで、{Date}はエポックミリ秒で表されています。例:contrast-assess-1691520302714.jsonl

      エイリアス:-f

    • --help

      assessコマンドの全てのオプションの使用方法を表示します。

    • --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

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
    • --fail

      検出された脆弱性の深刻度に基づいて、ビルドを失敗させます。--severityオプションと一緒に使用します。例えば、contrast scan --fail --severity highです。深刻度を指定しない場合、すべての深刻度で失敗が返ります。失敗が検出された場合、CLIコマンドはコード2で終了します。

    • --file

      スキャンするファイルのパスを指定します。ファイルが指定されていない場合は、Contrastはサポート対象ファイル(.jar、 .war、.js、.zipファイル)を作業ディレクトリ内で検索します。

      エイリアス: -f

    • --help

      scanコマンドの全てのオプションの使用方法を表示します。

    • --host

      エンタープライズユーザには必須です。ホスト名を指定します。(例) https://app.contrastsecurity.com/

    • --language

      有効な値:JAVA、JAVASCRIPT、DOTNET

      重要

      このオプションは、多言語ソースコードに対応したスキャンエンジンを使用している場合は無効です。

      エイリアス: -l

    • --memory

      多言語ソースコードに対応したスキャンエンジンのメモリをオーバーライドします。デフォルトのメモリ設定は2GBです。

    • --name

      Contrastのプロジェクト名を指定します。指定されていない場合、Contrastはcontrast.settingsを使用してプロジェクトを識別するか、プロジェクトを作成します。

      エイリアス:-n

    • -r

      Contrastのリソースグループ名を指定します。このオプションは、SaaS版をご利用のお客様でロールベースのアクセス制御が有効になっている場合に必要です。

    • --save

      検出結果をSARIF(Static Analysis Results Interchange Format)ファイルでダウンロードします。ファイルは、デフォルトの名前のresults.sarifで現在の作業ディレクトリにダウンロードされます。このファイルは、任意のテキストエディタで表示できます。

      エイリアス:-s

    • --severity

      ビルドを失敗させる脆弱性の最低レベルの深刻度を指定します。--failオプションと一緒に使用します。例えば、contrast scan --fail --severity highです。深刻度は、criticalhighmediumlow、またはnoteです。

    • --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にある最後の文字列です。

  • プロキシの設定:

    • --cacert

      CaCert(認証局(CA)による証明書)ファイルのパスを表示します。

    • --cert

      Cert(証明書)ファイルのパスを表示します。

    • --cert-self-signed

      ローカルインストールしたContrastオンプレミス(EOP)をご利用のお客様の場合、SSL証明書をバイパスして自己署名証明書を認識します。

    • --key

      証明書の鍵のパスを表示します。

    • --proxy

      プロキシサーバ経由の接続を許可します。認証が必要な場合は、ユーザ名とパスワード、プロトコル、ホスト、ポートを例のように指定します。(例) "http://username:password@<host>:<port>"

AWS Lambda関数をスキャンします。スキャンするAWS Lambdaの関数名を指定してください。

  • 使用法:contrast lambda --function-name <関数名> [オプション]

  • エイリアス:-f

  • オプション:

    • --endpoint-url

      AWSエンドポイントを上書きします。AWS CLIと同様です。

      エイリアス:-e

    • --help

      lambdaコマンドの全てのオプションの使用方法を表示します。

    • --region

      AWSリージョンを上書きします。デフォルトは、AWS_DEFAULT_REGIONです。AWS CLIと同様です。

      エイリアス:-r

    • --profile

      AWSの設定プロファイルを上書きします。AWS CLIと同様です。

      エイリアス:-p

    • --json

      人が判読できるデフォルトのフォーマットではなく、レスポンスをJSON形式で返します。

      エイリアス:-j

    • --verbose

      ターミナルに詳細情報を返します。

      エイリアス:-v

    • --list-functions

      スキャン可能なLambda関数を一覧表示します。

    • -–help

      使用方法を表示します。

      エイリアス:-h

  • プロキシの設定:

    • --cacert

      CaCert(認証局(CA)による証明書)ファイルのパスを表示します。

    • --cert

      Cert(証明書)ファイルのパスを表示します。

    • --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