久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何防止 XXE 攻擊

How to prevent XXE attack(如何防止 XXE 攻擊)
本文介紹了如何防止 XXE 攻擊的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我們對代碼進行了安全審計,其中提到我們的代碼容易受到 XML 外部實體 (XXE) 攻擊.

We had a security audit on our code, and it mentioned that our code is vulnerable to XML EXternal Entity (XXE) attacks.

XML 外部實體攻擊受益于在處理時動態構建文檔的 XML 特性.一個 XMLentity 允許動態地包含來自給定資源的數據.外部實體允許 XML 文檔包含數據來自外部 URI.除非另外配置,否則外部實體會強制 XML 解析器訪問指定的資源通過 URI,例如,本地計算機或遠程系統上的文件.此行為將應用程序暴露給 XML External實體 (XXE) 攻擊,可用于執行本地系統的拒絕服務,獲得對文件的未經授權的訪問本地機器,掃描遠程機器,并對遠程系統執行拒絕服務.

Explanation

XML External Entities attacks benefit from an XML feature to build documents dynamically at the time of processing. An XML entity allows inclusion of data dynamically from a given resource. External entities allow an XML document to include data from an external URI. Unless configured to do otherwise, external entities force the XML parser to access the resource specified by the URI, e.g., a file on the local machine or on a remote system. This behavior exposes the application to XML External Entity (XXE) attacks, which can be used to perform denial of service of the local system, gain unauthorized access to files on the local machine, scan remote machines, and perform denial of service of remote systems.

以下 XML 文檔顯示了 XXE 攻擊的示例.

The following XML document shows an example of an XXE attack.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///dev/random" >]><foo>&xxe;</foo>

如果 XML 解析器嘗試將實體替換為/dev/random 文件.

This example could crash the server (on a UNIX system), if the XML parser attempts to substitute the entity with the contents of the /dev/random file.

應該安全地配置 XML 解組器,以使其不允許外部實體作為傳入 XML 的一部分文件.

The XML unmarshaller should be configured securely so that it does not allow external entities as part of an incoming XML document.

為避免 XXE 注入,請勿使用將 XML 源直接處理為 java.io.Filejava.io.Readerjava.io.InputStream.使用安全配置的解析器解析文檔,并使用將安全解析器作為 XML 源的解組方法,如下例所示:

To avoid XXE injection do not use unmarshal methods that process an XML source directly as java.io.File, java.io.Reader or java.io.InputStream. Parse the document with a securely configured parser and use an unmarshal method that takes the secure parser as the XML source as shown in the following example:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setExpandEntityReferences(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(<XML Source>);
Model model = (Model) u.unmarshal(document);

以下代碼是審計發現 XXE 攻擊的地方:

The code below is where the audit found the XXE attack:

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
System.out.println("outputing to : " + outputLocation);
File outputFile = new File(outputLocation);
StreamResult result = new StreamResult(outputFile);
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);

如何在我的代碼中實施上述建議?我在哪里漏掉了東西?

How can I implement the above recommendation in my code? Where am I missing things?

推薦答案

您可以使用與 DocumentBuilderFactory 相同的方法:

You can use the same approach with DocumentBuilderFactory:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
...

要讓每個人都自動使用它,您需要創建自己的實現(通過擴展您當前使用的實現;使用您的調試器來找出答案).在構造函數中設置特征.

To make everyone use this automatically, you need to create your own implementation (by extending the one which you're currenly using; use your debugger to find out). Set the feature in the constructor.

然后你可以將System屬性javax.xml.parsers.DocumentBuilderFactory中的新工廠使用到Java VM,每個人都會使用它.

Then you can pass the new factory to use in the System property javax.xml.parsers.DocumentBuilderFactory to the Java VM and everyone will use it.

這篇關于如何防止 XXE 攻擊的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(Google 驅動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 日本久久黄色 | 老牛影视av一区二区在线观看 | 精品亚洲国产成av人片传媒 | 91精品中文字幕一区二区三区 | 亚洲国产精品久久久 | 中日韩av | 欧美在线一区二区三区 | 亚洲国产中文字幕 | 一区二区不卡视频 | 91在线一区 | 天天爱天天操 | 福利视频大全 | 国产精品一区二区av | 97精品超碰一区二区三区 | 超碰精品在线 | 亚洲男人网 | 国产精品无码专区在线观看 | 2一3sex性hd | 四虎影院新地址 | 欧美日韩精品一区二区三区四区 | 国产成人aⅴ | 日韩欧美视频网站 | 欧美日韩免费 | 国产网站在线播放 | 亚洲444kkkk在线观看最新 | 日本久久久久久 | 九九精品在线 | 一级在线观看 | h视频在线免费 | 久久综合伊人 | 中文字幕精品视频在线观看 | 国产精品成人在线观看 | 龙珠z在线观看 | 亚洲国产精品久久久久秋霞不卡 | 婷婷综合 | 最新国产福利在线 | 日韩精品一区二区三区中文在线 | 日本在线免费视频 | 久久999| 久久爱一区 | 一级特黄网站 |