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_sys.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 <time.h>
14
#include <sys/utsname.h>
15
#ifdef SYSCALL_REBOOT
16
#include <linux/reboot.h>
17
18
#define reboot(arg) reboot(0xfee1dead, 0x28121969, arg, NULL)
19
#else
20
#include <sys/reboot.h>
21
#endif
22
23
#include "cmd.h"
24
25
26
void cmd_time(int argc, char * argv[])
27
{
28
printf("%s\n", get_time_str("%a %b %d %H:%M:%S %Z %Y"));
29
}
30
31
void cmd_uname(int argc, char * argv[])
32
{
33
struct utsname info;
34
35
if(uname(&info) == -1)
36
perror("uname");
37
else
38
printf("%s %s %s %s %s\n", info.sysname, info.nodename, \
39
info.release, info.version, info.machine);
40
}
41
42
void cmd_hostname(int argc, char * argv[])
43
{
44
/* This should be big enough to accomodate all cases. */
45
char buf[8192];
46
47
if(argc > 1)
48
{
49
if(sethostname(argv[1], strlen(argv[1])) == -1)
50
perror("sethostname");
51
}
52
else
53
{
54
if(gethostname(buf, sizeof(buf)) == -1)
55
perror("gethostname");
56
else
57
printf("%s\n", buf);
58
}
59
}
60
61
void cmd_reboot(int argc, char * argv[])
62
{
63
sync();
64
65
if(reboot(0x01234567) == -1)
66
perror("reboot");
67
}
68
69
/* Linux >= 2.1.30 */
70
void cmd_shutdown(int argc, char * argv[])
71
{
72
sync();
73
74
if(reboot(0x4321fedc) == -1)
75
perror("shutdown");
76
}
77
78
/* Linux >= 1.1.76 */
79
void cmd_halt(int argc, char * argv[])
80
{
81
sync();
82
83
if(reboot(0xcdef0123) == -1)
84
perror("halt");
85
}
86
87