aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-04-24 23:52:41 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-04-24 23:52:41 +0300
commit9bf5719d4c59993c07113c089ebd5a92d692f785 (patch)
tree7310918ccac5bb3cfffc18861c286a6872554c01
parent2ca6677667af23ecb1e17479c5b5cc08efa53309 (diff)
skeleton done
-rw-r--r--.gitignore3
-rw-r--r--Makefile52
-rwxr-xr-xbuild.sh31
-rw-r--r--src/client/main.c6
-rw-r--r--src/daemon/main.c6
-rw-r--r--src/init8
-rw-r--r--src/initramfs-init.sh6
-rw-r--r--src/module/Makefile8
-rw-r--r--src/module/module.c (renamed from src/module.c)8
-rwxr-xr-xvm.sh41
10 files changed, 125 insertions, 44 deletions
diff --git a/.gitignore b/.gitignore
index 6dd29b7..cbbd0b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-bin/ \ No newline at end of file
+bin/
+obj/ \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a4a8911
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,52 @@
+CC := gcc
+CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -g
+
+SRCD := src
+OBJD := obj
+BIND := bin
+
+SRCS = $(shell find $(SRCD)/$(SUBD) -type f)
+OBJS = $(SRCS:$(SRCD)/$(SUBD)/%.c=$(OBJD)/$(SUBD)/%.o)
+
+DAEMON_TARGET_NAME := daemon
+CLIENT_TARGET_NAME := client
+MODULE_TARGET_NAME := keylogger.ko
+
+KERNEL_NAME := kernel-$(shell uname -r)
+INITFS_NAME := initramfs.img
+
+export
+
+all: daemon client module
+
+daemon client module:
+ $(MAKE) $(BIND)/$($(shell echo $@ | tr '[:lower:]' '[:upper:]')_TARGET_NAME) SUBD=$@
+
+clean:
+ rm -rf $(BIND)
+ rm -rf $(OBJD)
+
+# generic build
+$(BIND)/%: $(OBJS)
+ mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(SFLAGS) $^ -o $@
+
+$(OBJD)/$(SUBD)/%.o: $(SRCD)/$(SUBD)/%.c
+ mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(SFLAGS) -c $^ -o $@
+
+# build a module
+$(BIND)/%.ko: $(SRCS)
+ mkdir -p $(dir $@); mkdir -p $(OBJD)/$(SUBD)
+ make -C $(SRCD)/$(SUBD) name=$(@:$(BIND)/%.ko=%)
+ mv $(SRCD)/$(SUBD)/*.o $(OBJD)/$(SUBD)
+ mv $(SRCD)/$(SUBD)/*.ko $@
+ make -C $(SRCD)/$(SUBD) clean
+
+# VM things
+vm: vm.sh $(BIND)/$(INITFS_NAME) $(BIND)/$(KERNEL_NAME)
+ ./vm.sh run
+$(BIND)/$(INITFS_NAME): $(SRCD)/initramfs-init.sh module
+ ./vm.sh initramfs $@ $^
+$(BIND)/$(KERNEL_NAME):
+ ./vm.sh kernel $@
diff --git a/build.sh b/build.sh
deleted file mode 100755
index f285004..0000000
--- a/build.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-set -e
-
-cd ${0%/*} # go to project root
-
-KERNEL="bin/kernel-$(uname -r)"
-INITRAMFS="bin/initramfs"
-
-mkdir -p bin
-
-# get the kernel
-sudo cp /boot/vmlinuz-linux-lts "$KERNEL"
-
-# initramfs directory
-rm -rf $INITRAMFS
-mkdir -p $INITRAMFS
-
-# copy the init file
-cp src/init $INITRAMFS
-chmod +x $INITRAMFS/init
-
-# get the busybox things
-install -D $(which busybox) $INITRAMFS/bin/busybox
-ln -sf busybox $INITRAMFS/bin/sh
-
-# make the image
-(cd $INITRAMFS; find . | cpio -H newc -o | gzip > ../initramfs.img )
-
-qemu-system-x86_64 \
- -kernel "$KERNEL" \
- -initrd "$INITRAMFS.img" \
- -append "console=ttyS0" -nographic
diff --git a/src/client/main.c b/src/client/main.c
new file mode 100644
index 0000000..1e562d6
--- /dev/null
+++ b/src/client/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(void)
+{
+ return 0;
+}
diff --git a/src/daemon/main.c b/src/daemon/main.c
new file mode 100644
index 0000000..1e562d6
--- /dev/null
+++ b/src/daemon/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(void)
+{
+ return 0;
+}
diff --git a/src/init b/src/init
deleted file mode 100644
index f080d6c..0000000
--- a/src/init
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-echo "Hello, whats your name?"
-read -r name
-hostname $name
-
-export PS1="\[\033[32m\]\h:\[\033[36m\]\w\[\033[37m\]# " # set the prompt
-exec /bin/sh
diff --git a/src/initramfs-init.sh b/src/initramfs-init.sh
new file mode 100644
index 0000000..2144100
--- /dev/null
+++ b/src/initramfs-init.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+insmod /usr/bin/keylogger.ko
+dmesg
+
+exec /bin/sh
diff --git a/src/module/Makefile b/src/module/Makefile
new file mode 100644
index 0000000..c9db2e0
--- /dev/null
+++ b/src/module/Makefile
@@ -0,0 +1,8 @@
+obj-m += $(name).o
+$(name)-y := module.o
+
+all:
+ make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
+
+clean:
+ make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
diff --git a/src/module.c b/src/module/module.c
index 9c56d8b..43edb8c 100644
--- a/src/module.c
+++ b/src/module/module.c
@@ -4,17 +4,17 @@
static int __init init(void)
{
- pr_info("Hello, world 4\n");
+ pr_info("Hello World!\n");
return 0;
}
static void __exit exit(void)
{
- pr_info("Goodbye, world 4\n");
+ pr_info("Goodbye World!\n");
}
-module_init(init_hello_4);
-module_exit(cleanup_hello_4);
+module_init(init);
+module_exit(exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Kartofen");
diff --git a/vm.sh b/vm.sh
new file mode 100755
index 0000000..f77642f
--- /dev/null
+++ b/vm.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+function run
+{
+ qemu-system-x86_64 \
+ -kernel "$BIND/$KERNEL_NAME" \
+ -initrd "$BIND/$INITFS_NAME" \
+ -append "console=ttyS0" -nographic
+}
+
+function initramfs
+{
+ IMG="$(pwd)/$1"
+ DIR="${IMG%.*}"
+ mkdir -p $DIR
+
+ # get busybox things
+ install -D $(which busybox) $DIR/bin/busybox
+ ln -sf busybox $DIR/bin/sh
+ ln -sf busybox $DIR/bin/dmesg
+
+ # copy the compiled binaries
+ mkdir -p $DIR/usr/bin
+ cp $BIND/*.ko $DIR/usr/bin
+
+ # copy the script and the bin
+ cp $2 $DIR/init
+ chmod +x $DIR/init
+
+ # make image and delete folder
+ (cd $DIR; find . | cpio -H newc -o | gzip > $IMG)
+
+ rm -rf $DIR
+}
+
+function kernel
+{
+ sudo cp /boot/vmlinuz-linux-lts $1
+}
+
+$1 $2 $3