# ImageMagick Security

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

在[**https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html**](https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html)中查看更多详细信息。

ImageMagick是一个多功能的图像处理库，由于其广泛的选项和缺乏详细的在线文档，配置其安全策略是一个挑战。用户通常基于碎片化的互联网来源创建策略，导致潜在的配置错误。该库支持超过100种图像格式，每种格式都增加了其复杂性和易受攻击的概况，正如历史安全事件所证明的那样。

## 朝着更安全的策略迈进

为了解决这些挑战，[开发了一个工具](https://imagemagick-secevaluator.doyensec.com/)来帮助设计和审计ImageMagick的安全策略。该工具根植于广泛的研究，旨在确保策略不仅健壮，而且没有可以被利用的漏洞。

## 白名单与黑名单方法

历史上，ImageMagick的策略依赖于黑名单方法，其中特定的编码器被拒绝访问。然而，在ImageMagick 6.9.7-7中的变化改变了这一范式，实现了白名单方法。这种方法首先拒绝所有编码器的访问，然后有选择性地授予受信任的编码器访问权限，增强了安全性。

```xml
...
<policy domain="coder" rights="none" pattern="*" />
<policy domain="coder" rights="read | write" pattern="{GIF,JPEG,PNG,WEBP}" />
...
```

## 策略中的大小写敏感性

值得注意的是，ImageMagick 中的策略模式是大小写敏感的。因此，确保策略中的编码器和模块被正确地大写是至关重要的，以防止意外的权限问题。

## 资源限制

如果未正确配置，ImageMagick 容易受到拒绝服务攻击的影响。在策略中设置明确的资源限制是防止此类漏洞的关键。

## 策略碎片化

策略可能会分散在不同的 ImageMagick 安装中，导致潜在的冲突或覆盖。建议使用诸如以下命令来定位和验证活动策略文件：

```shell
$ find / -iname policy.xml
```

## 一个入门级、限制性策略

已提出一个限制性策略模板，侧重于严格的资源限制和访问控制。该模板可作为制定符合特定应用需求的定制策略的基准。

可以使用`identify -list policy`命令在ImageMagick中确认安全策略的有效性。此外，之前提到的[评估工具](https://imagemagick-secevaluator.doyensec.com/)可根据个人需求调整策略。

## 参考资料

* [https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html\*\*](https://blog.doyensec.com/2023/01/10/imagemagick-security-policy-evaluator.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/network-services-pentesting/pentesting-web/imagemagick-security.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
