Software Security 01

» 2022_SUMMER

Week 1

✅ Low-Level Security

  • buffer overflow

✅ Memory Layout

  • memory layout refresher

🟢 Stack and functions: Summary

  • Calling functionL
  1. push arguments onto the stack (in reverse)
  2. push the return address
  3. jump to the function’s address
  • Called function:
  1. push the old frame pointer onto the stack (%ebp)
  2. set frame pointer (%ebp) to where the end of the stack is right now (%esp)
  3. push local variables onto the stack <– Code Injection!
  • Returning function:
  1. reset the previous stack pointer: %esp = %ebp, %ebp = (%ebp)
  2. jump back to return address: %eip = 4(%esp)

✅ Buffer Overflow

✅ Code Injection

✅ Other Memory Exploits

  • Integer overflow
  • Read overflow

Ex) Heartbleed bug:

SSL 프로토콜의 heartbeat 기능 구현 시, 클라이언트는 heartbeat message를 서버로 전송, 서버에게 연결이 아직 유효함을 확인하는 회신 요구… heartbeat message는 message를 되돌려보내기 위해 메시지의 길이 가리키는 필드 포함, SSL 서버의 버그는 길이가 정확한지 확인하지 못해(실제로 그 길이는 자체보다 더 길 수 있어)… 공격자는 길이를 길게 지정하여 버그 포함하는 서버가 메시지 포함하는 버퍼 초과하여 읽도록 할 수 있어, 가까운 메모리에 무엇이 있었던지 리턴. overflow 이전의 서버 활동에 따라 가까운 메모리는 공격자의 관심을 끄는 사항 포함 할 수ㅇㅇ (암호화 키, 서버 특유의 기타 항목)

  • Stale memory : Dangling Pointer

포인터가 프리 상태가 되었는데, 프로그램이 이를 계속 사용할 때..

공격자는 프리 상태가 된 메모리가 재할당되도록 만들 수 있어, 해당 메모리 제어 가능.

struct foo {int (*cmp)(char*, char*);};
struct foo *p = malloc(...);
free(p);
...
q = malloc(...) // reuses memory
*q = 0xdeadbeef; // attacker control
...
p -> cmp("hello", "hello"); //dangling ptr