码迷,mamicode.com
首页 > 其他好文 > 详细

[C] Re-execute itself from elf file.

时间:2016-09-27 19:26:47      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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.

标签:

原文地址:http://www.cnblogs.com/bittorrent/p/5913894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!