Posts

Showing posts from April, 2015

Windows安全 之 向量化異常處理機制(Vectored Exception Handling, VEH) 之Hook

Image
本文需讀者具備基礎的匯編知識,調用約定知識, 以及基本逆向概念 提到Windows異常處理機制, 可分兩大類, 一類是向量化異常處理(VEH), 一類是結構化異常處理(Structured Exception Handling, SEH), 由於在Windows中, VEH 是除雙機調試及調試器外, 最優先處理的函數, 因此本文先集中解釋VEH 很多人編程時都不會使用異常機制, 因為當正常運行時, 異常根本沒有作出任何用途。 但當異常出現在我們預計之內, 異常處理函數就變得十分強大。 本文分兩大部份 1. 硬件斷點 2. VEH的使用與分析 1. 硬件斷點 這個在網上很多文章講得十分詳盡, 我這裡輕輕帶過。 每個線程中, 都有自己一套的CPU寄存器, 稱為上下文(CONTEXT) 結構如下: typedef struct _CONTEXT { // // The flags values within this flag control the contents of // a CONTEXT record. // // If the context record is used as an input parameter, then // for each portion of the context record controlled by a flag // whose value is set, it is assumed that that portion of the // context record contains valid context. If the context record // is being used to modify a threads context, then only that // portion of the threads context will be modified. // // If the context record is used as an IN OUT parameter to capture // the context of a thread, then only those portions of the thread's // context