### Cx-PM-Setup Script Execution Example Source: https://docs.checkmarx.com/en/34965-201747-deployment---additional-information.html Example of how to execute the cx-pm-setup.ps1 script with various parameters for CxSAST installation and configuration. ```powershell .\cx-pm-setup.ps1 -ServicePort 5555 -PortalPort 3000 -BaseAddressService http://xptomachine.dm.cx -BaseAddressPortal http://xptomachine.dm.cx -BaseAddressIdentityProvider http://IdentProvDomain -InstallationPath "C:\Program Files\Checkmarx" -DatabaseHost "localhost\SQLExpress" -Username SomeUser ``` -------------------------------- ### Example CxSAST Reporting Service Docker installation Source: https://docs.checkmarx.com/en/34965-132874-cxsast-reporting-schedule-installation--docker-image-.html An example command for running the CxSASTReportingService Docker container, mapping port 5002, mounting a local volume for reports, and using a specified environment file for configuration. ```bash docker run -p 5002:5002 \ -v ~/cx-reporting-service:/app/CxReports \ --env-file="/var/jenkins/workspace/reporting-service-validation_dev/pipelines/reporting-service/.env" \ cx-reporting-scheduler:latest ``` -------------------------------- ### Python: Get All Projects Source: https://docs.checkmarx.com/en/34965-102460-general.html Provides a Python example using the 'requests' library to get project details. Ensure your 'Authorization' header contains a valid Bearer token. ```Python import requests headers = { 'Accept': 'application/json;v=2.2', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://***.***.***.***/cxrestapi/help/projects', headers = headers) print(r.json()) ``` -------------------------------- ### Ruby: Get All Projects Source: https://docs.checkmarx.com/en/34965-102460-general.html Demonstrates how to retrieve project information using Ruby's 'rest-client' gem. This example requires a valid access token and API endpoint. ```Ruby require 'rest-client' require 'json' headers = { 'Accept' => 'application/json;v=2.2', 'Authorization' => 'Bearer {access-token}' } result = RestClient.get 'https://***.***.***.***/cxrestapi/help/projects', params: { }, headers: headers p JSON.parse(result) ``` -------------------------------- ### Install Gradle on Debian Source: https://docs.checkmarx.com/en/34965-19198-installing-supported-package-managers-for-resolver.html Use this command to install Gradle on Debian-based systems. Ensure Java is installed and JAVA_HOME is set. ```bash apt-get install gradle ``` -------------------------------- ### Install Yarn Source: https://docs.checkmarx.com/en/34965-19198-installing-supported-package-managers-for-resolver.html Installs Yarn, a JavaScript package manager. Ensure Yarn is installed by running `yarn --version`. ```bash yarn install --ignore-scripts ``` -------------------------------- ### Get Failed SAST Queries (Ruby) Source: https://docs.checkmarx.com/en/34965-103205-sast.html A Ruby example using 'rest-client' to get failed SAST queries. Ensure you have the 'rest-client' and 'json' gems installed. ```ruby require 'rest-client' require 'json' headers = { 'Accept' => 'application/json;v=3.0', 'Authorization' => 'Bearer {access-token}' } result = RestClient.get 'https://10.32.9.160/cxrestapi/help/sast/scans/{id}/failedQueries', params: { }, headers: headers p JSON.parse(result) ``` -------------------------------- ### Example Configuration File Structure Source: https://docs.checkmarx.com/en/34965-132888-checkmarx-sca-resolver-configuration-arguments.html Illustrates the basic KeyName: Value format for the configuration.yml file. Ensure this file is in the same directory as the ScaResolver binary. ```yaml Account: YourSCAAccountName AuthenticationServerUrl: https://platform.checkmarx.net LogsDirectory: logs Password: YourPassword ResolverResultPath: "/path/to/save/results" ProjectName: "MyProject" ScaAppUrl: https://sca.checkmarx.net ServerUrl: https://api-sca.checkmarx.net Username: YourUsername ``` -------------------------------- ### Get First Nodes in Path Example Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Retrieves the starting nodes of a data flow path. Use this when you need to identify the origin points of data influencing a specific operation. ```csharp public void setString (String str) { lst.add(str); } ``` ```csharp CxList paths = All.DataInfluencingOn(All.FindByShortName("add")); // similar to paths.GetStartAndEndNodes(CxList.GetStartEndNodesType.StartNodesOnly); result = paths.GetFirstNodesInPath(); ``` -------------------------------- ### Windows Sample Command Source: https://docs.checkmarx.com/en/34965-132888-checkmarx-sca-resolver-configuration-arguments.html This example shows how to execute the ScaResolver on Windows, including essential arguments for project scanning, authentication, and specifying the source code directory. ```bash ./ScaResolver.exe -s C:\home\jack\src\MyApp -n MyApp -a Checkmarx -u jack -p "demo123!" ``` -------------------------------- ### Resource and Credentials Example Source: https://docs.checkmarx.com/en/34965-278101-using-the-cxsast--rest--api--v8-6-0-and-up-.html This example shows how to format a request to the CxSAST resource server, including the resource URL and the Authorization header with a Bearer token. ```http Resource example: http://:/cxrestapi/projects Credentials example: Authorization: Bearer Accept: application/json;v=1.0 ``` -------------------------------- ### Get Start and End Nodes (StartNodesOnly) Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Retrieves only the start nodes of a path. Use this when you need to identify the entry points of data flow within a path. ```csharp public CxList GetStartAndEndNodes (GetStartEndNodesType type) ``` ```csharp CxList paths = All.DataInfluencingOn(All.FindByShortName("add")); result = paths.GetStartAndEndNodes(CxList.GetStartEndNodesType.StartNodesOnly); ``` -------------------------------- ### Linux/MacOS Sample Command Source: https://docs.checkmarx.com/en/34965-132888-checkmarx-sca-resolver-configuration-arguments.html This example demonstrates how to run the ScaResolver on Linux or MacOS using mandatory arguments for scanning a local source code path, specifying a project name, authentication details, and scan path. ```bash ./ScaResolver -s /home/jack/src/MyApp -n MyApp -a Checkmarx -u jack -p 'demo123!' ``` -------------------------------- ### Get OSA Libraries (Python) Source: https://docs.checkmarx.com/en/34965-103202-osa.html This Python example uses the requests library to fetch OSA libraries. It defines headers and passes the scanId as a parameter in the GET request. ```Python import requests headers = { 'Accept': 'application/json;v=3.0', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://10.32.9.160/cxrestapi/help/osa/libraries', params={ 'scanId': '497f6eca-6276-4993-bfeb-53cbbbba6f08' }, headers = headers) print(r.json()) ``` -------------------------------- ### Get Start and End Nodes (StartAndEndNodes) Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Retrieves both the start and end nodes of a path. Use this when you need to identify both the entry and exit points of data flow within a path. ```csharp CxList paths = All.DataInfluencingOn(All.FindByShortName("add")); result = paths.GetStartAndEndNodes(CxList.GetStartEndNodesType.StartAndEndNodes); ``` -------------------------------- ### Running Resolver with Command Line Arguments Source: https://docs.checkmarx.com/en/34965-132888-checkmarx-sca-resolver-configuration-arguments.html Demonstrates how to pass configuration parameters directly as command-line arguments when running the ScaResolver binary. This is an alternative to using a configuration file for most parameters. ```bash ./ScaResolver --account YourSCAAccountName --username YourUsername --password YourPassword --server-url https://api-sca.checkmarx.net --sca-app-url https://sca.checkmarx.net --scan-path /path/to/your/code --resolver-result-path /path/to/save/results ``` -------------------------------- ### Get Start and End Nodes (AllButNotStartAndEnd) Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Retrieves all nodes in a path except for the start and end nodes. Use this when you need to focus on the intermediate steps or transformations within a data flow path. ```csharp CxList paths = All.DataInfluencingOn(All.FindByShortName("add")); result = paths.GetStartAndEndNodes(CxList.GetStartEndNodesType.AllButNotStartAndEnd); ``` -------------------------------- ### Example AWS Credentials File Source: https://docs.checkmarx.com/en/34965-19110-container-scans.html This example shows the structure of the AWS credentials file, including default and production profiles. ```ini [default] aws_access_key_id=ASI aws_secret_access_key=abcd region=us-west -1 aws_session_token=Absd [prod] aws_access_key_id=AKI aws_secret_access_key=xyz region=us-west -1 ``` -------------------------------- ### Windows: Basic SCA Resolver Usage with Optional Arguments Source: https://docs.checkmarx.com/en/34965-132888-checkmarx-sca-resolver-configuration-arguments.html Shows how to execute the SCA Resolver on Windows with similar optional arguments as the Linux/MacOS example, including log level, evidence path, archive extraction, and Gradle exclusions. ```bash ./ScaResolver.exe -s C:\home\jack\src\MyApp -a Checkmarx -u jack -p "demo123!" --log-level Debug --save-evidence-path ./evidences.json --extract-archives zip,ear --extract-depth 3 --gradle-exclude-scopes api,testCompile ``` -------------------------------- ### Get Start and End Nodes (AllNodes) Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Retrieves all nodes within a path, including start, end, and intermediate nodes. Use this when a comprehensive view of all elements in a data flow path is required. ```csharp CxList paths = All.DataInfluencingOn(All.FindByShortName("add")); result = paths.GetStartAndEndNodes(CxList.GetStartEndNodesType.AllNodes); ``` -------------------------------- ### Get Query Version Code with RestClient in Ruby Source: https://docs.checkmarx.com/en/34965-104146-general.html Shows how to get the query version code using the RestClient gem in Ruby. This example includes setting parameters and headers for the API call. ```Ruby require 'rest-client' require 'json' headers = { 'Accept' => 'application/json;v=4.0', 'Authorization' => 'Bearer {access-token}' } result = RestClient.get 'https://***.***.***.***/cxrestapi/help/queries/queryVersionCode', params: { 'language' => 'string', 'severity' => 'string', 'queryName' => 'string' }, headers: headers p JSON.parse(result) ``` -------------------------------- ### Install Dependencies on Ubuntu Source: https://docs.checkmarx.com/en/34965-19197-checkmarx-sca-resolver-download-and-installation.html Run these commands as root on Ubuntu to install necessary certificates and libraries before installing the SCA Resolver, especially if encountering startup issues. ```bash apt update apt install ca-certificates libgssapi-krb5-2 ``` -------------------------------- ### Get Query Version Code with Requests in Python Source: https://docs.checkmarx.com/en/34965-104146-general.html Demonstrates retrieving the query version code using the Python requests library. This example shows how to set parameters and headers for the GET request. ```Python import requests headers = { 'Accept': 'application/json;v=4.0', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://***.***.***.***/cxrestapi/help/queries/queryVersionCode', params={ 'language': 'string', 'severity': 'Info', 'queryName': 'string' }, headers = headers) print(r.json()) ``` -------------------------------- ### Test NuGet CLI Installation Source: https://docs.checkmarx.com/en/34965-19198-installing-supported-package-managers-for-resolver.html Verify that the NuGet CLI is installed correctly. This command should be run from your terminal. ```bash nuget --version ``` -------------------------------- ### Install CxEngine using run.sh Source: https://docs.checkmarx.com/en/34965-165477-required-prerequisites-for-installing-cxengine.html Execute the `run.sh` script to install CxEngine. This script extracts the `cx-engine-server.tar` image, loads it, and establishes the Docker container. ```bash sh run.sh ``` -------------------------------- ### Example Hosts File Entry Source: https://docs.checkmarx.com/en/34965-201748-troubleshooting.html This is an example of how to configure the hosts file to map the IP address 127.0.0.1 to the hostname CxPolicyManagement. ```hosts 127.0.0.1 CxPolicyManagement ``` -------------------------------- ### Get Succeeded General SAST Queries (Go) Source: https://docs.checkmarx.com/en/34965-103205-sast.html This Go example shows how to retrieve succeeded general SAST queries using the 'net/http' package. It includes setting up request headers and making the GET request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json;v=3.0"}, "Authorization": []string{"Bearer {access-token}"}, } ``` -------------------------------- ### Create Project Source: https://docs.checkmarx.com/en/34965-102460-general.html This Go code snippet demonstrates how to create a new project with default settings using the Checkmarx API. Ensure you replace `{access-token}` with your valid authentication token. ```Go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json;v=2.2"}, "Accept": []string{"application/json;v=2.2"}, "Authorization": []string{"Bearer {access-token}"}, } ``` -------------------------------- ### Get active firewalld zones Source: https://docs.checkmarx.com/en/34965-165477-required-prerequisites-for-installing-cxengine.html List all active zones configured in firewalld to understand the current firewall zone setup. ```bash sudo firewall-cmd --get-active-zones ``` -------------------------------- ### Get Paths Origins Example Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Demonstrates the CxList.GetPathsOrigins() method to retrieve the end nodes of paths. The input source code defines a method to add strings to a list, and the example shows how to use GetPathsOrigins on data influencing an 'add' method. ```csharp public void setString (String str) { if (str.length >0) { lst.add(str); } } ``` ```csharp CxList paths = All.DataInfluencingOn(All.FindByShortName("add")); result = paths.GetPathsOrigins(); ``` ```text lst (in lst.add(str);) str(in lst.add(str);) str(in (String str);) ``` -------------------------------- ### Windows SCA Resolver Sample Source: https://docs.checkmarx.com/en/34965-132888-checkmarx-sca-resolver-configuration-arguments.html Example command for running the SCA Resolver on Windows, including SAST project and server details. ```bash ./ScaResolver.exe -s C:\home\jack\src\MyApp -a Checkmarx -u jack -p "demo123!" --cxuser bob --cxpassword "demoabc!" --cxprojectname DemoCxProject --cxserver "https://checkmarxServer" ``` -------------------------------- ### Execute Policy Management Setup Script Source: https://docs.checkmarx.com/en/34965-201745-deploying-policy-management-in-windows.html Run the cx-pm-setup.ps1 script with necessary parameters to configure Policy Management. Ensure you replace placeholders like and domain names with your specific values. ```powershell .\cx-pm-setup.ps1 -BaseAddressService http://CxPolicyManagement -BaseAddressPortal http://CxPolicyManagement -APIAlias api -BaseAddressAccessControl http://xptomachine.dm.cx -Username ``` -------------------------------- ### Get Leftmost Target Example Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Retrieves the leftmost target of a specified member. This is useful for analyzing complex member access chains. ```csharp int i = foo().Bar().a.b; ``` ```csharp CxList b = All.FindByName("b"); result = b.GetLeftmostTarget(); ``` -------------------------------- ### Java Spring Request Mapping Example Source: https://docs.checkmarx.com/en/34965-190118-api-security-language-and-framework-support.html Demonstrates how to register a mapping for a GET request to '/user/{id}' using RequestMappingInfo in Spring. ```Java RequestMappingInfo info = RequestMappingInfo .paths("/user/{id}").methods(RequestMethod.GET).build(); Method method = UserHandler.class.getMethod("getUser", Long.class); mapping.registerMapping(info, handler, method); ``` -------------------------------- ### Create a New Project (Go) Source: https://docs.checkmarx.com/en/34965-101581-general.html Use this Go snippet to create a new project via the Checkmarx API. Ensure you replace `{access-token}` with your valid token and the placeholder URL with your Checkmarx instance URL. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json;v=2.1"}, "Accept": []string{"application/json;v=2.1"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://***.***.***.***/cxrestapi/help/projects", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Get Scan Settings (Go) Source: https://docs.checkmarx.com/en/34965-104157-sast.html Example snippet for retrieving scan settings. Requires Bearer token authentication with sast_api scope. ```Go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json;v=4.0"}, "Authorization": []string{"Bearer {access-token}"}, } ``` -------------------------------- ### Get SCA Resolver Version Source: https://docs.checkmarx.com/en/34965-19199-running-scans-using-checkmarx-sca-resolver.html This command retrieves the version of the SCA Resolver executable. It is useful for support requests and verifying the installed version. ```bash ./ScaResolver --version ``` -------------------------------- ### Upload Zipped Source Code in Go Source: https://docs.checkmarx.com/en/34965-104146-general.html Provides a Go example for uploading zipped source code. This snippet demonstrates setting up headers for a POST request, including content type and authorization. ```Go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/x-www-form-urlencoded"}, "Accept": []string{"application/json;v=4.0"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://***.***.***.***/cxrestapi/help/projects/{id}/sourceCode/attachments", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Get Server License Data (Python) Source: https://docs.checkmarx.com/en/34965-104146-general.html Retrieves server license data using the Python requests library. Ensure the 'requests' library is installed. ```Python import requests headers = { 'Accept': 'application/json;v=4.0', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://***.***.***.***/cxrestapi/help/serverLicenseData', headers = headers) print(r.json()) ``` -------------------------------- ### Get dotnet executable path Source: https://docs.checkmarx.com/en/34965-132875-cxsast-reporting-schedule-installation--as-a-windows-service-.html Run this command in PowerShell to find the exact installation path of the `dotnet` executable on your system. This is crucial if the default path differs. ```powershell get-command dotnet | select -expandproperty Path ``` -------------------------------- ### Example CxEngine SSL Configuration (Linux) Source: https://docs.checkmarx.com/en/34965-147626-enabling-ssl-support-on-the-cxengine.html An example of the server.env file configuration for enabling SSL on CxEngine in a Linux environment. ```properties CX_ENGINE_TLS_ENABLE=true CX_ENGINE_CERTIFICATE_SUBJECT_NAME=CN=www.myhost.com CX_ENGINE_CERTIFICATE_PATH=/app/certificate/mycert.pfx CX_ENGINE_CERTIFICATE_PASSWORD=12345 ``` -------------------------------- ### Get Following Statements Example Source: https://docs.checkmarx.com/en/34965-270431-sast-query-language-apis.html Retrieves statements that directly follow the statements in the current CxList within the same scope. Useful for analyzing sequential execution flow. ```csharp if (a > 3) { a = 4; } if(a != 4) { a = 0; b = 5; } c = 2; d = 3; ``` ```csharp result = All.GetFollowingStatements(); ``` -------------------------------- ### Install Go 1.16.6 on Debian Source: https://docs.checkmarx.com/en/34965-19198-installing-supported-package-managers-for-resolver.html Installs Go version 1.16.6 and necessary tools on Debian. Remember to update the PATH environment variable with the extracted Go path. Verify the installation with `go version`. ```bash wget https://golang.org/dl/go1.16.6.linux-amd64.tar.gz ``` ```bash tar -xvzf go1.16.6.linux-amd64.tar.gz && rm -f go1.16.6.linux-amd64.tar.gz ``` ```bash export PATH=$PATH:{extractedPath}/go/bin ``` -------------------------------- ### Get Project Details (Java) Source: https://docs.checkmarx.com/en/34965-101581-general.html Fetches a specific project's details using its ID. This example demonstrates basic HTTP request handling in Java. ```Java URL obj = new URL("https://***.***.***.***/cxrestapi/help/projects/{id}"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); ``` -------------------------------- ### Test Gradle Installation Source: https://docs.checkmarx.com/en/34965-19198-installing-supported-package-managers-for-resolver.html Verify that Gradle is installed correctly by checking its version. This command should be run from within your project directory. ```bash gradle --version ``` -------------------------------- ### Test .NET CLI Installation Source: https://docs.checkmarx.com/en/34965-19198-installing-supported-package-managers-for-resolver.html Verify that the .NET CLI is installed correctly by checking its version. This command should be run from your terminal. ```bash dotnet --version ``` -------------------------------- ### Get Server License Data (Java) Source: https://docs.checkmarx.com/en/34965-104146-general.html Retrieves server license data using Java. This example demonstrates basic HTTP connection and response handling. ```Java URL obj = new URL("https://***.***.***.***/cxrestapi/help/serverLicenseData"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); ```