Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MASWE-0076 - Dependencies with Known Vulnerabilities (SBOM) #2912

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Ljava",
"loadbalancer",
"mainactivity",
"MASTG",
"MASVS",
"MITM",
"MSTG",
Expand Down
27 changes: 27 additions & 0 deletions demos/android/MASVS-CODE/MASTG-DEMO-0021/MASTG-DEMO-0021.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
platform: android
title: Identifying Insecure Dependencies in Android Studio
id: MASTG-DEMO-0021
code: [java]
test: MASTG-TEST-0216
---

### Sample

{{ build.gradle.kts # build.gradle.kts }}

### Steps

Execute `gradle` in Android Studio to trigger @MASTG-TOOL-0116.

{{ run.sh }}

### Observation

The scan has identified 262 unique dependencies with 35 vulnerable dependencies and 83 vulnerabilities (as more vulnerabilities might be found over time this number might increase).

{{ output.txt }}

### Evaluation

Due to the number of vulnerabilities, the `dependency-check` report can be lengthy and can contain false positives. Review each of the reported instances. The dependency `okhttp-4.8.0.jar` added in the `build.gradle.kts` has known vulnerabilities and should be updated to the latest version.
84 changes: 84 additions & 0 deletions demos/android/MASVS-CODE/MASTG-DEMO-0021/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.owasp.dependencycheck") version "10.0.4" // dependencyCheck Plugin
}

// dependencyCheck Configuration
dependencyCheck {

formats = listOf("HTML", "XML", "JSON") // Generate reports in HTML, JSON and XML format
nvd {
apiKey = "<YOUR-API-KEY>" // Set the NVD API key
delay = 16000
}

}

android {
namespace = "org.owasp.mastestapp"
compileSdk = 34

defaultConfig {
applicationId = "org.owasp.mastestapp"
minSdk = 29
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2024.04.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2024.04.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.10")
implementation ("com.squareup.okhttp3:okhttp:4.8.0") // vulnerable library

}
87 changes: 87 additions & 0 deletions demos/android/MASVS-CODE/MASTG-DEMO-0021/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
...
[redacted for readability]
...
{
"isVirtual": false,
"fileName": "okhttp-4.8.0.jar",
"filePath": "\/Users\/sushi2k\/.gradle\/caches\/modules-2\/files-2.1\/com.squareup.okhttp3\/okhttp\/4.8.0\/5c34a8c35bb3fd5ec39d3a67ceae691d0f3eb455\/okhttp-4.8.0.jar",
"md5": "5132d18a9ed0b5eb9a6137885959bcb5",
"sha1": "5c34a8c35bb3fd5ec39d3a67ceae691d0f3eb455",
"sha256": "04d68254c5216d059504d97e2cf2f8ba7922453059701a5adc65652809dd1599",
...
[redacted for readability]
...
"packages": [
{
"id": "pkg:maven\/com.squareup.okhttp3\/[email protected]",
"confidence": "HIGHEST",
"url": "https:\/\/ossindex.sonatype.org\/component\/pkg:maven\/com.squareup.okhttp3\/[email protected]?utm_source=dependency-check&utm_medium=integration&utm_content=10.0.4"
}
],
"vulnerabilityIds": [
{
"id": "cpe:2.3:a:squareup:okhttp:4.8.0:*:*:*:*:*:*:*",
"confidence": "LOW"
},
{
"id": "cpe:2.3:a:squareup:okhttp3:4.8.0:*:*:*:*:*:*:*",
"confidence": "LOW"
}
],
"vulnerabilities": [
{
"source": "OSSINDEX",
"name": "CVE-2021-0341",
"severity": "HIGH",
"cvssv3": {
"baseScore": 7.5,
"attackVector": "NETWORK",
"attackComplexity": "LOW",
"privilegesRequired": "NONE",
"userInteraction": "NONE",
"scope": "UNCHANGED",
"confidentialityImpact": "HIGH",
"integrityImpact": "NONE",
"availabilityImpact": "NONE",
"baseSeverity": "HIGH",
"version": "3.1"
},
"cwes": [
"CWE-295"
],
"description": "In verifyHostName of OkHostnameVerifier.java, there is a possible way to accept a certificate for the wrong domain due to improperly used crypto. This could lead to remote information disclosure with no additional execution privileges needed. User interaction is not needed for exploitation.Product: AndroidVersions: Android-8.1 Android-9 Android-10 Android-11Android ID: A-171980069",
"notes": "",
"references": [
{
"source": "OSSINDEX",
"url": "https:\/\/ossindex.sonatype.org\/vulnerability\/CVE-2021-0341?component-type=maven&component-name=com.squareup.okhttp3%2Fokhttp&utm_source=dependency-check&utm_medium=integration&utm_content=10.0.4",
"name": "[CVE-2021-0341] CWE-295: Improper Certificate Validation"
},
{
"source": "OSSIndex",
"url": "https:\/\/source.android.com\/security\/bulletin\/2021-02-01#android-runtime",
"name": "https:\/\/source.android.com\/security\/bulletin\/2021-02-01#android-runtime"
},
{
"source": "OSSIndex",
"url": "http:\/\/web.nvd.nist.gov\/view\/vuln\/detail?vulnId=CVE-2021-0341",
"name": "http:\/\/web.nvd.nist.gov\/view\/vuln\/detail?vulnId=CVE-2021-0341"
},
{
"source": "OSSIndex",
"url": "https:\/\/github.com\/square\/okhttp\/pull\/6353",
"name": "https:\/\/github.com\/square\/okhttp\/pull\/6353"
}
],
"vulnerableSoftware": [
{
"software": {
"id": "cpe:2.3:a:com.squareup.okhttp3:okhttp:4.8.0:*:*:*:*:*:*:*",
"vulnerabilityIdMatched": "true"
}
}
]
},
...
[redacted for readability]
...
1 change: 1 addition & 0 deletions demos/android/MASVS-CODE/MASTG-DEMO-0021/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./gradlew dependencyCheckAnalyze
24 changes: 24 additions & 0 deletions demos/android/MASVS-CODE/MASTG-DEMO-0022/MASTG-DEMO-022.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
platform: android
title: Identifying Insecure Dependencies through SBOM creation
id: MASTG-DEMO-0022
test: MASTG-TEST-0216
---

### Steps

Execute `cdxgen` in the root directory of the Android Studio project.

{{ run.sh }}

This will create a SBOM file that can be uploaded to @MASTG-TOOL-0117 by following @MASTG-TECH-0122.

### Observation

In the project of @MASTG-TOOL-0117, where the SBOM has been uploaded, the scan should have identified over 200 unique dependencies (components) with 7 vulnerable dependencies and 7 vulnerabilities (as more vulnerabilities might be found over time this number might increase).

{{ output.txt }}

### Evaluation

Review each of the reported instances. The dependency `okhttp` has 2 known vulnerabilities and `okio` has 1 known vulnerability and they should all be updated to the latest version.
1 change: 1 addition & 0 deletions demos/android/MASVS-CODE/MASTG-DEMO-0022/output.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions demos/android/MASVS-CODE/MASTG-DEMO-0022/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cdxgen -t java -o sbom.json
27 changes: 27 additions & 0 deletions demos/ios/MASVS-CODE/MASTG-DEMO-0020/MASTG-DEMO-0020.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
platform: ios
title: Scanning Package Manager Artifacts for Insecure iOS Dependencies
id: MASTG-DEMO-0020
code: [java]
test: MASTG-TEST-0215
---

### Sample

{{ Package.resolved # Package.resolved }}

### Steps

Let's run @MASTG-TOOL-0116 in the root directory of the Xcode project.

{{ run.sh }}

### Observation

The SARIF file can be opened by using @MASTG-TOOL-0118 for analyzing the identified vulnerabilities.

{{ output.txt }}

### Evaluation

Review each of the reported instances, as it can contain false positives. The library `swift-nio` has at least 2 known vulnerabilities as part of Swift with CVE-2022-3918 and CVE-2022-1642 and should be updated to the latest version.
15 changes: 15 additions & 0 deletions demos/ios/MASVS-CODE/MASTG-DEMO-0020/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"originHash" : "b68c973e78e301de37753c919a62c1dda9a70e82a8dbd432336372a4edf9b951",
"pins" : [
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "6aa9347d9bc5bbfe6a84983aec955c17ffea96ef",
"version" : "2.33.0"
}
}
],
"version" : 3
}
63 changes: 63 additions & 0 deletions demos/ios/MASVS-CODE/MASTG-DEMO-0020/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "dependency-check",
"version": "10.0.4",
"informationUri": "https://jeremylong.github.io/DependencyCheck/",
"rules": [
{
"id": "CVE-2020-9861",
"shortDescription": {
"text": "high severity - CVE-2020-9861 Uncontrolled Recursion vulnerability in pkg:swift\/[email protected]"
},
"fullDescription": {
"text": "A stack overflow issue existed in Swift for Linux. The issue was addressed with improved input validation for dealing with deeply nested malicious JSON input."
},
"help": {
"text": "",
"markdown": "For more information see [CVE-2020-9861](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-9861).\n\n\nIf this is a false positive - consider using the HTML report to generate a suppression file. For more information see [How dependency-check works](https://jeremylong.github.io/DependencyCheck/general/internals.html), [How to read the HTML report](https://jeremylong.github.io/DependencyCheck/general/thereport.html), and [Suppressing false positives](https://jeremylong.github.io/DependencyCheck/general/suppression.html)."
},
"properties": {
"cvssv2_score": 5.0,
"cvssv2_accessVector": "NETWORK",
"cvssv2_accessComplexity": "LOW",
"cvssv2_authenticationr": "NONE",
"cvssv2_confidentialityImpact": "NONE",
"cvssv2_integrityImpact": "NONE",
"cvssv2_availabilityImpact": "PARTIAL",
"cvssv2_severity": "MEDIUM",
"cvssv3_baseScore": 7.5,
"security-severity": "7.5",
"cvssv3_attackVector": "NETWORK",
"cvssv3_attackComplexity": "LOW",
"cvssv3_privilegesRequired": "NONE",
"cvssv3_userInteraction": "NONE",
"cvssv3_scope": "UNCHANGED",
"cvssv3_confidentialityImpact": "NONE",
"cvssv3_integrityImpact": "NONE",
"cvssv3_availabilityImpact": "HIGH",
"cvssv3_baseSeverity": "HIGH",
"cvssv3_exploitabilityScore": "3.9",
"cvssv3_impactScore": "3.6",
"cvssv3_version": "_3_1",
"source": "NVD"
}
},
{
"id": "CVE-2022-1642",
"shortDescription": {
"text": "high severity - CVE-2022-1642 Incorrect Type Conversion or Cast vulnerability in pkg:swift\/[email protected]"
},
"fullDescription": {
"text": "A program using swift-corelibs-foundation is vulnerable to a denial of service attack caused by a potentially malicious source producing a JSON document containing a type mismatch. This vulnerability is caused by the interaction between a deserialization mechanism offered by the Swift standard library, the Codable protocol; and the JSONDecoder class offered by swift-corelibs-foundation, which can deserialize types that adopt the Codable protocol based on the content of a provided JSON document. When a type that adopts Codable requests the initialization of a field with an integer value, the JSONDecoder class uses a type-erased container with different accessor methods to attempt and coerce a corresponding JSON value and produce an integer. In the case the JSON value was a numeric literal with a floating-point portion, JSONDecoder used different type-eraser methods during validation than it did during the final casting of the value. The checked casting produces a deterministic crash due to this mismatch. The JSONDecoder class is often wrapped by popular Swift-based web frameworks to parse the body of HTTP requests and perform basic type validation. This makes the attack low-effort: sending a specifically crafted JSON document during a request to these endpoints will cause them to crash. The attack does not have any confidentiality or integrity risks in and of itself; the crash is produced deterministically by an abort function that ensures that execution does not continue in the face of this violation of assumptions. However, unexpected crashes can lead to violations of invariants in services, so it's possible that this attack can be used to trigger error conditions that escalate the risk. Producing a denial of service may also be the goal of an attacker in itself. This issue is solved in Swift 5.6.2 for Linux and Windows. This issue was solved by ensuring that the same methods are invoked both when validating and during casting, so that no type mismatch occurs. Swift for Linux and Windows versions are not ABI-interchangeable. To upgrade a service, its owner must update to this version of the Swift toolchain, then recompile and redeploy their software. The new version of Swift includes an updated swift-corelibs-foundation package. Versions of Swift running on Darwin-based operating systems are not affected."
},
"help": {
"text": "",
"markdown": "For more information see [CVE-2022-1642](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2022-1642).\n\n\nIf this is a false positive - consider using the HTML report to generate a suppression file. For more information see [How dependency-check works](https://jeremylong.github.io/DependencyCheck/general/internals.html), [How to read the HTML report](https://jeremylong.github.io/DependencyCheck/general/thereport.html), and [Suppressing false positives](https://jeremylong.github.io/DependencyCheck/general/suppression.html)."

}
...[REDACTED]...
2 changes: 2 additions & 0 deletions demos/ios/MASVS-CODE/MASTG-DEMO-0020/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$NVD_API_KEY="YOUR_NVD_API"
dependency-check --enableExperimental -f SARIF --nvdApiKey $NVD_API_KEY -s Package.resolved
24 changes: 24 additions & 0 deletions demos/ios/MASVS-CODE/MASTG-DEMO-0023/MASTG-DEMO-0023.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
platform: ios
title: Identifying Insecure Dependencies in SwiftPM through SBOM creation
id: MASTG-DEMO-0023
test: MASTG-TEST-0215
---

### Steps

Execute @MASTG-TOOL-0119 in the root directory of the Xcode project.

{{ run.sh }}

This will create a SBOM file that can be uploaded to @MASTG-TOOL-0117 by following @MASTG-TECH-0123.

### Observation

In the project of @MASTG-TOOL-0117, where the SBOM has been uploaded, the scan should have identified 2 unique dependencies (components) with 2 vulnerable dependencies and 2 vulnerabilities (as more vulnerabilities might be found over time this number might increase).

{{ output.txt }}

### Evaluation

Review each of the reported instances. The dependency `swift-nio` has 2 known vulnerabilities and should be updated to the latest version.
Loading