- The Guide to Finding and Reporting Web Vulnerabilities
- About the Author
- About the Tech Reviewer
- Foreword
- Introduction
- Who This Book Is For
- What Is In This Book
- Happy Hacking!
- 1 Picking a Bug Bounty Program
- 2 Sustaining Your Success
- 3 How the Internet Works
- 4 Environmental Setup and Traffic Interception
- 5 Web Hacking Reconnaissance
- 6 Cross-Site Scripting
- 7 Open Redirects
- 8 Clickjacking
- 9 Cross-Site Request Forgery
- 10 Insecure Direct Object References
- 11 SQL Injection
- 12 Race Conditions
- 13 Server-Side Request Forgery
- 14 Insecure Deserialization
- 15 XML External Entity
- 16 Template Injection
- 17 Application Logic Errors and Broken Access Control
- 18 Remote Code Execution
- 19 Same-Origin Policy Vulnerabilities
- 20 Single-Sign-On Security Issues
- 21 Information Disclosure
- 22 Conducting Code Reviews
- 23 Hacking Android Apps
- 24 API Hacking
- 25 Automatic Vulnerability Discovery Using Fuzzers
Prevention
Preventing XXEs is all about limiting the capabilities of an XML parser. First, because DTD processing is a requirement for XXE attacks, you should disable DTD processing on the XML parsers if possible. If it’s not possible to disable DTDs completely, you can disable external entities, parameter entities (covered in “Escalating the Attack” on page 254 ), and inline DTDs (DTDs included in the XML document). And to prevent XXE-based DoS, you can limit the XML parser’s parse time and parse depth. You can also disable the expansion of entities entirely.
预防 XXE 攻击的关键在于限制 XML 解析器的能力。首先,由于对 DTD 的处理是 XXE 攻击的要求,如果可能的话,应该在 XML 解析器中禁用 DTD 处理。如果无法完全禁用 DTD,可以禁用外部实体、参数实体(在第 254 页的“加剧攻击”中介绍)和内联 DTD(包含在 XML 文档中的 DTD)。为了防止基于 XXE 的拒绝服务攻击,可以限制 XML 解析器的解析时间和解析深度。您还可以完全禁用实体扩展。
The mechanisms for disabling DTD processing and configuring parser behavior vary based on the XML parser in use. For example, if you’re using the default PHP XML parser, you need to set libxml_disable_entity_loader
to TRUE
to disable the use of external entities. For more information on how to do it for your parser, consult the OWASP Cheat Sheet at https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md .
禁用 DTD 处理和配置分析器行为的机制取决于所使用的 XML 分析器。例如,如果您使用默认的 PHP XML 解析器,则需要将 libxml_disable_entity_loader 设置为 TRUE 以禁用使用外部实体。有关如何为您的解析器执行此操作的更多信息,请参阅 OWASP 防伪劫持清单 https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md。
Another path you can take is input validation. You could create an allowlist for user-supplied values that are passed into XML documents, or sanitize potentially hostile data within XML documents, headers, or nodes. Alternatively, you can use less complex data formats like JSON instead of XML whenever possible.
另一种方法是进行输入验证。您可以创建用户提供的数值的允许列表,以传递到 XML 文档中,或清理 XML 文档中、标头或节点中的潜在恶意数据。另外,尽可能使用较少复杂的数据格式,例如 JSON,而不是 XML。
In classic XXEs (like the example I showed in “Mechanisms” on page 249 ), attackers exfiltrate data by making the application return data in an HTTP response. If the server takes XML input but does not return the XML document in an HTTP response, attackers can use blind XXEs to exfiltrate data instead. Blind XXEs steal data by having the target server make an outbound request to the attacker’s server with the stolen data. To prevent blind XXEs, you can disallow outbound network traffic.
在传统的 XXE 攻击中(比如我在第 249 页“机制”中展示的例子),攻击者通过让应用程序在 HTTP 响应中返回数据来将数据窃取。如果服务器接收 XML 输入,但不在 HTTP 响应中返回 XML 文档,则攻击者可以使用盲目的 XXE 来替代从而窃取数据。盲目的 XXE 通过让目标服务器向攻击者的服务器发出包含窃取数据的出站请求来窃取数据。为了防止盲目的 XXE,您可以禁止出站网络流量。
Finally, you can routinely review your source code to detect and fix XXE vulnerabilities. And because many XXEs are introduced by an application’s dependencies instead of its custom source code, you should keep all dependencies in use by your application or by the underlying operating system up-to-date.
最后,您可以定期检查您的源代码以检测和修复 XXE 漏洞。因为许多 XXE 是由应用程序的依赖项而不是其自定义源代码引入的,所以您应该始终保持应用程序或底层操作系统使用的所有依赖项最新。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论