WinREV-WriteUp

From
aaaddress1
資安食物不好吃
Compiler
.c -> .exe
- Source.cpp ->
Compiler
-> - Assembly codes ->
Assembler
-> - Object file ->
Linker
-> - Main.exe
Data section
.rdata Section
: push offset -> 從記憶體找到變數內容
.idata Section
: Import address table
Assemble to machine code
.text Section
1 | push 0 ; 6A 00 |
Finish
.data Section
point to.text Section
Demo
1 | $gcc -S hell_world.c ; compile only ,no assemble and linker -> hell_world.s |
COFF File
PE viewer
欄位
- IMAGE_FILE_HEADER
- IMAGE_SECTION_HEADER
… - SECTION
.text
.data
textS_Z6printfPKcz
.rdata
.rdataSzzz
.eh_frames_26printfPKcz
.eh_frame
Visual Studio
查看欄位
Symbol table
顯示欄位中包含的變數
- Strip
gcc -o output_file input_file.c [--strip or -s ]
用於從目標文件中刪除符號表和調試信息。這可以減少目標文件的大小,使其更適合用於部署。
Read COFF
Linker
COFF overview
cat ./a.out
cat ./PE
計算斷點
Star point
= Entry-Point + Image-Base
Process
- CreateProcess
- ChildProcess
File Mapping
- Kernal base module
- To AddressOfEntry
- Stack
- NT Header
- Section Header Array
- Data
Loader -> Section Mapping
NT header from
4000000
, before is stack memory
local variable -> stack
golbal variable -> .data .idata
- Mult threads from Modules
- 每新增一個Thread會創建一個 TEB 在 process 中
執行緒環境塊(Thread Environment Block,TEB)
access from FS segment register when operating on 32 bits ,and from GS in 64 bits
- FS[0] -> ExceptionList
- FS[0x4] -> StackBase
- FS[0x8] -> StackLimit
- FS[0x18] -> 可以拿到整塊TEB的記憶體位置
- FS[0x30] -> PEB
- File mapping 後創建 PEB
- FS[0x30] PEB -> File name/path , Command line下的參數
不論是 .exe 還是 .dll 都是一個 Obj File 的封裝,有 mapping 進不同的module
PEB offset +8 , ImageBaseAddress -> 標示出哪一個 Module 是主要的 (進去之後應該就會看到 MZ , DosHeader)
- main 是對於開發者的入口點
- 在 linking過程中 linker會把一包程式裝在前面,來自
c://windows/sysWOW64/msvcrt.dll
- 使用 cff explorer 可以看到 dll 裡面有什麼東西
- 從 eax的變化就可以大概看出他大概做了什麼
Process Hollowing
- M: My program
- T: Target exe (Have digital sign)
- Maping T
- write_memory 注入到T的記憶體中
- 把T的函數入口點改成M的
Review exe
PE-bear
x64-dbg
- Title: WinREV-WriteUp
- Author: Chihhh Linnn
- Created at : 2024-08-05 14:49:34
- Updated at : 2024-08-05 14:49:34
- Link: https://chihhhs.github.io/2024/08/05/rev-1/
- License: This work is licensed under CC BY-NC-SA 4.0.