-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add Tests and Demos about "Sensitive Data Stored Unencrypted via SQLite" #3534
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
Open
macik09
wants to merge
11
commits into
OWASP:master
Choose a base branch
from
macik09:MASWE-0006-DEMOS
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6bc899e
Add MASTG-DEMO-0065 for MASWE-0006 (Unencrypted SQLite storage)
macik09 dbc2643
Merge branch 'master' into MASWE-0006-DEMOS
cpholguera 640c3f2
Apply suggestions from code review
macik09 2e1c845
Update demos/android/MASVS-STORAGE/MASTG-DEMO-0068/run.sh
macik09 326e445
Merge branch 'master' into MASWE-0006-DEMOS
cpholguera d9fc682
Merge branch 'master' into MASWE-0006-DEMOS
cpholguera 5dd5634
Update tests-beta/android/MASVS-STORAGE/MASTG-TEST-0304.md
macik09 f413d42
Add MASTG-BEST-0025.md
macik09 4a53c5e
Split tests static/dynamic
macik09 de2f3e2
profile update
macik09 6cd521d
type fixed
macik09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 27 additions & 3 deletions
30
demos/android/MASVS-STORAGE/MASTG-DEMO-0068/MASTG-DEMO-0068.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,33 @@ | ||
| --- | ||
| platform: android | ||
| title: Reserved for MASWE-0006 - Unencrypted SQLite Storage (Alternative Demo) | ||
| title: Sensitive Data in Unencrypted SQLite | ||
| id: MASTG-DEMO-0068 | ||
| code: [kotlin] | ||
| test: MASTG-TEST-0304 | ||
|
macik09 marked this conversation as resolved.
|
||
| status: placeholder | ||
| note: This placeholder reserves the ID for a potential alternative or expanded demo related to unencrypted SQLite storage, linked to the MASTG-TEST-0304 test case. | ||
| status: new | ||
| --- | ||
|
|
||
| ### Sample | ||
|
|
||
| The snippet below shows sample code that uses the default SQLite API (`context.openOrCreateDatabase`) to store sensitive data, including PII and an access token, without any encryption. | ||
|
|
||
| {{ MastgTest.kt }} | ||
|
|
||
| ### Steps | ||
|
|
||
| 1. Install the application on a test device. | ||
| 2. Open the app and exercise it to trigger the database creation and data insertion. | ||
| 3. Execute the analysis script **`run.sh`**. | ||
| 4. The script pulls the database file (`PrivateUnencryptedData.db`) and queries its content. | ||
|
macik09 marked this conversation as resolved.
Outdated
|
||
|
|
||
| {{ run.sh }} | ||
|
|
||
| ### Observation | ||
|
|
||
| The `output.txt` file contains the extracted content from the `Users` table, showing the sensitive PII (email address) and the access token stored in **plaintext**. | ||
|
macik09 marked this conversation as resolved.
Outdated
|
||
|
|
||
| {{ output.txt }} | ||
|
|
||
| ### Evaluation | ||
|
|
||
| This test fails because the application stores highly sensitive data (Access Token and PII like the user's email address) using the standard SQLite API. By default, SQLite stores data in an unencrypted file within the app's private sandbox, violating the **MASVS-STORAGE** requirement (MASWE-0006). This data is trivially accessible if an attacker achieves privileged access to the device (e.g., via root). | ||
|
macik09 marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package org.owasp.mastestapp | ||
|
|
||
| import android.content.Context | ||
| import android.database.sqlite.SQLiteDatabase | ||
| import android.util.Log | ||
|
|
||
| class MastgTest (private val context: Context){ | ||
|
|
||
|
|
||
| fun writeSensitiveDataToUnencryptedSQLite() { | ||
| val username = "demoUser_sqlite" | ||
| val userEmail = "john.doe@maswe-0006.com" | ||
| val accessToken = "MASTG_ACCESS_TOKEN_B4C8D2F0E7A" | ||
|
macik09 marked this conversation as resolved.
Outdated
|
||
| val dbName = "PrivateUnencryptedData" | ||
|
|
||
| try { | ||
| val db: SQLiteDatabase = context.openOrCreateDatabase( | ||
| dbName, | ||
| Context.MODE_PRIVATE, | ||
| null | ||
| ) | ||
|
|
||
| db.execSQL("CREATE TABLE IF NOT EXISTS Users(Username VARCHAR, Email VARCHAR, Token VARCHAR);") | ||
|
|
||
|
|
||
| db.execSQL("DELETE FROM Users;") | ||
|
|
||
| db.execSQL("INSERT INTO Users VALUES('$username', '$userEmail', '$accessToken');") | ||
|
|
||
| db.close() | ||
| Log.i("MASTG-SQLITE", "Data written to unencrypted database: $dbName. Ready for ADB extraction.") | ||
|
|
||
| } catch (e: Exception) { | ||
| Log.e("MASTG-SQLITE", "Error writing data to SQLite: ${e.message}") | ||
| } | ||
| } | ||
|
|
||
| fun mastgTest(): String { | ||
| writeSensitiveDataToUnencryptedSQLite() | ||
| return "SQLite Demo Complete. Database 'PrivateUnencryptedData' created with PII and Token." | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
demos/android/MASVS-STORAGE/MASTG-DEMO-0068/MastgTest_reversed.java
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Java file does not seem to be the Java file resulting from decompiling the DEMO app. As commented previously, follow the DEMO guidelines (https://mas.owasp.org/contributing/writing-content/mastg-demo.instructions/) to provide these files accordingly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.owasp.mastestapp; | ||
|
|
||
| import android.content.Context; | ||
| import android.util.Log; | ||
| import kotlin.Metadata; | ||
| import kotlin.jvm.internal.Intrinsics; | ||
|
|
||
| /* compiled from: MastgTest.kt */ | ||
| @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\b\u0007\u0018\u00002\u00020\u0001B\u000f\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0004\b\u0004\u0010\u0005J\u0006\u0010\u0006\u001a\u00020\u0007R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\b"}, d2 = {"Lorg/owasp/mastestapp/MastgTest;", "", "context", "Landroid/content/Context;", "<init>", "(Landroid/content/Context;)V", "mastgTest", "", "app_debug"}, k = 1, mv = {2, 0, 0}, xi = 48) | ||
| /* loaded from: classes3.dex */ | ||
| public final class MastgTest { | ||
| public static final int $stable = 8; | ||
| private final Context context; | ||
|
|
||
| public MastgTest(Context context) { | ||
| Intrinsics.checkNotNullParameter(context, "context"); | ||
| this.context = context; | ||
| } | ||
|
|
||
| public final String mastgTest() throws Exception { | ||
| DemoResults r = new DemoResults("0000"); | ||
| try { | ||
| Log.d("MASTG-TEST", "Hello from the OWASP MASTG Test app."); | ||
| r.add(Status.PASS, "The app implemented a demo which passed the test with the following value: 'Hello from the OWASP MASTG Test app.'"); | ||
| r.add(Status.FAIL, "The app implemented a demo which failed the test."); | ||
| throw new Exception("Example exception: Method not implemented."); | ||
| } catch (Exception e) { | ||
| r.add(Status.ERROR, e.toString()); | ||
| return r.toJson(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- Users Table Content --- | ||
| demoUser_sqlite|john.doe@maswe-0006.com|MASTG_ACCESS_TOKEN_B4C8D2F0E7A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
macik09 marked this conversation as resolved.
|
||
|
|
||
| PACKAGE="org.owasp.mastestapp" | ||
| DB_NAME="PrivateUnencryptedData" | ||
| DB_PATH="/data/data/$PACKAGE/databases/$DB_NAME" | ||
| SDCARD_PULL_PATH="/sdcard/$DB_NAME.db" | ||
| OUTPUT_DB_FILE="${DB_NAME}.db" | ||
| OUTPUT_TXT_FILE="output.txt" | ||
|
|
||
| # Step 1: Database Extraction | ||
| adb shell "run-as $PACKAGE cp databases/$DB_NAME $SDCARD_PULL_PATH" 2>/dev/null | ||
|
|
||
| # Attempt to copy via root access using here document | ||
| adb shell <<EOF | ||
| su | ||
| cp $DB_PATH $SDCARD_PULL_PATH | ||
| exit | ||
| EOF | ||
|
macik09 marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Pull the file to the host machine | ||
| adb pull "$SDCARD_PULL_PATH" . | ||
|
|
||
| echo "--- Users Table Content ---" > $OUTPUT_TXT_FILE | ||
| sqlite3 "$OUTPUT_DB_FILE" "SELECT * FROM Users;" >> $OUTPUT_TXT_FILE | ||
|
|
||
| adb shell "rm $SDCARD_PULL_PATH" 2>/dev/null | ||
| rm $OUTPUT_DB_FILE 2>/dev/null | ||
|
macik09 marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DEMO must follow the content guidelines (https://mas.owasp.org/contributing/writing-content/mastg-demo.instructions).
For example, the "Evaluation" section should explain each relevant line of the output that is used as an evidence to give a FAIL to the test.