How can I execute a dead code in C by using cmd in Linux

Viewed 58

I have a C code with a function that is dead code.

Is there any method to execute this dead code function?

The code is shown below:

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

int i;

void do_not_call()
{
    puts("achieved attacker control flow!\n");
    exit(1);
}

int i, c;

void readinput()
{
    char buf[8]; 

    printf("Enter a string: ");
    for (i = 0; (c = getchar()) != '\n'; i++) buf[i] = c;
    buf[i] = '\0';
    printf("string = [%s]\n", buf);
}


int main(int argc, char *argv[])
{
    printf("do_not_call: %p\n", do_not_call);
    readinput();
    return 0;
}

From the main() function, I can get the memory address of do_not_call(). and I tried using gdb to get the memory address of the stack overflow due to input, but still don't know how to achieve that dead code (do_not_call()) execution.

1 Answers

Use gdb:

  1. gdb myExecutable # Run executable through gdb
  2. gdb b main # set a breakpoint at main()
  3. call do_not_call calls the function that you want to hack
Related