• Aucun résultat trouvé

Sécurité des logiciels

N/A
N/A
Protected

Academic year: 2022

Partager "Sécurité des logiciels"

Copied!
33
0
0

Texte intégral

(1)

1

Sécurité des logiciels

Assembly language, part 3

Samuel Thibault <samuel.thibault@u-bordeaux.fr>

Pieces from Emmanuel Fleury <emmanuel.fleury@u-bordeaux.fr>

CC-BY-NC-SA

(2)

2

Indirect memory accesses

(3)

3

Memory accesses

int i = 42;

int j = 43;

main() { i = 1;

j = i;

j++;

}

i: .long 42 j: .long 43

main:

movl $1, i movl i, j

movl i, %eax movl %eax, j incl j

ret

i

j

(4)

4

Indirect memory accesses

int i = 42;

main() { i = 1;

int *x = &i;

*x = 0;

(*x)++;

}

i: .long 42

main:

movl $1, i

movl $i, %eax movl $0, (%eax) incl (%eax)

ret

i

(5)

5

Indirect memory accesses

int i = 42;

int *x;

main() { i = 1;

x = &i;

*x = 0;

(*x)++;

}

i: .long 42 x: .long 0 main:

movl $1, i movl $i, x movl $0, (x) movl x, %eax

movl $0, (%eax) incl (%eax)

ret

i

x

(6)

6

Indirect memory accesses

int t[2] = {1,2};

main() {

t[0] = 3;

t[1] = 4;

int *x = &t[1];

*x = 0;

(*x)++;

}

t: .long 1 .long 2

main:

movl $3, t movl $4, t+4

movl $t+4, %eax movl $0, (%eax) incl (%eax)

ret

t

(7)

7

Indirect memory accesses

struct { int x;

int y;

} a = {.x = 1, .y = 2};

main() { a.x = 3;

a.y = 4;

int *x = &a.y;

*x = 0;

(*x)++;

}

a: .long 1 .long 2

main:

movl $3, a movl $4, a+4

movl $a+4, %eax movl $0, (%eax) incl (%eax)

ret

a x y

(8)

8

Indirect memory accesses

int i = 42, j = 43;

int *x;

int **z;

main() { x = &i;

z = &x;

[...]

*z = &j;

}

i:.long 42 j:.long 43 x:.long 0 z:.long 0 main:

movl $i, x movl $x, z [...]

movl z, %eax

movl $j, (%eax) ret

i j x z

(9)

9

Indirect memory accesses

struct foo{

int x;

int y;

} a = {.x = 1, .y = 2};

struct foo *b = ...;

main() {

b->x = 41;

b->y = 42;

b->y++;

}

a: .long 1 .long 2

b: .long ...

main:

movl b, %eax

movl $41, 0(%eax) movl $42, 4(%eax) incl 4(%eax)

ret

a x y

(10)

10

Indirect memory accesses

int t[10] = {0};

int *x = ...;

int i = ...;

main() { int *p;

t[i] = 41;

x[2] = 42;

x[i] = 43;

x[1]++;

p = &t[i];

p = &x[i];

}

t: .long 0 ...

x: .long ...

i: .long ...

main:

movl x, %eax movl i, %ebx

movl $41, t(%ebx,4) movl $42, 8(%eax)

movl $42, (%eax,%ebx,4) incl 4(%eax)

leal t(%ebx,4), %ecx

leal (%eax,%ebx,4), %ecx ret

t

x i

(11)

11

Stack

(12)

12

Stack

LIFO (Last In First Out)

push

pop

pushl $1 pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(13)

13

Stack

LIFO (Last In First Out)

push

pop

pushl $1 pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp 0x1000 1

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(14)

14

Stack

LIFO (Last In First Out)

push

pop

pushl $1 pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 2 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(15)

15

Stack

LIFO (Last In First Out)

push

pop

pushl $1 pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(16)

16

Stack

LIFO (Last In First Out)

push

pop

pushl $1 pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 2 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(17)

17

Stack

LIFO (Last In First Out)

push

pop

pushl $1 pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp 0x1000 1

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(18)

18

Stack

LIFO (Last In First Out)

push

pop

pushl $1 pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 333 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(19)

19

0 0 0 0 0 0 0 ...

