Skip to content

Update document for Quark Script CWE-749#383

Merged
haeter525 merged 5 commits into
ev-flow:masterfrom
haeter525:feat/update_doc_for_quark_script_APIs_to_detect_CWE-749
Sep 20, 2022
Merged

Update document for Quark Script CWE-749#383
haeter525 merged 5 commits into
ev-flow:masterfrom
haeter525:feat/update_doc_for_quark_script_APIs_to_detect_CWE-749

Conversation

@haeter525

Copy link
Copy Markdown
Member

CWE-749 Documentaion

API Spec

methodInstance.getArguments(none)

  • Description: Get arguments from method.
  • params: None
  • return: python list containing arguments

Detect CWE-749 in Android Application (MSTG-Android-Java.apk)

This scenario seeks to find exposed methods or functions in the APK file. See CWE-749 for more details.

Let's use this APK and the above APIs to show how Quark script find this vulnerability.

First, we design a detection rule configureJsExecution.json to spot on behavior using method setJavascriptEnabled. Then, we use API methodInstance.getArguments to check if it enables JavaScript execution on websites. Finally, we look for calls to method addJavaScriptInterface in the caller method. If yes, the APK exposes methods or functions to websites. That causes CWE-749 vulnerability.

Quark Script CWE-749.py

from quark.script import runQuarkAnalysis, Rule

SAMPLE_PATH = "MSTG-Android-Java.apk"
RULE_PATH = "configureJsExecution.json"

targetMethod = [
    "Landroid/webkit/WebView;",
    "addJavascriptInterface",
    "(Ljava/lang/Object; Ljava/lang/String;)V"
]

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

for configureJsExecution in quarkResult.behaviorOccurList:

    caller = configureJsExecution.methodCaller
    secondAPI = configureJsExecution.secondAPI

    enableJS = secondAPI.getArguments()[1]
    exposeAPI = quarkResult.findMethodInCaller(caller, targetMethod)

    if enableJS and exposeAPI:
        print(f"CWE-749 is detected in method, {caller.fullName}"

configureJsExecution.json

{
    "crime": "Configure JavaScript execution on websites",
    "permission": [],
    "api": [
        {
            "class": "Landroid/webkit/WebView;",
            "method": "getSettings",
            "descriptor": "()Landroid/webkit/WebSettings;"
        },
        {
            "class": "Landroid/webkit/WebSettings;",
            "method": "setJavaScriptEnabled",
            "descriptor": "(Z)V"
        }
    ],
    "score": 1,
    "label": []
}

Quark Script Result

$ python3 CWE-749.py
CWE-749 is detected in method, Lsg/vp/owasp_mobile/OMTG_Android/OMTG_ENV_005_WebView_Remote; onCreate (Landroid/os/Bundle;)V
CWE-749 is detected in method, Lsg/vp/owasp_mobile/OMTG_Android/OMTG_ENV_005_WebView_Local; onCreate (Landroid/os/Bundle;)V

@codecov-commenter

codecov-commenter commented Sep 20, 2022

Copy link
Copy Markdown

Codecov Report

Base: 77.92% // Head: 77.92% // No change to project coverage 👍

Coverage data is based on head (78cb321) compared to base (402e0a9).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #383   +/-   ##
=======================================
  Coverage   77.92%   77.92%           
=======================================
  Files          62       62           
  Lines        4629     4629           
=======================================
  Hits         3607     3607           
  Misses       1022     1022           
Flag Coverage Δ
unittests 77.92% <ø> (ø)

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

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@haeter525 haeter525 force-pushed the feat/update_doc_for_quark_script_APIs_to_detect_CWE-749 branch from bbdca84 to ce2781b Compare September 20, 2022 10:07
@haeter525 haeter525 force-pushed the feat/update_doc_for_quark_script_APIs_to_detect_CWE-749 branch from fbfe51d to 78cb321 Compare September 20, 2022 10:40
@18z

18z commented Sep 20, 2022

Copy link
Copy Markdown
Member

The script LGTM!

@haeter525 haeter525 force-pushed the feat/update_doc_for_quark_script_APIs_to_detect_CWE-749 branch from 2481a1f to 6c13531 Compare September 20, 2022 13:27
@18z

18z commented Sep 20, 2022

Copy link
Copy Markdown
Member

Thanks for the great work. @haeter525 please help me merge this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants