mina.ko.git


mina.ko

~ (wip)LKM rootkit for 6.1+ kernels
git clone https://github.com/djnnvx/mina.ko.git
log | files | refs | archive | README | LICENSE

commit 5882a78d36c16e4ee3fa1a4e1d686d9459bc549d
parent 810dae0ba550722fb59a5a27d85adb20a6adea3e
Author: djnn <[email protected]>
Date: Sat, 7 Dec 2024 17:31:07 +0900

feat(build): improving Makefile ergononmics^-^

Diffstat:
MMakefile | 56+++++++++++++++++++++++++++++++++++++++++++++++++-------

1 file changed, 49 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
@@ -1,14 +1,56 @@
-obj-m += src/mina.o
 
-all:
-	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
+.PHONY: all
+all: compile
 
-clean:
-	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
+.PHONY: help
+help:
+	@echo "\033[34mmina.ko targets:\033[0m"
+	@perl -nle'print $& if m{^[a-zA-Z_-\d]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}'
 
-deps:
+# check if shuf exists
+_FOUND_SHUF = $(shell command -v shuf 2> /dev/null)
+
+# options
+MINA_DEBUG = 1
+ifdef _FOUND_SHUF
+  MINA_MAGIC_R15 = $(shell shuf -i 100-100000 -n1)
+else
+  MINA_MAGIC_R15 = $(shell head -n50 /dev/urandom | wc -c)
+endif
+MINA_CLIENT_ID = DEBUG
+
+# kernel config is shit for out of tree modules
+EXTRA_CFLAGS += -DMINA_DEBUG=$(MINA_DEBUG)             \
+                -DMINA_MAGIC_R15=$(MINA_MAGIC_R15)     \
+                -DMINA_CLIENT_ID=\"$(MINA_CLIENT_ID)\"
+
+# kernel vars cant define with patsubst for some fucking reason
+obj-m := mina_$(MINA_CLIENT_ID).o
+mina_$(MINA_CLIENT_ID)-objs := src/mina.o
+
+compile: ## compiles the rootkit
+	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
+	rm -f *.order *.symvers *.mod *.mod.c *.o
+
+clean: ## cleans up build artifacts
+	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
+	find . -type f -name *.o -delete
+
+load: ## loads the rootkit on the system
+	@dmesg -C
+	@insmod *.ko
+	@dmesg
+
+unload: ## unloads the rootkit from the system
+	@dmesg -C
+	@rmmod *.ko
+	@dmesg
+
+deps: ## install build dependencies for debian-based systems
 	@apt-get install -y \
 		gcc make build-essential libncurses-dev exuberant-ctags \
 		build-essential linux-headers-`uname -r`
 
-.PHONY: clean deps
+
+
+.PHONY: clean deps load unload