0

please, need assistance on my assignment which is due soon.

1a: Examine the code below and draw stack frames when function1, function2 and function3 are called by the main program for a 32-bit system. Use objdumb and GDB debugger to analysis the assembly code of the functions. Draw the stack frame after analysing the assembly code. Figure 2 shows a sample stack frame of a function. The requirement of this part is to produce three stack frames corresponding to the three functions of the code. The addresses and the corresponding content of the stack (as per the assembly code of the functions) should be included according to the format shown in Figure 2. The screenshot of the assembly code of the functions should also be included.

1b: Identify a software vulnerability in the code. Exploit the vulnerability and execute function4 instead of function3. It is important to note that function4 never gets called by the main function. Your task is to inject a command line argument such that function4 gets called, instead of function3. Include screenshots of the entire process and explain the stack exploitation procedure.

int function1(int x, int y, int z)
{
    int result_func1;
    result_func1 = x + y + z;
    return result_func1
}

int function2(int x, int y, char* input_string)
{
    int result_func2;
    char buffer[20];
    strcpy(buffer, input_string);
    printf("your input string %s is copied in the buffer \n", input_string);
    result_func2= x - y;
    return result_func2
}

void function3(int result1, int result2)
{
    printf("The result of function 1 is %d\n", result1);
    printf("The result of function 1 is %d\n", result1);
}

void function4(void)
{
    printf("The function never gets called is \n");
    exit(-1);
}
int main(int argc, char* argv[])
{
    int result1;
    int result2;
    result1 = function1(5, 10, 15);
    result2 = function2(20, 8, argv[1]);
    function3(result1, result_func1);
}

Stack frame of function1

i'll really appreciate if someone can put me through

  • Q2 includes drawing the stack frame for the three functions (after using objdump and gdb). Why not do Q2 first, and then you know what the answer to Q1 is? – Paul Hankin Jan 07 '22 at 14:58
  • hey paul! thank you for the suggestion. but i'm still abit confused about the whole question. i dont mind if you could assist me please – Wale Olokunola Jan 07 '22 at 15:09
  • 2
    You'll have to compiler the C into asm with some specific compiler and compiler options, and see where it puts things relative to the stack pointer on entry to the function. (If this is x86, that points to the return address. If not, many RISC ISAs pass a return address in a "link register".) e.g. [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116) ISO C doesn't say anything about a stack, and compilers are free to leave gaps or place locals in any order relative to padding for alignment, so there is no answer until the code is nailed down into asm – Peter Cordes Jan 07 '22 at 15:09
  • 1
    Are those really two separate questions? What you've labeled "Q1" is hopefully just a title or summary for the details in the following paragraph. It even says "Draw the stack frame **after** analysing the assembly code." (Which is good, because the assignment would be nonsense if it told you to draw stack frames for the C code without looking at the asm.) – Peter Cordes Jan 07 '22 at 16:27
  • i have modified he post already. i already just posted the complete question in the post. – Wale Olokunola Jan 07 '22 at 16:55

0 Answers0