Wargame/pwn.college

Kernel security - 명령어 사용법

wyv3rn 2023. 9. 22. 13:54
728x90
반응형

서론

사실 커널 디버깅을 위해서는 사전 준비가 다소 필요하다.

하지만 pwn.college에서는 이를 위해 대부분의 사항을 준비해두어서 명령어 하나로 모두 처리할 수 있다.

처음에 다소 헤멧기에 정리해둔다.

 

모듈 디버깅

소스파일이 제공되지 않기에 커널 모듈을 직접 ida로 열어서 확인해야한다.

 

기본 명령어

기본적으로 vm 명령을 통해 모든 작업이 가능하다.

hacker@vm_kernel-security-level-1-0:~$ vm
usage: vm [-h] [--kaslr] [--no-kaslr] {connect,exec,start,stop,restart,logs,debug,build} ...
vm: error: the following arguments are required: command

 

virtual machine 실행 및 종료

해당 레벨에서 vm start 및 vm stop으로 머신을 켜고 끌 수 있다.

다만, vm connect만 실행하면 바로 vm이 실행되고 접속된다.

왠만하면 vm connect만 쓰자.

hacker@kernel-security-level-1-0:~$ vm connect
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
hacker@vm_kernel-security-level-1-0:~$

 

gdb connect

마찬가지로 해당 레벨에서 vm debug를 실행하면 된다.

단, practice 모드에서만 실행되며, 터미널은 실행된 상태여야 한다.

vm start를 통해 실행 후 디버거로만 접속하면 백그라운드에서 vm이 실행 중으로 판단하기에 실제 디버깅 시 제대로 디버거가 어태치 되지 않는 경우가 있는 듯.

그러므로 반드시 vm connect 이후에 디버거를 어태치하자.

hacker@practice~kernel-security-level-1-1:~$ vm debug
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
GEF for linux ready, type `gef' to start, `gef config' to configure
89 commands loaded and 5 functions added for GDB 9.2 in 0.01ms using Python engine 3.8
Reading symbols from /opt/linux/vmlinux...
[!] Using `target remote` with GEF does not work, use `gef-remote` instead. You've been warned.
Remote debugging using localhost:1234
default_idle () at arch/x86/kernel/process.c:581
581             trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());

 

kallsyms

practice 모드에서 sudo 명령어를 사용해 읽을 수 있다.

그냥 읽으면 아래와 같이 KADR로 인해 주소가 가려져서 나온다.

hacker@vm_practice~kernel-security-level-1-1:~$ cat /proc/kallsyms | tail
0000000000000000 T firmware_map_add_hotplug
0000000000000000 T firmware_map_remove
0000000000000000 T _einittext
0000000000000000 t device_open  [challenge]
0000000000000000 t device_write [challenge]
0000000000000000 t device_read  [challenge]
0000000000000000 t device_release       [challenge]
0000000000000000 t bin_padding  [challenge]
0000000000000000 t cleanup_module       [challenge]
0000000000000000 t init_module  [challenge]
hacker@vm_practice~kernel-security-level-1-1:~$ sudo cat /proc/kallsyms | tail
ffffffff82a44cbd T firmware_map_add_hotplug
ffffffff82a44d97 T firmware_map_remove
ffffffff82a44e1b T _einittext
ffffffffc0000000 t device_open  [challenge]
ffffffffc0000010 t device_write [challenge]
ffffffffc0000090 t device_read  [challenge]
ffffffffc0000150 t device_release       [challenge]
ffffffffc0000160 t bin_padding  [challenge]
ffffffffc0000a20 t cleanup_module       [challenge]
ffffffffc0000980 t init_module  [challenge]

 

kernel module compile

vm build 파일명

을 통해 커널 모듈 컴파일을 할 수 있다.

컴파일된 파일은 /challenge 폴더에 저장된다.

728x90
반응형