aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-04-24 01:00:36 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-04-24 01:00:36 +0300
commit2ca6677667af23ecb1e17479c5b5cc08efa53309 (patch)
tree37c4f62ac9f9ba124b37ca4767348c1f1ad74737
init
-rw-r--r--.gitignore1
-rw-r--r--README.md1
-rwxr-xr-xbuild.sh31
-rw-r--r--src/init8
-rw-r--r--src/module.c21
5 files changed, 62 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6dd29b7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+bin/ \ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..83dfee2
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+### Linux LKM thingy
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..f285004
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,31 @@
+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/init b/src/init
new file mode 100644
index 0000000..f080d6c
--- /dev/null
+++ b/src/init
@@ -0,0 +1,8 @@
+#!/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/module.c b/src/module.c
new file mode 100644
index 0000000..9c56d8b
--- /dev/null
+++ b/src/module.c
@@ -0,0 +1,21 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/printk.h>
+
+static int __init init(void)
+{
+ pr_info("Hello, world 4\n");
+ return 0;
+}
+
+static void __exit exit(void)
+{
+ pr_info("Goodbye, world 4\n");
+}
+
+module_init(init_hello_4);
+module_exit(cleanup_hello_4);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kartofen");
+MODULE_DESCRIPTION("A simple keylogger kernel module");