顯示具有 漏洞分析 標籤的文章。 顯示所有文章
顯示具有 漏洞分析 標籤的文章。 顯示所有文章

2008年2月23日 星期六

Protect your program from Security Holes

原文作者為 scott at santafe dot edu
常見的系統、程式安全漏洞,大致上可包含幾種情況:
http://www.undergroundnews.com/kbase/underground/hacking/
findhole.htm

1. 有瑕疵的 SUID/SGID 程式(特別是包含 gets(),sprintf(),
strcpy(),system(), popen(),execlp(),execvp() 等函式的
程式),例如 sendmail, httpd ,imapd ,samba 等 suid to
0 的瑕疵程式都可能被用來獲取系統 root 權限,或是
sgid to mail 的瑕疵程式可能被用來讀取他人信件(filter
in elm package),或是允許 shell escape 的程式。

2. 程式接收非(設計師/使用者)預期的輸入值。
( eg. Buffer overflow, delimiter problem, shell
escape, format string, directory traversal, path
disclosure, css, csrf, sql injection )

( ref: shellcode, ';', ':', "\!", "..", '%', '<', '>',
"<", ">", "\r" CR, "\n", LF, 或以其他編碼方式表現以上字元)

3. (Kernel)Race condition.
比如會用到暫存檔的程式,在開啟暫存檔之前,我們可以先預測暫
存檔的檔名,在程式存取之前 "先" 生出這個檔給他去存取,而這
個我們先的概念就是 "race" 的由來,當我們能比正常程序搶先一
步產生檔案,那這個檔案就可以用來覆蓋或是塞資料進去想要改變
的檔案
(ex: symbolic link, tmp file, 利用紅燈間隙闖越馬路或迴轉)

4. (Kernel)Device driver bug.

5. DoS. (Denial of Service)
系統資源的佔用,如記憶體(memory leak),硬碟空間,
process(fork bomb)
( ref: malloc bomb, memory leak, Intel Pentium f00f bug,
land:same ip ports, teardrop by route,ip fragmentation,
nestea, jolt, ping of death,bonk, jolt2 )

6. Secrecy revealed. (eg. cookie, screenshot、
%xwd > filename &)

7. Naming prediction problem.
Symbolic links in /tmp to be appended/overwritten (會被用
來修改、覆蓋可預期檔名的檔案)
( ref: race condition, tmpnam() )
hotmail email url predictable and email content exposing.

8. 病毒、木馬程式 (Trojans)、被修改過的常用工具程式
( ref: Elk cloner, Staog, Bliss, rootkit, logic bomb,
time bomb )




How to avoid , defeat security breaches ?
 Secure UNIX Programming FAQ

How to write secure code.


1. SUID/SGID 等瑕疵程式問題:
==> 寫程式時,即避免使用會有問題的函式,或者在使用較易出問
題的函式時預先處理好傳入的參數、資料。
(ref: 程式碼稽核軟體 rats, flawfinder, its4)

2. 程式接收非預期的輸入值:
==> 在接收任何輸入值前,做好資料的偵錯步驟,其中包括資料長
度的確認,資料是否是合法字元的確認。
(ref: 程式碼稽核軟體 rats, flawfinder, its4)

3. Race condition:
==> 在執行 critical section 的時候,須以各種 locking 方法
確保沒有其他程式能同時存取重要的資料。盡量不在
public /tmp 存取暫存檔案,考慮 /usr/tmp, home 目錄等其他
使用者無使用權限的目錄。使用更嚴謹的亂數暫存檔函式,不要
只用 getpid() 等容易遭到窮舉法攻擊的簡易參數。
(ref: atomic operation, mutual exclusive, bounded waiting,
spinlock, semaphore, disable interrupt, Bakery algorithm)

4. Device driver bug:
==> 盡量以外掛模組方式載入 driver,如此在出問題時較有機會
以移除模組的方式避免安全問題或主機死當。

5. DoS. (Denial of Service):
==> 對於任何電腦資源的使用必須設定上限,例如 process 數目
,硬碟 quota 限制,同時接受(同一來源、使用者)連線的數目
(application layer, tcp udp layer, ip layer...etc),使用
memory garbage collection library, 利用程式語言的
assertion 驗證 program memory resource(stack, heap),對於
使用者來說程式的漏洞、暇疵造成的阻斷服務問題,只有勤加修
補更新程式版本。

6. Secrecy revealed:
==> 程式設計師在使用資源內定的權限時,必須限定預設的權限
大小,以免使用者在使用時不自覺的洩漏資料。

7. Naming prediction problem:
Symbolic links in /tmp problem
hotmail email url predictable and email content exposing.
==> 使用暫存檔案時,必須使用不可預測的檔名,以免資料
外洩、損毀。存取暫存檔時,加上確認檔案為執行程式擁有者的
檢查碼。(ref:race condition, mktemp(), mkstemp())

==> 使用網頁參數當作信件、文件儲存時,必須使用無法預測的、
不重複使用的參數序號產生方法,以避免遭到猜測或窮舉法攻破,
對於存取文件的 URL 參數序號使用也要設定有效時間,當過久未
使用或動作,即自動取消該 URL 參數的有效性。
(ref: md5, /dev/random, /dev/urandom, timeout,
force reload, cookie)

8. Trojans:
==> 使用木馬偵測軟體、網路掃描軟體、掃毒軟體或可確認程式
檔案完整性的軟體,做自身主機的安全檢查。
(ref: md5 signatures, Trusted systems)
(ref: multi-security-level, no read up/no write down)