shellcode๋, ์ทจ์ฝํ ํ๋ก๊ทธ๋จ์ ๋ํ์ฌ ๊ณต๊ฒฉ์๊ฐ ์คํ์ํค๊ณ ์ ํ๋ ์ฝ๋์๋ค.
ํํ ์(shell)์ ์คํ์ํค๊ธฐ ๋๋ฌธ์ shellcode๋ผ๋ ์ด๋ฆ์ด ๋ถ์์ง์.
์ํฉ์๋ฐ๋ผ ์ฌ์ฉ๋๋ ์์ฝ๋์ ์ข ๋ฅ๋ ๊ต์ฅํ ๋ค์ํ๋ฐ,
๋งค๋ฒ ์ฐ๋ฆฌ๊ฐ ์ํ๋ ์์ฝ๋๋ฅผ ๊ตฌ๊ธ๋งํด์ ๋ถ์ฌ์ธ์๋ ์๊ฒ ์ฃ ?
๊ทธ๋์ ์ด๋ฒ ๊ธฐํ์ ์์ฝ๋ ์ ์์ ๊ดํ ์ ๋ฐ์ ์ธ ๊ณผ์ ๋ค์ ๊ฐ์ด ์์๋ณผ๊น ํฉ๋๋ค.
์ฒซ ์ฝ๋ฉ ๊ตญ๋ฃฐ, "์ธ์์๊ฒ ์ธ์ฌํ๊ธฐ"
์ฐ์ , ์ด๋ฒ์๊ฐ์๋ c์ธ์ด ํ๋ก๊ทธ๋จ์ ํจ์ ํธ์ถ๊ณผ์ ์ ๋ถ์ํด๋ณด๊ธฐ๊น์ง ํด๋ด ์๋ค.
๊น๋ํ๊ฒ ๋ถ์ํ๊ณ ์ ๋ณดํธ๊ธฐ๋ฒ๋ค์ ๋๊ฐ ๊บผ์ฃผ์์ต๋๋ค.
-fno-stack-protector
-no-pie
-fno-pic
๊ธ๊ณ ์ ์ ํ ๋น๊ณผ 32bit ์ปดํ์ผ ์ต์
-static
-m32
๊ฐ ๋ณดํธ๊ธฐ๋ฒ๋ค์ ์ธ์ธํ ์๋ ๊ณผ์ ์ ๋ฐ๋ก ํฌ์คํ ํด ๋๊ฒ ์ด๋ค.
์ฐ๋ฆฌ๊ฐ ์ฌ๊ธฐ์ ์ง์ค ๋ถ์ํด ๋ณผ ๊ณณ์ system call ๊น์ง์ ๋ถ๋ถ ์ ๋๋ค.
main + 29์ wirte ํจ์๋ ํธํ์ฑ, ํธ๋ฆฌ์ฑ์ ์ํ c์ธ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํจ์์ด๊ณ ,
ํด๋น ์ฝ๋ ์์ผ๋ก ๋ค์ด๊ฐ๋ณด๋ฉด kernal mode๋ก ์ง์ ํ๋ ๋ถ๋ถ
์ฆ, system call์ ํธ์ถํ๋ ๋ถ๋ถ์ด ์๋ต๋๋ค.
๋ฐ๋ก call dword ptr gs:0x10 <write + 32>
glibc-2.16.0/sysdeps/unix/sysv/linux/i386/sysdep.h:
/* The original calling convention for system calls on Linux/i386 is
to use int $0x80. */
#ifdef I386_USE_SYSENTER
# ifdef SHARED
# define ENTER_KERNEL call *%gs:SYSINFO_OFFSET
# else
# define ENTER_KERNEL call *_dl_sysinfo
# endif
#else
# define ENTER_KERNEL int $0x80
#endif
sysenter ๋ฐฉ์์ ๊ดํ ์์ธํ ์์ธํ ์ค๋ช ์ ์ด๊ณณ์ ์ฐธ๊ณ ํ์๊ธธ ๋ฐ๋ผ๊ฒ ์ต๋๋ค.
https://stackoverflow.com/questions/34741378/confusion-with-system-call
system call ํธ์ถ ์ , ์ธ์๋ค์ ์ด๋ ํ ๋ฐฉ์์ผ๋ก ์ ๋ฌํ ๊น์?
์ง์ ์ break point๋ฅผ ๊ฑธ๊ณ ๋ ์ง์คํฐ์ ์ํ๋ฅผ ํ์ธํด๋ด ์๋ค.
์๋ ๋งํฌ์ syscall reference ๋๋ก, ๋ค์๊ณผ๊ฐ์ด ์ธ์๋ฅผ ๋๊ฒจ์ฃผ๋ ๋ชจ์ต์ ๋๋ค.
eax | ebx | ecx | edx |
0x4 | 0x1 | 'hello world'์ ์ฃผ์ | 0xd |
eds000n.github.io/syscalls-x86.html
eax : system call ๋ฒํธ (4 → write)
ebx : fd (1 → stdout)
ecx : *buf
edx : count (0xd → ๋ฌธ์์ด์ ๊ธธ์ด)
๊ทธ๋ ๋ค๋ฉด ์ด ๋ถ๋ถ๋ง ๋ฐ๋ก ์ด์ ๋ธ๋ฆฌ์ด๋ก ๋ง๋ ๋ค๋ฉด?
to be continued..
'system hacking ๐ฑ > shellocde' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
shellcode (0x2f ์์ ๊ธฐ) (0) | 2020.12.19 |
---|---|
shellcode (4) (0) | 2020.12.19 |
shellcode (3) (0) | 2020.12.18 |
shellcode (2) (0) | 2020.12.18 |