hacktricks/network-services-pentesting/pentesting-web/imagemagick-security.md

72 lines
5.1 KiB
Markdown
Raw Normal View History

2023-01-16 14:53:23 +00:00
# ImageMagick Security
2024-07-19 09:06:54 +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)
2023-01-16 14:53:23 +00:00
2024-07-19 09:06:54 +00:00
<details>
2023-01-16 14:53:23 +00:00
2024-07-19 09:06:54 +00:00
<summary>Support HackTricks</summary>
2024-02-03 12:22:53 +00:00
2024-07-19 09:06:54 +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.
2023-01-16 14:53:23 +00:00
</details>
2024-07-19 09:06:54 +00:00
{% endhint %}
2023-01-16 14:53:23 +00:00
2024-02-08 21:36:15 +00:00
Check further details in [**https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html**](https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html)
2023-01-16 14:53:23 +00:00
2024-02-04 10:58:49 +00:00
ImageMagick, a versatile image processing library, presents a challenge in configuring its security policy due to its extensive options and lack of detailed online documentation. Users often create policies based on fragmented internet sources, leading to potential misconfigurations. The library supports a vast array of over 100 image formats, each contributing to its complexity and vulnerability profile, as demonstrated by historical security incidents.
2023-01-16 14:53:23 +00:00
2024-02-04 10:58:49 +00:00
## Towards Safer Policies
To address these challenges, a [tool has been developed](https://imagemagick-secevaluator.doyensec.com/) to aid in designing and auditing ImageMagick's security policies. This tool is rooted in extensive research and aims to ensure policies are not only robust but also free from loopholes that could be exploited.
2023-01-16 14:53:23 +00:00
2024-02-04 10:58:49 +00:00
## Allowlist vs Denylist Approach
Historically, ImageMagick policies relied on a denylist approach, where specific coders were denied access. However, changes in ImageMagick 6.9.7-7 shifted this paradigm, enabling an allowlist approach. This approach first denies all coders and then selectively grants access to trusted ones, enhancing the security posture.
2023-01-16 14:53:23 +00:00
```xml
...
<policy domain="coder" rights="none" pattern="*" />
<policy domain="coder" rights="read | write" pattern="{GIF,JPEG,PNG,WEBP}" />
...
```
2024-02-04 10:58:49 +00:00
## Case Sensitivity in Policies
It's crucial to note that policy patterns in ImageMagick are case sensitive. As such, ensuring that coders and modules are correctly upper-cased in policies is vital to prevent unintended permissions.
2023-01-16 14:53:23 +00:00
2024-02-04 10:58:49 +00:00
## Resource Limits
ImageMagick is prone to denial of service attacks if not properly configured. Setting explicit resource limits in the policy is essential to prevent such vulnerabilities.
2023-01-16 14:53:23 +00:00
2024-02-04 10:58:49 +00:00
## Policy Fragmentation
Policies may be fragmented across different ImageMagick installations, leading to potential conflicts or overrides. It's recommended to locate and verify the active policy files using commands like:
2023-01-16 14:53:23 +00:00
2024-02-04 10:58:49 +00:00
```shell
2023-01-16 14:53:23 +00:00
$ find / -iname policy.xml
```
2024-02-04 10:58:49 +00:00
## A Starter, Restrictive Policy
A restrictive policy template has been proposed, focusing on stringent resource limitations and access controls. This template serves as a baseline for developing tailored policies that align with specific application requirements.
2023-01-16 14:53:23 +00:00
2024-02-04 10:58:49 +00:00
The effectiveness of a security policy can be confirmed using the `identify -list policy` command in ImageMagick. Additionally, the [evaluator tool](https://imagemagick-secevaluator.doyensec.com/) mentioned earlier can be used to refine the policy based on individual needs.
2023-01-16 14:53:23 +00:00
2024-02-08 21:36:15 +00:00
## References
2024-02-04 10:58:49 +00:00
* [https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html**](https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html)
2023-01-16 14:53:23 +00:00
2024-07-19 09:06:54 +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)
2023-01-16 14:53:23 +00:00
2024-07-19 09:06:54 +00:00
<details>
2023-01-16 14:53:23 +00:00
2024-07-19 09:06:54 +00:00
<summary>Support HackTricks</summary>
2024-02-03 12:22:53 +00:00
2024-07-19 09:06:54 +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.
2023-01-16 14:53:23 +00:00
</details>
2024-07-19 09:06:54 +00:00
{% endhint %}