首页 > 代码库 > [C] Re-execute itself from elf file.

[C] Re-execute itself from elf file.

Re-execute itself from elf file.

 

#define _GNU_SOURCE#include <sched.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <string.h>#include <errno.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/wait.h>extern char **environ;int main(int argc, char *argv[]){        char **ep;        char *sh[] = {"/bin/sh", NULL};        char me[256], *mee[] = {me, "hello", NULL};        puts("hey~");        //execve(*sh, sh, environ);        if ( argc > 1 && strcmp(argv[1], "hello") == 0 ) {                printf("argv[1] : %s\n", argv[1]);                puts("from execve()...");                return 0;        }        memset(me, 0, sizeof(me));        readlink("/proc/self/exe", me, sizeof(me) - 1);        printf("[+] Found myself: ‘%s‘\n", me);        execve(*mee, mee, environ);        for ( ep = environ; *ep != NULL; ep++)                printf("environ: %s\n", *ep);}

[C] Re-execute itself from elf file.