์์ฑ 2026. 6. 12.ยท์์ 2026. 6. 12.
- ์ด 16๋ฌธํญ, 100์ ๋ง์
- 2024.12.11.
- ์ํํธ์จ์ด์ ์ ์ฌ์ ๋ณด์ ์ทจ์ฝ์ ์ ๋ฐ๊ฒฌํ๊ธฐ ์ํด ๋ฌด์์์ ์ ํจํ์ง ์๊ฑฐ๋ ๊ธฐํ์ ๋ฐ์ดํฐ๋ฅผ ์
๋ ฅ๊ฐ์ผ๋ก ์ฃผ์
ํ์ฌ ์ถฉ๋/์ค์๋์ ๋ชจ๋ํฐ๋งํ๋ ํ
์คํ
๊ธฐ๋ฒ
- ๊ณต๊ฒฉ์๊ฐ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์๋ฅผ ์์ธกํ๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด stack, heap ๋ฑ ์ฃผ์ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ ๋ฉ๋ชจ๋ฆฌ ์์น๋ฅผ ๋ฌด์์๋ก ์ฌ๋ฐฐ์นํ๋ ๊ธฐ๋ฒ
- ๋ฉ๋ชจ๋ฆฌ ํ์ด์ง๊ฐ write ๊ถํ๊ณผ execute ๊ถํ์ ๋์์ ๊ฐ์ง ์ ์๋๋ก ๊ฐ์ ํ๋ ๋ณด์ ์ ์ฑ
- (1) Process is a program in execution. (O)
- (2) Single-threaded process has only one program counter. (O)
- (3) Multi-threaded process has one program counter per thread. (O)
- (4)
A process has its own physical memory space. (X)
- (1) The static analysis method analyzes executable files without execution. (O)
- (2) The dynamic analysis method analyzes malware by executing the malware in a controlled enviornment. (O)
- (3) The static analysis method cannot analyze malware that applied with the packing techniques. (O)
- (4)
The dynamic analysis method cannot analyze malware with an encrypted code section. (X) - (5) The dynamic analysis method can analyze only a part of a code section. (O)
free(NULL)- ์๋ฌด๋ฐ ๋์๋ ์ํํ์ง ์์. (safe)
malloc(0)- ๊ตฌํ์ ๋ฐ๋ผ
NULL ๋๋ free ๊ฐ๋ฅํ ๊ณ ์ pointer ๋ฐํ
realloc(p, 0) (Suppose p is not a null pointer.) p๊ฐ ๊ฐ๋ฆฌํค๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํด์ (free(p)์ ๋์ผํ ํจ๊ณผ)
int *pn = new int;
if (pn) { ... }
else { ... }
- ํ์ค C++์์
new๋ ์คํจ ์ NULL ๋ฐํ ๋์ exception์ ๋ฐ์์ํค๋ฏ๋ก, if ๊ฒ์ฌ๋ ๋ฌด์๋ฏธํ๊ฑฐ๋ ํญ์ true
printf("%08x %08x");- ์ธ์๊ฐ ๋ถ์กฑํ๋ฏ๋ก stack ์์์ ์์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด 16์ง์๋ก ์ถ๋ ฅ (Information leak)
- DLL Injection: ํ๊ฒ process๊ฐ ์
์ฑ dll ํ์ผ์ ๊ฐ์ ๋ก loadํ๊ฒ ํ์ฌ, ํด๋น process์ memory space์ ๊ถํ ๋ด์์ ์ฝ๋๋ฅผ ์คํํ๋ ๊ธฐ๋ฒ
- Process Injection: ํ๊ฒ process์ memory space์ ์ง์ ์
์ฑ ์ฝ๋๋ฅผ ์ฝ์
(write)ํ๊ณ ์คํ ํ๋ฆ์ ์กฐ์ํ์ฌ ์ด๋ฅผ ์คํ์ํค๋ ๊ณต๊ฒฉ
- ์คํ ํ์ผ์ ์ฝ๋๋ฅผ ์์ถํ๊ฑฐ๋ ๋๋
ํ(Obfuscation)ํ์ฌ ๋ถ์๊ฐ๊ฐ ๋ด๋ถ ๋ก์ง์ ํ์
ํ๊ธฐ ์ด๋ ต๊ฒ ๋ง๋ค๊ณ , ์ ์ ๋ถ์์ ๋ฐฉํดํ๋ ๊ธฐ์
- Entropy: ์น์
์ ์ํธ๋กํผ๊ฐ ๋งค์ฐ ๋๊ฒ ์ธก์ ๋จ (์์ถ/์ํธํ๋ ๋ฐ์ดํฐ์ ํน์ฑ)
- Size Mismatch:
VirtualSize (๋ฉ๋ชจ๋ฆฌ์ ๋ก๋๋ ํฌ๊ธฐ)๊ฐ RawSize (ํ์ผ ์์ ํฌ๊ธฐ)๋ณด๋ค ํ์ ํ ํผ. - Section Name: ํ์ค์ ์ด์ง ์์ ์น์
์ด๋ฆ(UPX1 ๋ฑ) ์กด์ฌ
- Themida packer technology Code Virtualization์ ์ฌ์ฉ. ์๋ณธ ์ฝ๋๋ฅผ ์์ฒด์ ์ธ ๊ฐ์ CPU(VM)๊ฐ ํด์ํ ์ ์๋ ๋
์์ ์ธ bytecode๋ก ๋ณํํ์ฌ ์คํํ๊ณ , ๊ฐ๋ ฅํ anti-debugging ๋ฐ anti-tampering ๊ธฐ๋ฅ์ ํฌํจํจ.
- File System Type(
squashfs, cramfs, jffs2 ๋ฑ) ์๋ณ ๋ฐ ๊ตฌ์กฐ ๋ถ์ - Configuration Files: ํ๋์ฝ๋ฉ๋ ํจ์ค์๋, ์ํธํ ํค, ๋คํธ์ํฌ ์ค์ ์ ๋ณด
- Kernal & Bootloader: ๋ถํ
์ํ์ค ๋ฐ ์ปค๋ ์ค์ ๋ถ์
- Application Binaries: ์น ์๋ฒ, ๋ฐ๋ชฌ ๋ฑ ์คํ ํ์ผ์ ์ทจ์ฝ์ ๋ถ์
free๋ ์๋ฉธ์(Destructor)๋ ์์ธ ์ฒ๋ฆฌ ๊ณผ์ (Stack Unwinding) ์ค์ ํธ์ถ๋ ์ ์์. ๋ง์ฝ ์ด๋ ๋ ๋ค๋ฅธ ์์ธ๊ฐ ๋ฐ์ํ๋ฉด(Double fault), ๋ฐํ์์ด ์ด๋ฅผ ์ฒ๋ฆฌํ์ง ๋ชปํ๊ณ ํ๋ก๊ทธ๋จ์ ์ฆ์ ๊ฐ์ ์ข
๋ฃ(std::terminate)์ํค๊ธฐ ๋๋ฌธ
- Dynamic linking ๊ณผ์ ์์ ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํจ์(
printf ๊ฐ์)์ ์ค์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์๋ฅผ ์ ์ฅํ๋ ํ
์ด๋ธ. ํจ์ ํธ์ถ ์ PLT(Procedure Linkage Table)๋ฅผ ๊ฑฐ์ณ GOT์ ์ ์ฅ๋ ์ฃผ์๋ก ์ ํํจ. - Attack: GOT Overwrite. ๊ณต๊ฒฉ์๊ฐ GOT์ ์ ์ฅ๋ ์ ์ ํจ์(
printf)์ ์ฃผ์๋ฅผ ์
์ฑ ์ฝ๋๋ ๊ณต๊ฒฉ ํจ์(system)์ ์ฃผ์๋ก ๋ฎ์ด์. ์ดํ ํด๋น ํจ์ ํธ์ถ ์ ๊ณต๊ฒฉ์๊ฐ ์๋ํ ์ฝ๋๊ฐ ์คํ๋จ.
- ์ ์: ๊ด๋ฆฌ์ ๊ถํ(root)์ ํ๋/์ ์งํ๊ณ , ์์คํ
๋ด์์ ์์ ์ ์กด์ฌ๋ฅผ ์จ๊ธฐ๊ธฐ ์ํด ์ค๊ณ๋ ์
์ฑ ์ํํธ์จ์ด ๋ชจ๋
- Hiding Activity
- Kernal Object Manipulation (DKOM): ํ๋ก์ธ์ค ๋ฆฌ์คํธ ๋ฑ ์ปค๋ ๊ตฌ์กฐ์ฒด๋ฅผ ์ง์ ์กฐ์ํ์ฌ ์์ ์ ๋ฆฌ์คํธ์์ ์ ๊ฑฐ
- API Hooking: ํ์ผ ํ์์ด๋ ํ๋ก์ธ์ค ์กฐํ ์์คํ
์ฝ์ ๊ฐ๋ก์ฑ์ด ์์ ์ ํ์ผ์ด๋ ํ๋ก์ธ์ค ์ ๋ณด๋ฅผ ๊ฒฐ๊ณผ์์ ๋๋ฝ์ํด.
High Address
โโโโโโโโโโโโโโโโ
โReturn Addressโ
โโโโโโโโโโโโโโโโค
โ SFP โ
โโโโโโโโโโโโโโโโค
โ Canary โโโผโStack Guard
โโโโโโโโโโโโโโโโค (Check for modification)
โ Local Buffer โ
โโโโโโโโโโโโโโโโ
Low Address
- Structure: Local variable(buffer)์ SFP(Saved Frame Pointer) ์ฌ์ด์ Canary(Random variable)๋ฅผ ์ฝ์
- Mechanism: ํจ์ ์ข
๋ฃ(return) ์ง์ ์ canary๊ฐ์ด ๋ณ์กฐ๋์๋์ง ๊ฒ์ฌ
- Buffer overflow๋ก ์ธํด ๊ฐ์ด ๋ฐ๋์๋ค๋ฉด ๊ณต๊ฒฉ์ผ๋ก ๊ฐ์ฃผํ๊ณ ํ๋ก๊ทธ๋จ ์คํ ์ค๋จ
- Method: ๋ฉ๋ชจ๋ฆฌ์ ์ด๋ฏธ ๋ก๋๋ ์ฝ๋ ์ค
ret(return) ๋ช
๋ น์ด๋ก ๋๋๋ ์์ ์ฝ๋ ์กฐ๊ฐ(Sequence)๋ค์ ์ฒด์ธ์ฒ๋ผ gadget์ผ๋ก ์ฐ๊ฒฐํ์ฌ ๊ณต๊ฒฉ์๊ฐ ์ํ๋ ๋์์ ์ํํ๊ฒ ํ๋ ๊ธฐ๋ฒ. (Stack์ gadget๋ค์ ์ฃผ์๋ฅผ ์ฐ์์ผ๋ก ๋ฐฐ์นํ์ฌ ret ์คํ ์ ๋ค์ gadget์ผ๋ก ์ด๋) libc usage: libc ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ํ๋ก๊ทธ๋จ ์คํ ์ ๋ฉ๋ชจ๋ฆฌ์ ๋ก๋๋๋ฉฐ, ๋งค์ฐ ๋ฐฉ๋ํ ์ฝ๋๋ฅผ ํฌํจํ๊ณ ์์. ๊ณต๊ฒฉ์๋ libc ๋ด๋ถ์ ๋ค์ํ ๊ธฐ๊ณ์ด ์ฝ๋ ์กฐ๊ฐ(gadget)๋ค์ ์กฐํฉํ์ฌ ๊ฑฐ์ ๋ชจ๋ ๋ก์ง(Turing complete)์ ๊ตฌ์ฑํ ์ ์์ด, NX bit(์คํ ๋ฐฉ์ง) ๋ณดํธ ๊ธฐ๋ฒ์ ์ฐํํ๋๋ฐ ์ฌ์ฉ๋จ.
- ๋ถ์ฐ๋ ๋ค์์ ์ข๋น PC(Botnet)์ ์ด์ฉํด ํน์ ๋์์๊ฒ ๋์์ ๋ง๋ํ ์์ ํธ๋ํฝ์ ์ ์กํ์ฌ, ์์คํ
์์์ ๊ณ ๊ฐ์ํค๊ณ ์ ์์ ์ธ ์๋น์ค๋ฅผ ๋ถ๊ฐ๋ฅํ๊ฒ ๋ง๋๋ ๊ณต๊ฒฉ
- ๊ณต๊ฒฉ์๊ฐ spoofed IP๋ก ๋๋์
SYN ํจํท๋ง ์ ์กํ๊ณ , ์๋ฒ์ SYN-ACK ์๋ต์ ๋ํด ACK๋ฅผ ๋ณด๋ด์ง ์์. ์๋ฒ๋ ์ฐ๊ฒฐ์ ๋งบ๊ธฐ ์ํด half-open ์ํ๋ก ๋๊ธฐํ๋ฉฐ backlog queue๋ฅผ ๊ฐ๋ ์ฑ์ฐ๊ฒ ๋์ด, ๋ ์ด์ ์๋ก์ด ์ ์ ์ฐ๊ฒฐ์ ์๋ฝํ ์ ์๊ฒ ๋จ.
- SYN Cookies:
SYN ์์ฒญ ์ ์๋ฒ์ ์์(queue)๋ฅผ ํ ๋นํ์ง ์๊ณ , ์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ์ํธํํ์ฌ sequence number(cookie)๋ก ํด๋ผ์ด์ธํธ์ ์ ์ก. ๋์ค์ ํด๋ผ์ด์ธํธ๊ฐ ์ฌ๋ฐ๋ฅธ ACK๋ฅผ ๋ณด๋ผ ๋๋ง ์์ ํ ๋น - Time-out ๊ฐ์: Half-open ์ํ์ ๋๊ธฐ ์๊ฐ์ ์ค์ฌ ์์์ ๋น ๋ฅด๊ฒ ํ์
wchar_twide_str1[] = L"0123456789";
wchar_t*wide_str2 = (wchar_t*) malloc(strlen(wide_str1) + 1);
if (wide_str2 == NULL) {
}
strcpy(wide_str2, wide_str1);
free(wide_str2); wide_str2 = NULL;
wchar_t (Wide Character) ์ฌ์ฉ๊ณผ ๊ด๋ จ๋ ๋ฌธ๋ฒ ๋ฐ ๋ฉ๋ชจ๋ฆฌ ํ ๋น ์ค๋ฅ์
๋๋ค.- Line 1 (Syntax Error):
wchar_twide_str1 โ wchar_t wide_str1 (์๋ฃํ๊ณผ ๋ณ์๋ช
์ฌ์ด ๊ณต๋ฐฑ ๋๋ฝ)
- Line 2 (Semantic Error):
strlen์ char ๋จ์ ๊ธธ์ด๋ง ๋ฐํํ๋ฉฐ, malloc์ ๋ฐ์ดํธ ๋จ์ ํฌ๊ธฐ๋ฅผ ์๊ตฌํฉ๋๋ค. wchar_t ๋ฌธ์์ด ๊ธธ์ด ํจ์(wcslen)๋ฅผ ์ฌ์ฉํ๊ณ sizeof(wchar_t)๋ฅผ ๊ณฑํด์ผ ํฉ๋๋ค.- ์์ :
(wchar_t*) malloc((wcslen(wide_str1) + 1) - sizeof(wchar_t));
- Line 6 (Semantic Error):
strcpy๋ char* ์ ์ฉ ํจ์์
๋๋ค. wchar_t* ์ ์ฉ ๋ณต์ฌ ํจ์๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.- ์์ :
wcscpy(wide_str2, wide_str1);
char dst[16];
char src[] = "0123456789";
strncpy(dst, src, sizeof(dst));
- Safe. but inefficient
src์ ๊ธธ์ด(10)๊ฐ dst์ ํฌ๊ธฐ(16)๋ณด๋ค ์์ต๋๋ค. strncpy๋ ๋จ์ ๊ณต๊ฐ์ ๋ชจ๋ NULL๋ก ์ฑ์ฐ๋ฏ๋ก(Zero-padding), ์์ ํ๊ฒ Null-terminated๋์ง๋ง ๋ถํ์ํ ์ฐ์ฐ์ด ๋ฐ์ํฉ๋๋ค.
char dst[6];
char src[] = "0123456789";
strncpy(dst, src, sizeof(dst));
- Dangerous - No Null Termination
src์ ๊ธธ์ด(10)๊ฐ dst์ ํฌ๊ธฐ(6)๋ณด๋ค ํฝ๋๋ค. strncpy๋ ์ ํํ 6๋ฐ์ดํธ๋ง ๋ณต์ฌํ๊ณ ๋ฉ์ถ๊ธฐ ๋๋ฌธ์, dst ๋ง์ง๋ง์ NULL ๋ฌธ์(\0)๊ฐ ์ฝ์
๋์ง ์์ต๋๋ค.- ์ดํ
dst๋ฅผ ๋ฌธ์์ด๋ก ์ฌ์ฉํ๋ ค ํ ๋(์: printf, strcpy ๋ฑ) ๋ฉ๋ชจ๋ฆฌ ๊ฒฝ๊ณ๋ฅผ ๋์ด ์ฝ๋ Buffer Over-read๊ฐ ๋ฐ์ํฉ๋๋ค.
char outbuf[512];
char buffer[512];
sprintf(buffer, "ERR Wrong command: %.400s", user);
sprintf(outbuf, buffer);
- Format specifier์ Precision(์ ๋ฐ๋) ์ ํ์
%.400s๋ฅผ ์ฌ์ฉํ์ฌ, user ์
๋ ฅ๊ฐ ์ค ์ต๋ 400๋ฌธ์๊น์ง๋ง ์ฝ์ด์ค๋๋ก ์ ํํ๊ธฐ ๋๋ฌธ์ buffer(512 bytes) ๋์นจ์ ๋ฐฉ์งํ์ต๋๋ค.
- ๊ฐ๋ฅํฉ๋๋ค.
- Line 4์
sprintf(outbuf, buffer);์์ buffer ์์ฒด๊ฐ Format String์ผ๋ก ์ฌ์ฉ๋๊ณ ์์ต๋๋ค (Format String Vulnerability). - ์์
- ๊ณต๊ฒฉ์๊ฐ
user ์
๋ ฅ๊ฐ์ผ๋ก "%520d"์ ๊ฐ์ ๋ฌธ์์ด์ ๋ฃ์ผ๋ฉด, buffer์๋ "ERR ... %520d"๊ฐ ์ ์ฅ๋ฉ๋๋ค. Line 4 ์คํ ์ sprintf๋ ์ด๋ฅผ ํด์ํ์ฌ stack์ ๊ฐ์ ์ฝ์ด 520์๋ฆฌ ์ซ์๋ก ๋ณํํด outbuf์ ์ฐ๋ ค๊ณ ์๋ํฉ๋๋ค. ์ด๋ outbuf ํฌ๊ธฐ(512 bytes)๋ฅผ ์ด๊ณผํ์ฌ buffer overflow๊ฐ ๋ฐ์ํฉ๋๋ค.