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_privs.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 <sys/types.h>
8
#include <stdlib.h>
9
#include <unistd.h>
10
#include <string.h>
11
#include <errno.h>
12
#include <stdio.h>
13
#include <pwd.h>
14
#include <grp.h>
15
16
#include "cmd.h"
17
18
19
void cmd_getid(int argc, char * argv[])
20
{
21
struct passwd * pwd;
22
struct group * grp;
23
24
printf("uid=%u", getuid());
25
if((pwd = getpwuid(getuid())) != NULL)
26
printf("(%s)", pwd->pw_name);
27
28
printf(" gid=%u", getgid());
29
if((grp = getgrgid(getgid())) != NULL)
30
printf("(%s)", grp->gr_name);
31
32
if(geteuid() != getuid())
33
{
34
printf(" euid=%u", geteuid());
35
if((pwd = getpwuid(geteuid())) != NULL)
36
printf("(%s)", pwd->pw_name);
37
}
38
if(getegid() != getgid())
39
{
40
printf(" egid=%u", getegid());
41
if((grp = getgrgid(getegid())) != NULL)
42
printf("(%s)", grp->gr_name);
43
}
44
45
printf("\n");
46
}
47
48
void cmd_setuid(int argc, char * argv[])
49
{
50
if(setuid(atoi(argv[1])) == -1)
51
perror("setuid");
52
}
53
54
void cmd_setgid(int argc, char * argv[])
55
{
56
if(setgid(atoi(argv[1])) == -1)
57
perror("setgid");
58
}
59
60