Repository navigation
New Artifact: SamsungGalleryLogEncodedStrings - #1900
Conversation
Work completed offline for new ALEAPP parser: SamsungGalleryLogEncodedStrings
|
Thanks @dantitto, this is good work. The decoding is right. I ran it on every image in our corpus that has Gallery's local.db and checked each decoded value against my own decode, and all of them matched. The multi-user handling works too. A few changes before I merge:
Last point: the PR body's false-positive numbers (200,000 strings and so on) come from a run that isn't in the PR. Either add the script or say they come from your own synthetic test. |
…eryLogEncodedStrings.SamsungGalleryLogEncodedStrings.case1.20261110165127.json
…eryLogEncodedStrings.SamsungGalleryLogEncodedStrings.case2.20261110165127.json
…eryLogEncodedStrings.SamsungGalleryLogEncodedStrings.case3.20261110165127.json
…eryLogEncodedStrings.SamsungGalleryLogEncodedStrings.case4.20261110165127.json
|
@abrignoni Thank you for the detailed review, I hope all the points you've raised are addressed as you meant for them to be🤞. It's good to be on the contribution side of things for a change with this kind of project! I've tried to mimic the structure of your points to assist in working through them:
PR body. The false-positive and round-trip figures are now labelled as coming from my own synthetic test, which isn't part of the PR. The "rather than guessing" wording is replaced with what the code does: V3 shown, with Note listing both readings. Cheers, Dan |
Introduction
Adds a new artifact,
SamsungGalleryLogEncodedStrings, that finds and decodes the obfuscated strings Samsung Gallery'sLoggerfunction writes into the '__log' column of the 'log' table ofcom.sec.android.gallery3d/databases/local.db. It covers three generations of the obfuscation in a single parser. Each log cell that holds encoded strings is reported twice: once with the strings decoded in place, so the entry can be read in context, and once more exactly as stored. The decoded text is an interpretation shown beside the raw value to allow comparison.For a new or changed artifact
python admin/scripts/check_artifact_output.py <report folder>on that report and fixed or documented every finding. An empty or constant column is often a real result (no group chats, coarse location denied); the fix for those is a sentence in the artifact'snotesnaming the column and saying it was empty or uniform, which is also what stops the checker reporting it.--compare <multi-container report>reads the scaling for you: it should be exactly double.notes,descriptionandsample_datasay only what the data shows, and the numbers were re-derived from the finished run.Anything reviewers should know
Background
Samsung Gallery obfuscates certain strings (file paths, titles, transition names and similar) before they are logged or stored. Three encoding methodologies were identified during research:
Base64(text with dummy U+25CF ● / U+2605 ★ characters interspersed), then a random 7 character suffix (later builds list a third dummy, U+25C6 ◆, which is stripped as well). The affix characters are drawn from the Base64 alphabet, so the value looks like ordinary Base64." #G$E" + index + Base64(xorWithKey(text, sEncV2Key[index])).sEncV2Keyis 8 × 4-byte keys; 'getEncodedString' emits indices 0–3.#G$Emarker.sEncV3Keyindices 0–3 are single bytes{0,1,2,3}and indices 4–7 are 256-byte keys;getEncodedStringemits indices 4–7.xorWithKeycycles the key (key[i % key.length]), as the decompiled source shows.Decoding
local.db. For each#G$Etoken it tries every key defined at that index in both key tables and keeps whichever yields valid UTF-8, with a control-character check to reject a wrong key that still happens to produce decodable bytes. If both key tables give readable text for one string, the V3 reading is shown and Note lists both. V2 and V3 share the marker but use different index ranges and keys in practice, so this resolves them without needing to know the app version. On the tested images the strings decoded with V3 keys 4 to 7 and V2 key 3; the other keys were not exercised.logtable. V1 has no marker, so it is searched for only where the logger writes it.V1_TARGETSholds(table, column)wildcard pairs, matched case-insensitively; the default("log", "*log")covers the__logcolumn without depending on its exact number of underscores, and further pairs can be added. Each Base64-like run carrying one of the short patterns a dummy character always leaves in Base64 is tried, so V1 values within log text (album=… path=…, or bracketed as[…]) and cells that are a single value are both decoded in place. A reading is accepted only when the decoded text contains the encoder's dummy characters: the encoder puts one before each character with probability 2/3, so a genuine value carries them, while ordinary text and random Base64 virtually never decode to them. Measured in my own synthetic test (not part of this PR): no false positives across 200,000 random Base64 strings, 20,000 synthetic log lines and 30,000 path-heavy log lines with no V1 values; detection 100% for values of 10 or more characters and 99.9% at 6. Short values can be missed (about one in three at a single character). A missed value stays as stored when another value in the same cell decodes; otherwise the cell is not reported. No tested image held a V1 value, so V1 decoding has only been tested on synthetic data built from the decompiled code.V3[5], V3[7]orV1, V1). A#G$Etoken that does not decode is left exactly as stored and the reason is recorded in Note, so nothing is dropped.#G$Eindex is matched as 1–2 digits and its width is resolved per token, so a future key array grown past 10 entries (a two-digit index) still parses. Today's single-digit data is unaffected.Multiple Android Users
The
pathsglob (*/com.sec.android.gallery3d/databases/local.db*) matches every user's copy oflocal.dband its-wal/-shm: user 0, user 150, user 10 and any others, underdata/data,data/user/<n>,data/user_de/<n>anddata_mirror. Files are read throughunique_filesfromstoragePathViews, so the duplicate storage views of one database (data/data,data/user/0,data_mirror) are read once, while a second user's own copy is kept. A trailing Android User column names the user whose app folder holds the copy when databases from more than one user are read, and is left blank otherwise, following the convention of other ALEAPP artifacts. Onlylocal.dbis read. The app's other databases are not searched; if encoded strings are found in another of them, its name can be added topaths.Output
output_types = "standard"(HTML, TSV, LAVA and timeline via@artifact_processor). One row per log cell holding encoded strings.Columns: Timestamp (as stored), Category (as stored), Table, Column, Row ID, Decoded (in context), Raw (obfuscated), Scheme/key, Note, Android User. The source database(s) are given on the report’s source line rather than in a column.
Timestamp and Category are the log row’s __timestamp and __category, so the timeline places each row at the log entry’s time. Both are shown as stored. In the decompiled v15.9.02.2 code, DebugLogger.insertLog writes __timestamp via TimeUtil.getIsoLocalDateTimeWithMillis, which sets no time zone, so the value is the device’s local time with no offset stored; it isn’t typed as datetime or converted for that reason. The notes cover the details, and list the DebugLogger method behind each category number.
The artifact returns a single plain list of rows, as most artifacts do, and uses no
html_columns, so every column, the decoded text included, is escaped by the report writer.Forensic Housekeeping
open_sqlite_db_readonly. When a-walis staged beside the database, the committed contents of the write-ahead log are included, as for every other artifact.Reverse Engineering of Keys
Keys and logic were reverse-engineered from
com.sec.android.gallery3dbase APKs:sEncV2Key: from v14.0.00.10.sEncV3Key: from v15.9.00.52; identical in v15.1.03.15, v15.7.02.0 and v15.8.00.84.Logger.getEncodedStringin v7.0.00.9 and v10.0.01.17; unchanged apart from the added ◆ dummy in build 1000100022.Earlier Work
The V1 scheme was described publicly by Adrian Leong (Cheeky4n6Monkey) in January 2022, with standalone scripts for the
logtable in Gallery v10.x and v11.x (https://cheeky4n6monkey.blogspot.com/2022/01), (https://github.com/cheeky4n6monkey/4n6-scripts/tree/master/Samsung_Gallery3d_2022).SamsungGalleryLogEncodedStringswas developed independently using the app'sLoggersource and does not use that earlier code. To my knowledge, the V2 and V3 (#G$E) schemes have not been published or parsed elsewhere.