buffer overflow Flashcards

(20 cards)

1
Q

what is the text/ code segment in the stack

A

stores the code/ the executable instructions/programme

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

what is the data segment

A

stores the intialised and uninitialised global and static variables
also stores the strings in s&n

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

what is the stack segment

A

data in use, command line arguments , local variables

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

what do we look at specifically in s&n

A

the stack segment

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

what is the difference in memory management in java/python compared to C#

A

python/java
- interpreter/virtual machine takes care of what memory is accessed and when memory is released

C#
- have to do it yourself
- if this is wrong attacker can exploit bug and make application run arbitrary code

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

what is wrong with this code
void getname() {
char buffer[32];
gets(buffer);
printf(“Your name is %s.\n”, buffer);
}
int main(void) {
printf(“Enter your name:” );
getname();
return 0;
}

A

if we managed to write more then the sixe of the buffer (32) it overflows into the surroundings
but return address (saved instruction pointer) is also stored on the stack
Ip controls what is exececuted
and we can write on the stack
basically through this we can released the return address

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

what is a buffer overflow

A

program that writes data to a buffer beyond the intended boundaries

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

what can a buffer overflow be used for

A

overwrite local veriables
overwrite return address
jump to existing code
jump to own code

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

describe shell code in buffer overflows

A

shell code (under Linux) is assembly code for execve(“/bin/sh”, Null , 0)
some defences in modern linux

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

what do we use execve(“/bin/sh”, Null , 0) for

A

some defenses in modern linux , used to indirectly called binary
that first calls setuid(0) and then spawns a shell

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

name all the defenses against
bufferoverflow

A

stack canary
nx bit
ASLR
use memory safe programming language
uses hardware enchanced defenses like CHERI

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

how to defend against buffer overlows using C# code

A

use safe methods that have explicit length arguments
e.g strcpy,strncpy
most unsafe functions have a safe equivalent

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

describe the stack canary defense in buffer overflows

A
  • Intuition: It is hard for Buffer
    Overflows to keep variables
    untouched that are in-between.
  • So, if we add a check with a
    random value and mark it hard
    to guess, we can catch
    overflows.

if (canary != 1526378) {
high address
crash();
}
return;

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

describe the NX Bit defense in buffer overflows

A

intuition:
data/stack should never contain executable code
NX bit provides hadware distinction between Text and Stack
Used to mark non executable areas
program craches if instruction pointer points to a NX marked area

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

describe the NX Bit counterattack

A

reuse code from EXECUTABLE part of memory

jump to another function in program
jump to function from standard C library
String together little pieces of exisiting code

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

describe the return to libc counterattack to NX Bit

A

libc -> standard c library

17
Q

describe the ASLR defence

A

Intuition: To be able to run a successful exploit, you need to know the addresses of functions.
* Address space layout randomization (ASLR)
will add a random offset to the stack and code base each time the program runs.
* Jumps in the program are altered to point to the right line.
* The idea is that its now hard for an attacker to guess the address of where they inject code or the address of particular functions.
* On by default in all OS.

18
Q

what does ASLR mean

A

address space layout randomisation

19
Q

what is the counterattack to ASLR

A

there is a nop slide
big area of nop instruction in front of the code we want to call
increases the chance of guessing correctly
If the stack is 2MB, I could inject
999000 bytes of nop followed by
my shell code.
* I then guess a return address and
hope it is somewhere in the 2MB
of NOPs.
* If it is, the program slides down
the NOPs to my shell code.
* Often used with other methods of
guessing the randomness.

20
Q

what is a nop - slide

A

big area of nop instruction in front of the code we want to call
increases the chance of guessing correctly