<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>

    Buffer Overflow: Signed Comparison

    ABSTRACT

    該程序使用帶符號的比較來檢查稍候會被視為不帶符號的值。這將會導致程序在分配的內存邊界之外寫入數據,這可能會損壞數據、引起程序崩潰或為惡意代碼的執行提供機會。

    EXPLANATION

    Buffer overflow 可能是人們最熟悉的一種軟件安全漏洞。雖然絕大多數軟件開發者都知道什么是 Buffer overflow 漏洞,但是無論是對繼承下來的或是新開發的應用程序來說,Buffer overflow 攻擊仍然是一種最常見的攻擊形式。對于這個問題出現的原因,一方面是造成 buffer overflow 漏洞的方式有很多種,另一方面是用于防止 buffer overflow 的技術也容易出錯。

    在一個典型的 buffer overflow 攻擊中,攻擊者將數據傳送到某個程序,程序會將這些數據儲存到一個較小的堆棧緩沖區內。結果,調用堆棧上的信息會被覆蓋,其中包括函數的返回指針。數據會被用來設置返回指針的值,這樣,當該函數返回時,函數的控制權便會轉移給包含在攻擊者數據中的惡意代碼。

    雖然這種類型的堆棧 buffer overflow 在某些平臺和開發組織中十分常見,但仍不乏存在其他各種類型的 buffer overflow,其中包括堆 buffer overflow 和 off-by-one 錯誤等。有關 buffer overflow 如何進行攻擊的詳細信息,許多優秀的著作都進行了相關介紹,如 Building Secure Software[1]、Writing Secure Code[2] 以及 The Shellcoder's Handbook[3]。

    在代碼層上,buffer overflow 漏洞通常會違反程序員的各種假設。C 和 C++ 中的很多內存處理函數都沒有執行邊界檢查,因而可輕易地超出緩沖區所操作的、已分配的邊界。即使是邊界函數(如 strncpy()),使用方式不正確也會引發漏洞。對內存的處理加之有關數據段大小和結構方面所存在種種錯誤假設,是導致大多數 buffer overflow 漏洞產生的根源。

    示例:以下代碼嘗試通過檢查從 getInputLength() 中讀取的不可信的值,驗證其是否小于目標緩沖區 output 的大小,來避免 off-by-one buffer overflow。然而,因為 lenMAX 之間比較的是帶符號的值,所以如果 len 為負值,在其轉換為 memcpy() 不帶符號的參數時,將會變成一個超級大的正數。


    void TypeConvert() {
    char input[MAX];
    char output[MAX];

    fillBuffer(input);
    int len = getInputLength();

    if (len <= MAX) {
    memcpy(output, input, len);
    }
    ...
    }

    REFERENCES

    [1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A5 Buffer Overflow

    [2] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3550 CAT I, APP3590.1 CAT I

    [3] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3550 CAT I, APP3590.1 CAT I

    [4] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) Buffer Overflow

    [5] J. Viega, G. McGraw Building Secure Software Addison-Wesley

    [6] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 195, CWE ID 805

    [7] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.3.1.1

    [8] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.2

    [9] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.5

    [10] Standards Mapping - SANS Top 25 2010 - (SANS 2010) Risky Resource Management - CWE ID 805

    [11] J. Koziol et al. The Shellcoder's Handbook:Discovering and Exploiting Security Holes John Wiley & Sons

    [12] M. Howard, D. LeBlanc Writing Secure Code, Second Edition Microsoft Press


    Copyright 2013 Fortify Software - All rights reserved.
    (Generated from version 2013.1.1.0008 of the Fortify Secure Coding Rulepacks)
    desc.internal.cpp.buffer_overflow_signed_comparison

    97av