Overview
리λ
μ€ μ»€λ μμ€λ₯Ό ν΄λ‘ νκ³ , μμ©νλ‘κ·Έλ¨ λ€λ£¨λ―μ΄ λ§μκ» λ½κ°λλ‘,
User mode linux λΌλ feature λ₯Ό μ¬μ©νλ €κ³ ν©λλ€.
User mode Linux
리λ
μ€ μ»€λ μμ€ μ½λλ₯Ό ν΄λ‘ ν©λλ€.
λ²μ μ νμ λ§μλλ‘ νμλ©΄ λ©λλ€.
μ λ LTS λλ SLTS λ₯Ό λ μ νΈν©λλ€.
Github λ ν¬μ§ν λ¦¬κ° μλλΌ
kernel.org Git μμ ν΄λ‘ νλ μ΄μ λ λ§μ΄λ 릴리μ¦μ λν 컀λ°λ λ€μ΄κ°κΈ° λλ¬Έμ,
ν΄λΉ 릴리μ¦μ μ΅μ λ³κ²½ μ¬νμ νμΈν μ μμ΅λλ€.
Linux kernel source clone
1
2
3
4
5
|
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
# 5.10.x latest (SLTS)
git tag | grep "5.10."
git checkout 5.10.19
|
λΉλν λ νΉλ³ν μ€μ ν΄μ£Όλ νλκ·Έμ
λλ€.
Setup build flags
1
2
3
4
5
6
7
8
|
# arch setup & debug symbol
$ cat > set.sh
export CFLAGS="-g -Wall -Wextra"
export ARCH=um
export SUBARCH=x86_64 # arch/arm64/Makefile.um X arm64 μλ¨ :( export SUBARCH=arm64
# ctrl + d
$ source set.sh
|
μ΄μ λΉλλ₯Ό ν΄λ΄
μλ€.
config & compile 1
1
2
|
# make default config
make defconfig
|
μ¬κΈ°μ μ κΉ, μ°λ¦¬λ μ΄μ¬ν 리λ
μ€ μ»€λμ ν΄νΉν κ²μ΄λ―λ‘
κ³ μ μ μΈ DDDλ Insightλ₯Ό μ¬μ©ν΄μ λλ²κΉ
νλ κ²λ κ°λ₯ν©λλ€.
μ΅κ·Όμλ κ³μν΄μ λ¦΄λ¦¬μ¦ νκ³ μλ
μ νμ§κ° λ§λ€μ.
μλ¬΄νΌ μλμ μΆκ° μ€μ μ ν΄μ€μλ€!
컀λμ μ§μ λΉλνλ κ²½μ°μ λλ²κΉ
μ΄ κ°λ₯νκ² νλ €λ©΄ λ€μ μ΅μ
μ μ ννλ©΄ λ©λλ€.
Kernel Hacking
->Compile the kernel with frame pointers - Enable
->Show command line arguments on the host in TT mode - Disable
λ 리λ
μ€ μ»€λμ lock μ λλ²κΉ
νκΈ° μν΄μ μ€μ ν μ μλ λΆλΆμ΄ μμ΅λλ€.
config & compile +Ξ±
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
|
# make default config
sudo apt install -y libncurses-dev
make menuconfig
.config - Linux/x86 5.10.18 Kernel Configuration
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ Linux/x86 5.10.18 Kernel Configuration βββββββββββββββββββ
β Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty β
β submenus ----). Highlighted letters are hotkeys. Pressing <Y> includes, β
β <N> excludes, <M> modularizes features. Press <Esc><Esc> to exit, <?> β
β for Help, </> for Search. Legend: [*] built-in [ ] excluded <M> module β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β General setup ---> β β
β β [*] 64-bit kernel β β
β β Processor type and features ---> β β
β β Power management and ACPI options ---> β β
β β Bus options (PCI etc.) ---> β β
β β Binary Emulations ---> β β
β β Firmware Drivers ---> β β
β β [*] Virtualization (NEW) ---> β β
β β General architecture-dependent options ---> β β
β β [*] Enable loadable module support ---> β β
β β -*- Enable the block layer ---> β β
β β IO Schedulers ---> β β
β β Executable file formats ---> β β
β β Memory Management options ---> β β
β β [*] Networking support ---> β β
β β Device Drivers ---> β β
β β File systems ---> β β
β β Security options ---> β β
β β -*- Cryptographic API ---> β β
β β Library routines ---> β β
β β Kernel hacking ---> β β
β β β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β <Select> < Exit > < Help > < Save > < Load > β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# μλμ νλͺ©λ€ μ€ ν΄νΉμ μν΄μ νμν νλͺ©μ μ ννμ
# TODO: κ° νλͺ©μ΄ μ΄λ€ κΈ°λ₯μ νλμ§ κ΅¬μ²΄μ μΌλ‘ μ‘°μ¬κ° νμν¨
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β printk and dmesg options ---> β β
β β Compile-time checks and compiler options ---> β β
β β Generic Kernel Debugging Instruments ---> β β
β β [*] Kernel debugging β β
β β [*] Miscellaneous debug code β β
β β Memory Debugging ---> β β
β β [ ] Debug shared IRQ handlers β β
β β Debug Oops, Lockups and Hangs ---> β β
β β Scheduler Debugging ---> β β
β β [ ] Enable extra timekeeping sanity checking β β
β β Lock Debugging (spinlocks, mutexes, etc...) ---> β β
β β -*- Stack backtrace support β β
β β [ ] Warn for all uses of unseeded randomness β β
β β [ ] kobject debugging β β
β β Debug kernel data structures ---> β β
β β [ ] Debug credential management β β
β β RCU Debugging ---> β β
β β [ ] Force round-robin CPU selection for unbound work items β β
β β [ ] Force extended block device numbers and spread them β β
β β [ ] Latency measuring infrastructure β β
β β [*] Tracers ---> β β
β β [ ] Sample kernel code ---- β β
β β [*] Filter access to /dev/mem (NEW) β β
β β [ ] Filter I/O access to /dev/mem (NEW) β β
β β x86 Debugging ---> β β
β β Kernel Testing and Coverage ---> β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
config & compile 2
1
2
|
# make user mode linux
make -j8 linux
|
λ£¨νΈ νμΌμμ€ν
μ λ§μ΄νΈ ν©λλ€.
μ λ λ³΄ν΅ μμ€ λλ ν 리μ ν΄λμ΅λλ€.
root file system mount
1
2
3
4
|
sudo apt -y install supermin
supermin -v --prepare bash coreutils -o $PWD/rootfs.template
supermin -v --build --format chroot rootfs.template -o $PWD/rootfs
|
λ§μ§λ§μΌλ‘ λ§μ΄νΈν κ²½λ‘μ μ€ν¬λ¦½νΈλ₯Ό μμ±νκ³ ,
rootfs/boot/boot.sh
1
2
3
4
|
#!/bin/bash
mount -t sysfs /sys /sys
mount -t proc /proc /proc
exec /bin/bash
|
μ€νκΆνμ λ³κ²½νλ©΄ μ§λ£¨ν μ€μ μ λλ¬μ΅λλ€!
chmod
1
|
chmod +x rootfs/boot/boot.sh
|
μ μ΄μ user mode linux λ₯Ό μ€ννκ³ μ¦κ²¨λ΄
λλ€.
Have a lot of fun
1
|
./linux rootfstype=hostfs rootflags=$PWD/rootfs rw init=/boot/boot.sh
|
λ€μμλ 컀λ μμ€λ₯Ό Hack ν λ€μ GDB TUI λͺ¨λμμ λλ²κΉ
νλ κ³Όμ μ μ΄ν΄λ΄
λλ€.