masa-scan 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- masa_scan-1.3.0/LICENSE +21 -0
- masa_scan-1.3.0/PKG-INFO +316 -0
- masa_scan-1.3.0/README.md +283 -0
- masa_scan-1.3.0/masa/__init__.py +8 -0
- masa_scan-1.3.0/masa/__main__.py +6 -0
- masa_scan-1.3.0/masa/apk.py +841 -0
- masa_scan-1.3.0/masa/archive.py +91 -0
- masa_scan-1.3.0/masa/axml.py +358 -0
- masa_scan-1.3.0/masa/cli.py +224 -0
- masa_scan-1.3.0/masa/coverage.py +64 -0
- masa_scan-1.3.0/masa/decompile.py +106 -0
- masa_scan-1.3.0/masa/dex.py +63 -0
- masa_scan-1.3.0/masa/ipa.py +252 -0
- masa_scan-1.3.0/masa/models.py +197 -0
- masa_scan-1.3.0/masa/native.py +264 -0
- masa_scan-1.3.0/masa/plist.py +204 -0
- masa_scan-1.3.0/masa/policy.py +132 -0
- masa_scan-1.3.0/masa/report.py +825 -0
- masa_scan-1.3.0/masa/rules.py +840 -0
- masa_scan-1.3.0/masa/samples.py +552 -0
- masa_scan-1.3.0/masa/scanner.py +157 -0
- masa_scan-1.3.0/masa/taxonomy.py +129 -0
- masa_scan-1.3.0/masa_scan.egg-info/PKG-INFO +316 -0
- masa_scan-1.3.0/masa_scan.egg-info/SOURCES.txt +33 -0
- masa_scan-1.3.0/masa_scan.egg-info/dependency_links.txt +1 -0
- masa_scan-1.3.0/masa_scan.egg-info/entry_points.txt +2 -0
- masa_scan-1.3.0/masa_scan.egg-info/requires.txt +5 -0
- masa_scan-1.3.0/masa_scan.egg-info/top_level.txt +1 -0
- masa_scan-1.3.0/pyproject.toml +65 -0
- masa_scan-1.3.0/setup.cfg +4 -0
- masa_scan-1.3.0/tests/test_cli.py +140 -0
- masa_scan-1.3.0/tests/test_core.py +340 -0
- masa_scan-1.3.0/tests/test_coverage.py +384 -0
- masa_scan-1.3.0/tests/test_detection.py +567 -0
- masa_scan-1.3.0/tests/test_policy.py +299 -0
masa_scan-1.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Guerfi Ahmed Yacine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO MECHANICAL DETAILS, BUT NOT LIMITED TO
|
|
17
|
+
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
19
|
+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
20
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
21
|
+
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
masa_scan-1.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: masa-scan
|
|
3
|
+
Version: 1.3.0
|
|
4
|
+
Summary: Mobile App Security Analyzer - static security assessment of Android APKs and iOS IPAs with OWASP Mobile Top 10 compliance reporting
|
|
5
|
+
Author-email: Guerfi Ahmed Yacine <ay.guerfi@esi-sba.dz>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/N4khlA/MobileApp_SecAnalyzer
|
|
8
|
+
Project-URL: Documentation, https://github.com/N4khlA/MobileApp_SecAnalyzer#readme
|
|
9
|
+
Project-URL: Changelog, https://github.com/N4khlA/MobileApp_SecAnalyzer/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issues, https://github.com/N4khlA/MobileApp_SecAnalyzer/issues
|
|
11
|
+
Keywords: mobile,security,android,ios,apk,ipa,owasp,static-analysis,sast
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Information Technology
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# Mobile App Security Analyzer (`masa`)
|
|
35
|
+
|
|
36
|
+
[](https://github.com/N4khlA/MobileApp_SecAnalyzer/actions/workflows/ci.yml)
|
|
37
|
+
[](https://www.python.org/downloads/)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
[-red.svg)](https://owasp.org/www-project-mobile-top-10/)
|
|
40
|
+
|
|
41
|
+
`masa` is a lightweight, **zero-dependency** (Python standard library only) static security scanner for **Android (APK, source tree)** and **iOS (IPA, `.app` bundle)** applications.
|
|
42
|
+
|
|
43
|
+
It automatically evaluates application binaries and source code against the **OWASP Mobile Top 10 (2023 revision)** with backwards-compatible **2016 legacy mappings**, generating rich terminal summaries, JSON data exports, Markdown reports, and styled HTML dashboards.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Key Features
|
|
48
|
+
|
|
49
|
+
- **Zero External Dependencies**: Runs strictly on Python 3 standard library (`zipfile`, `xml.etree`, `plistlib`, `re`, `struct`).
|
|
50
|
+
- **Android & iOS Support**:
|
|
51
|
+
- **Android**: Parses binary AXML (`AndroidManifest.xml`), DEX string tables, resource files, and ELF `.so` native libraries.
|
|
52
|
+
- **iOS**: Parses binary/XML `Info.plist`, ATS configurations, `.mobileprovision` profiles, and Mach-O executables/frameworks.
|
|
53
|
+
- **Native String Scanning**: fast regex-based string extraction from native binaries.
|
|
54
|
+
- **Android IPC Checks**: intent redirection, mutable implicit PendingIntents, sticky broadcasts, spoofable caller checks, unflagged dynamic receivers, weak custom permissions and root-wide URI grants.
|
|
55
|
+
- **Binary Hardening**: PIE, RELRO, NX stack and stack canaries on ELF; encryption, stack canaries and ARC on Mach-O; APK signature scheme (v1-only / Janus).
|
|
56
|
+
- **OWASP Mobile Top 10 Compliance**: Scores app posture across all 10 categories (M1-M10) with positive security control detection (Keystore, Keychain, AEAD ciphers, Biometrics, Pinning).
|
|
57
|
+
- **Optional Decompiler Integration**: When an APK has no sources, masa tries `jadx`, then `dex2jar` + CFR, then `apktool` (smali), using whichever is on `PATH`. CFR is found as a `cfr` wrapper or via `MASA_CFR_JAR=/path/to/cfr.jar`.
|
|
58
|
+
- **Multi-Format Reporting**: Generates interactive HTML dashboards, Markdown summaries, structured JSON reports and SARIF 2.1.0 for code scanning.
|
|
59
|
+
- **CI Gate**: `--fail-on` turns findings into a non-zero exit code, so a pipeline can block on critical or high severity issues.
|
|
60
|
+
- **Adoptable in CI**: inline `masa-ignore` comments and a `.masa.toml` for accepted findings, plus `--baseline` so only new findings fail the build. Ships as a GitHub Action.
|
|
61
|
+
- **CWE + MASVS v2 ids** on every rule, in every report format and as SARIF tags.
|
|
62
|
+
- **File-type scoping**: API-call rules skip config and docs, and native rules only look at native code, which cuts duplicate and misplaced findings.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
### From PyPI
|
|
69
|
+
```bash
|
|
70
|
+
pip install masa-scan # installs the `masa` command
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### From Source
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/N4khlA/MobileApp_SecAnalyzer.git
|
|
76
|
+
cd MobileApp_SecAnalyzer
|
|
77
|
+
pip install .
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Development / Editable Mode
|
|
81
|
+
```bash
|
|
82
|
+
pip install -e ".[dev]"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Usage
|
|
88
|
+
|
|
89
|
+
### 1. Run the Demo
|
|
90
|
+
Build vulnerable sample Android (`.apk`) and iOS (`.ipa`) fixtures and analyze them end-to-end:
|
|
91
|
+
```bash
|
|
92
|
+
masa demo
|
|
93
|
+
```
|
|
94
|
+
or via Python module:
|
|
95
|
+
```bash
|
|
96
|
+
python -m masa demo
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 2. Analyze an Application
|
|
100
|
+
```bash
|
|
101
|
+
# Analyze an Android APK
|
|
102
|
+
masa analyze path/to/app.apk -o output_dir/
|
|
103
|
+
|
|
104
|
+
# Analyze an iOS IPA
|
|
105
|
+
masa analyze path/to/app.ipa -o output_dir/
|
|
106
|
+
|
|
107
|
+
# Analyze an unpacked directory (apktool output or a Gradle project;
|
|
108
|
+
# the manifest is found at the root or under src/main/)
|
|
109
|
+
masa analyze path/to/AndroidProject/ -o output_dir/
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 3. List Detection Rules
|
|
113
|
+
```bash
|
|
114
|
+
# List all active security rules
|
|
115
|
+
masa rules
|
|
116
|
+
|
|
117
|
+
# Filter rules by category (secrets, crypto, storage, network, ipc, auth,
|
|
118
|
+
# config, privacy, native, etc.)
|
|
119
|
+
masa rules --category crypto
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## CI Integration
|
|
125
|
+
|
|
126
|
+
Write SARIF for GitHub code scanning and fail the build on serious findings:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
masa analyze app.apk -o reports/ --sarif reports/masa.sarif --fail-on high --strict
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```yaml
|
|
133
|
+
- name: Scan APK
|
|
134
|
+
run: masa analyze app.apk --sarif masa.sarif --fail-on high --strict
|
|
135
|
+
- uses: github/codeql-action/upload-sarif@v3
|
|
136
|
+
if: always()
|
|
137
|
+
with:
|
|
138
|
+
sarif_file: masa.sarif
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### GitHub Action
|
|
142
|
+
|
|
143
|
+
```yaml
|
|
144
|
+
permissions:
|
|
145
|
+
contents: read
|
|
146
|
+
security-events: write # for the SARIF upload
|
|
147
|
+
steps:
|
|
148
|
+
- uses: actions/checkout@v4
|
|
149
|
+
- run: ./gradlew assembleRelease
|
|
150
|
+
- uses: N4khlA/MobileApp_SecAnalyzer@v1.3.0
|
|
151
|
+
with:
|
|
152
|
+
target: app/build/outputs/apk/release/app-release.apk
|
|
153
|
+
fail-on: high
|
|
154
|
+
# args: --baseline masa-baseline.json # only new findings fail
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Inputs: `target` (required), `fail-on` (default `high`), `sarif` (default
|
|
158
|
+
`masa.sarif`), `upload-sarif` (default `true`) and `args` for any other
|
|
159
|
+
`masa analyze` flags, such as `--baseline masa-baseline.json --strict`. SARIF is uploaded before the gate is
|
|
160
|
+
applied, so the alerts are visible even when the job fails.
|
|
161
|
+
|
|
162
|
+
### Suppressing findings
|
|
163
|
+
|
|
164
|
+
Accept a finding in code, on its line or on a comment line directly above:
|
|
165
|
+
|
|
166
|
+
```java
|
|
167
|
+
String key = "AKIAIOSFODNN7EXAMPLE"; // masa-ignore: SEC-001 -- AWS docs example key
|
|
168
|
+
// masa-ignore: CRY-002 -- MD5 is only a cache key here
|
|
169
|
+
String k = md5(url);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`masa-ignore` with no ids silences every rule on that line. For findings
|
|
173
|
+
without a line (manifest, binary and behaviour checks) or for whole folders,
|
|
174
|
+
use `.masa.toml` (Python 3.11+) or `.masa.json` in the directory you run
|
|
175
|
+
masa from, or pass `--config PATH`:
|
|
176
|
+
|
|
177
|
+
```toml
|
|
178
|
+
[[ignore]]
|
|
179
|
+
rule = "SEC-002"
|
|
180
|
+
path = "res/values/*.xml"
|
|
181
|
+
reason = "Maps key restricted to our package + signing cert"
|
|
182
|
+
|
|
183
|
+
[[ignore]]
|
|
184
|
+
path = "assets/vendor/*"
|
|
185
|
+
reason = "third-party SDK, tracked upstream"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Each entry needs a `reason`, plus a `rule`, a `path` or both. Suppressed
|
|
189
|
+
findings are listed under `suppressed` in the JSON report and carry SARIF
|
|
190
|
+
`suppressions`. They do not fail the gate or lower the grade.
|
|
191
|
+
|
|
192
|
+
### Baselines
|
|
193
|
+
|
|
194
|
+
To adopt masa on an existing app without fixing everything first, save a
|
|
195
|
+
report once and gate only on what is new:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
masa analyze app.apk -o reports/ # writes reports/app.report.json
|
|
199
|
+
cp reports/app.report.json masa-baseline.json # commit this
|
|
200
|
+
masa analyze app.apk --baseline masa-baseline.json --fail-on high
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Findings are matched by a fingerprint (rule, file, snippet) that ignores
|
|
204
|
+
line numbers, so moving code around does not create "new" findings. Known
|
|
205
|
+
findings stay in the report as `baselined` and still count toward the OWASP
|
|
206
|
+
grade, which describes the app rather than the diff.
|
|
207
|
+
|
|
208
|
+
| Exit code | Meaning |
|
|
209
|
+
|---|---|
|
|
210
|
+
| `0` | Scan finished and passed the gate |
|
|
211
|
+
| `1` | Gate failed: a finding at or above `--fail-on`, or an incomplete scan with `--strict` |
|
|
212
|
+
| `2` | Error: bad arguments, or input that could not be analysed |
|
|
213
|
+
|
|
214
|
+
`--fail-on` accepts `critical`, `high`, `medium`, `low`, `info` or `none`
|
|
215
|
+
(default). The reason for a failed gate is printed to stderr.
|
|
216
|
+
|
|
217
|
+
### Scan coverage
|
|
218
|
+
|
|
219
|
+
A scanner that silently drops a file reports fewer findings than the app really
|
|
220
|
+
has. masa records every file it could not analyse (corrupt, encrypted or
|
|
221
|
+
forged zip entries, unsupported compression, files over the size limits, unreadable
|
|
222
|
+
files) and every file it could only scan as raw strings (invalid dex, unrecognised
|
|
223
|
+
native libraries). Each report shows this:
|
|
224
|
+
|
|
225
|
+
- **Console and Markdown:** a `Coverage: INCOMPLETE` line or banner listing the files.
|
|
226
|
+
- **HTML:** an "Incomplete scan" section above the executive summary.
|
|
227
|
+
- **JSON:** a `coverage` object with `complete`, `files_seen`, `skipped` and `degraded`.
|
|
228
|
+
- **SARIF:** `toolExecutionNotifications` on the invocation, plus `run.properties.coverage`.
|
|
229
|
+
|
|
230
|
+
Add `--strict` to fail the build when coverage is incomplete. Media files (images,
|
|
231
|
+
audio, fonts) are never scanned and do not count as gaps.
|
|
232
|
+
|
|
233
|
+
### SARIF locations
|
|
234
|
+
|
|
235
|
+
Results point at paths *inside the analysed app* (for example `classes.dex` or
|
|
236
|
+
`res/values/strings.xml`), not at files in your repository. GitHub shows the alerts,
|
|
237
|
+
but the file links only resolve when you scan a source tree that is checked in.
|
|
238
|
+
|
|
239
|
+
This is a static analyzer. It does not replace dynamic testing, and a clean
|
|
240
|
+
scan is not proof that an app is secure.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## OWASP Mobile Top 10 (2023) Coverage
|
|
245
|
+
|
|
246
|
+
| OWASP Category | Name | Detection Scope |
|
|
247
|
+
|---|---|---|
|
|
248
|
+
| **M1** | Improper Credential Usage | Hardcoded AWS keys, Google API keys, Stripe secret keys, JWTs, private keys, passwords |
|
|
249
|
+
| **M2** | Inadequate Supply Chain Security | Deprecated Apache HTTP client, dynamic code loading (`DexClassLoader`), low target SDKs |
|
|
250
|
+
| **M3** | Insecure Authentication/Authorization | Client-side authorization checks, intent redirection, mutable implicit PendingIntents, sticky broadcasts, `checkCallingOrSelfPermission`, caller identity from Intent extras, dynamic receivers without an export flag, biometrics not bound to a key, custom URL schemes |
|
|
251
|
+
| **M4** | Insufficient Input/Output Validation | SQL injection (`rawQuery`), path traversal, dangerous WebView JavaScript bridges |
|
|
252
|
+
| **M5** | Insecure Communication | Cleartext HTTP URLs, ATS bypasses, `TrustAll` certificate manager overrides, hostname verification bypasses, user-installed CAs trusted in `network_security_config.xml`, WebView JavaScript |
|
|
253
|
+
| **M6** | Inadequate Privacy Protections | PII/credential logging in logcat/NSLog, hardware ID harvesting (IMEI/MAC), ATT prompt checks, secrets on the clipboard, missing `FLAG_SECURE` |
|
|
254
|
+
| **M7** | Insufficient Binary Protections | Unsafe string functions in native code (`strcpy`, `sprintf`), non-PIE binaries, missing RELRO, executable stack, missing stack canaries, Objective-C without ARC, unencrypted Mach-O, v1-only APK signing |
|
|
255
|
+
| **M8** | Security Misconfiguration | Debuggable builds, backup enabled without rules (`allowBackup=true`), staging endpoints, exported components without permission, providers missing read or write permission, weak or deprecated custom protection levels, root-wide `grant-uri-permission` |
|
|
256
|
+
| **M9** | Insecure Data Storage | Plaintext SharedPreferences, `NSUserDefaults` token storage, world-readable/writable files, `kSecAttrAccessibleAlways` Keychain items, files without Data Protection |
|
|
257
|
+
| **M10** | Insufficient Cryptography | DES/3DES, MD5, SHA-1, RC4, ECB encryption mode, hardcoded IVs, seeded PRNGs |
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Architecture Overview
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
masa/
|
|
265
|
+
├── __init__.py # Version and package metadata
|
|
266
|
+
├── __main__.py # Package CLI execution entry point
|
|
267
|
+
├── cli.py # Argument parsing and subcommand handler
|
|
268
|
+
├── apk.py # Android APK / source tree pipeline
|
|
269
|
+
├── ipa.py # iOS IPA / .app bundle pipeline
|
|
270
|
+
├── axml.py # Dependency-free Binary AXML parser & builder
|
|
271
|
+
├── plist.py # Dependency-free Binary Plist (bplist00) parser & builder
|
|
272
|
+
├── dex.py # Android classes.dex string table extractor
|
|
273
|
+
├── native.py # ELF (.so) and Mach-O binary security inspection
|
|
274
|
+
├── scanner.py # High-performance regex text/string scanner
|
|
275
|
+
├── rules.py # Detection rule definitions (OWASP 2023 & 2016)
|
|
276
|
+
├── taxonomy.py # CWE and MASVS v2 ids per rule
|
|
277
|
+
├── policy.py # Config-file suppressions and baseline matching
|
|
278
|
+
├── models.py # Core data models (Rule, Finding, PositiveCheck)
|
|
279
|
+
├── report.py # Compliance scoring and JSON/MD/HTML/SARIF generators
|
|
280
|
+
├── archive.py # Zip/tree readers with size limits
|
|
281
|
+
├── coverage.py # Tracks files that were skipped or only partly analysed
|
|
282
|
+
├── samples.py # Pure-Python vulnerable APK/IPA fixtures for `masa demo`
|
|
283
|
+
└── decompile.py # Optional external decompiler wrapper (jadx/apktool)
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Development
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
pip install -e ".[dev]"
|
|
292
|
+
ruff check .
|
|
293
|
+
pytest --cov=masa
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The tests use `unittest` cases and also run under `pytest`. The suite builds
|
|
297
|
+
its own vulnerable APK/IPA fixtures, so no Android SDK or Xcode is required.
|
|
298
|
+
`tests/test_detection.py` pairs every rule with a vulnerable and a safe
|
|
299
|
+
sample, and scans a clean Android project and iOS bundle to catch false
|
|
300
|
+
positives.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Changelog
|
|
305
|
+
|
|
306
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## License
|
|
311
|
+
|
|
312
|
+
Distributed under the [MIT License](LICENSE).
|
|
313
|
+
|
|
314
|
+
## Author
|
|
315
|
+
|
|
316
|
+
Built by **Guerfi Ahmed Yacine**, a cyber security engineering student at ESI Sidi Bel Abbès. Portfolio: [n4khla.github.io](https://n4khla.github.io) · [LinkedIn](https://www.linkedin.com/in/guerfi-ahmed-yacine-6831b32b8/)
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# Mobile App Security Analyzer (`masa`)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/N4khlA/MobileApp_SecAnalyzer/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[-red.svg)](https://owasp.org/www-project-mobile-top-10/)
|
|
7
|
+
|
|
8
|
+
`masa` is a lightweight, **zero-dependency** (Python standard library only) static security scanner for **Android (APK, source tree)** and **iOS (IPA, `.app` bundle)** applications.
|
|
9
|
+
|
|
10
|
+
It automatically evaluates application binaries and source code against the **OWASP Mobile Top 10 (2023 revision)** with backwards-compatible **2016 legacy mappings**, generating rich terminal summaries, JSON data exports, Markdown reports, and styled HTML dashboards.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Key Features
|
|
15
|
+
|
|
16
|
+
- **Zero External Dependencies**: Runs strictly on Python 3 standard library (`zipfile`, `xml.etree`, `plistlib`, `re`, `struct`).
|
|
17
|
+
- **Android & iOS Support**:
|
|
18
|
+
- **Android**: Parses binary AXML (`AndroidManifest.xml`), DEX string tables, resource files, and ELF `.so` native libraries.
|
|
19
|
+
- **iOS**: Parses binary/XML `Info.plist`, ATS configurations, `.mobileprovision` profiles, and Mach-O executables/frameworks.
|
|
20
|
+
- **Native String Scanning**: fast regex-based string extraction from native binaries.
|
|
21
|
+
- **Android IPC Checks**: intent redirection, mutable implicit PendingIntents, sticky broadcasts, spoofable caller checks, unflagged dynamic receivers, weak custom permissions and root-wide URI grants.
|
|
22
|
+
- **Binary Hardening**: PIE, RELRO, NX stack and stack canaries on ELF; encryption, stack canaries and ARC on Mach-O; APK signature scheme (v1-only / Janus).
|
|
23
|
+
- **OWASP Mobile Top 10 Compliance**: Scores app posture across all 10 categories (M1-M10) with positive security control detection (Keystore, Keychain, AEAD ciphers, Biometrics, Pinning).
|
|
24
|
+
- **Optional Decompiler Integration**: When an APK has no sources, masa tries `jadx`, then `dex2jar` + CFR, then `apktool` (smali), using whichever is on `PATH`. CFR is found as a `cfr` wrapper or via `MASA_CFR_JAR=/path/to/cfr.jar`.
|
|
25
|
+
- **Multi-Format Reporting**: Generates interactive HTML dashboards, Markdown summaries, structured JSON reports and SARIF 2.1.0 for code scanning.
|
|
26
|
+
- **CI Gate**: `--fail-on` turns findings into a non-zero exit code, so a pipeline can block on critical or high severity issues.
|
|
27
|
+
- **Adoptable in CI**: inline `masa-ignore` comments and a `.masa.toml` for accepted findings, plus `--baseline` so only new findings fail the build. Ships as a GitHub Action.
|
|
28
|
+
- **CWE + MASVS v2 ids** on every rule, in every report format and as SARIF tags.
|
|
29
|
+
- **File-type scoping**: API-call rules skip config and docs, and native rules only look at native code, which cuts duplicate and misplaced findings.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
### From PyPI
|
|
36
|
+
```bash
|
|
37
|
+
pip install masa-scan # installs the `masa` command
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### From Source
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/N4khlA/MobileApp_SecAnalyzer.git
|
|
43
|
+
cd MobileApp_SecAnalyzer
|
|
44
|
+
pip install .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Development / Editable Mode
|
|
48
|
+
```bash
|
|
49
|
+
pip install -e ".[dev]"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
### 1. Run the Demo
|
|
57
|
+
Build vulnerable sample Android (`.apk`) and iOS (`.ipa`) fixtures and analyze them end-to-end:
|
|
58
|
+
```bash
|
|
59
|
+
masa demo
|
|
60
|
+
```
|
|
61
|
+
or via Python module:
|
|
62
|
+
```bash
|
|
63
|
+
python -m masa demo
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Analyze an Application
|
|
67
|
+
```bash
|
|
68
|
+
# Analyze an Android APK
|
|
69
|
+
masa analyze path/to/app.apk -o output_dir/
|
|
70
|
+
|
|
71
|
+
# Analyze an iOS IPA
|
|
72
|
+
masa analyze path/to/app.ipa -o output_dir/
|
|
73
|
+
|
|
74
|
+
# Analyze an unpacked directory (apktool output or a Gradle project;
|
|
75
|
+
# the manifest is found at the root or under src/main/)
|
|
76
|
+
masa analyze path/to/AndroidProject/ -o output_dir/
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 3. List Detection Rules
|
|
80
|
+
```bash
|
|
81
|
+
# List all active security rules
|
|
82
|
+
masa rules
|
|
83
|
+
|
|
84
|
+
# Filter rules by category (secrets, crypto, storage, network, ipc, auth,
|
|
85
|
+
# config, privacy, native, etc.)
|
|
86
|
+
masa rules --category crypto
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## CI Integration
|
|
92
|
+
|
|
93
|
+
Write SARIF for GitHub code scanning and fail the build on serious findings:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
masa analyze app.apk -o reports/ --sarif reports/masa.sarif --fail-on high --strict
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
- name: Scan APK
|
|
101
|
+
run: masa analyze app.apk --sarif masa.sarif --fail-on high --strict
|
|
102
|
+
- uses: github/codeql-action/upload-sarif@v3
|
|
103
|
+
if: always()
|
|
104
|
+
with:
|
|
105
|
+
sarif_file: masa.sarif
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### GitHub Action
|
|
109
|
+
|
|
110
|
+
```yaml
|
|
111
|
+
permissions:
|
|
112
|
+
contents: read
|
|
113
|
+
security-events: write # for the SARIF upload
|
|
114
|
+
steps:
|
|
115
|
+
- uses: actions/checkout@v4
|
|
116
|
+
- run: ./gradlew assembleRelease
|
|
117
|
+
- uses: N4khlA/MobileApp_SecAnalyzer@v1.3.0
|
|
118
|
+
with:
|
|
119
|
+
target: app/build/outputs/apk/release/app-release.apk
|
|
120
|
+
fail-on: high
|
|
121
|
+
# args: --baseline masa-baseline.json # only new findings fail
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Inputs: `target` (required), `fail-on` (default `high`), `sarif` (default
|
|
125
|
+
`masa.sarif`), `upload-sarif` (default `true`) and `args` for any other
|
|
126
|
+
`masa analyze` flags, such as `--baseline masa-baseline.json --strict`. SARIF is uploaded before the gate is
|
|
127
|
+
applied, so the alerts are visible even when the job fails.
|
|
128
|
+
|
|
129
|
+
### Suppressing findings
|
|
130
|
+
|
|
131
|
+
Accept a finding in code, on its line or on a comment line directly above:
|
|
132
|
+
|
|
133
|
+
```java
|
|
134
|
+
String key = "AKIAIOSFODNN7EXAMPLE"; // masa-ignore: SEC-001 -- AWS docs example key
|
|
135
|
+
// masa-ignore: CRY-002 -- MD5 is only a cache key here
|
|
136
|
+
String k = md5(url);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`masa-ignore` with no ids silences every rule on that line. For findings
|
|
140
|
+
without a line (manifest, binary and behaviour checks) or for whole folders,
|
|
141
|
+
use `.masa.toml` (Python 3.11+) or `.masa.json` in the directory you run
|
|
142
|
+
masa from, or pass `--config PATH`:
|
|
143
|
+
|
|
144
|
+
```toml
|
|
145
|
+
[[ignore]]
|
|
146
|
+
rule = "SEC-002"
|
|
147
|
+
path = "res/values/*.xml"
|
|
148
|
+
reason = "Maps key restricted to our package + signing cert"
|
|
149
|
+
|
|
150
|
+
[[ignore]]
|
|
151
|
+
path = "assets/vendor/*"
|
|
152
|
+
reason = "third-party SDK, tracked upstream"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Each entry needs a `reason`, plus a `rule`, a `path` or both. Suppressed
|
|
156
|
+
findings are listed under `suppressed` in the JSON report and carry SARIF
|
|
157
|
+
`suppressions`. They do not fail the gate or lower the grade.
|
|
158
|
+
|
|
159
|
+
### Baselines
|
|
160
|
+
|
|
161
|
+
To adopt masa on an existing app without fixing everything first, save a
|
|
162
|
+
report once and gate only on what is new:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
masa analyze app.apk -o reports/ # writes reports/app.report.json
|
|
166
|
+
cp reports/app.report.json masa-baseline.json # commit this
|
|
167
|
+
masa analyze app.apk --baseline masa-baseline.json --fail-on high
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Findings are matched by a fingerprint (rule, file, snippet) that ignores
|
|
171
|
+
line numbers, so moving code around does not create "new" findings. Known
|
|
172
|
+
findings stay in the report as `baselined` and still count toward the OWASP
|
|
173
|
+
grade, which describes the app rather than the diff.
|
|
174
|
+
|
|
175
|
+
| Exit code | Meaning |
|
|
176
|
+
|---|---|
|
|
177
|
+
| `0` | Scan finished and passed the gate |
|
|
178
|
+
| `1` | Gate failed: a finding at or above `--fail-on`, or an incomplete scan with `--strict` |
|
|
179
|
+
| `2` | Error: bad arguments, or input that could not be analysed |
|
|
180
|
+
|
|
181
|
+
`--fail-on` accepts `critical`, `high`, `medium`, `low`, `info` or `none`
|
|
182
|
+
(default). The reason for a failed gate is printed to stderr.
|
|
183
|
+
|
|
184
|
+
### Scan coverage
|
|
185
|
+
|
|
186
|
+
A scanner that silently drops a file reports fewer findings than the app really
|
|
187
|
+
has. masa records every file it could not analyse (corrupt, encrypted or
|
|
188
|
+
forged zip entries, unsupported compression, files over the size limits, unreadable
|
|
189
|
+
files) and every file it could only scan as raw strings (invalid dex, unrecognised
|
|
190
|
+
native libraries). Each report shows this:
|
|
191
|
+
|
|
192
|
+
- **Console and Markdown:** a `Coverage: INCOMPLETE` line or banner listing the files.
|
|
193
|
+
- **HTML:** an "Incomplete scan" section above the executive summary.
|
|
194
|
+
- **JSON:** a `coverage` object with `complete`, `files_seen`, `skipped` and `degraded`.
|
|
195
|
+
- **SARIF:** `toolExecutionNotifications` on the invocation, plus `run.properties.coverage`.
|
|
196
|
+
|
|
197
|
+
Add `--strict` to fail the build when coverage is incomplete. Media files (images,
|
|
198
|
+
audio, fonts) are never scanned and do not count as gaps.
|
|
199
|
+
|
|
200
|
+
### SARIF locations
|
|
201
|
+
|
|
202
|
+
Results point at paths *inside the analysed app* (for example `classes.dex` or
|
|
203
|
+
`res/values/strings.xml`), not at files in your repository. GitHub shows the alerts,
|
|
204
|
+
but the file links only resolve when you scan a source tree that is checked in.
|
|
205
|
+
|
|
206
|
+
This is a static analyzer. It does not replace dynamic testing, and a clean
|
|
207
|
+
scan is not proof that an app is secure.
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## OWASP Mobile Top 10 (2023) Coverage
|
|
212
|
+
|
|
213
|
+
| OWASP Category | Name | Detection Scope |
|
|
214
|
+
|---|---|---|
|
|
215
|
+
| **M1** | Improper Credential Usage | Hardcoded AWS keys, Google API keys, Stripe secret keys, JWTs, private keys, passwords |
|
|
216
|
+
| **M2** | Inadequate Supply Chain Security | Deprecated Apache HTTP client, dynamic code loading (`DexClassLoader`), low target SDKs |
|
|
217
|
+
| **M3** | Insecure Authentication/Authorization | Client-side authorization checks, intent redirection, mutable implicit PendingIntents, sticky broadcasts, `checkCallingOrSelfPermission`, caller identity from Intent extras, dynamic receivers without an export flag, biometrics not bound to a key, custom URL schemes |
|
|
218
|
+
| **M4** | Insufficient Input/Output Validation | SQL injection (`rawQuery`), path traversal, dangerous WebView JavaScript bridges |
|
|
219
|
+
| **M5** | Insecure Communication | Cleartext HTTP URLs, ATS bypasses, `TrustAll` certificate manager overrides, hostname verification bypasses, user-installed CAs trusted in `network_security_config.xml`, WebView JavaScript |
|
|
220
|
+
| **M6** | Inadequate Privacy Protections | PII/credential logging in logcat/NSLog, hardware ID harvesting (IMEI/MAC), ATT prompt checks, secrets on the clipboard, missing `FLAG_SECURE` |
|
|
221
|
+
| **M7** | Insufficient Binary Protections | Unsafe string functions in native code (`strcpy`, `sprintf`), non-PIE binaries, missing RELRO, executable stack, missing stack canaries, Objective-C without ARC, unencrypted Mach-O, v1-only APK signing |
|
|
222
|
+
| **M8** | Security Misconfiguration | Debuggable builds, backup enabled without rules (`allowBackup=true`), staging endpoints, exported components without permission, providers missing read or write permission, weak or deprecated custom protection levels, root-wide `grant-uri-permission` |
|
|
223
|
+
| **M9** | Insecure Data Storage | Plaintext SharedPreferences, `NSUserDefaults` token storage, world-readable/writable files, `kSecAttrAccessibleAlways` Keychain items, files without Data Protection |
|
|
224
|
+
| **M10** | Insufficient Cryptography | DES/3DES, MD5, SHA-1, RC4, ECB encryption mode, hardcoded IVs, seeded PRNGs |
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Architecture Overview
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
masa/
|
|
232
|
+
├── __init__.py # Version and package metadata
|
|
233
|
+
├── __main__.py # Package CLI execution entry point
|
|
234
|
+
├── cli.py # Argument parsing and subcommand handler
|
|
235
|
+
├── apk.py # Android APK / source tree pipeline
|
|
236
|
+
├── ipa.py # iOS IPA / .app bundle pipeline
|
|
237
|
+
├── axml.py # Dependency-free Binary AXML parser & builder
|
|
238
|
+
├── plist.py # Dependency-free Binary Plist (bplist00) parser & builder
|
|
239
|
+
├── dex.py # Android classes.dex string table extractor
|
|
240
|
+
├── native.py # ELF (.so) and Mach-O binary security inspection
|
|
241
|
+
├── scanner.py # High-performance regex text/string scanner
|
|
242
|
+
├── rules.py # Detection rule definitions (OWASP 2023 & 2016)
|
|
243
|
+
├── taxonomy.py # CWE and MASVS v2 ids per rule
|
|
244
|
+
├── policy.py # Config-file suppressions and baseline matching
|
|
245
|
+
├── models.py # Core data models (Rule, Finding, PositiveCheck)
|
|
246
|
+
├── report.py # Compliance scoring and JSON/MD/HTML/SARIF generators
|
|
247
|
+
├── archive.py # Zip/tree readers with size limits
|
|
248
|
+
├── coverage.py # Tracks files that were skipped or only partly analysed
|
|
249
|
+
├── samples.py # Pure-Python vulnerable APK/IPA fixtures for `masa demo`
|
|
250
|
+
└── decompile.py # Optional external decompiler wrapper (jadx/apktool)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Development
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
pip install -e ".[dev]"
|
|
259
|
+
ruff check .
|
|
260
|
+
pytest --cov=masa
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The tests use `unittest` cases and also run under `pytest`. The suite builds
|
|
264
|
+
its own vulnerable APK/IPA fixtures, so no Android SDK or Xcode is required.
|
|
265
|
+
`tests/test_detection.py` pairs every rule with a vulnerable and a safe
|
|
266
|
+
sample, and scans a clean Android project and iOS bundle to catch false
|
|
267
|
+
positives.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Changelog
|
|
272
|
+
|
|
273
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## License
|
|
278
|
+
|
|
279
|
+
Distributed under the [MIT License](LICENSE).
|
|
280
|
+
|
|
281
|
+
## Author
|
|
282
|
+
|
|
283
|
+
Built by **Guerfi Ahmed Yacine**, a cyber security engineering student at ESI Sidi Bel Abbès. Portfolio: [n4khla.github.io](https://n4khla.github.io) · [LinkedIn](https://www.linkedin.com/in/guerfi-ahmed-yacine-6831b32b8/)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""masa - Mobile App Security Analyzer.
|
|
2
|
+
|
|
3
|
+
Static security analysis for Android APKs and iOS IPAs with OWASP
|
|
4
|
+
Mobile Top 10 compliance reporting. Dependency-free (Python stdlib only);
|
|
5
|
+
optionally integrates apktool/jadx/dex2jar when available on PATH.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "1.3.0"
|