简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM