• No results found

Lab_6_BufferOverflow.pdf

N/A
N/A
Protected

Academic year: 2020

Share "Lab_6_BufferOverflow.pdf"

Copied!
21
0
0

Loading.... (view fulltext now)

Full text

(1)

Security Testing

Laboratory

Emanuele Viglianisi

Security&Trust Research Unit

Fondazione Bruno Kessler

(2)

Agenda

Solve Homework-5

Call stack example

Exercises

(3)

Homework-5

Homework-5:

1. Download the code from

https://github.com/emavgl/sectestlab_2019/tree/master

/lab_5/homework-5

2. Exploit Integer Overflow vulnerability in order to buy the

iPhone for free.

(4)

Call Stack

When you call a function, the system sets

aside space in memory for that function to do

its necessary work.

-

We call such chunks of memory stack

(5)

Call Stack

When you call a function, the system sets

aside space in memory for that function to do

its necessary work.

-

We call such chunks of memory stack

frames

(6)

Call Stack

When you call a function, the system sets

aside space in memory for that function to do

its necessary work.

-

We call such chunks of memory stack

frames

(7)

Call Stack

When you call a function, the system sets

aside space in memory for that function to do

its necessary work.

-

We call such chunks of memory stack

frames

(8)

Call Stack

#include <stdio.h>

int foo1(int a, int b) { int c = a + b;

return c; }

int main() {

foo1(1, 2); return 0; }

Registries:

(9)

Call Stack

#include <stdio.h>

int foo1(int a, int b) { int c = a + b;

return c; }

int main() {

foo1(1, 2); return 0; }

Registries:

-

ESP: points to the last thing pushed on the stack

-

EIP: points to the next instruction to execute

-

EBP: address of the frame’s base

CALL <addr>

pushes the current value of EIP and changes

EIP to <addr>

(10)

Call Stack

// Main's code // ...

0x00000531 <+13>: push $0x2 0x00000533 <+15>: push $0x1

0x00000535 <+17>: call 0x4ed <foo1>

0x0000053a <+22>: add $0x8,%esp

0x00000

ESP

EBP

