1
0

Implements tests for kernel modules

This commit is contained in:
dump_stack() 2018-10-07 17:53:07 +00:00
parent a1eabd7df6
commit 9843778f06
4 changed files with 25 additions and 19 deletions

View File

@ -1,5 +1,6 @@
# out-of-tree called make with two arguments -- kernel headers path and name # out-of-tree called make with two arguments -- kernel headers path and name
# of target binary that MUST be produced by makefile # of target binary that MUST be produced by makefile
# - $(TARGET).ko_test: name of test binary that MUST be produced by makefile
# e.g.: # e.g.:
# make KERNEL=/lib/modules/4.8.0-58-generic/build TARGET=hello-world.ko # make KERNEL=/lib/modules/4.8.0-58-generic/build TARGET=hello-world.ko
KERNEL := /lib/modules/$(shell uname -r)/build KERNEL := /lib/modules/$(shell uname -r)/build
@ -10,6 +11,7 @@ $(TARGET)-objs = module.o
all: all:
make -C $(KERNEL) M=$(PWD) modules make -C $(KERNEL) M=$(PWD) modules
cp test.sh $(TARGET).ko_test
clean: clean:
make -C $(KERNEL) M=$(PWD) clean make -C $(KERNEL) M=$(PWD) clean

View File

@ -3,6 +3,7 @@
int init_module(void) int init_module(void)
{ {
printk("COOKIE!\n");
return 0; return 0;
} }

View File

@ -0,0 +1,3 @@
#!/bin/sh
# check for message in kernel log
dmesg | grep COOKIE

38
main.go
View File

@ -178,18 +178,13 @@ func cleanDmesg(q *qemu.QemuSystem) (err error) {
return return
} }
func testKernelModule(q *qemu.QemuSystem, ka artifact) (output string, err error) { func testKernelModule(q *qemu.QemuSystem, ka artifact, test string) (output string, err error) {
// TODO output, err = q.Command("root", test)
err = errors.New("Not implemented") // TODO generic checks for WARNING's and so on
return return
} }
func testKernelExploit(q *qemu.QemuSystem, ka artifact, test, exploit string) (output string, err error) { func testKernelExploit(q *qemu.QemuSystem, ka artifact, test, exploit string) (output string, err error) {
output, err = q.Command("user", "chmod +x "+test)
if err != nil {
return
}
output, err = q.Command("user", "chmod +x "+exploit) output, err = q.Command("user", "chmod +x "+exploit)
if err != nil { if err != nil {
return return
@ -280,19 +275,32 @@ func whatever(swg *sizedwaitgroup.SizedWaitGroup, ka artifact, ki kernelInfo) {
return return
} }
testPath := outFile + "_test"
remoteTest := fmt.Sprintf("/tmp/test_%d", rand.Int())
err = q.CopyFile("user", testPath, remoteTest)
if err != nil {
return
}
_, err = q.Command("root", "chmod +x "+remoteTest)
if err != nil {
return
}
if ka.Type == KernelModule { if ka.Type == KernelModule {
// TODO Write insmod log to file or database // TODO Write insmod log to file or database
output, err := q.CopyAndInsmod(outFile) output, err := q.CopyAndInsmod(outFile)
if err != nil { if err != nil {
log.Println(output) log.Println(output, err)
return return
} }
run_ok = true run_ok = true
// TODO Write test results to file or database // TODO Write test results to file or database
output, err = testKernelModule(q, ka) output, err = testKernelModule(q, ka, remoteTest)
if err != nil { if err != nil {
log.Println(output) log.Println(output, err)
return return
} }
test_ok = true test_ok = true
@ -303,14 +311,6 @@ func whatever(swg *sizedwaitgroup.SizedWaitGroup, ka artifact, ki kernelInfo) {
return return
} }
testPath := outFile + "_test"
remoteTest := fmt.Sprintf("/tmp/test_%d", rand.Int())
err = q.CopyFile("user", testPath, remoteTest)
if err != nil {
return
}
// TODO Write test results to file or database // TODO Write test results to file or database
output, err = testKernelExploit(q, ka, remoteTest, remoteExploit) output, err = testKernelExploit(q, ka, remoteTest, remoteExploit)
if err != nil { if err != nil {