https://zhuanlan.zhihu.com/p/25892385
棧溢出
棧溢出的四種利用形式
1 利用溢出執(zhí)行溢出的攻擊指令
2 利用溢出執(zhí)行內(nèi)存中的函數(shù)
3 利用溢出執(zhí)行內(nèi)存中的指令片段集
4 利用溢出把被調(diào)用函數(shù)的地址只向指定函數(shù)
1 2 方式的前提條件為內(nèi)存函數(shù)地址隨機化關(guān)閉
3 4 可繞過隨機化,方式是利用動態(tài)鏈接庫里兩個函數(shù)的相對位置固定,已知一個函數(shù)A的位置和第二個函數(shù)B與A的相對位移后窄俏,可算出B在動態(tài)鏈接庫的絕對位置
基礎(chǔ):函數(shù)調(diào)用中棧的變化
-參數(shù)
-eip(返回后的下一條指令)
-ebp
-局部變量
-esp
一段函數(shù)調(diào)用的匯編語言:
.486? //指明指令集
.MODEL FLAT? //程序工作模式
.CODE
PUBLIC _myFunc
_myFunc PROC
? ; Subroutine Prologue
? push ebp? ? ; Save the old base pointer value.
? mov ebp, esp ; Set the new base pointer value.
? sub esp, 4? ; Make room for one 4-byte local variable.
? push edi? ? ; Save the values of registers that the function
? push esi? ? ; will modify. This function uses EDI and ESI.
? ; (no need to save EBX, EBP, or ESP)
? ; Subroutine Body
? mov eax, [ebp+8]? ; Move value of parameter 1 into EAX
? mov esi, [ebp+12]? ; Move value of parameter 2 into ESI
? mov edi, [ebp+16]? ; Move value of parameter 3 into EDI
? mov [ebp-4], edi? ; Move EDI into the local variable
? add [ebp-4], esi? ; Add ESI into the local variable
? add eax, [ebp-4]? ; Add the contents of the local variable
? ? ? ? ? ? ? ? ? ? ; into EAX (final result)
? ; Subroutine Epilogue
? pop esi? ? ? ; Recover register values
? pop? edi
? mov esp, ebp ; Deallocate local variables
? pop ebp ; Restore the caller's base pointer value
? ret
_myFunc ENDP
END