Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (126 loc) · 6.19 KB
/
Copy pathMakefile
File metadata and controls
135 lines (126 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
obj-m := ksentinel.o
KDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
KEY_FILE := $(PWD)/ksentinel_key.h
all: $(KEY_FILE)
$(MAKE) -C $(KDIR) M=$(PWD) modules
@echo ""
@echo "╔═══════════════════════════════════════════════════════════════╗"
@echo "║ ksentinel compiled successfully! ║"
@echo "╚═══════════════════════════════════════════════════════════════╝"
@echo ""
$(KEY_FILE):
@echo ""
@echo "╔═══════════════════════════════════════════════════════════════╗"
@echo "║ GENERATING RANDOM UNLOCK KEY ║"
@echo "╚═══════════════════════════════════════════════════════════════╝"
@echo ""
@KEY=$$(head -c 16 /dev/urandom | od -A n -t x1 | tr -d ' \n' | head -c 32); \
echo "#ifndef KSENTINEL_KEY_H" > $(KEY_FILE); \
echo "#define KSENTINEL_KEY_H" >> $(KEY_FILE); \
echo "#define UNLOCK_KEY \"$$KEY\"" >> $(KEY_FILE); \
echo "#endif" >> $(KEY_FILE); \
echo ""; \
echo ""; \
echo " UNLOCK KEY: $$KEY"; \
echo ""; \
echo "════════════════════════════════════════════════════════════════"; \
echo " This key is embedded in the module and NOT saved anywhere."; \
echo " To unhide the module later: echo \"KEY\" > /proc/.ksctl"; \
echo " Or use: make unlock (and paste the key when prompted)"; \
echo "════════════════════════════════════════════════════════════════"; \
echo ""; \
read -p "Press ENTER after you have written down the key..." dummy
unlock:
@echo ""
@echo "╔═══════════════════════════════════════════════════════════════╗"
@echo "║ UNLOCK HIDDEN MODULE ║"
@echo "╚═══════════════════════════════════════════════════════════════╝"
@echo ""
@if [ ! -f /proc/.ksctl ]; then \
echo "[!] Error: /proc/.ksctl not found. Is the module loaded?"; \
exit 1; \
fi
@bash -c 'read -sp "Enter unlock key: " KEY; echo; \
if [ -z "$$KEY" ]; then \
echo "[!] Error: key cannot be empty"; \
exit 1; \
fi; \
echo "[*] Writing key to /proc/.ksctl..."; \
if echo "$$KEY" | sudo tee /proc/.ksctl > /dev/null 2>&1; then \
sleep 1; \
if lsmod | grep -q ksentinel; then \
echo "[+] SUCCESS! Module is now visible"; \
lsmod | grep ksentinel; \
else \
echo "[!] Key written, but module still hidden. Check dmesg."; \
fi \
else \
echo "[!] Failed to write to /proc/.ksctl"; \
fi'
install: all
@echo "[*] Loading ksentinel module..."
sudo insmod ksentinel.ko
@echo "[+] Module loaded! It is now hidden from lsmod."
@echo ""
@echo "To unhide it later:"
@echo " 1. echo \"YOUR_KEY\" > /proc/.ksctl"
@echo " 2. OR run: make unlock"
uninstall:
@echo "[*] Attempting to remove ksentinel..."
@if lsmod | grep -q ksentinel; then \
echo "[*] Module is visible, removing..."; \
sudo rmmod ksentinel; \
echo "[+] Module removed"; \
else \
echo "[!] Module is hidden. Unlock it first with: make unlock"; \
exit 1; \
fi
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
rm -f $(KEY_FILE)
@echo "[*] Build artifacts cleaned"
status:
@echo "╔═══════════════════════════════════════════════════════════════╗"
@echo "║ ksentinel STATUS ║"
@echo "╚═══════════════════════════════════════════════════════════════╝"
@echo ""
@if lsmod | grep -q ksentinel; then \
echo "[*] Module: LOADED and VISIBLE"; \
lsmod | grep ksentinel; \
else \
if dmesg | tail -100 | grep -q "ksentinel"; then \
echo "[*] Module: LOADED but HIDDEN"; \
else \
echo "[X] Module: NOT LOADED"; \
fi \
fi
@echo ""
@if [ -f /proc/.ksctl ]; then \
echo "[*] Control interface: /proc/.ksctl exists"; \
else \
echo "[X] Control interface: not found"; \
fi
help:
@echo "╔═══════════════════════════════════════════════════════════════╗"
@echo "║ ksentinel Makefile ║"
@echo "╚═══════════════════════════════════════════════════════════════╝"
@echo ""
@echo "Usage:"
@echo " make - Compile (generates random key - WRITE IT DOWN!)"
@echo " make install - Compile and load the module"
@echo " make unlock - Unhide the module (prompts for key)"
@echo " make uninstall - Remove the module (must be visible first)"
@echo " make status - Check module status"
@echo " make clean - Remove build artifacts"
@echo ""
@echo "Security:"
@echo " • Random 32-char key generated at compile time"
@echo " • Key is shown ONCE and embedded in the module"
@echo " • Key is NOT saved in any file"
@echo " • You must write it down manually"
@echo ""
@echo "Manual unlock:"
@echo " echo \"your_key_here\" > /proc/.ksctl"
@echo ""
.PHONY: all unlock install uninstall clean status help