diff --git a/.github/workflows/testQuarkScript.yml b/.github/workflows/testQuarkScript.yml index c97a567..605aaab 100644 --- a/.github/workflows/testQuarkScript.yml +++ b/.github/workflows/testQuarkScript.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: diff --git a/CWE-312/README.md b/CWE-312/README.md index 534b7fa..36e00e2 100644 --- a/CWE-312/README.md +++ b/CWE-312/README.md @@ -1,37 +1,36 @@ # Detect CWE-312 in Android Application +This scenario seeks to find **cleartext storage of sensitive data** in the APK file. -This scenario seeks to find **cleartext storage of sensitive data** in -the APK file. - -## CWE-312 Cleartext Storage of Sensitive Information +## CWE-312: Cleartext Storage of Sensitive Information We analyze the definition of CWE-312 and identify its characteristics. -See [CWE-312](https://cwe.mitre.org/data/definitions/312.html) for more -details. +See [CWE-312](https://cwe.mitre.org/data/definitions/312.html) for more details. -![image](https://i.imgur.com/cy2EiZx.jpg) +![image](https://imgur.com/mD2uXUy.jpg) ## Code of CWE-312 in ovaa.apk -We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to -explain the vulnerability code of CWE-312. +We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to explain the vulnerability code of CWE-312. + +![image](https://imgur.com/MfnYIYy.jpg) + +## CWE-312 Detection Process Using Quark Script API + +Let’s use the above APIs to show how the Quark script finds this vulnerability. -![image](https://i.imgur.com/KsFsxTu.jpg) +We have designed a [Frida](https://frida.re/) script ``agent.js`` to hook a specified method and get the arguments when the method is called. It can be found in [quark-engine/quark/script/frida](https://github.com/quark-engine/quark-engine/tree/master/quark/script/frida). + +To begin with, we hook the method ``putString`` to catch its arguments. Then, we check if sensitive information like email or password is passed. Finally, we use ``checkClearText`` imported from [Ares](https://github.com/bee-san/Ares) to check if the arguments are cleartext. If both **YES**, CWE-312 vulnerability might be caused. -## Quark Script CWE-312.py +![image](https://imgur.com/eNjm3ES.jpg) -Let\'s use the above APIs to show how the Quark script finds this -vulnerability. +## Quark Script: CWE-312.py -First, we designed a [Frida](https://frida.re) script `agent.js` to hook -the target method and get the arguments when the target method is -called. Then we hook the method `putString` to catch its arguments. -Finally, we use [Ares](https://github.com/bee-san/Ares) to check if -the arguments are encrypted. +![image](https://imgur.com/rxMPZX8.jpg) -``` python +```python from quark.script.frida import runFridaHook from quark.script.ares import checkClearText @@ -62,7 +61,7 @@ for putString in fridaResult.behaviorOccurList: ## Frida Script: agent.js -``` javascript +```javascript // -*- coding: utf-8 -*- // This file is part of Quark-Engine - https://github.com/quark-engine/quark-engine // See the file 'LICENSE' for copying permission. @@ -125,7 +124,7 @@ rpc.exports["watchMethodCall"] = (classAndMethodName, methodParamTypes) => watch ## Quark Script Result -``` TEXT +```TEXT $ python3 CWE-312.py The CWE-312 vulnerability is found. The cleartext is "test@email.com" The CWE-312 vulnerability is found. The cleartext is "password" diff --git a/CWE-312/agent.js b/CWE-312/agent.js deleted file mode 100644 index e69de29..0000000 diff --git a/CWE-798/README.md b/CWE-798/README.md index f16abee..d227fca 100644 --- a/CWE-798/README.md +++ b/CWE-798/README.md @@ -1,36 +1,35 @@ # Detect CWE-798 in Android Application -This scenario seeks to find hard-coded credentials in the APK file. +This scenario seeks to find **hard-coded credentials** in the APK file. -## CWE-798 Use of Hard-coded Credentials +## CWE-798: Use of Hard-coded Credentials We analyze the definition of CWE-798 and identify its characteristics. -See [CWE-798](https://cwe.mitre.org/data/definitions/798.html) for more -details. +See [CWE-798](https://cwe.mitre.org/data/definitions/798.html) for more details. -![image](https://i.imgur.com/0G9APpf.jpg) +![image](https://imgur.com/rF8J8hE.png) ## Code of CWE-798 in ovaa.apk -We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to -explain the vulnerability code of CWE-798. +We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to explain the vulnerability code of CWE-798. -![image](https://i.imgur.com/ikaJlDW.jpg) +![image](https://imgur.com/Cg7DacP.png) -## Quark Script: CWE-798.py -Let\'s use the above APIs to show how the Quark script finds this -vulnerability. +## CWE-798 Detection Process Using Quark Script API + +![image](https://imgur.com/R8CfDqD.png) + +Let’s use the above APIs to show how the Quark script finds this vulnerability. + +First, we design a detection rule ``findSecretKeySpec.json`` to spot on behavior using the constructor ``SecretKeySpec``. Second, we get all the parameter values from this constructor. Then, we parse the AES key from the parameter values. Finally, we check if the AES key is hardcoded in the APK file. If the answer is **YES**, BINGO!!! We find hard-coded credentials in the APK file. -First, we design a detection rule `findSecretKeySpec.json` to spot on -behavior using the method `SecretKeySpec`. Then, we get all the -parameter values that are input to this method. And we parse the AES key -out of the parameter values. Finally, we check if the AES key is -hardcoded in the APK file. If the answer is YES, BINGO!!! We find -hard-coded credentials in the APK file. +## Quark Script: CWE-798.py + +![image](https://imgur.com/IOyrqDc.png) -``` python +```python import re from quark.script import runQuarkAnalysis, Rule @@ -54,7 +53,9 @@ for secretKeySpec in quarkResult.behaviorOccurList: ## Quark Rule: findSecretKeySpec.json -``` json +![image](https://imgur.com/2BYOE70.png) + +```json { "crime": "Detect APK using SecretKeySpec.", "permission": [], @@ -77,8 +78,7 @@ for secretKeySpec in quarkResult.behaviorOccurList: ## Quark Script Result -``` TEXT -$ python3 findSecretKeySpec.py - +```TEXT +$ python3 CWE-798.py Found hard-coded AES key 49u5gh249gh24985ghf429gh4ch8f23f ```