๋ฆฌ๋ ์ค ์ํคํ ์ฒ ํ์ธ ๋ช ๋ น์ด
uname -a
syscall ํ ์ด๋ธ
https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#x86_64-64_bit
Chromium OS Docs - Linux System Call Table
Linux System Call Table These are the system call numbers (NR) and their corresponding symbolic names. These vary significantly across architectures/ABIs, both in mappings and in actual name. This is a quick reference for people debugging things (e.g. secc
chromium.googlesource.com
์์ 1. Hello world! ํ๋ฉด ์ถ๋ ฅ(write syscall ์ฌ์ฉ)
section .data
txt db "Hello world!"
section .text
global _start
_start:
mov rax, 0x01 ; write(syscall)
mov rdi, 0x01 ; stdout
mov rsi, txt ; buf
mov rdx, 0xC ; buf size
syscall ; syscall
nasm -f elf64 hello.asm
ld -o hello hello.o
./hello
์์ 2. /tmp/flag ํ์ผ ์ด๊ณ (open), ์ฝ๊ณ (read), ์ถ๋ ฅ(write)
section .data
path db "/tmp/flag"
section .text
global _start
_start:
; open
mov rax, 0x02 ; open(2)
mov rdi, path ; /tmp/flag
xor rsi, rsi ; 0(O_RDONLY)
xor rdx, rdx
syscall ; ์์คํ
์ฝ
; read
mov rdi, rax ; fd(File Descriptor)
mov rsi, rsp ; buf
sub rsi, 0x50 ; 0x50๋งํผ ๊ณต๊ฐ ํ ๋น
mov rdx, 0x50 ; 0x50๋งํผ ์ฝ์ด์จ๋ค.
xor rax, rax ; read(0)
syscall ; ์์คํ
์ฝ
; write
mov rdi, 1 ; fd = stdout
mov rax, 0x01 ; write(1)
syscall ; ์์คํ
์ฝ
nasm -f elf64 orw.asm
ld -o orw orw.o
./orw
.text ์น์ ์ถ์ถํ๊ธฐ
$ objcopy --dump-section .text=write.bin write.o
$ xxd write.bin
00000000: 48b8 6865 6c6c 6f0a 0000 5048 89e6 6a01 H.hello...PH..j.
00000010: 5f6a 065a 6a01 580f 05 _j.Zj.X..
์ฐธ๊ณ :
์ด์ ๋ธ๋ฆฌ์ด๋ก Hello world ์ถ๋ ฅํ๊ณ ๋๋ฒ๊น ํด๋ณด๊ธฐ
์นผ๋ฆฌ๋ฆฌ๋ ์ค ํฐ๋ฏธ๋์ฐฝ์ ๋์ด ํ nano helloworld.s ๋ฅผ ์ ๋ ฅํด์ค๋๋ค. s๋ ์ด์ ๋ธ๋ฆฌ ์ฝ๋ํ์ผ์ ์๋ฏธํฉ๋๋ค. ์ ๋ ฅํ ํ section .data msg db "hello word" section .text global_start _start: mov rax, 1//mov๋ฅผ ํตํด rax์ 1๊ฐ
ye0ye0.tistory.com
https://learn.dreamhack.io/50#6
๋ก๊ทธ์ธ | Dreamhack
dreamhack.io