Repository navigation
Expand file tree
/
Copy pathsimple_test.cpp
More file actions
198 lines (174 loc) · 7.65 KB
/
Copy pathsimple_test.cpp
File metadata and controls
198 lines (174 loc) · 7.65 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
#include <iostream>
#include "pangu_shell/process_injection/process_injector.h"
#include "pangu_shell/memory_management/memory_manager.h"
#include "pangu_shell/network/network_manager.h"
int main() {
std::cout << "=== Pangu Shell Core Library Simple Test ===\n\n";
// 测试结果统计
int tests_passed = 0;
int tests_failed = 0;
// 1. 测试内存管理功能
std::cout << "1. Testing Memory Management...\n";
pangu_shell::memory_management::MemoryManager memory_manager;
pangu_shell::memory_management::MemoryProtectionConfig config;
config.enable_encryption = true;
config.encryption_algorithm = pangu_shell::memory_management::EncryptionAlgorithm::kAes256Cbc;
config.enable_anti_dump = true;
config.enable_anti_debug = false;
config.self_destruct_timeout = 0;
if (memory_manager.Initialize(config)) {
std::cout << " ✅ Memory Manager initialized successfully\n";
tests_passed++;
// 分配受保护的内存
size_t mem_size = 1024;
void* mem_ptr = memory_manager.AllocateProtectedMemory(
mem_size,
pangu_shell::syscall::MemoryProtection::kReadWrite,
true,
pangu_shell::memory_management::EncryptionAlgorithm::kAes256Cbc
);
if (mem_ptr) {
std::cout << " ✅ Allocated protected memory at address: " << mem_ptr << "\n";
tests_passed++;
// 写入数据
std::string test_data = "Hello, Pangu Shell!";
std::memcpy(mem_ptr, test_data.c_str(), test_data.size() + 1);
std::cout << " ✅ Written test data: " << static_cast<const char*>(mem_ptr) << "\n";
tests_passed++;
// 测试内存加密
auto encrypt_result = memory_manager.EncryptMemory(mem_ptr, mem_size);
if (encrypt_result == pangu_shell::memory_management::EncryptionResult::kSuccess) {
std::cout << " ✅ Encrypted memory successfully\n";
tests_passed++;
// 测试内存解密
auto decrypt_result = memory_manager.DecryptMemory(mem_ptr, mem_size);
if (decrypt_result == pangu_shell::memory_management::EncryptionResult::kSuccess) {
std::cout << " ✅ Decrypted memory successfully\n";
tests_passed++;
// 验证数据完整性
if (std::string(static_cast<const char*>(mem_ptr)) == test_data) {
std::cout << " ✅ Data integrity verified after encryption/decryption\n";
tests_passed++;
} else {
std::cout << " ❌ Data integrity failed after encryption/decryption\n";
tests_failed++;
}
} else {
std::cout << " ❌ Failed to decrypt memory\n";
tests_failed++;
}
} else {
std::cout << " ❌ Failed to encrypt memory\n";
tests_failed++;
}
// 测试内存隐藏
if (memory_manager.HideMemoryRegion(mem_ptr, mem_size)) {
std::cout << " ✅ Hidden memory region\n";
tests_passed++;
// 测试内存显示
if (memory_manager.ShowMemoryRegion(mem_ptr, mem_size)) {
std::cout << " ✅ Showed memory region\n";
tests_passed++;
} else {
std::cout << " ❌ Failed to show memory region\n";
tests_failed++;
}
} else {
std::cout << " ❌ Failed to hide memory region\n";
tests_failed++;
}
// 释放内存
if (memory_manager.FreeProtectedMemory(mem_ptr)) {
std::cout << " ✅ Freed protected memory\n";
tests_passed++;
} else {
std::cout << " ❌ Failed to free protected memory\n";
tests_failed++;
}
} else {
std::cout << " ❌ Failed to allocate protected memory\n";
tests_failed++;
}
memory_manager.Shutdown();
std::cout << " ✅ Memory Manager shutdown successfully\n";
tests_passed++;
} else {
std::cout << " ❌ Failed to initialize Memory Manager\n";
tests_failed++;
}
// 2. 测试进程注入功能
std::cout << "\n2. Testing Process Injector...\n";
pangu_shell::process_injection::ProcessInjector injector;
if (injector.Initialize()) {
std::cout << " ✅ Process Injector initialized successfully\n";
tests_passed++;
// 测试获取技术名称
std::string technique_name = injector.GetTechniqueName(pangu_shell::process_injection::InjectionTechnique::kRemoteThread);
if (!technique_name.empty()) {
std::cout << " ✅ Got technique name: " << technique_name << "\n";
tests_passed++;
} else {
std::cout << " ❌ Failed to get technique name\n";
tests_failed++;
}
// 测试获取结果描述
std::string result_desc = injector.GetResultDescription(pangu_shell::process_injection::InjectionResult::kSuccess);
if (!result_desc.empty()) {
std::cout << " ✅ Got result description: " << result_desc << "\n";
tests_passed++;
} else {
std::cout << " ❌ Failed to get result description\n";
tests_failed++;
}
} else {
std::cout << " ❌ Failed to initialize Process Injector\n";
tests_failed++;
}
// 3. 测试网络管理器功能
std::cout << "\n3. Testing Network Manager...\n";
pangu_shell::network::NetworkManager network_manager;
std::cout << " ✅ Network Manager created successfully\n";
tests_passed++;
// 测试隧道配置
pangu_shell::network::TunnelConfig tunnel_config;
tunnel_config.type = pangu_shell::network::TunnelType::kHttp;
tunnel_config.server = "localhost";
tunnel_config.port = 8080;
tunnel_config.username = "test";
tunnel_config.password = "test";
tunnel_config.use_encryption = true;
std::cout << " ✅ Configured HTTP tunnel\n";
tests_passed++;
// 测试DNS隧道配置
pangu_shell::network::DnsTunnelConfig dns_config;
dns_config.domain = "test.example.com";
dns_config.resolver = "8.8.8.8";
dns_config.resolver_port = 53;
dns_config.ttl = 30;
dns_config.use_tcp = false;
std::cout << " ✅ Configured DNS tunnel\n";
tests_passed++;
// 4. 测试系统调用管理器
std::cout << "\n4. Testing Syscall Manager...\n";
pangu_shell::syscall::SyscallManager syscall_manager;
if (syscall_manager.Initialize()) {
std::cout << " ✅ Syscall Manager initialized successfully\n";
syscall_manager.Shutdown();
std::cout << " ✅ Syscall Manager shutdown successfully\n";
tests_passed += 2;
} else {
std::cout << " ❌ Failed to initialize Syscall Manager\n";
tests_failed++;
}
// 输出测试结果
std::cout << "\n=== Test Results ===\n";
std::cout << "Tests Passed: " << tests_passed << "\n";
std::cout << "Tests Failed: " << tests_failed << "\n";
std::cout << "Total Tests: " << tests_passed + tests_failed << "\n";
if (tests_failed == 0) {
std::cout << "\n🎉 All tests passed! The Pangu Shell Core Library is working correctly.\n";
} else {
std::cout << "\n❌ Some tests failed. Please check the output above for details.\n";
}
return tests_failed;
}