int main() {

foo1(1, 2);

(11)

Calling foo1

// Main's code // ...

0x00000531 <+13>: push $0x2

0x00000533 <+15>: push $0x1

0x00000535 <+17>: call 0x4ed <foo1>

0x0000053a <+22>: add $0x8,%esp

0x00000

2

ESP

EIP

int main() {

foo1(1, 2);

(12)

Calling foo1

// Main's code // ...

0x00000531 <+13>: push $0x2

0x00000533 <+15>: push $0x1

0x00000535 <+17>: call 0x4ed <foo1>

0x0000053a <+22>: add $0x8,%esp

0x00000

2

ESP

EIP

1

EBP

int main() {

foo1(1, 2);

(13)

Calling foo1

// Main's code // ...

0x00000531 <+13>: push $0x2 0x00000533 <+15>: push $0x1

0x00000535 <+17>: call 0x4ed <foo1> 0x0000053a <+22>: ...

0x00000

2

ESP

EIP

1

<return-addr>

0x0...53a

EBP

int main() {

foo1(1, 2);

(14)

Calling foo1

int foo1(int a, int b) { int c = a + b;

return c; }

// Foo1's code // ...

0x00000504 <+0>: push %ebp

0x00000505 <+1>: mov %esp,%ebp

0x00000514 <+16>: mov 0x8(%ebp),%edx

0x00000517 <+19>: mov 0xc(%ebp),%eax

0x0000051a <+22>: add %edx,%eax

0x0000051c <+24>: mov %eax,-0x4(%ebp)

0x0000051f <+27>: mov -0x4(%ebp),%eax

0x00000522 <+30>: leave

0x00000523 <+31>: ret

0x00000

2

ESP

EIP

1

<return-addr>

0x0...53a

EBP

(15)

Calling foo1

int foo1(int a, int b) { int c = a + b;

return c; }

// Foo1's code // ...

0x00000504 <+0>: push %ebp

0x00000505 <+1>: mov %esp,%ebp

0x00000514 <+16>: mov 0x8(%ebp),%edx

0x00000517 <+19>: mov 0xc(%ebp),%eax

0x0000051a <+22>: add %edx,%eax

0x0000051c <+24>: mov %eax,-0x4(%ebp)

0x0000051f <+27>: mov -0x4(%ebp),%eax

0x00000522 <+30>: leave

0x00000523 <+31>: ret

0x00000

2

ESP

EIP

1

<return-addr>

0x0...53a

(16)

Calling foo1

int foo1(int a, int b) { int c = a + b;

return c; }

// Foo1's code // ...

0x00000504 <+0>: push %ebp

0x00000505 <+1>: mov %esp,%ebp

0x00000514 <+16>: mov 0x8(%ebp),%edx

0x00000517 <+19>: mov 0xc(%ebp),%eax 0x0000051a <+22>: add %edx,%eax

0x0000051c <+24>: mov %eax,-0x4(%ebp)

0x0000051f <+27>: mov -0x4(%ebp),%eax

0x00000522 <+30>: leave

0x00000523 <+31>: ret

0x00000

2

ESP

EIP

1

<return-addr>

0x0...53a

<old-ebp>

EBP

EBP + 8

EDX

(17)

Calling foo1

int foo1(int a, int b) { int c = a + b;

return c; }

// Foo1's code // ...

0x00000504 <+0>: push %ebp

0x00000505 <+1>: mov %esp,%ebp

0x00000514 <+16>: mov 0x8(%ebp),%edx

0x00000517 <+19>: mov 0xc(%ebp),%eax

0x0000051a <+22>: add %edx,%eax

0x0000051c <+24>: mov %eax,-0x4(%ebp)

0x0000051f <+27>: mov -0x4(%ebp),%eax

0x00000522 <+30>: leave

0x00000523 <+31>: ret

0x00000

2

ESP

EIP

1

<return-addr>

0x0...53a

<old-ebp>

EBP

EBP + 8

EDX

EBP + 12

EAX

(18)

Calling foo1

int foo1(int a, int b) { int c = a + b;

return c; }

// Foo1's code // ...

0x00000504 <+0>: push %ebp

0x00000505 <+1>: mov %esp,%ebp

0x00000514 <+16>: mov 0x8(%ebp),%edx

0x00000517 <+19>: mov 0xc(%ebp),%eax

0x0000051a <+22>: add %edx,%eax

0x0000051c <+24>: mov %eax,-0x4(%ebp) 0x0000051f <+27>: mov -0x4(%ebp),%eax

0x00000522 <+30>: leave

0x00000523 <+31>: ret

0x00000

2

ESP

EIP

1

<return-addr>

0x0...53a

<old-ebp>

EBP

EBP + 8

EDX

EBP + 12

EAX

(19)

Calling foo1

int foo1(int a, int b) { int c = a + b;

return c; }

// Foo1's code // ...

0x00000504 <+0>: push %ebp

0x00000505 <+1>: mov %esp,%ebp

0x00000514 <+16>: mov 0x8(%ebp),%edx

0x00000517 <+19>: mov 0xc(%ebp),%eax

0x0000051a <+22>: add %edx,%eax

0x0000051c <+24>: mov %eax,-0x4(%ebp)

0x0000051f <+27>: mov -0x4(%ebp),%eax

0x00000522 <+30>: leave 0x00000523 <+31>: ret

0x00000

2

ESP

EIP

1

<return-addr>

0x0...53a

<old-ebp>

EBP

EBP + 8

EDX

EBP + 12

EAX

(20)

Buffer Overflow

Buffer Overflow (BOF) consists on reading/writing more than

the allocated buffer amount

int foo() { char a;

char buf[3];

char password[] = "ciao";

strcpy(buf, password);

return 0; }

int main() { foo(); return 0;

Buffer of 3 chars

(21)

Buffer Overflow

Buffer Overflow (BOF) consists on reading/writing more than

the allocated buffer amount

int foo() { char a;

char buf[3];

char password[] = "ciao"; strcpy(buf, password); return 0;

}

int main() { foo(); return 0;

<return-addr>

0x0...53a

<old-ebp>

a

buf

…..

…..

https://github.com/emavgl/sectestlab_2019/tree/master/lab_5/homework-5

References

Related documents

lf such delay or failure continues for at least seven (7) days, the Party not affected by such delay or failure shall be entitled to terminate this Agreement by notice

Over 250 client planners and project managers use Safran Project to plan, monitor, control and manage some of the most complex, critical projects in the industry.. Where

Bahrain Arabian Gulf University College of Medicine and Medical Sciences – Department of Family and Community Medicine Egypt Assiut University Faculty of Medicine – Department

The exclusion of coverage for the dishonest acts of owners, partners, principals of an insured does not apply when a management company is an insured under an

The single-phase active PFC techniques can be divided into two categories: the two- stage approach and the single-stage approach. The two-stage approach is most commonly used. In

factory agreement is the fact that the calculated maximum bending moment is not very sensitive to small variations inthe assumed distribution of lateral earth pressures or to

The company adjusts expectations for the profit before tax from DKK 35-40m to DKK 40-50m, as the development in prices, and the company’s possibilities to earn high margins on a

While Levitt is referring to efforts to define terrorism in an international context, the advantages to be gained from a single definitional approach are nevertheless