Skip to content

Conversation

JerryTasi
Copy link
Collaborator

@JerryTasi JerryTasi commented Dec 13, 2024

Detect CWE-921 in Android Application

This scenario seeks to find the unsecured storage mechanism of sensitive data in the APK file.

CWE-921: Storage of Sensitive Data in a Mechanism without Access Control

We analyze the definition of CWE-921 and identify its characteristics.

See CWE-921 for more details.

image

Code of CWE-921 in ovaa.apk

We use the ovaa.apk sample to explain the vulnerability code of CWE-921.

image

CWE-921 Detection Process Using Quark Script API

image

Let’s use the above APIs to show how the Quark script finds this vulnerability.

First, we design a detection rule checkFileExistence.json to spot on behavior that checks if a file exists on a given storage mechanism. Then, we use API methodInstance.getArguments() to get the file path. Finally, CWE-921 is found if the file path contains the keyword sdcard.

Quark Script: CWE-921.py

image

from quark.script import runQuarkAnalysis, Rule

SAMPLE_PATH = "ovaa.apk"
RULE_PATH = "checkFileExistence.json"

ruleInstance = Rule(RULE_PATH)
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)

for existingFile in quarkResult.behaviorOccurList:
    filePath = existingFile.secondAPI.getArguments()[0]
    if "sdcard" in filePath:
        print(f"This file is stored inside the SDcard\n")
        print(f"CWE-921 is detected in {SAMPLE_PATH}.")

Quark Rule: checkFileExistence.json

image

{
    "crime": "Check file existence",
    "permission": [],
    "api": [
        {
            "descriptor": "(Ljava/lang/String;)V",
            "class": "Ljava/io/File;",
            "method": "<init>"
        },
        {
            "descriptor": "()Z",
            "class": "Ljava/io/File;",
            "method": "exists"
        }
    ],
    "score": 1,
    "label": []
}

Quark Script Result

$ python3 CWE-921.py
This file is stored inside the SDcard

CWE-921 is detected in ovaa.apk.

Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.22%. Comparing base (e36feec) to head (f25b284).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #723   +/-   ##
=======================================
  Coverage   79.22%   79.22%           
=======================================
  Files          73       73           
  Lines        5732     5732           
=======================================
  Hits         4541     4541           
  Misses       1191     1191           
Flag Coverage Δ
unittests 79.22% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@haeter525 haeter525 self-requested a review December 17, 2024 05:02
@haeter525 haeter525 self-assigned this Dec 17, 2024
@haeter525 haeter525 added pr-processing-state-05 documentation Improvements or additions to documentation labels Dec 17, 2024
Copy link
Member

@haeter525 haeter525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@haeter525 haeter525 merged commit d9ad85e into quark-engine:master Dec 18, 2024
19 checks passed
@JerryTasi JerryTasi deleted the patch-1 branch January 9, 2025 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation pr-processing-state-05
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants