lecture 08 – format string vulnerabilities · lecture 08 – format string vulnerabilities...

53
Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College

Upload: others

Post on 16-Oct-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Lecture 08 – Format string vulnerabilities

Stephen CheckowayOberlin College

Page 2: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Goal• Take control of the program (as usual)

• How?

• Write4 (write 4 bytes to an arbitrary location)

• Inject shellcode (or other exploits) into the process

Page 3: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

What should we overwrite?• Saved instruction pointer/return address (seip) on the stack

• Other pointers to code (we’ll come back to this)

Page 4: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

printf operation• printf takes a format string and arguments

• printf copies the format string to its output, replacing conversion specifiers with values determined by the arguments

• Arguments are (normally) accessed one at a time, in turn

• Internally, printf keeps a pointer to the next argument to be converted by a conversion specifier

• Example: printf("value = %d %c”, 42, 'm'); prints: value = 42 m

Page 5: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Common conversion specifiers

%c Character %s String%d, %i Integer %p Pointer%u Unsigned integer %% Literal %%x, %X Hex %n Stores number of characters written%e, %f, %g

Double

Page 6: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

printf family• printf

• fprintf

• sprintf

• snprintf

• asprintf

• dprintf

• vprintf

• vfprintf

• vsprintf

• vsnprintf

• vasprintf

• vdprintf

Page 7: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____________________

ending

5

500

seip

format string

“s”

next arg

Page 8: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________________H___

ending

5

500

seip

format string

“s”

next arg

Page 9: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________________He__

ending

5

500

seip

format string

“s”

next arg

Page 10: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________________Hel_

ending

5

500

seip

format string

“s”

next arg

Page 11: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________________Hell

ending

5

500

seip

format string

“s”

next arg

Page 12: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____________o___Hell

ending

5

500

seip

format string

“s”

next arg

Page 13: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____________o␣__Hell

ending

5

500

seip

format string

“s”

next arg

Page 14: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____________o␣5_Hell

ending

5

500

seip

format string

“s”next arg

Page 15: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____________o␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 16: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________w___o␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 17: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________wo__o␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 18: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________wor_o␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 19: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf________worlo␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 20: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____d___worlo␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 21: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____ds__worlo␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 22: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

The way snprintf() normally works

void foo(int w) {char buf[500];const char *ending = w==1? “”:”s”;snprintf(buf, 500, “Hello %d world%s”,

w, ending);}…foo(5);

w: 5seipsebpbuf____

ds␀_worlo␣5␣Hell

ending

5

500

seip

format string

“s”next arg

Page 23: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Now with %n

void foo(int w) {char buf[500];int x;snprintf(buf, 500, “Hello %d world%n”,

w, &x);}…foo(5);

w: 5seipsebpbuf____________________x: _

5

500

seip

format stringnext arg

Page 24: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Now with %n

void foo(int w) {char buf[500];int x;snprintf(buf, 500, “Hello %d world%n”,

w, &x);}…foo(5);

w: 5seipsebpbuf________

o␣__Hellx: _

5

500

seip

format stringnext arg

Page 25: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Now with %n

void foo(int w) {char buf[500];int x;snprintf(buf, 500, “Hello %d world%n”,

w, &x);}…foo(5);

w: 5seipsebpbuf____________o␣5_Hellx: _

5

500

seip

format string

next arg

Page 26: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Now with %n

void foo(int w) {char buf[500];int x;snprintf(buf, 500, “Hello %d world%n”,

w, &x);}…foo(5);

w: 5seipsebpbuf____d___worlo␣5␣Hellx: _

5

500

seip

format string

next arg

Page 27: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Now with %n

void foo(int w) {char buf[500];int x;snprintf(buf, 500, “Hello %d world%n”,

w, &x);}…foo(5);

w: 5seipsebpbuf____d___worlo␣5␣Hellx: 13

5

500

seip

format string

next arg

Page 28: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Now with %n

void foo(int w) {char buf[500];int x;snprintf(buf, 500, “Hello %d world%n”,

w, &x);}…foo(5);

w: 5seipsebpbuf____

d␀__worlo␣5␣Hellx: 13

5

500

seip

format string

next arg

Page 29: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Attacker controlled format string

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf____________________

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg format string

Page 30: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf________________ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg format string

Attacker controlled format string

Page 31: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf____________2b__ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next argformat string

Attacker controlled format string

Page 32: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf________f___2b72ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

Attacker controlled format string

Page 33: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf________fa__2b72ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

Attacker controlled format string

Page 34: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf________fa752b72ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

Attacker controlled format string

Page 35: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf5a5a5a5afa752b72ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

Attacker controlled format string

Page 36: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebpbuf5a5a5a5afa752b72ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

‘Z’ = 0x5a

Attacker controlled format string

Page 37: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“ZZZZ%x%x%x%x%x”);

evilseipsebp

␀___5a5a5a5afa752b72ZZZZ

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

Attacker controlled format string

Page 38: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Overwriting seip

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“\xe6\xff\xff\xbf%x%x%x%x%n”);

evilseipsebpbuf____________________

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg format string

0xbfffffe6

Page 39: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Overwriting seip

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“\xe6\xff\xff\xbf%x%x%x%x%n”);

evilseipsebpbuf____________________

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg format string

0xbfffffe6

Page 40: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Overwriting seip

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“\xe6\xff\xff\xbf%x%x%x%x%n”);

