2018-10-07 PWN 笔记

https://zhuanlan.zhihu.com/p/25892385

栈溢出

栈溢出的四种利用形式

1 利用溢出执行溢出的攻击指令

2 利用溢出执行内存中的函数

3 利用溢出执行内存中的指令片段集

4 利用溢出把被调用函数的地址只向指定函数

1 2 方式的前提条件为内存函数地址随机化关闭

3 4 可绕过随机化,方式是利用动态链接库里两个函数的相对位置固定,已知一个函数A的位置和第二个函数B与A的相对位移后,可算出B在动态链接库的绝对位置

基础:函数调用中栈的变化

-参数

-eip(返回后的下一条指令)

-ebp

-局部变量

-esp

一段函数调用的汇编语言:

.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

你可能感兴趣的:(2018-10-07 PWN 笔记)