-
Notifications
You must be signed in to change notification settings - Fork 16
/
engine.h
216 lines (196 loc) · 4.38 KB
/
engine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <lua.hpp>
#define PCRE_STATIC
#include <pcrecpp.h>
#include <boost/thread/thread_only.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <algorithm>
#include <bitset>
#include <csignal>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
#include <windows.h>
extern void sleep(int t);
#endif
#define ENGINE_NAME "The Hacker's Sandbox"
#define ENGINE_VERSION 1.20
#define debug cout
#define T_FOLDER 0
#define T_FILE 1
#define E_NO_FILE 1
#define E_DENIED 2
#define E_BAD 3
#define E_OK 0
#define E_BREAK -1
#define ERR_NO_VM 1
#define ERR_BAD_SET 2
#define ERR_BAD_MIS_PACK 3
using namespace std;
namespace pt = boost::property_tree;
struct RT
{
string hash;
string plain;
RT(string h, string p):hash(h),plain(p){};
};
class File
{
int filetype;
string parent;
string filename;
string exec;
string content;
string owner;
string acl;
string on_delete;
vector <bitset<3> > getBitset();
bool setuid;
public:
File ();
File (string n, int t, string c, string e);
string getAcl ();
string getContent();
string getExec ();
int getType ();
string getName ();
string getOwner();
string getParent ();
string getOnDelete();
bool setAcl(string acl);
bool setOwner(string s);
bool setOnDelete(string s);
bool isReadable();
bool isWritable();
bool isExecutable();
void setSUID(bool);
string drawAcl();
};
class Mail
{
string header_to;
string header_subject;
string header_from;
string msg_body;
public:
Mail(string t, string s, string f, string b);
string to();
string subject();
string from();
string body();
};
bool registerPassword(string s);
class User
{
string name;
string password;
bool broken;
vector<Mail> inbox;
public:
User (string username, string password);
string getName();
bool isPassword(string s);
bool setPassword(string s);
bool addMail(Mail);
bool deleteMail(int index);
Mail* getMail(int index);
vector<Mail> listInbox();
int inboxSize();
};
struct Daemon
{
public:
int port;
string name;
string exec;
string query;
bool started;
Daemon(int port, string name, string exec, string query);
};
class VM
{
int broken_counter;
string cpu;
vector<string> gpus;
int compute_power;
string cwd;
int fs_maxSize;
bool has_root;
string hostname;
string ip;
string uname;
string hint;
vector<User> users;
vector<User*> user_chain;
vector<File> filesystem;
string on_root;
string on_login;
string on_logout;
vector<Daemon> services;
vector<int> net_domains;
public:
VM (string hn);
//string serialize();
pt::ptree serialize();
string getCpu ();
string getCwd ();
const vector<string> getFiles (string s);
File *pFile (string s);
string getHint();
string getHostname ();
string getIp ();
string getUname ();
string getUsername ();
User *getUser(string username);
int getUserCount();
int setCwd (string s);
void setHint(string s);
void setIp (string s);
void setUname (string s);
bool addFile (File f);
bool deleteFile (string filename);
bool addUser (User u);
bool login(string username, string password);
bool login(string username);
int logout();
bool startBrokenCounter();
void setBrokenCounter(int);
bool hasRoot();
void setRoot(bool);
void onRoot(string s);
void onLogin(string s);
void onLogout(string s);
bool startDaemon(string daemon);
bool stopDaemon(string daemon);
bool addDaemon(Daemon d);
vector<Daemon*> getDaemons();
vector<string> tabComplete(string);
void addGPU(string, int);
int getCPower();
vector<string> getGPUs();
void setDefaultNetDomain();
void addNetDomain(int);
void listNetDomains();
bool inNetDomain(int);
bool getNetRoute(string ip);
string printUserChain();
void reset();
int FSgetFree();
void FSsetMax(int);
};
std::string ab64_encode(char const* bytes_to_encode, unsigned int in_len);
std::string ab64_decode(std::string const& encoded_string);
int explode(std::string line,std::string delimiter,std::vector<std::string> &store);
string vhash(string s);
string realpath(string path);
extern bool debug_on;
extern vector<VM> vPC;
extern vector<VM*> shell;
extern vector<RT> vhashes;
extern std::map<int, std::string> netd_map;
extern lua_State *lua; // Lua state object