簡體   English   中英

Fortify 修復經常被誤用的身份驗證

[英]Fortify fix for Often Misused Authentication

當我使用 fortify 進行掃描時,我在下面的代碼中發現了諸如“經常誤用:身份驗證”之類的漏洞。 為此,我們有任何解決方法可以避免此問題。 我看過相關帖子,但無法獲得解決方案。使用 ESAPI 我已經為主機名和 ipadress 提供了正則表達式,但它不起作用。 addr.getHostAddress() java.net.InetAddress.getByName(nameServiceHost); java.net.InetAddress.getLocalHost().getCanonicalHostName() localhost.getHostName()

請建議我解決這個問題。

所有其他答案都嘗試通過不使用內置 API,而是使用命令行或其他方式來提供解決方法。 但是,他們忽略了實際問題,這里的問題不是 API,而是假設 DNS 可用於身份驗證。

攻擊者可以欺騙(即偽造)偽裝成有效調用者的 DNS 響應。 他們還可以在不攻擊 DNS 的情況下使用IP 地址欺騙偽裝成一個有效的呼叫者。

TL;DR 不使用 DNS 或呼叫者 IP 作為身份驗證源。 而是將 SSL/TLS 與加密連接一起使用,然后您可以使用Basic-AuthenticationOauth2或什至更好的客戶端證書,即 mTLS

您可以驗證請求是否來自受信任的主機

String ip = request.getRemoteAddr(); 
InetAddress addr = InetAddress.getByName(ip); 
if (addr.getCanonicalHostName().endsWith("trustme.com")) { 
 trusted = true; 
} 

對於我的情況,我已經重新編寫了這樣的代碼

    public static String getIPAddress(String hostname) {
    Process process;
    String ipAddress = null;
    String localIpAddress = null;
    String[] commandArray;

    if(System.getProperty("os.name").startsWith("Windows")) {
        commandArray = new String[] {"cmd", "/c", "ping "+hostname+ " -4 | findstr Pinging"}; // For Windows
    } else {
        commandArray = new String[] { "bash", "-c", "host "+hostname}; // For Linux and OSX
    }

    try {
        process = Runtime.getRuntime().exec(commandArray);
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String[] output;
         // Reading the output of a command executed.
         while ((localIpAddress = stdInput.readLine()) != null) {
             if(System.getProperty("os.name").startsWith("Windows")) {
                 output = localIpAddress.split(" ");
                 ipAddress = output[2].replace("[", "").replace("]", "").trim();
             } else {                
                 output = localIpAddress.split("has address"); 
                 ipAddress = output[1];
             }
         }
    } catch (IOException e) {
        org.owasp.esapi.reference.Log4JLogFactory.getInstance().getLogger(" com.util.esapi.InetAddressWrapper.getIPAddress() << "+e+" >>");
    }
    return ipAddress;
}   

嘗試使用 InetSocketAddress 包裝器,尤其是用於 Elasticsearch 傳輸客戶端:

new InetSocketAddress(hostname, port)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM