Skip to content

Commit 6bf12fa

Browse files
committed
Update MASTG-DEMO-0002.md to clarify file management in MediaStore
1 parent c08773c commit 6bf12fa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

demos/android/MASVS-STORAGE/MASTG-DEMO-0002/MASTG-DEMO-0002.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The snippet below shows sample code that creates two files in external storage u
2222

2323
The `run.sh` script injects a @MASTG-TOOL-0001 script named `script.js`. This script hooks and logs calls to the native `open` function and to `android.content.ContentResolver.insert`. It logs the paths of files written to external storage, the caller's stack trace, and additional details such as the `ContentValues` provided.
2424

25+
**Note**: When apps write files using the `ContentResolver.insert()` method, the files are managed by Android's MediaStore and are identified by `content://` URIs, not direct file system paths. This design abstracts the actual file locations, making them inaccessible through standard file system operations like the `open` function in libc. Consequently, when using Frida to hook into file operations, intercepting calls to `open` won't reveal these files.
26+
2527
{{ run.sh # script.js }}
2628

2729
### Observation
@@ -32,16 +34,21 @@ In the output you can observe the file paths, the relevant stack traces, and oth
3234

3335
Two files are written to external storage:
3436

35-
- `/storage/emulated/0/Android/data/org.owasp.mastestapp/files/secret.txt`: written via `java.io.FileOutputStream` from `org.owasp.mastestapp.MastgTest.mastgTestApi(MastgTest.kt:26)`.
36-
- `content://media/external/downloads/1000000108`: written via `android.content.ContentResolver.insert` from `org.owasp.mastestapp.MastgTest.mastgTestMediaStore(MastgTest.kt:44)`.
37+
- `/storage/emulated/0/Android/data/org.owasp.mastestapp/files/secret.txt`:
38+
- Written via `java.io.FileOutputStream`
39+
- Location: `org.owasp.mastestapp.MastgTest.mastgTestApi(MastgTest.kt:26)`.
40+
- `secretFile55.txt`:
41+
- Written via `android.content.ContentResolver.insert`
42+
- Location: `org.owasp.mastestapp.MastgTest.mastgTestMediaStore(MastgTest.kt:44)`.
43+
- Found as URI: `content://media/external/downloads/1000000108`.
3744

3845
The `ContentResolver.insert` call used the following `ContentValues`:
3946

4047
- `_display_name: secretFile55.txt`
4148
- `mime_type: text/plain`
4249
- `relative_path: Download`
4350

44-
Note that calls via `ContentResolver.insert` write to the MediaStore content provider rather than directly to the file system. As a result, you see a `content://` URI instead of a typical file path. However, the provided `ContentValues` still reveal the intended file name and the target directory.
51+
Using this information we can infer the path of the file written to external storage: `/storage/emulated/0/Download/secretFile55.txt`.
4552

4653
### Evaluation
4754

0 commit comments

Comments
 (0)