zoukankan      html  css  js  c++  java
  • [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
    ", argv[1]);
                    puts("from execve()...");
                    return 0;
            }
    
            memset(me, 0, sizeof(me));
            readlink("/proc/self/exe", me, sizeof(me) - 1);
            printf("[+] Found myself: '%s'
    ", me);
            execve(*mee, mee, environ);
    
            for ( ep = environ; *ep != NULL; ep++)
                    printf("environ: %s
    ", *ep);
    
    }
  • 相关阅读:
    HUST 1017 Exact cover (Dancing links)
    HDU 1160 FatMouse's Speed (DP)
    HDU 1058 Humble Numbers (DP)
    Kubernetes(k8s)
    linux命令
    入侵检测系统
    lynis检测
    CPU死锁
    检测工具lynis
    Linux表面工作
  • 原文地址:https://www.cnblogs.com/bittorrent/p/5913894.html
Copyright © 2011-2022 走看看