-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (97 loc) · 3.49 KB
/
main.cpp
File metadata and controls
103 lines (97 loc) · 3.49 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
#include "main.h"
#include "config.h"
#include "crypto_utils.h"
CUdkdAgentOptions IAgentOptions;
CUsageCollector IUsageOption;
CLoggingManager ILoggingOption;
CPacketHandler INetworkingOption;
CEventMonitor IEventMonitor;
CFileScanner IFileScanner;
CNetworkInterface IUserProgram;
CAntiDebugger IAntiDebugger;
CFirewall IFirewall;
// 인자값 필요로 한다면 :붙이기 ex) hib:s:
void CheckOption(int &argc, char** &argv) {
int nOptionIndex = 0;
int nOpt;
const char* pOption = "c:dhilmsunfe";
bool bNetworkOption = false;
std::string configPath;
while ((nOpt = getopt_long(argc, argv, pOption, options, &nOptionIndex)) != -1) {
switch (nOpt) {
case 'd':
IAntiDebugger.Detect();
break;
case 'h':
IAgentOptions.DisplayHelpOption();
break;
case 'i':
IAgentOptions.DisplayInfoOption();
break;
case 'l':
ILoggingOption.TestLogging();
break;
case 'm':
if (configPath.empty()) {
configPath = CONFIGPATH;
}
std::cout << "Configuration path for -m: " << configPath << std::endl;
LoadConfig(configPath);
IEventMonitor.StartMonitoring();
break;
case 's':
IFileScanner.StartScan();
break;
case 'u':
IUsageOption.CollectAndSaveUsage();
break;
case 'n':
IUserProgram.ManageInterface();
bNetworkOption = true;
break;
case 'c':
LoadConfig(optarg);
IFileScanner.StartIniScan();
break;
case 'f':
IFirewall.StartFirewall();
break;
case 'e': {
std::string configPath = CONFIGPATH;
LoadConfig(configPath);
std::string recipientEmailAddress = Config::Instance().GetEmailAddress(); // 이메일 주소 가져오기
std::cout << "Recipient Email Address: " << recipientEmailAddress << std::endl; // 이메일 주소 출력 (디버그용)
EmailSender IEmailSender("smtps://smtp.gmail.com", 465, recipientEmailAddress); // EmailSender 객체 초기화
IEmailSender.SendLogEmail(); // 이메일 보내기 함수 호출
break;
}
case '?':
IAgentOptions.DisplayErrorOption();
break;
default:
abort();
}
}
}
int main(int argc, char **argv){
const std::string keyFilePath = ENCRYPTION_KEY;
if (!CCryptoUtils::FileExists(keyFilePath)) {
std::vector<unsigned char> key = CCryptoUtils::GenerateRandomKey(32);
CCryptoUtils::SaveKeyToFile(key, keyFilePath);
}
if (argc > 1)
CheckOption(argc, argv);
else
std::cout << "Try 'UdkdAgent --help' for more information." << std::endl;
return 0;
}
void LoadConfig(const std::string& configPath) {
try {
Config::Instance().Load(configPath);
std::cout << "Configuration loaded successfully from " << configPath << ".\n";
std::cout << "----------------------------------------\n";
} catch (const std::exception &e) {
std::cerr << "Failed to load configuration from " << configPath << ": " << e.what() << "\n";
exit(ERROR_CANNOT_OPEN_FILE);
}
}