forked from Vic020/HackTheDlnu
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHackTheDlnu.cpp
More file actions
384 lines (349 loc) · 9.41 KB
/
HackTheDlnu.cpp
File metadata and controls
384 lines (349 loc) · 9.41 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <windows.h>
using namespace std;
struct node_filesystem //文件系统 结点
{
string name; //此结点名字
string document[1000]; //文件结点,用数组保存文件名
int document_length;
node_filesystem *filedir[1000]; //
int filedir_length;
node_filesystem *pri_dir;
node_filesystem()
{
document_length = 0;
filedir_length = 0;
}
};
node_filesystem *rootdir = new node_filesystem(); //根目录
string target_ip;
string target_port;
string target_user;
string target_password;
node_filesystem *workpoint ; //工作指针
int filesystem_read(string filename) //文件系统
{
rootdir->pri_dir = NULL;
rootdir->name = "/";
workpoint = rootdir;
filename = "FileSystem\\" + filename;
ifstream infile(filename.c_str());
if(!infile)
{
cerr << "初始文件读取出错" <<filename<<"\n";
return 1;
}
string fileinput;
string fileflag = "-";
while(infile>>fileinput)
{
// cout<<fileflag<<":"<<fileflag.length()<<endl;
int flag = 0;
for(int i = fileflag.length() - 1; i >= 0 ; i --) //文件判断标志,判断当前录入的是文件还是文件夹
{
// cout<<"fileinput="<<fileinput<<" fileflag="<<fileflag<<endl;
if(fileinput[i] != fileflag[i])
{
if(fileinput[i] == '+')
{
flag = 1;
break;
}
else
{
workpoint = workpoint->pri_dir;
fileflag = fileflag.substr(0,fileflag.length()-1);
}
}
}
if (flag)
{
node_filesystem *newfilepoint = new node_filesystem();
newfilepoint->name = fileinput.substr(fileflag.length(),fileinput.length());
newfilepoint->pri_dir = workpoint;
workpoint->filedir[workpoint->filedir_length++] = newfilepoint;
workpoint = workpoint->filedir[workpoint->filedir_length - 1];
fileflag += "-";
}
else
{
workpoint->document[workpoint->document_length++] = fileinput.substr(fileflag.length(),fileinput.length());
}
}
infile.close();
workpoint = rootdir;
}
void mail() //读取mail
{
string email = "Mail_01.htd";
email="MissionPack\\"+email;
ifstream infile(email.c_str()); //读取邮件系统
string input_file;
system("cls");
while(getline(infile , input_file)) //读取邮件以获得文件中的IP地址
{
cout<<input_file<<endl;
for(int i=0;i<input_file.length();i++)
{
if(input_file[i]=='I' && input_file[i+1]=='P') //读取IP
{
target_ip=input_file.substr(3 , input_file.length());
}
if(input_file[i]=='p' && input_file[i+1]=='o' && input_file[i+2]=='r' &&input_file[i+3]=='t') //读取端口
{
target_port=input_file.substr(5 , input_file.length());
}
if(input_file[i]=='u' && input_file[i+1]=='s' && input_file[i+2]=='e' && //读取用户名
input_file[i+3]=='r')
{
target_user=input_file.substr(5 , input_file.length());
}
if(input_file[i]=='p' && input_file[i+1]=='a' && input_file[i+2]=='s' && //读取密码
input_file[i+3]=='s' && input_file[i+4]=='w' && input_file[i+5]=='o'
&& input_file[i+6]=='r' &&input_file[i+7]=='d')
{
target_password=input_file.substr(9 , input_file.length());
}
}
}
cout<<endl<<endl;
}
void command_telnet(string IP , string port)
{
void login();
if(IP == "" || port == "")
{
cout<<"wrong input !"<<endl;
return;
}
if(IP==target_ip && port == target_port)
{
system("cls");
login();
}
}
void command_ls()
{
cout<<endl;
for(int i = 0; i < workpoint->filedir_length ; i++)
{
cout<<workpoint->filedir[i]->name<<" <dir>"<<endl;
}
for(int i = 0; i < workpoint->document_length ; i++)
{
cout<<workpoint->document[i]<<endl;
}
cout<<endl
<<workpoint->document_length<<" file(s)"<<endl
<<workpoint->filedir_length<<" folder(s)"<<endl<<endl;
}
void command_cd(string inputdir)
{
if(inputdir == "")
{
cout<<endl
<<"Syntax error! Correct syntax : cd foldername"<<endl<<endl;
return ;
}
if(inputdir == "..")
{
if(workpoint->pri_dir != NULL)
{
workpoint = workpoint->pri_dir;
}
return ;
}
for(int i = 0 ; i < workpoint->filedir_length ; i++)
{
if(inputdir == workpoint->filedir[i]->name)
{
workpoint = workpoint->filedir[i];
return ;
}
}
cout<<endl<< "cannot find the folder "<<inputdir<<endl<<endl;
}
void command_copy(string file_name) //拷贝文件函数
{
if(file_name == "")
{
cout<<endl
<<" Syntax error! Correct syntax : copy [filename]"<<endl<<endl;
return ;
}
// workpoint=rootdir ;
ofstream out("FileSystem\\default.htd" , ios::app);
for(int i=0 ; i<workpoint->document_length ; i++)
{
if(workpoint->document[i] == file_name)
{
string str="\n--";
str=str + workpoint->document[i];
out<<str;
cout<<endl<<endl<<" copy succssfully!"<<endl<<endl;
}
}
out.close();
// delete rootdir ; //此处仅为测试是否能写入文件
// rootdir = new node_filesystem() ;
// filesystem_read("default.htd");
}
void command_hangup()
{
delete rootdir ;
rootdir = new node_filesystem() ;
workpoint = rootdir ;
filesystem_read("default.htd");
}
void command_del(string ip)
{
}
long long calculatecommand(string inputcommand)
{
long long result = 0 ;
long long power = 1;
for(int i = inputcommand.length() -1 ; i >=0 ; i--)
{
result += power * (inputcommand[i] - 'a' + 1 );
power *= 26;
}
return result;
}
int command(string inputcommand) //命令系统
{
istringstream inputcommand_stream(inputcommand);
while(inputcommand_stream>>inputcommand)
{
int temp = calculatecommand(inputcommand);
switch (temp)
{
case 104358: //exit 数值210来自自己计算
{
exit(0);
break;
}
case 1585264: //clear 清屏
{
system("cls");
return 0;
}
case 82: //cd
{
string inputdir;
inputcommand_stream>>inputdir;
command_cd(inputdir);
return 0;
}
case 331: //ls
{
command_ls();
return 0;
}
case 2956: //dir
{
return 0;
}
case 144316: //help
{
return 0;
}
case 240132926:
{
string ip , port;
inputcommand_stream>>ip>>port;
command_telnet(ip,port);
return 0;
}
case 229410:
{
mail();
return 0;
}
case 63309:
{
string file_name;
inputcommand_stream>>file_name;
command_copy(file_name);
return 0;
}
case 95759342: //hangup
{
command_hangup();
return 0;
}
case 2846:
{
string ip;
inputcommand_stream>>ip;
command_del(ip);
return 0;
}
default :
{
return 1;
}
}
}
}
void work()
{
delete rootdir;
rootdir = new node_filesystem();
filesystem_read("TheFirstStage.htd");
while(1)
{
string inputcommand;
cout<<"[Target@"<<workpoint->name<<"]#";
getline(cin,inputcommand);
if(command(inputcommand))
{
cout<<endl<<" Unknown command"<<endl<<endl;
}
}
}
void login()
{
string user , password;
cout<<"user:";
cin>>user;
cout<<"password:";
cin>>password;
if(user == target_user && target_password==password)
{
getchar();
system("cls");
work();
}
}
void welcomeinformation() //欢迎信息
{
cout<<"Hack The Dlnu -Console Command"<<endl
<<" -version 0.1"<<endl
<<" By Vic_"<<endl //自己把名字补上
<<endl
<<"---------------------------------------"<<endl
<<"Input \"help\" get help;"<<endl
<<endl;
}
int main ()
{
welcomeinformation();
// filesystem_read
filesystem_read("default.htd");
string str;
while(1)
{
string inputcommand = "";
cout<<"[Vic@"<<workpoint->name<<"]#";
getline(cin,inputcommand);
if(command(inputcommand))
{
cout<<endl<<" Unknown command"<<endl<<endl;
}
}
return 0;
}