Stack

For real

initially 0 memory

no cleanup pushl $1

pushl $2 pushl $42 popl %eax popl %eax pushl $333

0x1000 esp

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(20)

20

0 0 0 0 0 0 0 ...

Stack

For real

initially 0 memory

no cleanup pushl $1

pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp 0x1000 1

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(21)

21

0 0 0 0 0 0 0 ...

Stack

For real

initially 0 memory

no cleanup pushl $1

pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 2 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(22)

22

0 0 0 0 0 0 0 ...

Stack

For real

initially 0 memory

no cleanup pushl $1

pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(23)

23

0 0 42

0 0 0 0 ...

Stack

For real

initially 0 memory

no cleanup pushl $1

pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 2 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

eax: 42

(24)

24

0 2 42

0 0 0 0 ...

Stack

For real

initially 0 memory

no cleanup pushl $1

pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp 0x1000 1

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

eax: 2

(25)

25

0 0 42

0 0 0 0 ...

Stack

For real

initially 0 memory

no cleanup pushl $1

pushl $2 pushl $42 popl %eax popl %eax pushl $333

esp

1 333 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

eax: 2

(26)

26

Indirect indexing

From there

movl %esp, %eax -> 0xff4

movl (%esp),%eax -> 42

movl 4(%esp),%eax -> 2

movl -4(%esp),%eax

-> 0 # but not supposed # to access here!

0 0 0 0 0 0 0 ...

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(27)

27

Indirect indexing

I.e.

pushl $333

<=>

subl $4,%esp

movl $333,(%esp)

0 0 0 0 0 0 0 ...

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(28)

28

Indirect indexing

I.e.

pushl $333

<=>

subl $4,%esp

movl $333,(%esp)

0 0 0 0 0 0 0 ...

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(29)

29

Indirect indexing

I.e.

pushl $333

<=>

subl $4,%esp

movl $333,(%esp)

0 0 0

0 0 0 ...

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

333

(30)

30

Indirect indexing

I.e.

popl %eax

<=>

movl (%esp),%eax addl $4,%esp

0 0 0 0 0 0 0 ...

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

(31)

31

Indirect indexing

I.e.

popl %eax

<=>

movl (%esp),%eax addl $4,%esp

0 0 0 0 0 0 0 ...

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

eax: 42

(32)

32

Indirect indexing

I.e.

popl %eax

<=>

movl (%esp),%eax addl $4,%esp

0 0 0 0 0 0 0 ...

esp

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

eax: 42

(33)

33

Indirect indexing

And with ebp

movl %ebp, %eax -> 0xff8

movl (%ebp),%eax -> 2

movl 4(%ebp),%eax -> 1

movl -4(%ebp),%eax -> 42

esp ebp

0 0 0 0 0 0 0 ...

1 2 42 0x1000

0x0ffc 0x0ff8 0x0ff4 0x0ff0 0x0fec 0x0fe8 0x0fe4

...

Références

Documents relatifs

Cynthia Fleury nous parler ce soir du transhumanisme sous un angle philosophique et humaniste?. Bibliographie indica ve autour du thème du

Most failing radial arterial catheters had no luminal obstruction, but were associated with an intravascular thrombosis located in front of the catheter tip?. The sever- ity

Cette intrigue, si légère en elle-même, eut cepen- dant des résultats assez notables ; elle refroidit mon zèle pour l'état ecclé- siastique ; je fus ébranlé dans ma vocation et

Samedi 12 octobre 2019, de 10h à 12h Auditoire E (Forum, Campus Plaine). Ø  Entrée: 5 €, gratuit pour les étudiants et les

IPP double dose 1-2 mois puis Protocole planimétrique Haut grade. Endoscopie

Un homme peut, à la rigueur, personnellement et, même alors, seulement pour quelque temps, retarder les Lumières dans ce qu’il a l’obligation de savoir ; mais y

Macron har fått brett stöd från flera håll, bland annat François Bayrou från Demokratiska rörelsen (MoDem), Europa- parlamentarikern Daniel Cohn-Bendit, ekologen François de Rugy

Autour de sa maison, il avait créé comme un petit jardin bo- tanique, où,il était fier de posséder un certain nombre de plantes les plus rares du Valais, qu'il rapportait de