# Reverse Class 3
## IDA小知識
* ALT + M : 可標註 mark
* Ctrl + M : 可查看 mark
* structure 結構 Ctrl + R:可更改 address 顯示方式,可透過 RVA 直接到該位置
## Structured Exception Handling (SEH in x86-64)
* 微軟在 C/C++ 上的擴充功能,用來處理 Exception
* 在x86 和 x86-64上不同
* 透過查看 UNWIND_INFO 定義 SCOPE_RECORD
* SCOPE_RECORD
* BeginAddress
* EndAddress
* HandlerAddress
* -1 : 恢復 context,回到觸發 exception 的地方繼續執行
* 0 : FINALLYHANDLER -> continue,不執行 handler
* 1 : 為 try-except,執行 handler
* JumpTarget

## Base Relocation
* 若相同的 image 被 load 到同一個 ImageBase,則需要做 Relocation

* Demo

## Asynchronous Procedure Call(APC)
## TLS Callback
* thread 會在 `entry point 之前`執行的 callback function
AKA 在執行 main 之前呼叫

## 工具介紹
* [System Informer(LATEST) (Process Hacker(OLDEST))](https://github.com/winsiderss/systeminformer)
* 功能較多之`工作管理員`
* [API Monitor](http://www.rohitab.com/apimonitor)
* 可觀察 API 之呼叫資訊
* Call stack
* Parameter
* 設定斷點
## Process Injection
* 將程式碼注入目標 Process 中,讓其作一些事情,常被惡意程式用來隱藏 payload
* Injection 手法
* DLL Injection
* Target :
1. 將 DLL 路徑注入目標 Process 的 memory 中
2. 想辦法讓目標 Process 載入 dll 並執行 DLLMain
* 如何取得 LoadLibrary 位置?
* ALL Processes 的 kernel32.dll 在記憶體中的位置皆相同,而 LoadLibrary 會在 kernel32.dll 內部,因此 LoadLibrary 位置也是固定的 -> 從當前 Process 取
* 常用 API : VirtualAlloc, WriteProcessMemory, GetModuleHandle, LoadLibrary,GetProcAddress, CreateRemoteThread
* APC Injection
* Target :
1. 不使用 CreateRemotedThread API 的注入方式,由於其實在太可疑
2. 找一個很多 Thread 之 Process 作為注入目標,然後替所有 Thread 註冊 APC callback function,因 Thread 很多個,因此容易被執行,此作法偏向硬體層面
* 常用 API : OpenProcess, VirtualAlloc, WriteProcessMemory, QueueUserAPC
* [Early Bird APC Injection](https://www.youtube.com/watch?v=_sI76NLPMjI)
* Target : Better than APC Injection,可穩定觸發 APC Callback,作法為自己建立一個 Thread,並在一開始幫其註冊 APC
* 常用 API : VirtualAlloc, WriteProcessMemory, GetModuleHandle, LoadLibrary,GetProcAddress, QueueUserAPC
* [Process Hollowing](https://github.com/adamhlt/Process-Hollowing)
* Target : 建立一個正常的 Process,將其 Memory 改成實際想執行的程式
* 常用 API : CreateProcess, VirtualAlloc, WriteProcessMemory,NtUnmapViewOfSection,NtQueryInformationProcess
* Reflective DLL Injection
* Target : 將 dll 寫入 Remote Process Memory,再寫入 RemoteLibraryLoader(載入dll,並執行 DLLMain),並想辦法使其被執行