|
| 1 | +# Quick Start Guide |
| 2 | + |
| 3 | +In this section, you will learn how to use CodeSecTools. |
| 4 | + |
| 5 | +This guide mainly used the tool on Java projects, it is perfectly possible to run it on any project that language is supported. |
| 6 | + |
| 7 | +## 1. Prerequisites |
| 8 | + |
| 9 | +For this guide, there are two ways to install the tool: |
| 10 | + |
| 11 | +!!! cube "Normal installation" |
| 12 | + - You will need to install the following packages: |
| 13 | + |
| 14 | + - `git` |
| 15 | + - `cloc` |
| 16 | + - Java Development Kit (17) |
| 17 | + - `maven` |
| 18 | + |
| 19 | + - And the following SAST tools: |
| 20 | + |
| 21 | + - [Bearer](/sast/supported/bearer.j2.html){:target="_blank"} |
| 22 | + - [Semgrep Community Edition](/sast/supported/semgrepce.j2.html){:target="_blank"} |
| 23 | + - [SpotBugs](/sast/supported/spotbugs.j2.html){:target="_blank"} |
| 24 | + |
| 25 | +!!! docker "Docker image" |
| 26 | + A Docker image used to run tests is available with the prerequisites installed. |
| 27 | + You can use it to test CodeSecTools without installing extra packages on your system. |
| 28 | + |
| 29 | + ⚠️ However, this container is intended for running tests, not for normal usage. |
| 30 | + Therefore, any data and results inside the container will be deleted when you exit. |
| 31 | + |
| 32 | + Please perform a normal installation if you want to keep your results. |
| 33 | + |
| 34 | + |
| 35 | +## 2. Installation |
| 36 | + |
| 37 | +!!! cube "Normal installation" |
| 38 | + |
| 39 | + - Clone the repository: |
| 40 | + ```bash |
| 41 | + git clone https://github.com/OPPIDA/CodeSecTools.git |
| 42 | + cd CodeSecTools |
| 43 | + ``` |
| 44 | + |
| 45 | + - Install the project: |
| 46 | + |
| 47 | + - Using [uv](https://github.com/astral-sh/uv): |
| 48 | + ```bash |
| 49 | + uv tool install . |
| 50 | + ``` |
| 51 | + |
| 52 | + - Using [pipx](https://github.com/pypa/pipx): |
| 53 | + ```bash |
| 54 | + pipx install . |
| 55 | + ``` |
| 56 | + |
| 57 | + - Using pip (not recommended, as it can break your system packages): |
| 58 | + ```bash |
| 59 | + pip install . |
| 60 | + ``` |
| 61 | + |
| 62 | +!!! docker "Docker image" |
| 63 | + To start the Docker container, run the command: |
| 64 | + ```bash |
| 65 | + make test-debug |
| 66 | + ``` |
| 67 | + |
| 68 | + ⚠️ The container will be deleted when you exit. |
| 69 | + |
| 70 | + |
| 71 | +## 3. First run |
| 72 | + |
| 73 | +!!! abstract "Install completion (optional)" |
| 74 | + ```bash |
| 75 | + cstools --install-completion |
| 76 | + # For bash |
| 77 | + source ~/.bash_completions/cstools.sh |
| 78 | + ``` |
| 79 | + |
| 80 | +!!! abstract "Download external resources" |
| 81 | + This command downloads datasets, rules, and plugins required for the SAST tools. |
| 82 | + |
| 83 | + For each external resource, you will be prompted with resource information and, most importantly, its license/term. |
| 84 | + ```bash |
| 85 | + cstools download all |
| 86 | + ``` |
| 87 | + |
| 88 | +!!! abstract "Check the integration status" |
| 89 | + This command allows you to check if a SAST tool or dataset is available. |
| 90 | + |
| 91 | + If not, it will specify what is missing. |
| 92 | + ```bash |
| 93 | + cstools status |
| 94 | + ``` |
| 95 | + |
| 96 | + For this guide, the status for Bearer, SemgrepCE, and SpotBugs should be `Full ✅`. |
| 97 | + |
| 98 | +## 4. Common Use Cases |
| 99 | + |
| 100 | +### Analysis with multiple SAST tools |
| 101 | + |
| 102 | +One important feature of CodeSecTools is the ability to run **multiple** SAST tools in order to: |
| 103 | + |
| 104 | +- **aggregate** all the results to take advantage of each SAST tool's strengths (detecting specific vulnerabilities); |
| 105 | +- **cross-verify** results and increase the confidence that a finding is a true positive. |
| 106 | + |
| 107 | +Here are some analyses running CodeSecTools on vulnerable projects: |
| 108 | + |
| 109 | +??? scan "cyclonedx-core-java (CVE-2025-64518)" |
| 110 | + *Vulnerability details are from [Github Advisory](https://github.com/advisories/GHSA-6fhj-vr9j-g45r).* |
| 111 | + |
| 112 | + - Weakness: [CWE-611](https://cwe.mitre.org/data/definitions/611.html) (Improper Restriction of XML External Entity Reference). |
| 113 | + - Introduced in commit [162aa59](https://github.com/CycloneDX/cyclonedx-core-java/commit/162aa594f347b3f612fe0a45071693c3cd398ce9#diff-fc28290f55c35403fc95b45ee2714337621f54b48caba5e01f08d5760b54139a). |
| 114 | + - Patched in pull request [#737](https://github.com/CycloneDX/cyclonedx-core-java/pull/737/files#diff-fc28290f55c35403fc95b45ee2714337621f54b48caba5e01f08d5760b54139a). |
| 115 | + - Vulnerable file: [`src/main/java/org/cyclonedx/CycloneDxSchema.java`](https://github.com/CycloneDX/cyclonedx-core-java/commit/162aa594f347b3f612fe0a45071693c3cd398ce9#diff-fc28290f55c35403fc95b45ee2714337621f54b48caba5e01f08d5760b54139a). |
| 116 | + |
| 117 | + Download the vulnerable version of the project: |
| 118 | + ```bash |
| 119 | + git clone https://github.com/CycloneDX/cyclonedx-core-java |
| 120 | + cd cyclonedx-core-java |
| 121 | + git checkout 162aa59 |
| 122 | + ``` |
| 123 | + |
| 124 | + Compile the project to generate Java bytecode for SAST tools that require it: |
| 125 | + ```bash |
| 126 | + mvn clean compile |
| 127 | + ``` |
| 128 | + |
| 129 | + Run analysis with all SAST tools: |
| 130 | + ```bash |
| 131 | + cstools allsast analyze java --artifacts target/classes/ |
| 132 | + ``` |
| 133 | + |
| 134 | + Generate figures and report: |
| 135 | + ```bash |
| 136 | + cstools allsast plot cyclonedx-core-java |
| 137 | + cstools allsast report cyclonedx-core-java |
| 138 | + ``` |
| 139 | + |
| 140 | + Open the project report (`~/.codesectools/output/AllSAST/cyclonedx-core-java/report/home.html`). |
| 141 | + |
| 142 | + The report of the vulnerable file is shown here: |
| 143 | + |
| 144 | + <iframe width="100%" height="500" style="zoom: 0.5;" src="quick_start_guide/cyclonedx-core-java/report.html"></iframe> |
| 145 | + |
| 146 | + Some issues have been found by the tools in the vulnerable file, and the file is ranked high (high score) overall among all other files where issues were found. |
| 147 | + |
| 148 | + SpotBugs is the only tool that detected issues and correctly identified the vulnerability (exact CWE ID). |
| 149 | + |
| 150 | +??? scan "conductor (CVE-2025-26074)" |
| 151 | + *Vulnerability details are from [Github Advisory](https://github.com/advisories/GHSA-8gqp-hr9g-pg62).* |
| 152 | + |
| 153 | + - Weakness: [CWE-78](https://cwe.mitre.org/data/definitions/78.html) (Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')). |
| 154 | + - Patched in commit [e981650](https://github.com/conductor-oss/conductor/commit/e9816501df1e364a3d39d7fe37d6e167c40eaa1b). |
| 155 | + - Vulnerable file: [`core/src/main/java/com/netflix/conductor/core/events/ScriptEvaluator.java`](https://github.com/conductor-oss/conductor/blob/main/core/src/main/java/com/netflix/conductor/core/events/ScriptEvaluator.java). |
| 156 | + - *Note: the patch did not modify the vulnerable file but other files, which attenuated the vulnerability.* |
| 157 | + |
| 158 | + Download the vulnerable version of the project: |
| 159 | + ```bash |
| 160 | + git clone https://github.com/conductor-oss/conductor |
| 161 | + cd conductor |
| 162 | + git checkout 5976cad |
| 163 | + ``` |
| 164 | + |
| 165 | + Compile the project to generate Java bytecode for SAST tools that require it: |
| 166 | + ```bash |
| 167 | + ./gradlew compileJava |
| 168 | + ``` |
| 169 | + |
| 170 | + Run analysis with all SAST tools: |
| 171 | + ```bash |
| 172 | + cstools allsast analyze java --artifacts . |
| 173 | + ``` |
| 174 | + |
| 175 | + Generate figures and report: |
| 176 | + ```bash |
| 177 | + cstools allsast plot conductor |
| 178 | + cstools allsast report conductor |
| 179 | + ``` |
| 180 | + |
| 181 | + Open the project report (`~/.codesectools/output/AllSAST/conductor/report/home.html`). |
| 182 | + |
| 183 | + The report of the vulnerable file is shown here: |
| 184 | + |
| 185 | + <iframe width="100%" height="500" style="zoom: 0.5;" src="quick_start_guide/conductor/report.html"></iframe> |
| 186 | + |
| 187 | + Only one issue has been found by the tools in the vulnerable file, and the file is ranked low (low score) overall among all other files where issues were found. |
| 188 | + |
| 189 | + SemgrepCE is the only tool that detected issues and partially identified the vulnerability. |
| 190 | + It has detected a `code injection` that could leads to an `OS command injection`. |
| 191 | + |
| 192 | + *Note: If we did not know that a vulnerability existed, we would have had to verify it (by attempting to exploit it) because the `eval` function is a feature.* |
| 193 | + |
| 194 | +### Benchmarking SAST tool |
| 195 | + |
| 196 | +It is possible to benchmark any SAST tool on any dataset that are integrated to CodeSecTools thanks to the prior integration: |
| 197 | + |
| 198 | +```bash |
| 199 | +cstools spotbugs benchmark BenchmarkJava_java |
| 200 | +``` |
| 201 | + |
| 202 | +If the SAST tool requires artifacts, the expected artifacts and build command are provided: |
| 203 | + |
| 204 | +```bash |
| 205 | +cstools spotbugs benchmark BenchmarkJava_java |
| 206 | +╭──────────────────────── SpotBugs - PrebuiltSAST ────────────────────────╮ |
| 207 | +│ │ |
| 208 | +│ Please build BenchmarkJava before running the benchmark │ |
| 209 | +│ Build command: mvn clean compile │ |
| 210 | +│ Full command: (cd │ |
| 211 | +│ /home/michel/.codesectools/cache/BenchmarkJava && mvn clean compile) │ |
| 212 | +│ Expected arteficts: │ |
| 213 | +│ /home/michel/.codesectools/cache/BenchmarkJava/target/classes/org/owasp │ |
| 214 | +│ /benchmark/testcode/*.class │ |
| 215 | +╰─────────────────────────────────────────────────────────────────────────╯ |
| 216 | +``` |
| 217 | + |
| 218 | +Then generating figures using the analysis output: |
| 219 | + |
| 220 | +```bash |
| 221 | +cstools spotbugs plot BenchmarkJava_java --overwrite |
| 222 | +Figure overview saved at /home/michel/.codesectools/output/SpotBugs/BenchmarkJava_java/_figures/overview.png |
| 223 | +Figure top_cwes saved at /home/michel/.codesectools/output/SpotBugs/BenchmarkJava_java/_figures/top_cwes.png |
| 224 | +``` |
| 225 | + |
| 226 | +Figures: |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
0 commit comments