Cod sursa(job #82)

Utilizator fluffyDan-Leonard Crestez fluffy Data 4 decembrie 2006 23:09:18
Problema A+B Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.69 kb
// Automated test for jrun.
// The following are parsed by test.php
// JRUN_ARGS = --time-limit 100 --memory-limit 16000
// JRUN_RES = FAIL: time [0-9]+ms memory [0-9]+kb: Blocked system call: chroot.
//
// This is a classic chroot escape
// It attempts to create a file outside of the jail.
// If it fails the file will appear inside the jail.
// Will succeed if there's no setuid
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(void)
{
    mkdir("gigi", 0777);
    chroot("gigi");
    chdir("../");
    FILE *f = fopen("chroot escape", "w");
    fprintf(f, "Hello from the jail!\n");
    fclose(f);
    return 0;
}