W5.2 - Buffer Overflow

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/29

flashcard set

Earn XP

Description and Tags

CS6301

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

30 Terms

1
New cards

What is a buffer overflow vulnerability?

A security flaw where a program writes more data to a buffer than it can hold, causing data to overflow into adjacent memory locations and potentially overwriting critical system information

2
New cards

What are the main memory segments in a program?

• Text Segment: Contains executable code (lowest addresses)
• Data Segment: Contains initialized global variables
• BSS Segment: Contains uninitialized global variables
• Heap: Dynamic memory allocation (grows upward)
• Stack: Function calls and local variables (grows downward from highest addresses)

3
New cards

What is the critical concept about stack growth direction?

The stack grows from high memory addresses to low memory addresses, but arrays within the stack grow from low to high addresses. This opposing growth direction creates the fundamental vulnerability for buffer overflow attacks

4
New cards

What registers are used for stack management in x86 architecture?

• ebp (Extended Base Pointer): Points to the current frame's base
• esp (Extended Stack Pointer): Points to the top of the stack

5
New cards

How are function arguments accessed in x86 stack frames?

Arguments are accessed at positive offsets from ebp:
• First argument: ebp+8
• Second argument: ebp+12
• Return address: ebp+4
• Local variables: negative offsets like ebp-4, ebp-8

6
New cards

What is the structure of a stack frame?

• Function Arguments (higher addresses)
• Return Address
• Previous Frame Pointer (ebp)
• Local Variables (lower addresses)

7
New cards

What makes strcpy() dangerous for buffer security?

strcpy() performs no bounds checking when copying strings. It continues copying until it encounters a null terminator, regardless of the destination buffer size, making it prone to buffer overflows

8
New cards

What happens during a buffer overflow attack?

• Data exceeds allocated buffer space
• Overflow overwrites adjacent memory locations
• Critical stack data gets corrupted (frame pointer, return address)
• Program execution can be redirected to malicious code

9
New cards

What are the two main tasks for exploiting a buffer overflow?

• Task A: Find the offset distance between buffer start and return address
• Task B: Determine the address where shellcode will be placed in memory

10
New cards

How do you find the offset distance using GDB?

Set breakpoint at vulnerable function, print buffer address with 'p &buffer', print frame pointer with 'p $ebp', then calculate offset with 'p $ebp + 4 - &buffer'

11
New cards

What is a NOP sled and why is it used?

A sequence of NOP (No Operation) instructions that do nothing but take up space. Used to increase attack reliability by creating a large target area - execution will slide down the NOPs to reach the actual shellcode

12
New cards

Why can't return addresses contain null bytes?

strcpy() and similar functions treat null bytes as string terminators, so the copy operation would stop prematurely if a null byte is encountered, causing the attack to fail

13
New cards

What is shellcode?

Assembly code designed to launch a shell program (/bin/sh) and provide an attacker with system access, typically executing with the target program's privileges

14
New cards

What system call does shellcode typically use?

The execve() system call to execute /bin/sh with the format: execve("/bin/sh", argv, NULL)

15
New cards

What registers must be set up for the execve() system call?

• eax: System call number (11 for execve)
• ebx: Pointer to program path ("/bin/sh")
• ecx: Pointer to argument array
• edx: Environment pointer (NULL)
• int 0x80: Triggers the system call

16
New cards

How do you avoid null bytes in shellcode?

Use XOR operations to zero registers instead of direct assignment:
• Bad: mov eax, 0x0000000b (contains nulls)
• Good: xorl %eax, %eax

17
New cards

movb $0x0b, %al

18
New cards

What are the four categories of buffer overflow countermeasures?

• Developer approaches: Safe functions and input validation
• OS approaches: Address Space Layout Randomization (ASLR)
• Compiler approaches: Stack Guard/Stack Canaries
• Hardware approaches: Non-Executable Stack (NX bit)

19
New cards

What do safe functions provide that unsafe functions don't?

Safe functions include bounds checking to prevent buffer overflows:
• strcpy() → strncpy() or strlcpy()
• sprintf() → snprintf()
• gets() → fgets()

20
New cards

What is ASLR and how does it work?

Address Space Layout Randomization randomizes the memory layout each time a program runs:
• Stack base address changes on each execution
• Makes it difficult to predict shellcode location
• Can be set to randomize stack only or both stack and heap

21
New cards

What are the ASLR configuration levels?

• Level 0: No randomization
• Level 1: Randomize stack only
• Level 2: Randomize both stack and heap

22
New cards

How can ASLR be defeated?

• Brute force: Repeatedly attempt exploitation until addresses align
• Information disclosure: Leak memory addresses through other vulnerabilities
• Return-to-libc: Use existing code instead of injected shellcode

23
New cards

What is a stack canary?

A secret value placed between local variables and the return address. The program checks if this value has been modified before returning from a function, detecting buffer overflow attempts

24
New cards

How does the stack canary detection work?

• Compiler inserts secret value before function execution
• Value is checked before function returns
• If value has changed, program aborts (stack smashing detected)
• Prevents return address modification from succeeding

25
New cards

What is the NX bit?

The No-eXecute bit is a CPU feature that marks certain memory areas as non-executable, preventing injected shellcode from running on the stack

26
New cards

How can the NX bit protection be bypassed?

• Return-to-libc: Use existing library functions instead of injected code
• ROP (Return-Oriented Programming): Chain existing code snippets
• JIT-ROP: Just-in-time ROP chain construction

27
New cards

What is defense in depth for buffer overflow protection?

A layered security approach:
• Development: Use safe coding practices
• Compilation: Enable all security features
• OS Configuration: Enable ASLR and protections
• Hardware: Utilize NX bit and CPU features

28
New cards

Why do buffer overflow vulnerabilities remain critical today?

• Allow arbitrary code execution
• Enable privilege escalation
• Can bypass security controls
• Provide pathway to complete system compromise
• Legacy systems often remain vulnerable

29
New cards

What is the key principle for secure buffer management?

Never trust user input - always validate buffer boundaries and input lengths before processing any data from external sources

30
New cards

What makes a buffer overflow attack successful?

• Precise offset calculation to reach return address
• Reliable shellcode placement in predictable memory location
• Proper payload construction avoiding null bytes
• Successful redirection of program execution flo

Explore top flashcards

Unit 11: Evolution
Updated 861d ago
flashcards Flashcards (95)
Biology Test 2
Updated 712d ago
flashcards Flashcards (24)
Unit 6 MWH
Updated 993d ago
flashcards Flashcards (28)
CRIM EXAM 2
Updated 733d ago
flashcards Flashcards (113)
Unit 11: Evolution
Updated 861d ago
flashcards Flashcards (95)
Biology Test 2
Updated 712d ago
flashcards Flashcards (24)
Unit 6 MWH
Updated 993d ago
flashcards Flashcards (28)
CRIM EXAM 2
Updated 733d ago
flashcards Flashcards (113)