Weeks 1-2: Binary Analysis Flashcards

1
Q

What is the key differences between x86 and x64?

A

Addresses in x64 are twice as long.

In x86, arguments are past on the stack.
In x64, first 6 arguments are past in registers (e.g. rax, rcx, XMM0 for floating points).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the x64 architecture?

A

LOW ADDRESS
Text (program code)
Data Heap (longer lived data - static vars, strings etc)
Free Memory
Stack (data in use by functions, env vars, etc)
HIGH ADDRESS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are some registers in x64 architecture?

A

RAX - accumulator: primary work register, function return results
RIP - next command to ex
RSP - top of stack
RBP - bottom of stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the calling conventions for functions in x64?

A

1 -> (first six) Arguments put in registers (RDI, RSI, etc)
2 -> Old RIP written to stack, RIP updated.
4 -> Old RBP stored on stack for function return.
5 -> RBP = RSP.
5 -> Results return in RAX and RDX.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are executable files?

A
  • Packages up assembly with info the OS needs to run it.
  • Includes entry point to code, required libraries and links to important functions.

Linux: ELF
Mac: Mach-O
Windows: PE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain Buffer Overflows on x86 machines?

A

Instruction pointer stored on stack.
If program does not check input length, can overwrite.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain the NX-bit defense?

A

Provides hardware distinction between text and stack.
Program will crash if EIP ever points to stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain ASLR?

A

Adds random offset to stack base on each run of the program.
Jumps in program are altered to point to right line.

Now much harder to guess adress of functions + where to inject code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain Stack Canaries/Stack Protection?

A

At the start of a function a random value from heap is written to the base of the stack.
When function finishes the value on the stack is checked against the value on the heap.

Any overwrite attempts will lead to a mismatch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can the NX-bit be bypassed?

A

Re-use code from executable part of memory.
These include functions from main binary or from any loaded libraries.
Can just to any point in function, not just the start.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain return-to-libc attacks?

A

Lots of useful functions in standard C library (e.g. “system” that runs any command) which is almost always loaded.
Memory map tells you where they are loaded.
Find function offsets in IDA.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain ROP attacks?

A

Can queue up instruction pointers on stack and execute any number of code segments one after another.

In x64: must load arg /bin/sh to RDI prior, calls to libc must make stack end in 0 - bytes alligned in groups of 16.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What attacks are possible against ASLR/Stack Canaries?

A

Brute forcing may be possible on 32-bit, not 64-bit.
Stack canaries only protect instruction pointer, can overwrite other values.

Heap overflow lets us overwrite data below it on the heap (mem alloc errors).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain Memory Allocation Vunerabilites?

A

Copying to/reading allocated memory with incorrect bound can overflow/learn heap memory.
Incorrect allocation can also lead to vunerabilities.

E.g: Use after free.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain Use-After-Free attacks?

A

malloc->use->free->use

After free, data remains in memory so program may work.
However other data may be allocated in its place.
If attacker controls new data they can control old data too.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Explain Double-Free attacks?

A

malloc->free->free

Address gets added to list of free addresses twice.

Attacker can allocate variable which points to same address as important info.

17
Q

What information leaks make attacking a program easier, and how are they possible?

A

ASLR -> Stack and code offset.
Canary -> Canary value.

  • Memory copy/read, if attacker controls size param. in memcpy.
  • CPU side channels.
  • Format string vunerabilites.
18
Q

Explain String-Format vunerabilities?

A

If number of %s does not match number of args, values inside registers will be printed.

If attacker can control string being printed, they can look on the stack to find addresses and the stack canary.