Heap-Based Attacks and Defences (Lecture 6)

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/35

flashcard set

Earn XP

Description and Tags

36 question-and-answer flashcards covering heap attacks, use-after-free, heap spraying, and the main defensive techniques discussed in Lecture 6.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

36 Terms

1
New cards

What region of memory is used for dynamically allocated data in a program?

The heap.

2
New cards

Which C standard library functions are commonly used to allocate and de-allocate heap memory?

malloc/calloc/realloc for allocation and free for de-allocation.

3
New cards

Name two heap-based control-hijacking attacks introduced in this lecture.

Heap spraying and use-after-free.

4
New cards

How does a simple heap overflow occur in the ‘user / adminuser’ example?

strcpy copies more bytes than allocated for user, overflowing into adminuser’s buffer and altering its data.

5
New cards

In memory layout terms, how do the heap and stack typically grow?

The stack grows downward (toward lower addresses) and the heap grows upward (toward higher addresses).

6
New cards

Why is heap spraying used by attackers?

To fill large areas of the heap with NOP sleds and shellcode so that an overwritten pointer can land reliably anywhere in the spray area.

7
New cards

What is a virtual table (vtable) in C++ and why is it a target for heap exploits?

A compiler-generated table of function pointers; if overwritten, it lets an attacker redirect virtual method calls to malicious code.

8
New cards

Describe the basic sequence of a use-after-free attack.

1) A pointer references heap chunk A. 2) A is freed. 3) A is re-allocated with attacker-controlled data. 4) The stale pointer is used, executing attacker-supplied code or data.

9
New cards

Which IE11 CVE discussed in class demonstrates a use-after-free triggered via form element reset?

CVE-2014-0282.

10
New cards

What common design mistake underlies many control-hijacking vulnerabilities?

Mixing data and control information in the same memory region.

11
New cards

List three general strategies to prevent control hijacking mentioned in the lecture.

1) Fix bugs through safe coding and audits, 2) Platform defences to block code execution, 3) Harden executables to detect tampering (e.g., canaries, shadow stacks).

12
New cards

What does DEP/NX do?

Marks pages such as stack or heap as non-executable to prevent injected code from running.

13
New cards

Which hardware bits are used to mark pages non-executable on AMD64, Intel x86, and ARM?

NX-bit (AMD64), XD-bit (Intel), XN-bit (ARM).

14
New cards

Why can Return-Oriented Programming (ROP) bypass DEP?

Because ROP reuses existing executable code snippets (gadgets) instead of injecting new code into non-executable regions.

15
New cards

What is Address Space Layout Randomisation (ASLR)?

A defence that randomises the base addresses of code, stacks, heaps, and libraries on each run so attackers cannot predict where code resides.

16
New cards

How many bits of randomness does Windows 8+ provide for ASLR on 64-bit processors?

24 bits.

17
New cards

What is a stack canary in StackGuard?

A secret value placed before the return address; if it changes when the function returns, the program aborts, signalling a stack smash.

18
New cards

Name two types of stack canaries and their key difference.

Random canary (random value per run) and terminator canary ({0, newline, linefeed, EOF} to stop string copies).

19
New cards

Which GCC option inserts stack canaries?

-fstack-protector (or -fstack-protector-all).

20
New cards

Which linker flag on Windows produces a table of safe structured exception handlers?

/SAFESEH.

21
New cards

What is SEHOP and what problem does it address?

Structured Exception Handler Overwrite Protection; it ensures the SEH chain is intact to block attacks that overwrite exception handler pointers before canaries are checked.

22
New cards

Why are canaries not fool-proof? Give one reason.

Some attacks (e.g., heap overflows, integer overflows, SEH overwrites) can hijack control without altering the canary.

23
New cards

How can a crashing program unintentionally leak a canary value?

If the process is automatically restarted (forked) without re-randomising the canary, attackers can brute-force the canary byte-by-byte via repeated crashes.

24
New cards

What is a shadow stack and how does it defend against control-flow hijacking?

A protected copy of return addresses; on a function return, the CPU compares the real return address to the shadow copy and aborts on mismatch.

25
New cards

Which Intel technology natively supports shadow stacks?

Intel CET (Control-flow Enforcement Technology).

26
New cards

Explain how memory tagging can prevent both buffer overflows and use-after-free.

Each memory chunk and pointer carries a tag; on access, tags must match, so out-of-bounds or stale pointers cause a tag mismatch exception.

27
New cards

What is the goal of Control Flow Integrity (CFI)?

To ensure every indirect branch or call targets only legitimate locations defined by the program’s control-flow graph.

28
New cards

What is Control Flow Guard (CFG) in Windows and what does it check?

A coarse CFI implementation that ensures indirect calls target valid function entry points marked in a bitmap.

29
New cards

Give two limitations of coarse CFI mechanisms like CFG or BTI.

1) They allow jumps to any valid but possibly unintended function, 2) Static analysis may miss valid targets, causing false positives or negatives.

30
New cards

Name two safe C library functions recommended over their insecure counterparts.

fgets instead of gets, and strncpy instead of strcpy.

31
New cards

What classic attack bypasses DEP by re-using existing library code rather than injecting new code?

Return-to-libc (or more broadly, Return-Oriented Programming).

32
New cards

How does /NXCOMPAT relate to DEP on Windows?

It is a linker flag indicating the binary is compatible with DEP (no need for executable stack/heap).

33
New cards

What are GS Cookies in Windows?

Microsoft’s implementation of stack canaries inserted by the compiler to detect stack buffer overflows.

34
New cards

Why might some applications legitimately require an executable heap despite DEP?

Just-In-Time (JIT) compilers need to generate and execute code at runtime, which requires write-and-execute permissions.

35
New cards

During heap spraying, what is the purpose of the NOP sled?

To create a large landing zone so that an imprecise jump into the sprayed area will slide down the NOPs into the actual shellcode.

36
New cards

What Windows platform defence verifies the presence of a dummy SEH record during exception dispatch?

SEHOP (Structured Exception Handler Overwrite Protection).