DOC PREVIEW
CMU CS 15213 - Recitation

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

15213 Recitation Section C Shimin Chen Sept 30 2002 Outline Buffer overflow Putting code onto stack Example 1 Buffer Overflow Please draw the stack frame of example1 What are the values of n and x at the marked points void example1 volatile int n char buf 8 volatile int x n 0x12345678 x 0xdeadbeef strcpy buf abcdefghijk a 0x61 b 0x62 buf 8 0xab buf 4 0xcd 15213 Recitation C 2 1 n x 2 n x 3 n x Shimin Chen ASM of example1 0x80483f0 0x80483f1 0x80483f3 0x80483f6 0x80483fd 0x8048404 0x8048407 0x804840c 0x804840f 0x8048410 0x8048415 0x8048418 0x804841c 0x8048421 0x8048424 0x8048428 0x804842a 0x804842b 15213 Recitation C push mov sub movl movl add push lea push call add movb mov lea movb mov pop ret ebp esp ebp 0x18 esp 0x12345678 0xfffffffc ebp 0xdeadbeef 0xfffffff0 ebp 0xfffffff8 esp 0x80484a8 0xfffffff4 ebp eax eax 0x8048308 strcpy 0x10 esp 0xab 0xfffffffc ebp 0xfffffffc eax 0xfffffff4 ebp edx 0xcd eax edx 1 ebp esp ebp 3 Shimin Chen Stack Frame push mov sub movl movl add push lea push call add movb mov lea movb mov pop ret ebp esp ebp 0x18 esp 0x12345678 0xfffffffc ebp 0xdeadbeef 0xfffffff0 ebp 0xfffffff8 esp 0x80484a8 0xfffffff4 ebp eax eax ebp 0x8048308 strcpy 0x10 esp 0xab 0xfffffffc ebp 0xfffffffc eax 0xfffffff4 ebp edx 0xcd eax edx 1 ebp esp esp ebp 15213 Recitation C 4 Return addr old ebp n 0xfc buf x 0xf4 0xf0 Shimin Chen Before Calling strcpy push mov sub movl movl ebp esp ebp 0x18 esp 0x12345678 0xfffffffc ebp 0xdeadbeef 0xfffffff0 ebp Address high Return addr old ebp ebp n 12 34 56 78 0xfc low buf 0xf4 x de ad be ef 0xf0 esp 15213 Recitation C 5 Shimin Chen After Calling strcpy push mov sub movl movl add push lea push call add ebp esp ebp 0x18 esp 0x12345678 0xfffffffc ebp 0xdeadbeef 0xfffffff0 ebp 0xfffffff8 esp 0x80484a8 Return addr 0xfffffff4 ebp eax old ebp eax ebp 0x8048308 strcpy n 00 6b 6a 69 0xfc 0x10 esp 68 67 66 65 buf 64 63 62 61 0xf4 x de ad be ef 0xf0 Strcpy buf abcdefghijk 15213 Recitation C 6 esp Shimin Chen Before Return push mov sub movl movl add push lea push call add movb mov lea movb ebp esp ebp 0x18 esp 0x12345678 0xfffffffc ebp 0xdeadbeef 0xfffffff0 ebp 0xfffffff8 esp 0x80484a8 0xfffffff4 ebp eax eax ebp 0x8048308 strcpy n 0x10 esp buf 0xab 0xfffffffc ebp 0xfffffffc eax x 0xfffffff4 ebp edx 0xcd eax edx 1 Return addr old ebp 00 6b 6a ab 0xfc 68 67 66 65 64 63 62 61 0xf4 de ad be cd 0xf0 esp 15213 Recitation C 7 Shimin Chen What If What if we instead strcpy buf abcdefghijklmn 14 1 chars Old ebp is overwritten What if we instead strcpy buf abcdefghijklmnopq 17 1 chars Return addr is overwritten 15213 Recitation C 8 Shimin Chen Example 2 How to Put Code onto Stack int example2 char buf 8 gets buf return 0 15213 Recitation C push mov sub add lea push call xor mov pop ret 9 ebp esp ebp 0x18 esp 0xfffffff4 esp 0xfffffff8 ebp eax eax 0x80482e8 gets eax eax ebp esp ebp Shimin Chen Steps 1 2 3 4 Write assembly code Get binary representation of the code Generate ASCII for the binary code Run the program with the input 15213 Recitation C 10 Shimin Chen Write assembly code Use your favorite text editor For example movl 0 8 ebp addl 0x12345678 eax Save as s e g input s 15213 Recitation C 11 Shimin Chen Get binary representation of the code Compile the assembly with gcc gcc c input s Display binary representation with objdump objdump d input o Copy the byte code into a text file 15213 Recitation C 12 Shimin Chen Generate ASCII for the binary code Use sendstring to generate ASCII string sendstring input txt input raw 15213 Recitation C 13 Shimin Chen Run the program with the input Run at the command line example2 input raw Run in gdb gdb example2 run input raw 15213 Recitation C 14 Shimin Chen Show Code on the Stack gdb gdb gdb gdb gdb gdb gdb 15213 Recitation C break example2 break 0x80483f6 run input raw p x ebp 8 p x ebp 3 continue disas 0xbffffa40 0xbffffa4b 15 Shimin Chen Important Dates Lab 3 due Monday Oct 7 11 59pm Exam 1 Tuesday Oct 8 6 00 7 30pm Doherty Hall 2315 15213 Recitation C 16 Shimin Chen


View Full Document

CMU CS 15213 - Recitation

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Recitation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Recitation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Recitation and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?