我正在使用https://github.com/croemheld/lkm-rootkit
在pwd
├── LICENSE
├── Makefile
├── README.md
└── src
├── core.c
├── getdents_hook.c
├── headers
│ ├── core.h
│ ├── getdents_hook.h
│ ├── module_hiding.h
│ ├── network_keylog.h
│ ├── packet_hiding.h
│ ├── port_knocking.h
│ ├── privilege_escalation.h
│ ├── server.h
│ └── socket_hiding.h
├── include
│ ├── headers
│ │ └── utils.h -->this is where the error happens
│ └── utils.c
├── libs
│ ├── headers
│ │ └── syscalltable.h
│ └── syscalltable.c
├── module_hiding.c
├── network_keylog.c
├── packet_hiding.c
├── port_knocking.c
├── privilege_escalation.c
├── server.c
└── socket_hiding.c
6 directories, 25 files
--------------------------------------------------- -----------
使用以下Makefile
# Module name
ROOTKIT := rootkit
# Build
MODULEDIR := /lib/modules/$(shell uname -r)
BUILDDIR := $(MODULEDIR)/build
KERNELDIR := $(MODULEDIR)/kernel
# Source files
SRCS_S := src
LIBS_S := src/libs
INCL_S := src/include
# Header files
SRCS_H := $(shell pwd)/$(SRCS_S)/headers
LIBS_H := $(shell pwd)/$(LIBS_S)/headers
INCL_H := $(shell pwd)/$(INCL_S)/headers
# Module
obj-m := $(ROOTKIT).o
# Core
$(ROOTKIT)-y += src/core.o
# Source
$(ROOTKIT)-y += src/server.o
$(ROOTKIT)-y += src/network_keylog.o
$(ROOTKIT)-y += src/getdents_hook.o
$(ROOTKIT)-y += src/socket_hiding.o
$(ROOTKIT)-y += src/packet_hiding.o
$(ROOTKIT)-y += src/port_knocking.o
$(ROOTKIT)-y += src/privilege_escalation.o
$(ROOTKIT)-y += src/module_hiding.o
# Libs
$(ROOTKIT)-y += src/libs/syscalltable.o
# Include
$(ROOTKIT)-y += src/include/utils.o
ccflags-y := -I$(SRCS_H) -I$(LIBS_H) -I$(INCL_H)
subdir-ccflags-y := -I$(SRCS_H) -I$(LIBS_H) -I$(INCL_H)
# Recipes
all: print_file_vars
$(MAKE) -C $(BUILDDIR) M=$(shell pwd) modules
load:
insmod $(KERNELDIR)/net/ipv4/netfilter/nf_reject_ipv4.ko
insmod $(KERNELDIR)/net/ipv6/netfilter/nf_reject_ipv6.ko
insmod rootkit.ko
clean:
$(MAKE) -C $(BUILDDIR) M=$(shell pwd) clean
print_file_vars:
$(foreach v, $(.VARIABLES), $(info $(v) = $($(v))))
但是当我使用sudo make时,出现错误:
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-106-generic'
CC [M] /home/eric/Code/linux/module/lkm-rootkit/src/core.o /home/eric/Code/linux/module/lkm-rootkit/src/core.c:1:19: fatal error: utils.h: No such file or directory compilation terminated.
但是已设置了ccflags-y,已将包含路径添加到ccflags-y,有人可以帮助我吗,慈悲
答案 0 :(得分:0)
在ccflags-y
中使用“ Makefile
”结构来引用“当前”目录(您的$(src)
所在的目录):
ccflags-y := -I$(src)/src/headers
使用$(shell pwd)
引用此目录是不正确的:构建模块时,当前目录引用内核构建树,而不引用您的{{1 }}。
请记住:您的Makefile
被解析了两次:
Makefile
时。make
行时。第一次使用常规方式处理$(MAKE) -C $(BUILDDIR) M=$(shell pwd) modules
,Makefile
扩展到了模块的源目录。那时Make执行pwd
目标及其依赖的任何其他目标。例如。那时Make执行您的all
目标,该目标将打印print_file_vars
变量的值,您会发现此变量是正确的。
将SRCS_H
扩展为内核构建目录,第二次将您的Makefile
作为较大Makefile的一部分进行处理。仅使用时间变量pwd
,obj-m
和其他变量,例如ccflags-y
或*-m
,这就是为什么您不能对此变量使用*-y
的原因。 / p>