Skip to content

Commit 51a56a2

Browse files
1 parent 2d76ba0 commit 51a56a2

2 files changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-5vp3-3cg6-2rq3",
4+
"modified": "2026-03-24T19:22:21Z",
5+
"published": "2026-03-24T19:22:21Z",
6+
"aliases": [],
7+
"summary": "JustHTML is vulnerable to XSS via code fence breakout in <pre> content",
8+
"details": "## Summary\n\n`to_markdown()` is vulnerable when serializing attacker-controlled `<pre>` content. The `<pre>` handler emits a fixed three-backtick fenced code block, but writes decoded text content into that fence without choosing a delimiter longer than any backtick run inside the content.\n\nAn attacker can place backticks and HTML-like text inside a sanitized `<pre>` element so that the generated Markdown closes the fence early and leaves raw HTML outside the code block. When that Markdown is rendered by a CommonMark/GFM-style renderer that allows raw HTML, the HTML executes.\n\nThis is a bypass of the v1.12.0 Markdown hardening. That fix escaped HTML-significant characters for regular text nodes, but `<pre>` uses a separate serialization path and does not apply the same protection.\n\n## Details\n\nThe vulnerable `<pre>` Markdown path:\n\n- extracts decoded text from the `<pre>` subtree\n- opens a fenced block with a fixed delimiter of ``````\n- writes the decoded text directly into the output\n- closes with another fixed ``````\n\nBecause the fence length is fixed, attacker-controlled content containing a backtick run of length 3 or more can terminate the code block. If the content also contains decoded HTML-like text such as `&lt;img ...&gt;`, that text appears outside the fence in the resulting Markdown and is treated as raw HTML by downstream Markdown renderers.\n\nThe issue is not that HTML-like text appears inside code blocks. The issue is that the serializer allows attacker-controlled `<pre>` text to break out of the fixed fence.\n\n## Reproduction\n\n```python\nfrom justhtml import JustHTML\n\npayload = \"<pre>&#96;&#96;&#96;\\n&lt;img src=x onerror=alert(1)&gt;</pre>\"\ndoc = JustHTML(payload, fragment=True) # default sanitize=True\n\nprint(doc.to_html(pretty=False))\n# <pre>```\n# &lt;img src=x onerror=alert(1)&gt;</pre>\n\nprint(doc.to_markdown())\n# ```\n# ```\n# <img src=x onerror=alert(1)>\n# ```\n\n```\n\nRendered as CommonMark/GFM-style Markdown, that output is interpreted as:\n\n1. Line 1 opens a fenced code block\n2. Line 2 closes it\n3. Line 3 is raw HTML outside the fence\n4. Line 4 opens a new fence\n\n## Impact\n\nApplications that treat `JustHTML(..., sanitize=True).to_markdown()` output as safe for direct rendering in Markdown contexts may be exposed to XSS, depending on the downstream Markdown renderer's raw-HTML handling.\n\n## Root Cause\n\nThe `<pre>` Markdown serializer uses a fixed fence instead of selecting a delimiter longer than the longest backtick run in the content.\n\n## Fix\n\nWhen serializing `<pre>` content to Markdown, choose a fence length longer than any backtick run present in the code block content, with a minimum length of 3.",
9+
"severity": [
10+
{
11+
"type": "CVSS_V4",
12+
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N"
13+
}
14+
],
15+
"affected": [
16+
{
17+
"package": {
18+
"ecosystem": "PyPI",
19+
"name": "justhtml"
20+
},
21+
"ranges": [
22+
{
23+
"type": "ECOSYSTEM",
24+
"events": [
25+
{
26+
"introduced": "0"
27+
},
28+
{
29+
"fixed": "1.13.0"
30+
}
31+
]
32+
}
33+
],
34+
"database_specific": {
35+
"last_known_affected_version_range": "<= 1.12.0"
36+
}
37+
}
38+
],
39+
"references": [
40+
{
41+
"type": "WEB",
42+
"url": "https://github.com/EmilStenstrom/justhtml/security/advisories/GHSA-5vp3-3cg6-2rq3"
43+
},
44+
{
45+
"type": "WEB",
46+
"url": "https://github.com/EmilStenstrom/justhtml/commit/f35f8f723c713bd8f912d86e9ec6881275ff5af9"
47+
},
48+
{
49+
"type": "PACKAGE",
50+
"url": "https://github.com/EmilStenstrom/justhtml"
51+
},
52+
{
53+
"type": "WEB",
54+
"url": "https://github.com/EmilStenstrom/justhtml/releases/tag/v1.13.0"
55+
}
56+
],
57+
"database_specific": {
58+
"cwe_ids": [
59+
"CWE-79",
60+
"CWE-80"
61+
],
62+
"severity": "HIGH",
63+
"github_reviewed": true,
64+
"github_reviewed_at": "2026-03-24T19:22:21Z",
65+
"nvd_published_at": null
66+
}
67+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-hqjr-43r5-9q58",
4+
"modified": "2026-03-24T19:23:52Z",
5+
"published": "2026-03-24T19:23:52Z",
6+
"aliases": [
7+
"CVE-2026-33545"
8+
],
9+
"summary": "MobSF has SQL Injection in its SQLite Database Viewer Utils",
10+
"details": "## Description\n\nMobSF's `read_sqlite()` function in `mobsf/MobSF/utils.py` (lines 542-566) uses Python string formatting (`%`) to construct SQL queries with table names read from a SQLite database's `sqlite_master` table. When a security analyst uses MobSF to analyze a malicious mobile application containing a crafted SQLite database, attacker-controlled table names are interpolated directly into SQL queries without parameterization or escaping.\n\nThis allows an attacker to:\n\n1. **Cause Denial of Service** -- A malicious table name causes the database viewer to crash, preventing the analyst from viewing ANY data in the SQLite database. A malicious app can use this to hide sensitive data (C2 server URLs, stolen credentials, API keys) from MobSF's analysis.\n\n2. **Achieve SQL Injection** -- The `SELECT * FROM` query on line 557 is provably injectable via `UNION SELECT`, allowing attacker-controlled data to be returned in query results. The current code structure (a `PRAGMA` statement that runs first on line 553) limits the full exploitation chain, but the underlying code is verifiably injectable.\n\n## Root Cause\n\nThe vulnerable code in `mobsf/MobSF/utils.py:542-566`:\n\n```python\ndef read_sqlite(sqlite_file):\n \"\"\"Sqlite Dump - Readable Text.\"\"\"\n table_dict = {}\n try:\n con = sqlite3.connect(sqlite_file)\n cur = con.cursor()\n cur.execute('SELECT name FROM sqlite_master WHERE type=\\'table\\';')\n tables = cur.fetchall()\n for table in tables:\n table_dict[table[0]] = {'head': [], 'data': []}\n cur.execute('PRAGMA table_info(\\'%s\\')' % table) # <-- INJECTION POINT 1\n rows = cur.fetchall()\n for sq_row in rows:\n table_dict[table[0]]['head'].append(sq_row[1])\n cur.execute('SELECT * FROM \\'%s\\'' % table) # <-- INJECTION POINT 2\n rows = cur.fetchall()\n for sq_row in rows:\n tmp_row = []\n for each_row in sq_row:\n tmp_row.append(str(each_row))\n table_dict[table[0]]['data'].append(tmp_row)\n except Exception:\n logger.exception('Reading SQLite db')\n return table_dict\n```\n\n**Lines 553 and 557** use `%` string formatting to interpolate `table` (a tuple from `sqlite_master`) directly into SQL strings. The `table` value is attacker-controlled when the SQLite database originates from a malicious application being analyzed.\n\n## Attack Vector\n\nThe `read_sqlite()` function is called from two locations:\n\n1. **Dynamic Analysis File Viewer** (`mobsf/DynamicAnalyzer/views/common/device.py:64`):\n - Triggered when an analyst clicks to view a `.db` file in device data\n - Applies to both Android and iOS dynamic analysis\n\n2. **iOS Static Analysis File Viewer** (`mobsf/StaticAnalyzer/views/ios/views/view_source.py:123`):\n - Triggered when an analyst clicks to view a `.db` file during iOS static analysis\n\n### Attack Scenario\n\n1. Attacker creates a malicious Android APK (or iOS IPA) containing a SQLite database with a crafted table name in the `assets/` directory\n2. The SQLite database contains a table created with:\n ```sql\n CREATE TABLE \"x' UNION SELECT 'SQL_INJECTION_PROOF'--\" (id INTEGER);\n ```\n3. Security analyst uploads the application to MobSF for analysis\n4. Analyst browses the extracted files and clicks to view the SQLite database\n5. MobSF's `read_sqlite()` reads table names from `sqlite_master`, including the malicious name `x' UNION SELECT 'SQL_INJECTION_PROOF'--`\n6. The table name is interpolated into SQL queries via string formatting:\n - `PRAGMA table_info('x' UNION SELECT 'SQL_INJECTION_PROOF'--')` -- causes syntax error (DoS)\n - `SELECT * FROM 'x' UNION SELECT 'SQL_INJECTION_PROOF'--'` -- SQL injection (UNION SELECT returns attacker data)\n\n## Impact\n\n### Denial of Service (Confirmed)\n\nWhen the malicious table name is the first table in `sqlite_master` (i.e., created first in the database), the `PRAGMA` statement on line 553 raises a `sqlite3.OperationalError`, which is caught by the outer `try/except`. This causes `read_sqlite()` to return an empty or partial result, preventing the analyst from viewing **any** database content.\n\n**Security impact:** A malicious app author can use this technique to **hide incriminating data** stored in SQLite databases from MobSF's analysis. This directly undermines MobSF's core purpose as a security analysis tool.\n\n### SQL Injection (Confirmed in Isolation)\n\nThe `SELECT * FROM` query on line 557 is demonstrably injectable. When the malicious table name `x' UNION SELECT 'SQL_INJECTION_PROOF'--` is interpolated, the resulting query:\n\n```sql\nSELECT * FROM 'x' UNION SELECT 'SQL_INJECTION_PROOF'--'\n```\n\nSuccessfully executes and returns attacker-controlled data via `UNION SELECT`. The `--` comments out the trailing single quote. This is verified by the PoC script.\n\n**Note:** In the current code structure, the `PRAGMA table_info()` statement on line 553 runs before the `SELECT * FROM` on line 557. The PRAGMA fails with a syntax error for injected payloads, which triggers the exception handler before the SELECT can execute. This limits the full exploitation chain. However, the code flaw is real and any future refactoring that changes the execution order or removes the PRAGMA would immediately expose the full SQL injection.\n\n## Proof of Concept\n\n### Files Provided(Gdrive)\n\n| File | Description |\n|------|-------------|\n| `poc_sqlite_injection.py` | Standalone PoC demonstrating the vulnerability |\n| `malicious.db` | Crafted SQLite database (generated by PoC) |\n| `create_malicious_apk.sh` | Script to package the malicious DB into an APK |\n| `malicious_sqli.apk` | Pre-built APK for testing against MobSF |\n\nhttps://drive.google.com/drive/folders/1mNGkFfNowkaZ5J018HFi4IQcnjKaWCym?usp=sharing\n\n\n### Running the PoC\n\n```bash\n# Run the standalone PoC (no MobSF required)\npython3 poc_sqlite_injection.py\n\n# Build the malicious APK (requires Android SDK)\n./create_malicious_apk.sh\n\n# Test against MobSF\n# 1. Start MobSF\n# 2. Upload malicious_sqli.apk\n# 3. Browse extracted files -> click app_data.db\n# 4. Observe: database viewer fails (DoS)\n```\n\n### PoC Output (Abbreviated)\n\n```\n[STEP 2] Running MobSF's read_sqlite() against malicious database...\n [!] EXCEPTION CAUGHT: OperationalError: near \"UNION\": syntax error\n [!] DoS CONFIRMED: read_sqlite() crashed\n\n[STEP 3] Demonstrating SELECT * FROM injection in isolation...\n Query: SELECT * FROM 'x' UNION SELECT 'SQL_INJECTION_PROOF'--'\n [+] Query executed successfully!\n [+] Results: [('SQL_INJECTION_PROOF',), ('normal_data',)]\n [+] SQL INJECTION CONFIRMED\n\n[STEP 4] Complete DoS (malicious table created first):\n Tables with data: NONE\n [!] COMPLETE DoS CONFIRMED\n```\n\n## Suggested Fix\n\nReplace string formatting with properly quoted identifiers. SQLite uses double quotes for identifiers:\n\n```python\ndef read_sqlite(sqlite_file):\n \"\"\"Sqlite Dump - Readable Text.\"\"\"\n table_dict = {}\n try:\n con = sqlite3.connect(sqlite_file)\n cur = con.cursor()\n cur.execute('SELECT name FROM sqlite_master WHERE type=\\'table\\';')\n tables = cur.fetchall()\n for table in tables:\n table_name = table[0]\n # Properly escape table name as a double-quoted identifier\n safe_name = table_name.replace('\"', '\"\"')\n table_dict[table_name] = {'head': [], 'data': []}\n cur.execute(f'PRAGMA table_info(\"{safe_name}\")')\n rows = cur.fetchall()\n for sq_row in rows:\n table_dict[table_name]['head'].append(sq_row[1])\n cur.execute(f'SELECT * FROM \"{safe_name}\"')\n rows = cur.fetchall()\n for sq_row in rows:\n tmp_row = []\n for each_row in sq_row:\n tmp_row.append(str(each_row))\n table_dict[table_name]['data'].append(tmp_row)\n except Exception:\n logger.exception('Reading SQLite db')\n return table_dict\n```\n\nThis escapes any double quotes within table names by doubling them (`\"` → `\"\"`), which is the standard SQL mechanism for identifier quoting. This prevents breakout from the double-quoted identifier context.\n\n## Resources\n\n- **CWE-89**: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')\n- **OWASP SQL Injection**: https://owasp.org/www-community/attacks/SQL_Injection\n- **Affected File**: `mobsf/MobSF/utils.py`, lines 542-566",
11+
"severity": [
12+
{
13+
"type": "CVSS_V3",
14+
"score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:N/A:H"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "PyPI",
21+
"name": "mobsf"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "4.4.6"
32+
}
33+
]
34+
}
35+
],
36+
"database_specific": {
37+
"last_known_affected_version_range": "<= 4.4.5"
38+
}
39+
}
40+
],
41+
"references": [
42+
{
43+
"type": "WEB",
44+
"url": "https://github.com/MobSF/Mobile-Security-Framework-MobSF/security/advisories/GHSA-hqjr-43r5-9q58"
45+
},
46+
{
47+
"type": "WEB",
48+
"url": "https://github.com/MobSF/Mobile-Security-Framework-MobSF/commit/6f8a43c1b78d21cfbd7186aaafa7f622d990e0f1"
49+
},
50+
{
51+
"type": "PACKAGE",
52+
"url": "https://github.com/MobSF/Mobile-Security-Framework-MobSF"
53+
},
54+
{
55+
"type": "WEB",
56+
"url": "https://github.com/MobSF/Mobile-Security-Framework-MobSF/releases/tag/v4.4.6"
57+
}
58+
],
59+
"database_specific": {
60+
"cwe_ids": [
61+
"CWE-89"
62+
],
63+
"severity": "MODERATE",
64+
"github_reviewed": true,
65+
"github_reviewed_at": "2026-03-24T19:23:52Z",
66+
"nvd_published_at": null
67+
}
68+
}

0 commit comments

Comments
 (0)