evilseipsebpbuf________fa752b72____

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

0xbfffffe6

Page 41: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Overwriting seip

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“\xe6\xff\xff\xbf%x%x%x%x%n”);

evil12

sebpbuf________fa752b72____

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

0xbfffffe6

Page 42: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Overwriting seip

void foo(const char *evil) {char buf[500];snprintf(buf, 500, evil);

}…foo(“\xe6\xff\xff\xbf%x%x%x%x%n”);

evil12

sebpbuf____

␀___fa752b72____

garbage: 117garbage: 10

garbage: 1839garbage: 43

evil500

seip

next arg

format string

0xbfffffe6

Page 43: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Picking the bytes to write• Use %⟨len⟩x to control the length of the output

• Use %hhn to write just the least-significant byte of the length

Page 44: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Almost putting it all together

evil = “⟨address⟩ZZZZ” “⟨address+1⟩ZZZZ” “⟨address+2⟩ZZZZ” “⟨address+3⟩” “%8x%8x…%8x” “%⟨len⟩x%hhn” “%⟨len⟩x%hhn” “%⟨len⟩x%hhn” “%⟨len⟩x%hhn”;

Page 45: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Misaligned buf• If buf is not 4-byte aligned, prepend 1, 2, or 3 characters to evil

Page 46: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Advantages of format string exploits• No need to smash the stack (targeted write)

• Avoids defenses such as stack canaries!

• Stack canary is a random word pushed onto the stack that is checked before the function returns

Page 47: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Stack Canariesint bar(char *);char foo(void) {

char buf[100];bar(buf);return buf[0];

}foo: push {r4, lr} sub sp, sp, #104 movw r4, #:lower16:__stack_chk_guard movt r4, #:upper16:__stack_chk_guard ldr r3, [r4] str r3, [sp, #100] mov r0, sp bl bar ldrb r0, [sp] @ zero_extendqisi2 ldr r2, [sp, #100] ldr r3, [r4] cmp r2, r3 beq .L2 bl __stack_chk_fail.L2: add sp, sp, #104 pop {r4, pc}

saved lr

saved r4

canary

buf

Page 48: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Disadvantages of format string exploits• Easy to catch so rarer:

$ gcc -Wformat=2 f.c f.c: In function ‘main’: f.c:5: warning: format not a string literal and no format arguments

• Tricky to exploit compared to buffer overflows

Page 49: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

What else can we overwrite?• Function pointers

• C++ vtables

• Global offset table (GOT)

Page 50: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Function pointers#include <stdlib.h>#include <stdio.h>

int compare(const void *a, const void *b) { const int *x = a; const int *y = b; return *x - *y;}

int main() { int i; int arr[6] = {2, 1, 5, 13, 8, 4}; qsort(arr, 6, 4, compare); for (i = 0; i < 6; ++i) printf("%d ", arr[i]); putchar('\n'); return 0;}

main:pushl %ebpmovl %esp, %ebp…leal 24(%esp), %esi // arr…movl $compare, 12(%esp)movl $4, 8(%esp)movl $6, 4(%esp)movl %esi, (%esp)call qsort

qsort:…call *0x14(%ebp)…

Page 51: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

C++ Virtual function tables (vtable)struct Foo { Foo() { } virtual ~Foo() { } virtual void fun1() { } virtual void fun2() { }};

void bar(Foo &f) { f.fun1(); f.fun2();}

int main() { Foo f; foo(f);}

_Z3barR3Foo: // bar(Foo&)pushl %ebpmovl %esp, %ebppushl %ebxsubl $20, %espmovl 8(%ebp), %ebx // ebx <- fmovl (%ebx), %eax // eax <- vtablemovl %ebx, (%esp) // (esp) <- thiscall *8(%eax) // call virtual functionmovl (%ebx), %eax // eax <- vtablemovl %ebx, (%esp) // (esp) <- thiscall *12(%eax) // call virtual functionaddl $20, %esppopl %ebxpopl %ebpret

Page 52: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

vtable for Foo// Real code_ZN3FooC1Ev:pushl %ebpmovl %esp, %ebpmovl 8(%ebp), %eaxmovl $_ZTV3Foo+8, (%eax)popl %ebpret

_ZTV3Foo:.long 0.long _ZTI3Foo.long _ZN3FooD1Ev.long _ZN3FooD0Ev.long _ZN3Foo4fun1Ev.long _ZN3Foo4fun2Ev

// DemangledFoo::Foo():pushl %ebpmovl %esp, %ebpmovl 8(%ebp), %eaxmovl vtable for Foo+8, (%eax)popl %ebpret

vtable for Foo:.long 0.long typeinfo for Foo.long Foo::~Foo().long Foo::~Foo().long Foo::fun1().long Foo::fun2()

address of vtable+8 stored in first word of object

Page 53: Lecture 08 – Format string vulnerabilities · Lecture 08 – Format string vulnerabilities Stephen Checkoway Oberlin College. Goal • Take control of the program (as usual) •

Global Offset Table (GOT)• Contains pointers to code and data in shared libraries

• Library functions aren’t called directly; stub in the Procedure Linkage Table (PLT) called

• E.g., call exit -> call exit@plt

• exit@plt looks up the address of exit in the GOT and jumps to it (not the whole story)

• Overwrite function pointer in GOT